Class CharSet

An immutable set of Chars represented as a sorted set of disjoint non-adjacent intervals (CharRange).

All characters in the set have to be between 0 (inclusive) and the maximum of the set (inclusive).

Hierarchy

  • CharSet

Properties

maximum: Char

The greatest character which can be element of the set.

ranges: readonly CharRange[]

An array of ranges representing this character set.

The array must be guaranteed to have the following properties at all times:

  1. Any two ranges are disjoint.
  2. Any two ranges are non-adjacent.
  3. 0 <= min <= max <= this.maximum for all ranges.
  4. All ranges are sorted by ascending min.

Accessors

  • get isAll(): boolean
  • Returns true if all characters in the range from 0 to this.maximum, including 0 and this.maximum, are in the set.

    Returns boolean

  • get isEmpty(): boolean
  • Returns true if this set doesn't contain any characters.

    Returns boolean

  • get size(): number
  • Returns the number of unique characters in the set.

    The returned number will be at least 0 and at most this.maximum + 1.

    Returns number

Methods

  • Returns an iterable of all characters in this set.

    Characters are sorted by ascending order and each character is yielded exactly once.

    Note: The iterable is stable. It can be iterated multiple times.

    Returns Iterable<Char>

  • Returns any one of the common characters of this set and the given set or range.

    If this character set is disjoint with the given character set/range, then undefined will be returned.

    Parameters

    Returns undefined | Char

  • Compares this set with given set and returns an integer value describing their relation. Two equivalent set are always guaranteed to return 0.

    The order defined by this function is guaranteed to be a total order. Apart from this, no other guarantees are given.

    Parameters

    Returns number

  • Returns whether this and the given character set are equivalent.

    Two CharSets are equal if and only if:

    1. They have the same maximum.
    2. They contain the same characters.

    Since each set of characters has a unique range representation, 2 equal CharSets are guaranteed to have equal ranges.

    A CharSet and a CharRange are equal if and only if they contain the same characters.

    Parameters

    Returns boolean

  • Returns whether this set contains the given character.

    Parameters

    Returns boolean

  • Returns the intersection of this set and the given set/ranges of characters.

    The returned set will have the same maximum as this set.

    Parameters

    Returns CharSet

    Throws

    RangeError If the maximum of the given set differs from the maximum of this set.

  • Returns whether this set and the given set (or range) are disjoint.

    Parameters

    Returns boolean

  • Returns a character set with the given maximum.

    The ranges of the returned character set are equivalent to the ranges of this.intersect({ min: 0, max: newMaximum }).

    Parameters

    Returns CharSet

  • Returns a string representation of the ranges of this character set.

    The string representation has the following rules:

    1. Each character is represented as a hexadecimal number.
    2. Each range where min == max will be represented by the min character.
    3. Each range where min != max will be represented by min followed by ".." followed by max.
    4. The sequence of ranges will be joined together using ", ".

    The returned string representation will have the following format:

    string = [ ranges ]
    ranges = range *( ", " range )
    range = +hex [ ".." +hex ]
    hex = "a" | "b" | "c" | "d" | "e" | "f" | digit
    digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"

    Returns string

  • Returns a string representation of the character set.

    Returns string

  • Returns a string representation of the Unicode ranges of this character set.

    The primary purpose of this function is provide an easy way to get a readable representation of a Unicode or Unicode-like character set. The format is optimized for ease of reading for humans.

    The format follows these rules:

    • If the character set is empty, empty will be returned.
    • If the character set contains all characters, all will be returned.
    • Ranges may be negated, which is indicated with not. E.g. not a b is the character set that contains all characters except for a and b.
    • A contiguous range of characters is represented using min-max where min and max are formatted characters.
    • Single characters are formatted as either:
      • a Unicode character (e.g. a),
      • a quoted Unicode character (e.g. '-'), or
      • a Unicode escape (e.g. U+FF).

    The returned string representation will have the following format:

    string  = "all" | "empty" | ranges | "not " ranges
    ranges = range *( " " range )
    range = char [ "-" char ]
    char = literal | quoted | escape
    literal = ?Printable Unicode characters?
    literal = "'" ?any character? "'"
    escape = "U+" +hex
    hex = "A" | "B" | "C" | "D" | "E" | "F" | digit
    digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"

    Returns string

  • Returns the union of this set and all given sets and character ranges.

    The returned set will have the same maximum as this set.

    Parameters

    Returns CharSet

    Throws

    RangeError If the maximum of one of the given sets differs from the maximum of this set or if the maximum of one of the given ranges is greater than the maximum of this set.

  • Returns a set that contains all characters of this set that are not in the given set/range.

    The returned set will have the same maximum as this set.

    Parameters

    Returns CharSet

    Throws

    RangeError If the maximum of the given set differs from the maximum of this set.

  • Returns a complete character set with the given maximum.

    Parameters

    • maximum: Char

      The greatest character which will be element of the set.

    Returns CharSet

  • Returns an empty character set with the given maximum.

    Parameters

    • maximum: Char

      The greatest character which can be element of the set.

    Returns CharSet

  • Returns a character set which contains the given character.

    Parameters

    • maximum: Char

      The greatest character which will be element of the set.

    • char: Char

    Returns CharSet

    Throws

    RangeError if the maximum of the given range is greater than maximum.

  • Returns a character set which contains the given characters.

    Parameters

    • maximum: Char

      The greatest character which will be element of the set.

    • characters: Iterable<Char>

      A sorted collection of characters.

    Returns CharSet

    Throws

    RangeError if the given collection is not sorted or contains characters greater than maximum.

  • Returns a character set which contains the given range.

    Parameters

    • maximum: Char

      The greatest character which will be element of the set.

    • range: CharRange

    Returns CharSet

    Throws

    RangeError if the maximum of the given range is greater than maximum.