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.c | |
| parent | f10afce9821a81c8dd138b84a4f1ab56116af20b (diff) | |
Added string view
Diffstat (limited to 'src/string.c')
| -rw-r--r-- | src/string.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/string.c b/src/string.c index c808642..38d7824 100644 --- a/src/string.c +++ b/src/string.c @@ -3,6 +3,7 @@ #include "log.h" #include "string.h" +#include <ctype.h> #include <string.h> strng_t *strng_new(smrt_arena_t *arena, u64 size) { @@ -81,3 +82,17 @@ void strng_clear(strng_t *string) { memset((u8*)string+STRNG_BASE_POS, 0, string->len); string->len = 0; } + +strng_view_t sv_from_chars(char const* c) { u64 l = strlen(c); + return (strng_view_t){ + .start=0, + .end=l, + .max=l, + .string=c, }; } + +void sv_trim_left(strng_view_t *sv) { while (sv->start<= sv->end && isspace(*(sv->string+sv->start)) ) sv->start++; } +void sv_trim_right(strng_view_t *sv) { while (sv->end >=sv->start && isspace(*( sv->string+sv->end)) ) sv->end--; } +void sv_trim(strng_view_t *sv) { sv_trim_left(sv); + sv_trim_right(sv); } + +void sv_reset(strng_view_t *sv) { sv->end=sv->max; sv->start=0; } |