class TwitterCldr::Parsers::UnicodeRegexParser::Literal

Constants

SPECIAL_CHARACTERS

Attributes

text[R]

Public Class Methods

new(text) click to toggle source
# File lib/twitter_cldr/parsers/unicode_regex/literal.rb, line 33
def initialize(text)
  @text = text
end
ordinalize(char) click to toggle source

ord is good enough (don't need unpack) because ASCII chars have the same numbers as their unicode equivalents

# File lib/twitter_cldr/parsers/unicode_regex/literal.rb, line 15
def self.ordinalize(char)
  if char.respond_to?(:ord)
    char.ord
  else
    char[0]
  end
end

Public Instance Methods

to_regexp_str() click to toggle source
# File lib/twitter_cldr/parsers/unicode_regex/literal.rb, line 37
def to_regexp_str
  text
end
to_s() click to toggle source
# File lib/twitter_cldr/parsers/unicode_regex/literal.rb, line 59
def to_s
  text
end
to_set() click to toggle source
# File lib/twitter_cldr/parsers/unicode_regex/literal.rb, line 41
def to_set
  if text =~ /^\\/
    special_char = text[1..-1]

    if SPECIAL_CHARACTERS.include?(special_char.downcase)
      set_for_special_char(special_char)
    else
      TwitterCldr::Utils::RangeSet.from_array([
        self.class.ordinalize(special_char)
      ])
    end
  else
    TwitterCldr::Utils::RangeSet.from_array([
      self.class.ordinalize(text)
    ])
  end
end
type() click to toggle source
# File lib/twitter_cldr/parsers/unicode_regex/literal.rb, line 63
def type
  :literal
end

Private Instance Methods

set_for_special_char(char) click to toggle source
# File lib/twitter_cldr/parsers/unicode_regex/literal.rb, line 69
def set_for_special_char(char)
  special_char_set_cache[char] ||= begin
    chars = TwitterCldr::Utils::RangeSet.from_array(
      SPECIAL_CHARACTERS[char.downcase]
    )

    if char.upcase == char
      TwitterCldr::Shared::UnicodeRegex.valid_regexp_chars.subtract(chars)
    else
      chars
    end
  end
end
special_char_set_cache() click to toggle source
# File lib/twitter_cldr/parsers/unicode_regex/literal.rb, line 83
def special_char_set_cache
  @@special_char_set_cache ||= {}
end