aboutsummaryrefslogtreecommitdiff
path: root/src/std/str.c
diff options
context:
space:
mode:
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); }