Sha256: 744b380f98a597ebba645ac2e1aad0ed58ce7de5008fa39e5d0df7399248669f

Contents?: true

Size: 1.66 KB

Versions: 19

Compression:

Stored size: 1.66 KB

Contents

# encoding: UTF-8

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

module TwitterCldr
  module Parsers
    class UnicodeRegexParser

      # Can exist inside and outside of character classes
      class CharacterSet < Component

        attr_reader :property, :property_value

        def initialize(text)
          if (name_parts = text.split("=")).size == 2
            @property = name_parts[0].downcase
            @property_value = name_parts[1].to_sym
          else
            @property_value = text
          end
        end

        def to_regexp_str
          set_to_regex(to_set)
        end

        def to_set
          codepoints.subtract(
            TwitterCldr::Shared::UnicodeRegex.invalid_regexp_chars
          )
        end

        private

        def codepoints
          if property
            method = :"code_points_for_#{property}"

            if TwitterCldr::Shared::CodePoint.respond_to?(method)
              ranges = TwitterCldr::Shared::CodePoint.send(method, property_value)

              if ranges
                TwitterCldr::Utils::RangeSet.new(ranges)
              else
                raise UnicodeRegexParserError.new(
                  "Couldn't find property '#{property}' containing property value '#{property_value}'"
                )
              end
            else
              raise UnicodeRegexParserError.new(
                "Couldn't find property '#{property}"
              )
            end
          else
            TwitterCldr::Utils::RangeSet.new(
              TwitterCldr::Shared::CodePoint.code_points_for_property_value(property_value)
            )
          end
        end

      end
    end
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
solidus_backend-1.0.0.pre3 vendor/bundle/gems/twitter_cldr-3.2.1/lib/twitter_cldr/parsers/unicode_regex/character_set.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/twitter_cldr-3.2.1/lib/twitter_cldr/parsers/unicode_regex/character_set.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/twitter_cldr-3.1.2/lib/twitter_cldr/parsers/unicode_regex/character_set.rb
twitter_cldr-3.2.1 lib/twitter_cldr/parsers/unicode_regex/character_set.rb
twitter_cldr-3.2.0 lib/twitter_cldr/parsers/unicode_regex/character_set.rb
twitter_cldr-3.1.2 lib/twitter_cldr/parsers/unicode_regex/character_set.rb
twitter_cldr-3.1.1 lib/twitter_cldr/parsers/unicode_regex/character_set.rb
twitter_cldr-3.1.0 lib/twitter_cldr/parsers/unicode_regex/character_set.rb
twitter_cldr-3.0.10 lib/twitter_cldr/parsers/unicode_regex/character_set.rb
twitter_cldr-3.0.9 lib/twitter_cldr/parsers/unicode_regex/character_set.rb
twitter_cldr-3.0.8 lib/twitter_cldr/parsers/unicode_regex/character_set.rb
twitter_cldr-3.0.7 lib/twitter_cldr/parsers/unicode_regex/character_set.rb
twitter_cldr-3.0.6 lib/twitter_cldr/parsers/unicode_regex/character_set.rb
twitter_cldr-3.0.5 lib/twitter_cldr/parsers/unicode_regex/character_set.rb
twitter_cldr-3.0.4 lib/twitter_cldr/parsers/unicode_regex/character_set.rb
twitter_cldr-3.0.3 lib/twitter_cldr/parsers/unicode_regex/character_set.rb
twitter_cldr-3.0.2 lib/twitter_cldr/parsers/unicode_regex/character_set.rb
twitter_cldr-3.0.1 lib/twitter_cldr/parsers/unicode_regex/character_set.rb
twitter_cldr-3.0.0 lib/twitter_cldr/parsers/unicode_regex/character_set.rb