slice.h (1343B)
1 #ifndef KIT_SLICE_H 2 #define KIT_SLICE_H 3 4 /* 5 * Internal fat-pointer string/byte view. `Slice` is the internal alias of the 6 * public KitSlice, and the internal slice_* names are thin aliases of the 7 * public kit_slice_* inline implementations in <kit/core.h>: there is a 8 * single source of truth for the logic. Only slice_dup (which needs an Arena, 9 * so it cannot live in the freestanding public header) is internal-only. 10 * 11 * kit carries lengths everywhere; NUL termination is only a boundary 12 * convenience. slice_from_cstr() is the single sanctioned place that scans a 13 * NUL terminator, used to lift OS/argv strings into slices at the boundary. 14 */ 15 16 #include "core/arena.h" 17 #include "core/core.h" 18 19 typedef KitSlice Slice; 20 21 /* Short internal spellings of the public slice surface. The logic lives once, 22 * in <kit/core.h>; these are aliases (cf. core/hashmap.h aliasing the public 23 * KIT_HASHMAP_DEFINE / kit_hash_*). */ 24 #define SLICE_LIT(lit) KIT_SLICE_LIT(lit) 25 #define SLICE_NULL KIT_SLICE_NULL 26 #define SLICE_ARG(x) KIT_SLICE_ARG(x) 27 28 #define slice_from_cstr kit_slice_cstr 29 #define slice_eq kit_slice_eq 30 #define slice_eq_cstr kit_slice_eq_cstr 31 32 /* Copy into the arena with a trailing NUL (so the result is also usable at a 33 * boundary). The trailing NUL is not counted in the returned length. */ 34 Slice slice_dup(Arena*, Slice); 35 36 #endif