summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--qstd/str.c31
-rw-r--r--qstd/str.h7
2 files changed, 38 insertions, 0 deletions
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;
+}
+
diff --git a/qstd/str.h b/qstd/str.h
index da9bf36..308e92d 100644
--- a/qstd/str.h
+++ b/qstd/str.h
@@ -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