lib/textmagic/charset.rb in textmagic-0.6.0 vs lib/textmagic/charset.rb in textmagic-0.7.0

- old
+ new

@@ -1,30 +1,35 @@ -# encoding: utf-8 - module TextMagic class API module Charset - GSM_CHARSET = "@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\e\f^{}\\[~]|€ÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà".scan(/./u) - ESCAPED_CHARS = "{}\\~[]|€" + GSM_CHARSET = + "@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\e\f^{}\\[~]|€ÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>?¡"\ + "ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà".scan(/./u).freeze + ESCAPED_CHARS = "{}\\~[]|€".freeze # Returns +true+ if the supplied text contains only characters from # GSM 03.38 charset, otherwise it returns +false+. - def is_gsm(text) + def gsm?(text) text.scan(/./u).each { |c| return false unless GSM_CHARSET.include?(c) } true end + alias is_gsm gsm? # Returns +true+ if the supplied text contains characters outside of # GSM 03.38 charset, otherwise it returns +false+. - def is_unicode(text) + def unicode?(text) !is_gsm(text) end + alias is_unicode unicode? def real_length(text, unicode) text.size + (unicode ? 0 : text.scan(/[\{\}\\~\[\]\|€]/).size) end + end + end + end