gitlabhq/lib/gitlab/encode.rb

21 lines
436 B
Ruby
Raw Normal View History

module Gitlab
2012-04-11 22:03:56 +02:00
module Encode
extend self
def utf8 message
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")
# Prevent app from crash cause of
# encoding errors
rescue
""
2012-04-11 22:03:56 +02:00
end
end
end