Sha256: 76a431b58c8100d4615351c6811bbb4d1512210b775b012f903d0429c8ad3506

Contents?: true

Size: 514 Bytes

Versions: 20

Compression:

Stored size: 514 Bytes

Contents

module ICU
  class Util
    # Decide if a string is valid UTF-8 or not, returning true or false.
    def self.is_utf8(str)
      dup = str.dup
      dup.force_encoding("UTF-8")
      dup.valid_encoding?
    end
    
    # Try to convert any string to UTF-8.
    def self.to_utf8(str)
      utf8 = is_utf8(str)
      dup = str.dup
      return dup.force_encoding("UTF-8") if utf8
      dup.force_encoding("Windows-1252") if dup.encoding.name.match(/^(ASCII-8BIT|UTF-8)$/)
      dup.encode("UTF-8")
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
icu_name-1.0.10 lib/icu_name/util.rb
icu_name-1.0.9 lib/icu_name/util.rb
icu_name-1.0.8 lib/icu_name/util.rb
icu_name-1.0.7 lib/icu_name/util.rb
icu_name-1.0.6 lib/icu_name/util.rb
icu_name-1.0.5 lib/icu_name/util.rb
icu_name-1.0.4 lib/icu_name/util.rb
icu_name-1.0.3 lib/icu_name/util.rb
icu_name-1.0.2 lib/icu_name/util.rb
icu_name-1.0.1 lib/icu_name/util.rb
icu_name-1.0.0 lib/icu_name/util.rb
icu_name-0.1.4 lib/icu_name/util.rb
icu_name-0.1.3 lib/icu_name/util.rb
icu_name-0.1.2 lib/icu_name/util.rb
icu_name-0.1.1 lib/icu_name/util.rb
icu_name-0.1.0 lib/icu_name/util.rb
icu_name-0.0.7 lib/icu_name/util.rb
icu_name-0.0.6 lib/icu_name/util.rb
icu_name-0.0.5 lib/icu_name/util.rb
icu_name-0.0.4 lib/icu_name/util.rb