str.nx
buildroot/runtime/str.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 · 1 importers
imports: syscalls.nx
imported by: str_test.nx
structs
| 18 | struct str { |
consts
| none |
functions
| 28 | func str_sys_mmap(size: i64) -> *u8 { |
| 36 | func str_from_cstr(p: *u8) -> *str { |
| 48 | func str_new(p: *u8, len: i64) -> *str { |
| 58 | func str_empty() -> *str { |
| 64 | func str_len(s: *str) -> i64 { return s.len }
called by 1: main |
| 65 | func str_is_empty(s: *str) -> i64 { |
| 72 | func str_at(s: *str, i: i64) -> i64 { |
| 79 | func str_eq(a: *str, b: *str) -> i64 {
called by 1: main |
| 93 | func str_eq_cstr(a: *str, cstr: *u8) -> i64 {
called by 1: main |
| 109 | func str_substr(s: *str, begin: i64, end: i64) -> *str { |
| 116 | func str_starts_with(s: *str, prefix: *str) -> i64 {
called by 1: main |
| 129 | func str_index_of(s: *str, c: i64) -> i64 { |
| 143 | func str_split_once(s: *str, c: i64, rest_out: *i64) -> *str { |
| 156 | func str_trim(s: *str) -> *str { |
| 178 | func str_parse_int(s: *str, consumed_out: *i64) -> i64 {
called by 1: main |
| 203 | func str_write(fd: i64, s: *str) -> i64 { |
| 210 | func str_ends_with(s: *str, suffix: *str) -> i64 { |
| 224 | func str_contains(s: *str, needle: *str) -> i64 { |
| 244 | func str_to_lower(s: *str) -> *str {
calls 1: str_new |
| 259 | func str_to_upper(s: *str) -> *str {
calls 1: str_new |
| 275 | func str_format_int(n: i64) -> *str {
calls 1: str_new |