Sha256: b028c4d789b561dbdc37b19a2fcc55bcb27d7efa7ca77e3a62247c01a8e71202

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

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

class TwitterCldr.Literal extends TwitterCldr.Component

  constructor : (@text) ->
    @special_characters = {
      s : [32]  # space
      t : [9]   # tab
      r : [13]  # carriage return
      n : [10]  # newline
      f : [12]  # form feed
      d : (char for char in [48..57]) # digits 0-9
      w : (char for char in [97..122].concat([65..90]).concat([48..57]).concat([95])) # lowercase, uppercase, numbers
    }


    super

  ordinalize : (char) ->
    TwitterCldr.Utilities.char_code_at(char, 0)

  to_regexp_str : ->
    @text

  to_set : ->
    if @text.match(/^\\/)
      special_char = @text.slice(1)

      if @special_characters[special_char.toLowerCase()]?
        @set_for_special_char(special_char)

      else
        TwitterCldr.RangeSet.from_array([@ordinalize(special_char)])

    else
      TwitterCldr.RangeSet.from_array([@ordinalize(@text)])

  set_for_special_char : (char) ->
    chars = TwitterCldr.RangeSet.from_array(@special_characters[char.toLowerCase()])
    if char.toUpperCase() == char
      TwitterCldr.UnicodeRegex.get_valid_regexp_chars().subtract(chars)
    else
      chars

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
twitter_cldr_js-3.3.0 lib/twitter_cldr/js/mustache/implementation/parsers/unicode_regex/literal.coffee
twitter_cldr_js-3.2.0 lib/twitter_cldr/js/mustache/implementation/parsers/unicode_regex/literal.coffee
twitter_cldr_js-3.1.1 lib/twitter_cldr/js/mustache/implementation/parsers/unicode_regex/literal.coffee
twitter_cldr_js-3.1.0 lib/twitter_cldr/js/mustache/implementation/parsers/unicode_regex/literal.coffee
twitter_cldr_js-2.4.0 lib/twitter_cldr/js/mustache/parsers/unicode_regex/literal.coffee