lib/charset.rb in bobes-textmagic-0.3.1 vs lib/charset.rb in bobes-textmagic-0.3.2

- old
+ new

@@ -3,10 +3,11 @@ 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) } @@ -15,9 +16,13 @@ # 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