code wiki / (root) / nx_string_ops.nx

nx_string_ops.nx

buildroot/runtime/nx_string_ops.nx

9592 B313 linesdepth 5pulls 5 transitivereach 36 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_string_ops.nx -- byte-buffer string primitives (Python/JS stdlib analog). Every program ends up needing: substring search, slicing, length, trim, parse-int, equality, hash, split. Without a substrate-level home for these, every caller hand-rolls a while-loop scanning bytes -- the exact kind of duplicated bullshit the user named in the "loops within loops" feedback. PRIMITIVES (16 total): Family 1: scan + length nx_str_len(buf) -- length until first 0 byte nx_str_index_of(buf, n, ch) -- first index of byte ch, -1 if none nx_str_last_index_of(buf, n, ch) -- last index of ch, -1 if none Family 2: equality / prefix / suffix nx_str_equals(a, na, b, nb) nx_str_starts_with(buf, n, prefix, np) nx_str_ends_with(buf, n, suffix, ns) nx_str_find(haystack, nh, needle, nn) -- first occurrence, -1 if none Family 3: slice + copy nx_str_slice_copy(src, lo, hi, dst, cap) -- copy [lo, hi) into dst nx_str_trim_left(buf, n) -- returns new start offset nx_str_trim_right(buf, n) -- returns new end offset (exclusive) Family 4: parse + format nx_str_parse_int(buf, n) -- parse signed decimal nx_str_format_int(v, dst, cap) -- write decimal; returns length Family 5: classify nx_str_is_empty(buf, n) nx_str_is_all_digits(buf, n) nx_str_is_all_whitespace(buf, n) Family 6: hash nx_str_hash_fnv1a(buf, n) -- 64-bit FNV-1a, well-distributed DESIGN PRINCIPLES: - All take explicit length n; no null-terminator assumption (bytes in buffers may contain 0)

dependencies 3 imports · 31 importers

nx_syscalls.nx nx_tier.nx nx_essentials.nx nx_string_ops.nx nx_doc_census.nx nx_doc_census_real_audit_test.nx nx_doc_census_real_listing_test.nx nx_doc_census_run_test.nx nx_doc_census_test.nx nx_doc_dashboard.nx nx_doc_dashboard_substrate_state_t nx_doc_dashboard_test.nx nx_doc_decision.nx nx_doc_decision_test.nx

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

imports: nx_syscalls.nxnx_tier.nxnx_essentials.nx

imported by: nx_doc_census.nxnx_doc_census_real_audit_test.nxnx_doc_census_real_listing_test.nxnx_doc_census_run_test.nxnx_doc_census_test.nxnx_doc_dashboard.nxnx_doc_dashboard_substrate_state_test.nxnx_doc_dashboard_test.nxnx_doc_decision.nxnx_doc_decision_test.nxnx_doc_func_scan.nxnx_doc_func_scan_test.nxnx_doc_incumbent.nxnx_doc_incumbent_test.nxnx_doc_inref.nxnx_doc_inref_test.nxnx_doc_render_mermaid.nxnx_doc_render_mermaid_test.nxnx_doc_xref.nxnx_doc_xref_dual_audit_test.nxnx_doc_xref_real_audit_test.nxnx_doc_xref_test.nxnx_find.nxnx_find_test.nxnx_grep_rt.nxnx_ngram.nxnx_scaffolding_audit.nxnx_string_ops_test.nxnx_tool_census.nxnx_tool_census_run_test.nxnx_tool_census_test.nx

structs

none

consts

296const NX_FNV1A_PRIME: nx_int = 1099511628211 // 0x100000001b3

functions

64func nx_str_len(buf: *u8) -> nx_int
71func nx_str_index_of(buf: *u8, n: nx_int, ch: nx_int) -> nx_int
called by 1: main
82func nx_str_last_index_of(buf: *u8, n: nx_int, ch: nx_int) -> nx_int
called by 1: main
94func nx_str_equals(a: *u8, na: nx_int, b: *u8, nb: nx_int) -> nx_int
105func nx_str_starts_with(buf: *u8, n: nx_int, prefix: *u8, np: nx_int) -> nx_int
116func nx_str_ends_with(buf: *u8, n: nx_int, suffix: *u8, ns: nx_int) -> nx_int
131func nx_str_find(haystack: *u8, nh: nx_int, needle: *u8, nn: nx_int) -> nx_int
156func nx_str_slice_copy(src: *u8, lo: nx_int, hi: nx_int, dst: *u8, cap: nx_int) -> nx_int
171func nx_str_trim_left(buf: *u8, n: nx_int) -> nx_int
called by 1: main calls 1: nx_char_is_whitespace
183func nx_str_trim_right(buf: *u8, n: nx_int) -> nx_int
called by 1: main calls 1: nx_char_is_whitespace
199func nx_str_parse_int(buf: *u8, n: nx_int) -> nx_int
called by 1: main calls 1: nx_char_is_digit
222func nx_str_format_int(v: nx_int, dst: *u8, cap: nx_int) -> nx_int
260func nx_str_is_empty(buf: *u8, n: nx_int) -> nx_int
called by 1: main
265func nx_str_is_all_digits(buf: *u8, n: nx_int) -> nx_int
called by 1: main calls 1: nx_char_is_digit
275func nx_str_is_all_whitespace(buf: *u8, n: nx_int) -> nx_int
called by 1: main calls 1: nx_char_is_whitespace
299func nx_fnv1a_offset_basis() -> nx_int
303func nx_str_hash_fnv1a(buf: *u8, n: nx_int) -> nx_int
called by 1: main calls 1: nx_fnv1a_offset_basis