Sha256: 7a9335735b713f49e9a6cd56fb5c665a4859c04a85ef887622005b243a583e70

Contents?: true

Size: 1.18 KB

Versions: 17

Compression:

Stored size: 1.18 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
          array_to_regex(Array(codepoints))
        end

        def to_s
          to_regexp_str
        end

      end
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/twitter_cldr-4.4.5/lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/twitter_cldr-4.4.5/lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
twitter_cldr-4.4.5 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
twitter_cldr-4.4.4 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
twitter_cldr-4.4.3 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
twitter_cldr-4.4.2 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
twitter_cldr-4.4.1 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
twitter_cldr-4.4.0 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
twitter_cldr-4.3.1 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
twitter_cldr-4.3.0 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
twitter_cldr-4.2.0 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
twitter_cldr-4.1.0 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
twitter_cldr-4.0.0 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
twitter_cldr-3.6.0 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
twitter_cldr-3.5.0 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
twitter_cldr-3.4.0 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb
twitter_cldr-3.3.0 lib/twitter_cldr/parsers/unicode_regex/unicode_string.rb