aboutsummaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2025-01-31 08:02:09 +0100
committerMartin Kagamino Lehoux <martin@lehoux.net>2025-01-31 08:02:09 +0100
commit8a9e6b1bd3be1041792311a86d8aac68b659e891 (patch)
tree2a62729da17b2e6669c3d71a162525ff37e42c6a /string.c
feat: First version, failing json parse string
Diffstat (limited to 'string.c')
-rw-r--r--string.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/string.c b/string.c
new file mode 100644
index 0000000..509163f
--- /dev/null
+++ b/string.c
@@ -0,0 +1,33 @@
+#include "string.h"
+
+#include <stdint.h>
+#include <string.h>
+
+#include "memory.h"
+
+Str *Str_new(Arena *a, uintptr_t len) {
+ Str *s = new (a, Str, 1);
+ s->data = new (a, char, len);
+ return s;
+}
+
+int Str_equals(Str a, Str b) {
+ return (a.len == b.len) && (!a.len || !memcmp(a.data, b.data, a.len));
+}
+
+uint64_t Str_hash64(Str s) {
+ uint64_t h = 0x100;
+ for (ptrdiff_t i = 0; i < s.len; i++) {
+ h ^= s.data[i] & 255;
+ h *= 1111111111111111111;
+ }
+ return h;
+}
+
+Str Str_copy(Arena *a, char *data, uintptr_t len) {
+ Str str = {0};
+ str.data = new (a, char, len);
+ if (str.len)
+ memcpy(str.data, data, len);
+ return str;
+}