code wiki / (root) / nx_utf8.nx

nx_utf8.nx

buildroot/runtime/nx_utf8.nx

8837 B237 linesdepth 2pulls 2 transitivereach 5 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

utf8.nx -- UTF-8 validator + codepoint decoder (RFC 3629). Needed by: X.509 UTF8String fields, HTTP headers, JSON strings, NishiLang source code itself. Without a validator we either accept malformed sequences (security problem: overlong forms can hide dangerous characters) or reject valid input (bugs). UTF-8 byte patterns (RFC 3629 §3): 0xxxxxxx 1 byte, U+0000..U+007F 110xxxxx 10xxxxxx 2 bytes, U+0080..U+07FF 1110xxxx 10xxxxxx 10xxxxxx 3 bytes, U+0800..U+FFFF 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx 4 bytes, U+10000..U+10FFFF RFC 3629 §4 additional constraints: - Reject overlong encodings (fewer bytes than minimum for the codepoint). E.g., U+0000 must be `00`, not `C0 80`. - Reject surrogates U+D800..U+DFFF (reserved for UTF-16). - Reject codepoints > U+10FFFF. Invariants: U1 utf8_validate returns exact byte position of first invalid byte, or input length on clean success. U2 utf8_decode_one advances the caller's position by the number of bytes consumed; returns negative codepoint on invalid sequence. U3 No reads beyond the input's declared length; no buffer overruns possible from malformed input.

dependencies 1 imports · 5 importers

nx_syscalls.nx nx_utf8.nx nx_caption_render_uni.nx nx_cyrillic_render_gate.nx nx_live_xlate_call_gate.nx nx_multilang_call_gate.nx nx_multilang_render_gate.nx

imports: nx_syscalls.nx

imported by: nx_caption_render_uni.nxnx_cyrillic_render_gate.nxnx_live_xlate_call_gate.nxnx_multilang_call_gate.nxnx_multilang_render_gate.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap utf8_encode_one utf8_validate utf8_decode_one

structs

none

consts

38const UTF8_ERR_INVALID_BYTE: i64 = -1
39const UTF8_ERR_TRUNCATED: i64 = -2
40const UTF8_ERR_OVERLONG: i64 = -3
41const UTF8_ERR_SURROGATE: i64 = -4
42const UTF8_ERR_OUT_OF_RANGE: i64 = -5

functions

49func utf8_validate(bytes: *u8, n: i64) -> i64
called by 1: main
121func utf8_decode_one(bytes: *u8, len: i64, pos: *i64) -> i64
174func utf8_encode_one(cp: i64, out: *u8, pos: *i64) -> i64
called by 1: main
209func main() -> i64