Module: TextMagic::API::Charset
- Included in:
- TextMagic::API
- Defined in:
- lib/textmagic/charset.rb
Constant Summary collapse
- GSM_CHARSET =
"@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\e\f^{}\\[~]|€ÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà".scan(/./u)
- ESCAPED_CHARS =
"{}\\~[]|€"
Instance Method Summary collapse
-
#is_gsm(text) ⇒ Object
Returns
trueif the supplied text contains only characters from GSM 03.38 charset, otherwise it returnsfalse. -
#is_unicode(text) ⇒ Object
Returns
trueif the supplied text contains characters outside of GSM 03.38 charset, otherwise it returnsfalse. - #real_length(text, unicode) ⇒ Object
Instance Method Details
#is_gsm(text) ⇒ Object
Returns true if the supplied text contains only characters from GSM 03.38 charset, otherwise it returns false.
14 15 16 17 |
# File 'lib/textmagic/charset.rb', line 14 def is_gsm(text) text.scan(/./u).each { |c| return false unless GSM_CHARSET.include?(c) } true end |
#is_unicode(text) ⇒ Object
Returns true if the supplied text contains characters outside of GSM 03.38 charset, otherwise it returns false.
21 22 23 |
# File 'lib/textmagic/charset.rb', line 21 def is_unicode(text) !is_gsm(text) end |
#real_length(text, unicode) ⇒ Object
25 26 27 |
# File 'lib/textmagic/charset.rb', line 25 def real_length(text, unicode) text.size + (unicode ? 0 : text.scan(/[\{\}\\~\[\]\|€]/).size) end |