diff options
| author | steven-na <noreply.github@stvnc.dev> | 2026-07-28 02:54:05 -0700 |
|---|---|---|
| committer | steven-na <noreply.github@stvnc.dev> | 2026-07-28 02:54:05 -0700 |
| commit | 3372ec87759b83e6cc8b73e37a298cb804cbba5a (patch) | |
| tree | cd2011edfbf37f4c27b448fe748e6e0fc3283ea0 /src/string.c | |
| parent | 8bec6205ae1631dc0896fe25795b2946ed414df0 (diff) | |
String tests
Diffstat (limited to 'src/string.c')
| -rw-r--r-- | src/string.c | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/string.c b/src/string.c index be96c63..9328911 100644 --- a/src/string.c +++ b/src/string.c @@ -18,8 +18,31 @@ strng_t *strng_new(smrt_arena_t *arena, u64 size) { strng_t *strng_from(smrt_arena_t *arena, char *c) { u64 size = strlen(c); - return strng_new(arena, size); + strng_t *s = strng_new(arena, size); + + if (!s) { + return NULL; + } + + memcpy((u8*)s+STRNG_BASE_POS, c, size); + s->len = size; + + return s; } - b32 strng_set(strng_t *string, char *c); - void strng_clear(strng_t *string); +b32 strng_set(strng_t *string, char *c) { + u64 size = strlen(c); + + if (string->alloc_size < size) { + return false; + } + + memcpy((u8*)string+STRNG_BASE_POS, c, size); + string->len = size; + + return true; +} + +void strng_clear(strng_t *string) { + string->len = 0; +} |