class TwitterCldr::Parsers::UnicodeRegexParser::Component

Protected Instance Methods

array_to_regex(arr) click to toggle source
# File lib/twitter_cldr/parsers/unicode_regex/component.rb, line 25
def array_to_regex(arr)
  arr.map { |elem| "(?:#{to_utf8(elem)})" }.join
end
range_to_regex(range) click to toggle source
# File lib/twitter_cldr/parsers/unicode_regex/component.rb, line 17
def range_to_regex(range)
  if range.first.is_a?(Array)
    array_to_regex(range)
  else
    "[#{to_utf8(range.first)}-#{to_utf8(range.last)}]"
  end
end
set_to_regex(set) click to toggle source
# File lib/twitter_cldr/parsers/unicode_regex/component.rb, line 29
def set_to_regex(set)
  strs = set.to_a(true).uniq.map do |obj|
    case obj
      when Range
        range_to_regex(obj)
      when Array
        array_to_regex(obj)
      else
        to_utf8(obj)
    end
  end

  "(?:#{strs.join("|")})"
end
to_utf8(codepoints) click to toggle source
# File lib/twitter_cldr/parsers/unicode_regex/component.rb, line 13
def to_utf8(codepoints)
  Array(codepoints).map { |cp| "\\u{#{cp.to_s(16).rjust(4, "0")}}"}.join
end