Class: TwitterCldr::Parsers::UnicodeRegexParser::UnicodeString

Inherits:
Component
  • Object
show all
Defined in:
lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb

Overview

unicode_char, escaped_char, string, multichar_string Can exist inside and outside of character classes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(codepoints) ⇒ UnicodeString

Returns a new instance of UnicodeString.



16
17
18
# File 'lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb', line 16

def initialize(codepoints)
  @codepoints = codepoints
end

Instance Attribute Details

#codepointsObject (readonly)

Returns the value of attribute codepoints.



14
15
16
# File 'lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb', line 14

def codepoints
  @codepoints
end

Instance Method Details

#to_regexp_strObject



33
34
35
# File 'lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb', line 33

def to_regexp_str
  array_to_regex(Array(codepoints))
end

#to_sObject



37
38
39
# File 'lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb', line 37

def to_s
  to_regexp_str
end

#to_setObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb', line 20

def to_set
  # If the number of codepoints is greater than 1, treat them as a
  # group (eg. multichar string). This is definitely a hack in that
  # it means there has to be special logic in RangeSet that deals
  # with data types that aren't true integer ranges. I can't think
  # of any other way to support multichar strings :(
  if codepoints.size > 1
    TwitterCldr::Utils::RangeSet.new([codepoints..codepoints])
  else
    TwitterCldr::Utils::RangeSet.new([codepoints.first..codepoints.first])
  end
end

#typeObject



41
42
43
# File 'lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb', line 41

def type
  :unicode_string
end