Sha256: 856a2e1c165a5ebac9932d83ef7e102898218717b169cf8eeb5dbcc3c18659ed

Contents?: true

Size: 1.39 KB

Versions: 4

Compression:

Stored size: 1.39 KB

Contents

module RunLoop
  module Encoding

    # Removes diacritic markers from string.
    #
    # The ruby Encoding tools cannot perform this action, they can only change
    # convert one encodign to another by substituting characters.
    #
    # In ruby 1.9.3 we would have used Iconv, but that does not exist in 2.0.
    #
    # The Encoding::Convert in 2.0 does not work on string with UTF-16 characters.
    def transliterate(string)
			require "i18n"
      locales = I18n.available_locales
      if !locales.include?(:en)
        I18n.available_locales = locales + [:en]
      end
      I18n.transliterate(string)
    end

    # Raised when a string cannot be coerced to UTF8
    class UTF8Error < RuntimeError; end

    # @!visibility private
    def ensure_command_output_utf8(string, command)
      return '' if !string

      utf8 = string.force_encoding("UTF-8").chomp

      return utf8 if utf8.valid_encoding?

      encoded = utf8.encode("UTF-8", "UTF-8",
                            invalid: :replace,
                            undef: :replace,
                            replace: "")

      return encoded if encoded.valid_encoding?

      raise UTF8Error, %Q{
Could not force UTF-8 encoding on this string:

#{string}

which is the output of this command:

#{command}

Please file an issue with a stacktrace and the text of this error.

https://github.com/calabash/run_loop/issues
      }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
run_loop_tcc-2.1.6 lib/run_loop/encoding.rb
run_loop_tcc-2.1.5 lib/run_loop/encoding.rb
run_loop_tcc-2.1.4 lib/run_loop/encoding.rb
run_loop_tcc-2.1.3 lib/run_loop/encoding.rb