Welcome to mirror list, hosted at ThFree Co, Russian Federation.

encode.rb « gitlabhq « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: df40206d5eb5bf2b3192b58570e35d4cad361725 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module Gitlabhq
  module Encode 
    extend self

    def utf8 message
      return nil unless message

      hash = CharlockHolmes::EncodingDetector.detect(message) rescue {}
      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
      ""
    end
  end
end