class String
Public Instance Methods
char_length()
click to toggle source
Helper function to count the character length by first converting to an array. This is needed because with unicode strings, the return value of length may be incorrect
# File lib/twitter-text/extractor.rb, line 6 def char_length if respond_to? :codepoints length else chars.kind_of?(Enumerable) ? chars.to_a.size : chars.size end end
to_char_a()
click to toggle source
Helper function to convert this string into an array of unicode characters.
# File lib/twitter-text/extractor.rb, line 15 def to_char_a @to_char_a ||= if chars.kind_of?(Enumerable) chars.to_a else char_array = [] 0.upto(char_length - 1) { |i| char_array << [chars.slice(i)].pack('U') } char_array end end