From 82767020e84ec8c1af2e3817fc7efede5497c82d Mon Sep 17 00:00:00 2001 From: quou Date: Sun, 22 Dec 2024 22:17:35 +1100 Subject: add some string functions --- qstd/str.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'qstd/str.c') diff --git a/qstd/str.c b/qstd/str.c index b6b0eb7..49ad396 100644 --- a/qstd/str.c +++ b/qstd/str.c @@ -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; +} + -- cgit v1.2.3-54-g00ecf