summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-03-05 21:31:01 +1100
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-03-05 21:31:01 +1100
commit428765380da3e7fdb8122e440b5d4065620fc8fb (patch)
tree045c1ea373fe3a71f46fca5a47d3678afb656be6
parent3854bef8b853a369c4fc3a39abff5e2e9cd77625 (diff)
parenta627f75cc956a463e3910a8f5f615932bad3a418 (diff)
Merge branch 'master' into cel-41-port-over-a-basic-3d-scene-example
-rw-r--r--src/std/containers/ring_queue.c2
-rw-r--r--src/std/str.c22
-rw-r--r--src/std/str.h2
3 files changed, 23 insertions, 3 deletions
diff --git a/src/std/containers/ring_queue.c b/src/std/containers/ring_queue.c
index a9d3506..8bfc10b 100644
--- a/src/std/containers/ring_queue.c
+++ b/src/std/containers/ring_queue.c
@@ -1,5 +1,7 @@
#include "ring_queue.h"
+
#include <stdlib.h>
+#include <string.h>
#include "defines.h"
ring_queue* ring_queue_new(size_t type_size, size_t capacity, void* memory) {
diff --git a/src/std/str.c b/src/std/str.c
index 3b2770e..1c687fa 100644
--- a/src/std/str.c
+++ b/src/std/str.c
@@ -1,6 +1,6 @@
#include "str.h"
+#include <assert.h>
#include <string.h>
-
#include "mem.h"
str8 str8_create(u8* buf, size_t len) { return (str8){ .buf = buf, .len = len }; }
@@ -41,4 +41,22 @@ str8 str8_concat(arena* a, str8 left, str8 right) {
dest[n_bytes - 1] = '\0';
return str8_create(dest, n_bytes);
-} \ No newline at end of file
+}
+
+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_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_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 9f96430..9d30cba 100644
--- a/src/std/str.h
+++ b/src/std/str.h
@@ -14,7 +14,7 @@
#include "mem.h"
/**
- * @brief Fat pointer representing a UTF8 encoded string
+ * @brief Fat pointer representing a UTF8 (TODO some APIs supporting utf8) encoded string
* @note when using `printf` you must use %s.*s length, string until our own modified
print routines are written. alternatively wrap in `cstr()` and pass to `%s`.
*/