fix the issue on github #157.

directly force_encoding is wrong,
must detect the file string's encoding.
then force_encoding the string to it's encoding.
last convert it to utf-8.
This commit is contained in:
Saito 2011-11-28 17:46:41 +08:00
parent 75fa0632e6
commit 46cbe54189
5 changed files with 23 additions and 8 deletions

View file

@ -16,9 +16,20 @@ module Utils
end
end
module CharEncode
def encode(string)
cd = CharDet.detect(string)
if cd.confidence > 0.6
string.force_encoding(cd.encoding)
end
string.encode("utf-8", :undef => :replace, :replace => "?", :invalid => :replace)
end
end
module Colorize
include CharEncode
def colorize
system_colorize(data, name)
system_colorize(encode(data), name)
end
def system_colorize(data, file_name)