diff options
Diffstat (limited to 'qstd')
-rw-r--r-- | qstd/str.c | 31 | ||||
-rw-r--r-- | qstd/str.h | 7 |
2 files changed, 38 insertions, 0 deletions
@@ -1,3 +1,4 @@ +#include "memory.h" #include "str.h" uint64_t fnv1a64(uint8_t* buf, size_t size) { @@ -18,3 +19,33 @@ uint32_t hash_string(const char* s) { } return h; } + +int string_equal(const char* a, const char* b) { + while (*a && *b) { + if (*a != *b) { return 0; } + a++; b++; + } + return 1; +} + +int string_copy(char* dst, const char* src) { + int i; + for (i = 0; *src; src++, dst++, i++) { + *dst = *src; + } + return i; +} + +int string_len(const char* s) { + int l; + for (l = 0; *s; s++, l++); + return l; +} + +char* dup_string(Arena* a, const char* s) { + int size = string_len(s) + 1; + char* d = arena_alloc_aligned(a, size, 1); + string_copy(d, s); + return d; +} + @@ -4,7 +4,14 @@ #include <stddef.h> #include <stdint.h> +struct Arena; + uint64_t fnv1a64(uint8_t* buf, size_t size); uint32_t hash_string(const char* s); +int string_equal(const char* a, const char* b); +int string_copy(char* dst, const char* src); +int string_len(const char* s); +char* dup_string(struct Arena* a, const char* s); + #endif |