Revert "merge charlock_holmes to master"

This reverts commit a25a85b939.
This commit is contained in:
Saito 2011-12-30 18:30:57 +08:00
parent 5719f02f34
commit 7279e8c177
3 changed files with 11 additions and 9 deletions

View file

@ -17,13 +17,15 @@ module Utils
end
module CharEncode
def encode(content)
content ||= ''
detection = CharlockHolmes::EncodingDetector.detect(content)
if hash = detection
content = CharlockHolmes::Converter.convert(content, hash[:encoding], 'UTF-8') if hash[:encoding]
def encode(string)
return '' unless string
cd = CharDet.detect(string)
if cd.confidence > 0.6
string.force_encoding(cd.encoding)
end
content
string.encode("utf-8", :undef => :replace, :replace => "?", :invalid => :replace)
rescue
"Invalid Encoding"
end
end