code wiki / (root) / str.nx

str.nx

buildroot/runtime/str.nx

8469 B305 linesdepth 3pulls 3 transitivereach 1 importersview sourcekind librarytopic str
docsdependenciesstructsconstsfunctions

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 · 1 importers

syscalls.nx str.nx str_test.nx

imports: syscalls.nx

imported by: str_test.nx

structs

18struct str {

consts

none

functions

28func str_sys_mmap(size: i64) -> *u8 {
36func str_from_cstr(p: *u8) -> *str {
called by 1: main calls 1: str_sys_mmap
48func str_new(p: *u8, len: i64) -> *str {
58func str_empty() -> *str {
called by 1: str_split_once calls 1: str_new
64func str_len(s: *str) -> i64 { return s.len }
called by 1: main
65func str_is_empty(s: *str) -> i64 {
72func str_at(s: *str, i: i64) -> i64 {
79func str_eq(a: *str, b: *str) -> i64 {
called by 1: main
93func str_eq_cstr(a: *str, cstr: *u8) -> i64 {
called by 1: main
109func str_substr(s: *str, begin: i64, end: i64) -> *str {
called by 3: str_split_oncestr_trimmain calls 1: str_new
116func str_starts_with(s: *str, prefix: *str) -> i64 {
called by 1: main
129func str_index_of(s: *str, c: i64) -> i64 {
called by 2: str_split_oncemain
143func str_split_once(s: *str, c: i64, rest_out: *i64) -> *str {
156func str_trim(s: *str) -> *str {
called by 1: main calls 1: str_substr
178func str_parse_int(s: *str, consumed_out: *i64) -> i64 {
called by 1: main
203func str_write(fd: i64, s: *str) -> i64 {
210func str_ends_with(s: *str, suffix: *str) -> i64 {
224func str_contains(s: *str, needle: *str) -> i64 {
244func str_to_lower(s: *str) -> *str {
calls 1: str_new
259func str_to_upper(s: *str) -> *str {
calls 1: str_new
275func str_format_int(n: i64) -> *str {
calls 1: str_new