Skip to main content

Module charsets

Module charsets 

Source
Expand description

Character classification for XML 1.0 names.

§ASCII lookup tables

Two 256-entry tables let callers classify ASCII bytes with a single array access. Bytes ≥ 0x80 are always zero in the table; callers must fall back to the Unicode range functions for those.

  • ASCII_XML_NAME — XML Name (§2.3): : counts as a name-start char.
  • ASCII_NCNAME — XPath NCName: : is a separator, not part of a name.

§Unicode range functions

Non-ASCII characters are checked with is_name_start_char / is_name_char_unicode (5th edition, the current default) or is_name_start_char_4e / is_name_char_4e (4th edition, enabled via ParseOptions::xml10_fourth_edition).

Both editions agree on all ASCII characters; the tables above handle those uniformly. The non-ASCII functions cover ≥ 0x80 only.

Constants§

ASCII_NCNAME
XPath NCName lookup table. Excludes : (it is a separator in XPath). Bytes ≥ 0x80 are 0; use is_name_start_char / is_name_char_unicode for those.
ASCII_XML_NAME
XML Name lookup table. Includes : as a name-start char (§2.3). Bytes ≥ 0x80 are 0; use is_name_start_char / is_name_char_unicode (or their 4th-edition counterparts) for those.
ASCII_XML_NAME_CHAR
Boolean fast-path: 1 iff the byte is an ASCII NameChar (NS|NC) per XML 1.0 § 2.3 production [4a]. Non-ASCII bytes (≥ 0x80) are 0 so the tight inner loop in scan_name_raw exits and falls into the explicit UTF-8 path. Layout matches ASCII_XML_NAME for NS|NC.
NC
Byte is an ASCII name character but NOT a name-start (09, -, .).
NS
Byte is an ASCII name-start character (A–Z, a–z, _, and for XML Name, :).

Functions§

is_name_char_4e
XML 1.0 §2.3 NameChar — 4th edition.
is_name_char_unicode
Returns true if c (≥ U+0080) is a valid XML 1.0 5th-edition name character. ASCII name chars (09, -, .) are handled by the tables.
is_name_start_char
Returns true if c (≥ U+0080) is a valid XML 1.0 5th-edition name-start character. The : and _ cases are ASCII and handled by the tables.
is_name_start_char_4e
XML 1.0 §2.3 NameStartChar — 4th edition (Letter | '_' | ':').