Module: Fontisan::Cldr::UnicodeSetParser

Defined in:
lib/fontisan/cldr/unicode_set_parser.rb

Overview

Parses ICU UnicodeSet bracket notation as used in CLDR exemplarCharacters fields.

Supported syntax (sufficient for exemplar sets):

- Single chars: `a`, `à`, any BMP or supplementary codepoint
- Ranges: `a-z`, `A-Z`
- Escapes: `\uXXXX`, `\UXXXXXXXX`, `\u{XXXX...}`
- Negation: `[^...]` (inverts against 0..0x10FFFF)

Unsupported (CLDR exemplars do not use these; raise ParseError):

- Property syntax `[:script=Latin:]`
- Set operations `[a-z & [b-c]]`
- Nested sets `[a[b-c]]`
- Named sequences `{a b c}`

Output: sorted, deduplicated Array of codepoints.

Defined Under Namespace

Classes: ParseError

Class Method Summary collapse

Class Method Details

.call(set_string) ⇒ Array<Integer>

Returns sorted, deduplicated codepoints.

Parameters:

  • set_string (String)

    bracketed ICU UnicodeSet, e.g. "[a-zà]"

Returns:

  • (Array<Integer>)

    sorted, deduplicated codepoints



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fontisan/cldr/unicode_set_parser.rb', line 30

def call(set_string)
  unless set_string.start_with?("[") && set_string.end_with?("]")
    raise ParseError,
          "input must be bracketed"
  end

  body = set_string[1..-2]
  negate = body.start_with?("^")
  body = body[1..] if negate

  cps = parse_body(body)
  cps = invert(cps) if negate
  cps.sort.uniq
end