From 3372ec87759b83e6cc8b73e37a298cb804cbba5a Mon Sep 17 00:00:00 2001 From: steven-na Date: Tue, 28 Jul 2026 02:54:05 -0700 Subject: String tests --- src/string.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'src/string.c') 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; +} -- cgit v1.2.3