std1.0.0-beta-7 SafeC docs

Module str

#include <std/str.h> source

String and memory declarations (C11/C17/C23 coverage)

Functions

str_lenReturn the length (in bytes) of a null-terminated string.
str_bytesThe 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_cmpLexicographic comparison. Returns <0, 0, or >0.
str_ncmpLexicographic comparison of at most n bytes.
str_eqReturn 1 if a and b are equal, 0 otherwise.
str_copyCopy 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_catAppend 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_ncatAppend 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_findFind first occurrence of needle in haystack. Returns pointer or NULL.
str_find_charFind first occurrence of character c in s. Returns pointer or NULL.
str_rfind_charFind last occurrence of character c in s. Returns pointer or NULL.
str_find_anyFind first character in s that is also in accept. Returns pointer or NULL.
str_spanReturn length of initial segment of s consisting only of chars in accept.
str_cspanReturn length of initial segment of s with no chars from reject.
str_tokReentrant 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_chrThe first byte == c in s, or null.
str_dupReturn a heap-allocated NUL-terminated copy of s. Caller must call dealloc().
str_ndupReturn a heap-allocated copy of at most the first n bytes of s (stopping at its terminator), NUL-terminated.