Module: StringTools::CharDet

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

Instance Method Summary collapse

Instance Method Details

#cp1251_compatible_encodingsObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/string_tools.rb', line 33

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



20
21
22
# File 'lib/string_tools.rb', line 20

def detect_encoding(str)
  str.detect_encoding
end

#to_cp1251(str) ⇒ Object



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

def to_cp1251(str)
  str.to_cp1251
end

#to_utf8(str) ⇒ Object

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



25
26
27
# File 'lib/string_tools.rb', line 25

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
# File 'lib/string_tools.rb', line 15

def valid_utf8?(string)
  string.respond_to?(:is_utf8?) && string.is_utf8?
end