Files
ww/lib/encoding/utf8/utf8.ww
Hojun-Cho e9c3f75fd1 lib: graduate utf8.runesz and bufio.readbyte to (i32 | void)
Both used the -1 sentinel return; both had no external callers, so
the graduation is purely the API-shape change. utf8.runesz uses void
for "rune outside legal range"; bufio.readbyte uses void for EOF
(empty buffer). The full Hare shapes ((size | invalid) and
(u8 | EOF | io::error)) are still richer than this — those richer
returns arrive when utf8 grows an explicit invalid type and bufio
wires through io::stream's error path.
2026-05-12 02:12:33 +09:00

16 lines
518 B
Plaintext

// encoding/utf8 — UTF-8 helpers. RFC 3629; we only handle the legal
// subset (no over-long encodings, no surrogates).
def MAX: rune = 1114111; // 0x10FFFF
// runesz — encoded byte length of `r` as UTF-8. void variant means
// `r` is outside the legal range (negative, > 0x10FFFF).
export fn runesz(r: rune) (i32 | void) = {
if (r < 0) { return; };
if (r < 128) { return 1; };
if (r < 2048) { return 2; };
if (r < 65536) { return 3; };
if (r <= MAX) { return 4; };
return;
};