code wiki / (root) / nx_utf8.nx

nx_utf8.nx

buildroot/runtime/nx_utf8.nx

8837 B237 linesdepth 2pulls 2 transitivereach 196 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 · 26 importers

nx_syscalls.nx nx_utf8.nx nx_bright_reasoned_import.nx nx_caption_render_uni.nx nx_chat_demo_unicode_t59.nx nx_chat_unicode_store_t60.nx nx_chat_utf8_primitive_t59.nx nx_claude_harvest.nx nx_claude_harvest_requests_t144.nx nx_cyrillic_render_gate.nx nx_font.nx nx_game_page_affine_candidate_t361

diagram shows first 10 each side; +0 more imports, +16 more importers in the complete lists below.

imports: nx_syscalls.nx

imported by: nx_bright_reasoned_import.nxnx_caption_render_uni.nxnx_chat_demo_unicode_t59.nxnx_chat_unicode_store_t60.nxnx_chat_utf8_primitive_t59.nxnx_claude_harvest.nxnx_claude_harvest_requests_t144.nxnx_cyrillic_render_gate.nxnx_font.nxnx_game_page_affine_candidate_t361.nxnx_game_page_host_candidate_t341.nxnx_game_page_integrated_t73.nxnx_game_page_motion_candidate_t328.nxnx_game_page_motion_inventory_candidate_t330.nxnx_game_page_procedural_review_candidate_t333.nxnx_game_page_rig_comparison_t332.nxnx_game_page_rig_observation_candidate_t331.nxnx_game_page_scene_light_candidate_t364.nxnx_game_page_shared_candidate_t340.nxnx_game_page_static_candidate_t338.nxnx_game_page_workbench_candidate_t342.nxnx_live_xlate_call_gate.nxnx_multilang_call_gate.nxnx_multilang_render_gate.nxnx_orchestrate_raci.nxnx_orchestrate_raci_evaluate_t144.nx

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

main sys_mmap nxa_die sys_write sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ 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
121func utf8_decode_one(bytes: *u8, len: i64, pos: *i64) -> i64
174func utf8_encode_one(cp: i64, out: *u8, pos: *i64) -> i64
209func main() -> i64