Sha256: 8a928ccb42270167e90384296dbdd21a067317a5430a01e7556c52ca7ee12813

Contents?: true

Size: 915 Bytes

Versions: 3

Compression:

Stored size: 915 Bytes

Contents

# encoding: utf-8

module TextMagic

  class API

    module Charset

      GSM_CHARSET = "@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\e\f^{}\\[~]|€ÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà".scan(/./u)
      ESCAPED_CHARS = "{}\\~[]|€"

      # Returns +true+ if the supplied text contains only characters from
      # GSM 03.38 charset, otherwise it returns +false+.
      def is_gsm(text)
        text.scan(/./u).each { |c| return false unless GSM_CHARSET.include?(c) }
        true
      end

      # Returns +true+ if the supplied text contains characters outside of
      # GSM 03.38 charset, otherwise it returns +false+.
      def is_unicode(text)
        !is_gsm(text)
      end

      def real_length(text, unicode)
        text.size + (unicode ? 0 : text.scan(/[\{\}\\~\[\]\|€]/).size)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
textmagic-0.6.0 lib/textmagic/charset.rb
textmagic-0.5.0 lib/textmagic/charset.rb
textmagic-0.4.0 lib/charset.rb