Module: StringTools::CharDet

Included in:
StringTools
Defined in:
lib/string_tools.rb

Instance Method Summary collapse

Instance Method Details

#cp1251_compatible_encodingsObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/string_tools.rb', line 36

def cp1251_compatible_encodings
  [
    'windows-1253',
    'windows-1254',
    'windows-1255',
    'windows-1256',
    'windows-1258',
    'EUC-TW',
    'ISO-8859-8'
  ]
end

#detect_encoding(str) ⇒ Object

shorthand



23
24
25
# File 'lib/string_tools.rb', line 23

def detect_encoding(str)
  str.detect_encoding
end

#to_cp1251(str) ⇒ Object



32
33
34
# File 'lib/string_tools.rb', line 32

def to_cp1251(str)
  str.to_cp1251
end

#to_utf8(str) ⇒ Object

привести строку к utf8



28
29
30
# File 'lib/string_tools.rb', line 28

def to_utf8(str)
  str.to_utf8
end

#valid_utf8?(string) ⇒ Boolean

Возвращает true если строка содержит допустимую последовательность байтов для кодировки utf8 и false в обратном случае см. en.wikipedia.org/wiki/UTF-8

Returns:

  • (Boolean)


15
16
17
18
19
20
# File 'lib/string_tools.rb', line 15

def valid_utf8? string
  case string
  when String then string.is_utf8?
  else false
  end
end