summaryrefslogtreecommitdiff
path: root/src/std
diff options
context:
space:
mode:
authoromnisci3nce <omniscient.oce@gmail.com>2024-07-17 14:45:31 +1000
committeromnisci3nce <omniscient.oce@gmail.com>2024-07-17 14:45:31 +1000
commitf8641a5cc4c8baf1f0a7be3685afc219d90143d9 (patch)
tree6f6edf43f88b456933330ec83a203bf2f414bea4 /src/std
parentb9315f9cb625db09c3c41d8adf5230a67510bef7 (diff)
whole thing is compiling and running again
Diffstat (limited to 'src/std')
-rw-r--r--src/std/str.c88
-rw-r--r--src/std/str.h2
2 files changed, 45 insertions, 45 deletions
diff --git a/src/std/str.c b/src/std/str.c
index e15c38f..2aac15f 100644
--- a/src/std/str.c
+++ b/src/std/str.c
@@ -3,62 +3,62 @@
#include <string.h>
#include "mem.h"
-// str8 str8_create(u8* buf, size_t len) { return (str8){ .buf = buf, .len = len }; }
+Str8 Str8_create(u8* buf, size_t len) { return (Str8){ .buf = buf, .len = len }; }
-// str8 str8_cstr_view(char* string) { return str8_create((u8*)string, strlen(string)); }
+Str8 Str8_cstr_view(char* string) { return Str8_create((u8*)string, strlen(string)); }
-// bool str8_equals(str8 a, str8 b) {
-// if (a.len != b.len) {
-// return false;
-// }
+bool Str8_equals(Str8 a, Str8 b) {
+ if (a.len != b.len) {
+ return false;
+ }
-// for (size_t i = 0; i < a.len; i++) {
-// if (a.buf[i] != b.buf[i]) {
-// return false;
-// }
-// }
-// return true;
-// }
+ for (size_t i = 0; i < a.len; i++) {
+ if (a.buf[i] != b.buf[i]) {
+ return false;
+ }
+ }
+ return true;
+}
-// char* str8_to_cstr(arena* a, str8 s) {
-// bool is_null_terminated = s.buf[s.len - 1] == 0;
-// size_t n_bytes = is_null_terminated ? s.len : s.len + 1;
+char* Str8_to_cstr(arena* a, Str8 s) {
+ bool is_null_terminated = s.buf[s.len - 1] == 0;
+ size_t n_bytes = is_null_terminated ? s.len : s.len + 1;
-// u8* dest = arena_alloc(a, n_bytes);
+ u8* dest = arena_alloc(a, n_bytes);
-// memcpy(dest, s.buf, s.len);
-// if (is_null_terminated) {
-// dest[s.len] = '\0';
-// }
-// return (char*)dest;
-// }
+ memcpy(dest, s.buf, s.len);
+ if (is_null_terminated) {
+ dest[s.len] = '\0';
+ }
+ return (char*)dest;
+}
-// str8 str8_concat(arena* a, str8 left, str8 right) {
-// size_t n_bytes = left.len + right.len + 1;
+Str8 Str8_concat(arena* a, Str8 left, Str8 right) {
+ size_t n_bytes = left.len + right.len + 1;
-// u8* dest = arena_alloc(a, n_bytes);
-// memcpy(dest, left.buf, left.len);
-// memcpy(dest + right.len, right.buf, right.len);
+ u8* dest = arena_alloc(a, n_bytes);
+ memcpy(dest, left.buf, left.len);
+ memcpy(dest + right.len, right.buf, right.len);
-// dest[n_bytes - 1] = '\0';
+ dest[n_bytes - 1] = '\0';
-// return str8_create(dest, n_bytes);
-// }
+ return Str8_create(dest, n_bytes);
+}
-// str8 str8_substr(str8 s, u64 min, u64 max) {
-// assert(min >= 0);
-// assert(min < s.len);
-// assert(max >= 0);
-// assert(max <= s.len);
-// uint8_t* start = s.buf + (ptrdiff_t)min;
-// size_t new_len = max - min;
-// return (str8){ .buf = start, .len = new_len };
-// }
+Str8 Str8_substr(Str8 s, u64 min, u64 max) {
+ assert(min >= 0);
+ assert(min < s.len);
+ assert(max >= 0);
+ assert(max <= s.len);
+ uint8_t* start = s.buf + (ptrdiff_t)min;
+ size_t new_len = max - min;
+ return (Str8){ .buf = start, .len = new_len };
+}
-// str8 str8_take(str8 s, u64 first_n) { return str8_substr(s, 0, first_n); }
+Str8 Str8_take(Str8 s, u64 first_n) { return Str8_substr(s, 0, first_n); }
-// str8 str8_drop(str8 s, u64 last_n) { return str8_substr(s, s.len - last_n, s.len); }
+Str8 Str8_drop(Str8 s, u64 last_n) { return Str8_substr(s, s.len - last_n, s.len); }
-// str8 str8_skip(str8 s, u64 n) { return str8_substr(s, n, s.len); }
+Str8 Str8_skip(Str8 s, u64 n) { return Str8_substr(s, n, s.len); }
-// str8 str8_chop(str8 s, u64 n) { return str8_substr(s, 0, s.len - n); }
+Str8 Str8_chop(Str8 s, u64 n) { return Str8_substr(s, 0, s.len - n); }
diff --git a/src/std/str.h b/src/std/str.h
index e9c4098..9e712e6 100644
--- a/src/std/str.h
+++ b/src/std/str.h
@@ -31,7 +31,7 @@ typedef struct {
#define str8(s) \
(Str8) { (u8*)s, ((sizeof(s) / sizeof(*(s)) - 1)) }
-Str8 str8_create(u8* buf, size_t len);
+Str8 Str8_create(u8* buf, size_t len);
/** @brief Return a null-terminated C string cloned onto an arena */
char* Str8_to_cstr(arena* a, Str8 s);