aboutsummaryrefslogtreecommitdiff
path: root/src/std/str.c
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-04-08 13:14:27 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-04-08 13:15:01 +0200
commitcf534d762754860ed5b714974f99acd282d48b3b (patch)
treebf22341cedfb50ee7bcd4e15f85add2329783f31 /src/std/str.c
parent630fcb1846aed16b9ab62bcf700f668883f4521f (diff)
Restructure into src/{std,json}/
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'src/std/str.c')
-rw-r--r--src/std/str.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/std/str.c b/src/std/str.c
new file mode 100644
index 0000000..714cc59
--- /dev/null
+++ b/src/std/str.c
@@ -0,0 +1,32 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "memory.h"
+#include "str.h"
+
+u64 Str_hash64(Str s) {
+ u64 h = 0x100;
+ for (size i = 0; i < s.len; i++) {
+ h ^= s.data[i] & 255;
+ h *= 1111111111111111111;
+ }
+ return h;
+}
+
+Str Str_copy(Arena *a, byte *data, size len) {
+ Str str = {0};
+ str.len = len;
+ str.data = new(a, byte, len);
+ if (str.len) memcpy(str.data, data, len);
+ return str;
+}
+
+StrView Str_view(byte *data, size len) {
+ StrView str = {0};
+ str.len = len;
+ str.data = data;
+ return str;
+}
+
+Str StrView_copy(Arena *a, StrView s) { return Str_copy(a, s.data, s.len); }