Module: StringTools::CharDet

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

Constant Summary collapse

CP1251_COMPATIBLE_ENCODINGS =
%w(windows-1253 windows-1254 windows-1255 windows-1256 windows-1258 EUC-TW ISO-8859-8).freeze

Instance Method Summary collapse

Instance Method Details

#detect_encoding(str) ⇒ Object

shorthand



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

def detect_encoding(str)
  str.detect_encoding
end

#to_cp1251(str) ⇒ Object



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

def to_cp1251(str)
  str.to_cp1251
end

#to_utf8(str) ⇒ Object

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



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

def to_utf8(str)
  str.to_utf8
end

#valid_utf8?(string) ⇒ Boolean

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

Returns:

  • (Boolean)


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

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