48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/ting_yun/support/serialize/encoding_normalizer.rb', line 48
def self.normalize(str)
encoding = str.encoding
if (encoding == Encoding::UTF_8 || encoding == Encoding::ISO_8859_1) && str.valid_encoding?
return str
end
normalized = str.dup
if encoding == Encoding::ASCII_8BIT || !str.valid_encoding?
normalized.force_encoding(Encoding::ISO_8859_1)
else
begin
normalized.encode!(Encoding::UTF_8)
rescue
normalized.force_encoding(Encoding::ISO_8859_1)
end
end
normalized
end
|