|
cbase 1.50.0
C/C++ Static Template
|
Sized UTF-8 string slices (String8) and manipulation utilities. More...


Go to the source code of this file.
Classes | |
| struct | String8 |
| A sized UTF-8 string slice. More... | |
| struct | String8Node |
| A node for building singly-linked lists of strings. More... | |
| struct | String8List |
| A singly-linked list of String8 slices. More... | |
Macros | |
| #define | STR8(s) |
| Wraps a C string literal into a String8 at compile time. | |
| #define | STR8_FMT(s) |
| Helper macro to use a String8 in a printf-style format string. Example: | |
Typedefs | |
| typedef struct String8 | String8 |
| A sized UTF-8 string slice. | |
| typedef struct String8Node | String8Node |
| A node for building singly-linked lists of strings. | |
| typedef struct String8List | String8List |
| A singly-linked list of String8 slices. | |
Functions | |
| static String8 | str8 (u8 *str, usize size) |
| Creates a String8 from a raw pointer and explicit byte length. | |
| static String8 | str8_range (u8 *first, u8 *one_past_last) |
Creates a String8 spanning from first to one_past_last. | |
| static String8 | str8_cstr (const char *cstr) |
| Converts a null-terminated C string into a String8. | |
| static String8 | str8_prefix (String8 str, usize size) |
Returns the first size bytes of str. | |
| static String8 | str8_suffix (String8 str, usize size) |
Returns the last size bytes of str. | |
| static String8 | str8_skip (String8 str, usize amt) |
Returns str with the first amt bytes removed. | |
| static String8 | str8_chop (String8 str, usize amt) |
Returns str with the last amt bytes removed. | |
| static String8 | str8_substr (String8 str, usize first, usize one_past_last) |
Returns the substring from byte index first to one_past_last. | |
| static b32 | str8_match (String8 a, String8 b) |
Returns 1 if a and b contain identical bytes (case-sensitive). | |
| static b32 | str8_match_nocase (String8 a, String8 b) |
Returns 1 if a and b are equal ignoring ASCII case. | |
| static b32 | str8_starts_with (String8 str, String8 prefix) |
Returns 1 if str begins with prefix. | |
| static b32 | str8_ends_with (String8 str, String8 suffix) |
Returns 1 if str ends with suffix. | |
| static usize | str8_find_first (String8 str, u8 byte) |
Returns the byte index of the first occurrence of byte in str. | |
| static void | str8_list_push (String8List *list, String8Node *node, String8 str) |
| Appends a String8 to a String8List via a caller-allocated node. | |
Sized UTF-8 string slices (String8) and manipulation utilities.
Provides safe, allocation-free string operations using pointer/length pairs rather than null-terminated C strings. This eliminates a whole class of bugs: buffer overflows from missing null terminators, O(n) strlen calls on hot paths, and ambiguous ownership when slicing into existing buffers.
For building strings dynamically, see str_builder.h. For interning and deduplication, see base_map.h.
Definition in file base_strings.h.