Sha256: 10bf9675352b8824b6e41727a81823d05879e896a301d9cad98fc164e8ecb071

Contents?: true

Size: 898 Bytes

Versions: 4

Compression:

Stored size: 898 Bytes

Contents

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

4 entries across 4 versions & 2 rubygems

Version Path
bobes-textmagic-0.3.2 lib/charset.rb
bobes-textmagic-0.3.3 lib/charset.rb
textmagic-0.3.2 lib/charset.rb
textmagic-0.3.3 lib/charset.rb