Module str
String and memory declarations (C11/C17/C23 coverage)
Functions
| str_len | Return the length (in bytes) of a null-terminated string. |
| str_bytes | The bytes of a NUL-terminated string (without the NUL) as a slice — the way to hand a literal or C string to an API taking []const char / []const unsigned char: base64_encode(str_bytes("foobar")) |
| str_cmp | Lexicographic comparison. Returns <0, 0, or >0. |
| str_ncmp | Lexicographic comparison of at most n bytes. |
| str_eq | Return 1 if a and b are equal, 0 otherwise. |
| str_copy | Copy src into dst — at most dst.len-1 bytes, then a NUL (when dst is not empty). Returns 1 when all of src fit, 0 when it was truncated. |
| str_cat | Append src to the NUL-terminated string in dst, within dst.len (always NUL-terminated). Returns 1 when all of src fit, 0 when it was truncated (or dst held no NUL). |
| str_ncat | Append at most n bytes of src to the string in dst, within dst.len, and
NUL-terminate. Returns 1 when those bytes fit, 0 when truncated. |
| str_find | Find first occurrence of needle in haystack. Returns pointer or NULL. |
| str_find_char | Find first occurrence of character c in s. Returns pointer or NULL. |
| str_rfind_char | Find last occurrence of character c in s. Returns pointer or NULL. |
| str_find_any | Find first character in s that is also in accept. Returns pointer or NULL. |
| str_span | Return length of initial segment of s consisting only of chars in accept. |
| str_cspan | Return length of initial segment of s with no chars from reject. |
| str_tok | Reentrant tokeniser (wraps strtok_r / strtok_s).
On first call: pass the string to tokenise as s and a '?&char' cursor
for saveptr. Subsequent calls: pass null as s.
Returns the next token, or null when exhausted.
The input string IS modified (NUL-terminators are written). |
| mem_chr | The first byte == c in s, or null. |
| str_dup | Return a heap-allocated NUL-terminated copy of s. Caller must call dealloc(). |
| str_ndup | Return a heap-allocated copy of at most the first n bytes of s (stopping
at its terminator), NUL-terminated. |