42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/new_relic/agent/encoding_normalizer.rb', line 42
def self.normalize(raw_string)
encoding = raw_string.encoding
if (encoding == Encoding::UTF_8 || encoding == Encoding::ISO_8859_1) && raw_string.valid_encoding?
return raw_string
end
normalized = raw_string.dup
if encoding == Encoding::ASCII_8BIT || !raw_string.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
|