Sha256: a423d789e8897d0ac1ea824cc8dc8c71766ed39e0b482e8d48ae2179c12e8f21

Contents?: true

Size: 1.19 KB

Versions: 8

Compression:

Stored size: 1.19 KB

Contents

# encoding: UTF-8

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

module TwitterCldr
  module Parsers
    class UnicodeRegexParser

      # unicode_char, escaped_char, string, multichar_string
      # Can exist inside and outside of character classes
      class UnicodeString < Component

        attr_reader :codepoints

        def initialize(codepoints)
          @codepoints = codepoints
        end

        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

        def to_regexp_str
          cps = codepoints.is_a?(Array) ? codepoints : [codepoints]
          array_to_regex(codepoints)
        end

      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
twitter_cldr-3.0.7 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
twitter_cldr-3.0.6 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
twitter_cldr-3.0.5 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
twitter_cldr-3.0.4 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
twitter_cldr-3.0.3 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
twitter_cldr-3.0.2 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
twitter_cldr-3.0.1 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
twitter_cldr-3.0.0 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb