class String

Public Instance Methods

codepoint_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 12
def codepoint_length
  if respond_to? :codepoints
    length
  else
    chars.kind_of?(Enumerable) ? chars.to_a.size : chars.size
  end
end
to_codepoint_a() click to toggle source

Helper function to convert this string into an array of unicode code points.

# File lib/twitter-text/extractor.rb, line 21
def to_codepoint_a
  @to_codepoint_a ||= if chars.kind_of?(Enumerable)
    chars.to_a
  else
    codepoint_array = []
    0.upto(codepoint_length - 1) { |i| codepoint_array << [chars.slice(i)].pack('U') }
    codepoint_array
  end
end