diff options
| author | steven-na <noreply.github@stvnc.dev> | 2026-08-14 16:58:01 -0700 |
|---|---|---|
| committer | steven-na <noreply.github@stvnc.dev> | 2026-08-14 16:58:01 -0700 |
| commit | 06ebe0aa31569c017f43e513047b1e339f52b6e6 (patch) | |
| tree | da6690e4905708139e20a20edc6c7fd5c1a7c999 /src/string.h | |
| parent | f10afce9821a81c8dd138b84a4f1ab56116af20b (diff) | |
Added string view
Diffstat (limited to 'src/string.h')
| -rw-r--r-- | src/string.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/string.h b/src/string.h index 5a89dec..999add8 100644 --- a/src/string.h +++ b/src/string.h @@ -18,3 +18,28 @@ strng_t * strng_dup(smrt_arena_t *arena, strng_t const *src); void strng_clear(strng_t *string); #define STRNG_FMT(s) (i32)s->len, (char *)((u8*)s+STRNG_BASE_POS) + +typedef struct { + u64 start; + u64 end; + u64 max; +char const *string; +} strng_view_t; + +static inline strng_view_t sv_from(strng_t *string) { + return (strng_view_t){ + .string=(char*)((u8*)string+STRNG_BASE_POS), + .start=0, + .end=string->len, + .max=string->len, + }; +} +strng_view_t sv_from_chars(char const* c); + +void sv_trim_left(strng_view_t *sv); +void sv_trim_right(strng_view_t *sv); +void sv_trim(strng_view_t *sv); +void sv_reset(strng_view_t *sv); + +#define SV_FMT(sv) (i32)((sv)->end - (sv)->start), (char *)((u8*)((sv)->string) + (sv)->start) + |