2012-05-26 12:37:49 +02:00
|
|
|
module Gitlab
|
2012-04-11 22:03:56 +02:00
|
|
|
module Encode
|
|
|
|
extend self
|
|
|
|
|
|
|
|
def utf8 message
|
2012-05-21 22:17:41 +02:00
|
|
|
return nil unless message
|
|
|
|
|
2012-04-24 12:41:20 +02:00
|
|
|
hash = CharlockHolmes::EncodingDetector.detect(message) rescue {}
|
2012-04-11 22:03:56 +02:00
|
|
|
if hash[:encoding]
|
|
|
|
CharlockHolmes::Converter.convert(message, hash[:encoding], 'UTF-8')
|
|
|
|
else
|
|
|
|
message
|
|
|
|
end.force_encoding("utf-8")
|
2012-05-22 13:57:04 +02:00
|
|
|
# Prevent app from crash cause of
|
|
|
|
# encoding errors
|
|
|
|
rescue
|
|
|
|
""
|
2012-04-11 22:03:56 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|