nx_str_canonical.nx
buildroot/runtime/nx_str_canonical.nx
about
str.nx -- first-class string / byte-slice type for NishiLang.
Carries (ptr, length) by pointer. Fixes the null-terminator
problem: `str` can store embedded zeros, and length is O(1).
Eventually generalizes to `Slice<T>` once A4 (generics) lands;
for now we specialize to bytes because that's 99% of the use
case (HTTP parsing, markdown, file contents, console I/O).
Usage pattern:
let hello: *str = str_from_cstr("Hello, World\n")
sys_write(1, hello.ptr, hello.len)
Helper `str_from_cstr(ptr)` computes length by walking to NUL.
For true runtime-constructed slices (e.g. a substring), use
`str_new(ptr, len)` which stores as-given.
dependencies 1 imports · 0 importers
imports: nx_syscalls.nx
imported by: nobody (leaf or entry point)
structs
| 18 | struct str |
consts
| none |
functions
| 34 | func str_sys_mmap(size: i64) -> *u8 |
| 42 | func str_from_cstr(p: *u8) -> *str calls 1: str_sys_mmap |
| 54 | func str_new(p: *u8, len: i64) -> *str |
| 64 | func str_empty() -> *str |
| 70 | func str_len(s: *str) -> i64 { return s.len } |
| 71 | func str_is_empty(s: *str) -> i64 |
| 78 | func str_at(s: *str, i: i64) -> i64 |
| 85 | func str_eq(a: *str, b: *str) -> i64 |
| 99 | func str_eq_cstr(a: *str, cstr: *u8) -> i64 |
| 115 | func str_substr(s: *str, begin: i64, end: i64) -> *str |
| 122 | func str_starts_with(s: *str, prefix: *str) -> i64 |
| 135 | func str_index_of(s: *str, c: i64) -> i64 called by 1: str_split_once |
| 149 | func str_split_once(s: *str, c: i64, rest_out: *i64) -> *str |
| 162 | func str_trim(s: *str) -> *str calls 1: str_substr |
| 184 | func str_parse_int(s: *str, consumed_out: *i64) -> i64 |
| 209 | func str_write(fd: i64, s: *str) -> i64 |
| 216 | func str_ends_with(s: *str, suffix: *str) -> i64 |
| 230 | func str_contains(s: *str, needle: *str) -> i64 |
| 250 | func str_to_lower(s: *str) -> *str |
| 265 | func str_to_upper(s: *str) -> *str |
| 281 | func str_format_int(n: i64) -> *str |