Sha256: 297bd96abb639e90cb4f7e1aaaceb62b97acacd42d93d34ada0493e4a5f95705

Contents?: true

Size: 1.51 KB

Versions: 4

Compression:

Stored size: 1.51 KB

Contents

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

class TwitterCldr.Component
  to_utf8 : (codepoints) ->
    unless codepoints instanceof Array
      codepoints = [codepoints]

    (@to_hex(cp) for cp in codepoints)

  to_hex : (codepoint) ->
    if (codepoint >= 0 and codepoint <= 0xD7FF or codepoint >= 0xE000 and codepoint <= 0xFFFF)
      return @to_escaped_hex(codepoint)
    else if (codepoint >= 0x10000 and codepoint <= 0x10FFFF)
      codepoint -= 0x10000
      first = ((0xffc00 & codepoint) >> 10) + 0xD800
      second = (0x3ff & codepoint) + 0xDC00
      return @to_escaped_hex(first) + '+' + @to_escaped_hex(second)

  to_escaped_hex : (codepoint) ->
    s = codepoint.toString(16)
    s = "0000".slice(0, 4 - s.length) + s
    return "\\u" + s;

  range_to_regex : (range) ->
    if range.first instanceof Array
      @array_to_regex(range)
    else
      if range.size is 1
        "[" + @to_utf8(range.first) + "]"
      else
        "[" + @to_utf8(range.first) + "-" + @to_utf8(range.last) + "]"

  array_to_regex : (arr) ->
    ("(?:" + @to_utf8(c) + ")" for c in arr).join("")

  set_to_regex : (set) ->
    strs = ((@._set_element_to_regex(element)
    ) for element in TwitterCldr.Utilities.remove_duplicates(
      set.to_array(true))
    )

    ("(?:" + strs.join("|") + ")")

  _set_element_to_regex : (element) ->
    if element instanceof TwitterCldr.Range
      @range_to_regex(element)
    else if element instanceof Array
      @array_to_regex(element)
    else
      @to_utf8(element)

Version data entries

4 entries across 4 versions & 1 rubygems

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