A set of code points, kept as sorted disjoint inclusive ranges.
Character classes, \p{...}, \w and the rest are all this one shape, sothe set algebra a pattern needs — union for [a-z], difference for --,intersection for &&, complement for [^…] — lives here once.
A set prints as its name and how much it holds, never as its ranges: acategory can carry four thousand of them, and no failure message isimproved by reading them.
Close the set under simple case folding: add the folded form of everythingin it, and the unfolded form of everything that folds into it.
This is what (?i) does to a class at parse time: fold the pattern, notthe input, so the executor stays a plain membership test. Only single codepoint folds exist here, so ß does not grow an ss — matching it againstSS is out of scope, exactly as it is in Python's re.
Build a set from ranges, sorting and merging them first.
The input may be in any order and may overlap; the stored form is alwayssorted, disjoint and coalesced, which is what makes contains a binarysearch and the algebra linear.
The simple fold of a code point: the one character it becomes when casestops counting. A code point whose fold is longer than one character, ßto ss, is its own, since a class holds code points, not strings.
The fold pairs both ways, sorted by source — what a class is closed under.
The code points that change under casefolding are the ones a class growsfrom, and each of them brings its whole fold class with it, so the pairscome out of the orbit table instead of a walk of the code space.
Any property, however it is spelled — the shape \p{...} takes.
name=value is accepted too: Script=Latin, General_Category=Lu,Block=CJK Unified Ideographs. The left side picks the table, the rightside the entry; without it, every table is searched in the order a Unicodename would be looked up: category, script, block, binary property.
\w under the Python and mrab spellings: letters, numbers and theunderscore. Python's own words for it are "alphanumeric (as str.isalnumhas it) plus _", which is exactly these categories.