Module
std.unicode — the posture module: what wolf promises about Unicode in v1, spelled as functions where it can be and as a filing where it cannot. Stability tier: core.
The posture, in one paragraph. v1 ships three things and no more: UTF-8 validity as a type invariant (str is valid UTF-8 by construction, D24 — the language's, not this module's), byte-offset slicing that refuses to split a code point (D25, also the language's), and the ASCII-true classification below, named so that no caller can mistake it for Unicode-true classification. NOT in v1: general category tables, case mapping and folding, normalization (NFC/NFD/NFKC/NFKD), and grapheme segmentation data. Those are a BUDGET decision — table size, generation, and the maintenance cost of tracking Unicode releases — filed upstream (F-0018) with the recommendation that they land in penumbra or std/x rather than core, so that a core that must be welded to the compiler does not carry megabytes of derived data. Report 07's nursery clock applies to whichever nursery takes them.
**THE CURRENCY IS char NOW (sc25), AND THE INT INTERIM IS GONE.** From sc03 to sc24 this module spelled a code point as an int because no pinned binary had a char; D58 ruled the type at the sc24 data pin ([type.char]: a Unicode scalar value, 0..=0x10FFFF minus the surrogate gap, ordered by scalar value, NOT an integer) and the sc24 wolf pair executed it — but lupin 0.1.14 did not (' refused at lex; the interpreter's char tier was is26, running concurrently), so sc24 shipped only code and recorded the reviewed char-typed signatures per function rather than trading the module's executing interpreter lane for them. lupin 0.1.15 — the is26 scalar release — closed that gap, and this is the recorded flip, at the sprint it was owed to: every signature below is char-typed, the flip cost no lane (re-measured on both executing lanes at the sc25 pins; the native column keeps its recorded values under the nomad-1 posture, the s121 surface having been verified on both wolf rungs at sc24), and the reviewed-final-signature notes retired into the signatures themselves.
D58's rule is this module's law: no arithmetic on the scalar, anywhere. code and from_code bracket the ONLY two places in std where a number and a code point trade places — c as int (total by [type.char.cast]) and the validated n as char (every trap row of the raw cast is a none here, so the cast can never trap). The predicates COMPARE c against char literals under [type.char.order] — they never compute, and no helper that does will ever sit beside them. utf8_len is TOTAL now: its {none} row existed only because the interim's int could hold a non-scalar, and a non-scalar cannot exist as a char at all.
Absence is spelled none, which is the convention's own spelling and no longer an interim: F-0003 died at the sc05 pins and the rename landed tree-wide at sc06. This header described the interim for six sprints after it was gone.
Functions and methods
fn · Source line 80
pub fn from_code(n: int) -> char ! {none}
n as a Unicode scalar value; none when n is not one — negative, above U+10FFFF, or in the surrogate range U+D800..U+DFFF, which UTF-8 may never encode. This is the validating constructor: the one place in std a number becomes a code point, and the recoverable face of the D56 cast — int as char TRAPS overflow on exactly the shapes this function answers none for ([type.char.cast]), so the cast in the body runs only on values it has already admitted and can never trap.
(unicode.from_code(65) else '?') == 'A'
(unicode.from_code(233) else '?') == 'é'
(unicode.from_code(128058) else '?') == '🐺'
(unicode.from_code(1114111) else '?') == '\u{10FFFF}'
(unicode.from_code(1114112) else '?') == '?'
(unicode.from_code(0 - 1) else '?') == '?'
(unicode.from_code(55296) else '?') == '?'
(unicode.from_code(57343) else '?') == '?'
fn · Source line 111
pub fn code(c: char) -> int
The Unicode scalar value of c, as an int — the sc03 contract's char.code, code since sc24. The body is c as int, which [type.char.cast] rules TOTAL: every char is a scalar value by construction (D58 — the surrogate gap and the range cap are enforced where a number tries to become a char, not here), so this projection has no row and can never trap. With from_code it brackets the only two places in std where a number and a code point trade places; the predicates below compare, they never compute.
var total = 0
for c in "Aé".chars() { total = total + unicode.code(c) }
total == 298
unicode.code('A') == 65
unicode.code('🐺') == 128058
fn · Source line 131
pub fn utf8_len(c: char) -> int
The number of bytes c occupies in UTF-8 — 1, 2, 3 or 4. TOTAL now (sc25): the {none} row the int interim carried existed only because an int can hold a non-scalar, and a non-scalar cannot exist as a char (D58). The class boundaries are compared as char literals under the scalar order ([type.char.order]) — never computed.
unicode.utf8_len('A') == 1
unicode.utf8_len('\u{7F}') == 1
unicode.utf8_len('é') == 2
unicode.utf8_len('\u{7FF}') == 2
unicode.utf8_len('中') == 3
unicode.utf8_len('\u{FFFF}') == 3
unicode.utf8_len('🐺') == 4
unicode.utf8_len('\u{10FFFF}') == 4
fn · Source line 156
pub fn is_ascii(c: char) -> bool
Whether c is an ASCII character, U+0000..U+007F. Total, and one comparison now: the negative guard the int interim carried has no value to guard against — a char below '\0' does not exist.
unicode.is_ascii('A') == true
unicode.is_ascii('\0') == true
unicode.is_ascii('\u{7F}') == true
unicode.is_ascii('\u{80}') == false
unicode.is_ascii('é') == false
unicode.is_ascii('🐺') == false
fn · Source line 170
pub fn is_ascii_alpha(c: char) -> bool
Whether c is an ASCII letter, A..Z or a..z. ASCII-true, as the name says: a Unicode letter outside ASCII answers false, and unicode-true classification is the filed table decision. Total.
unicode.is_ascii_alpha('A') == true
unicode.is_ascii_alpha('z') == true
unicode.is_ascii_alpha('0') == false
unicode.is_ascii_alpha('é') == false
fn · Source line 182
pub fn is_ascii_digit(c: char) -> bool
Whether c is an ASCII decimal digit, 0..9. Total.
unicode.is_ascii_digit('0') == true
unicode.is_ascii_digit('9') == true
unicode.is_ascii_digit('/') == false
unicode.is_ascii_digit('A') == false
fn · Source line 196
pub fn is_ascii_alnum(c: char) -> bool
Whether c is an ASCII letter or digit. Total.
unicode.is_ascii_alnum('A') == true
unicode.is_ascii_alnum('0') == true
unicode.is_ascii_alnum('_') == false
fn · Source line 216
pub fn is_ascii_space(c: char) -> bool
Whether c is ASCII whitespace: tab ('\t'), line feed ('\n'), vertical tab (U+000B), form feed (U+000C), carriage return ('\r') or space. Total.
This is deliberately NARROWER than the whitespace std.str.trim and std.str.words use, which is Unicode White_Space (the builtin's set, pinned by a test there). The names are the difference: is_ascii_space promises ASCII and delivers ASCII.
unicode.is_ascii_space(' ') == true
unicode.is_ascii_space('\t') == true
unicode.is_ascii_space('\r') == true
unicode.is_ascii_space('A') == false
unicode.is_ascii_space('\u{A0}') == false
fn · Source line 234
pub fn is_ascii_upper(c: char) -> bool
Whether c is an ASCII uppercase letter, A..Z. Total.
unicode.is_ascii_upper('A') == true
unicode.is_ascii_upper('Z') == true
unicode.is_ascii_upper('a') == false
unicode.is_ascii_upper('É') == false
fn · Source line 249
pub fn is_ascii_lower(c: char) -> bool
Whether c is an ASCII lowercase letter, a..z. Total.
unicode.is_ascii_lower('a') == true
unicode.is_ascii_lower('z') == true
unicode.is_ascii_lower('A') == false
unicode.is_ascii_lower('é') == false