aboutsummaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2025-07-21 14:26:06 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2025-07-21 14:26:06 +0200
commit88eb8c969f6abe119994c7ab307b9be58ff076a5 (patch)
tree3a8fed52b29bdf12f5a6ac65393df8abb0c8f437 /string.c
parenta378ff1b173f7a67272e574fb1a2c275ecb9661b (diff)
feat: JSON object parsing
Diffstat (limited to 'string.c')
-rw-r--r--string.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/string.c b/string.c
index cc78719..191059e 100644
--- a/string.c
+++ b/string.c
@@ -1,16 +1,11 @@
#include "string.h"
#include <stdint.h>
+#include <stdio.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;
-}
-
// Returns 1 if strings are equal, 0 otherwise
int Str_equals(Str a, Str b) {
return (a.len == b.len) && (!a.len || !memcmp(a.data, b.data, a.len));
@@ -26,9 +21,13 @@ uint64_t Str_hash64(Str s) {
}
Str Str_copy(Arena *a, char *data, uintptr_t len) {
- Str str = {0, len};
- str.data = new (a, char, len);
+ Str str = {.data = NULL, .len = len};
+ str.data = new (a, char, len);
if (str.len)
memcpy(str.data, data, len);
return str;
}
+
+void Str_print(Str s) {
+ printf("%.*s", (int)s.len, s.data);
+}