diff options
Diffstat (limited to 'lib/utils.rb')
-rw-r--r-- | lib/utils.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/utils.rb b/lib/utils.rb index f43e2edd207..23f05f6f919 100644 --- a/lib/utils.rb +++ b/lib/utils.rb @@ -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) |