Sha256: 76a431b58c8100d4615351c6811bbb4d1512210b775b012f903d0429c8ad3506
Contents?: true
Size: 514 Bytes
Versions: 20
Compression:
Stored size: 514 Bytes
Contents
module ICU class Util # Decide if a string is valid UTF-8 or not, returning true or false. def self.is_utf8(str) dup = str.dup dup.force_encoding("UTF-8") dup.valid_encoding? end # Try to convert any string to UTF-8. def self.to_utf8(str) utf8 = is_utf8(str) dup = str.dup return dup.force_encoding("UTF-8") if utf8 dup.force_encoding("Windows-1252") if dup.encoding.name.match(/^(ASCII-8BIT|UTF-8)$/) dup.encode("UTF-8") end end end
Version data entries
20 entries across 20 versions & 1 rubygems