From 109b6dd1881d90915e972f0d263a032bd262adb5 Mon Sep 17 00:00:00 2001 From: Omniscient <17525998+omnisci3nce@users.noreply.github.com> Date: Sun, 25 Feb 2024 17:31:17 +1100 Subject: disclaimer about some string apis not being unicode aware --- src/std/str.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/std/str.h b/src/std/str.h index 3d3cb41..f3ade5a 100644 --- a/src/std/str.h +++ b/src/std/str.h @@ -7,8 +7,9 @@ #include "defines.h" /** - * @brief Fat pointer representing a UTF8 (TODO) encoded string - * @note when using `printf` you must use %s.*s length, 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`. */ typedef struct { u8 *buf; -- cgit v1.2.3-70-g09d2 From 7e4e763d8f2e15c4f2b2a77402f4fe0c4e8b5f68 Mon Sep 17 00:00:00 2001 From: segunkayode1 Date: Mon, 26 Feb 2024 01:52:17 +1100 Subject: string subview functions --- src/std/str.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/std/str.c b/src/std/str.c index 3b2770e..1e092bc 100644 --- a/src/std/str.c +++ b/src/std/str.c @@ -41,4 +41,28 @@ 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){ + s.buf = s.buf + (ptrdiff_t)min; + s.len = max - min; + return s; +} + +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); +} + + -- cgit v1.2.3-70-g09d2 From 055b213beac82f1ca0fb10b2eebce6df3cb216b2 Mon Sep 17 00:00:00 2001 From: segunkayode1 Date: Mon, 26 Feb 2024 20:42:44 +1100 Subject: update --- src/std/str.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/std/str.c b/src/std/str.c index 1e092bc..7dafef1 100644 --- a/src/std/str.c +++ b/src/std/str.c @@ -1,6 +1,6 @@ #include "str.h" #include - +#include #include "mem.h" str8 str8_create(u8* buf, size_t len) { return (str8){ .buf = buf, .len = len }; } @@ -43,25 +43,29 @@ str8 str8_concat(arena* a, str8 left, str8 right) { return str8_create(dest, n_bytes); } -str8 str8_substr(str8 s, u64 min, u64 max){ - s.buf = s.buf + (ptrdiff_t)min; - s.len = max - min; - return s; +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){ +str8 str8_take(str8 s, u64 first_n) { return str8_substr(s, 0, first_n); } -str8 str8_drop(str8 s, u64 last_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){ +str8 str8_skip(str8 s, u64 n) { return str8_substr(s, n, s.len); } -str8 str8_chop(str8 s, u64 n){ +str8 str8_chop(str8 s, u64 n) { return str8_substr(s, 0, s.len - n); } -- cgit v1.2.3-70-g09d2 From cb4a2f1bda4d4a8220bf01dcf557d68543ebf40b Mon Sep 17 00:00:00 2001 From: Omniscient Date: Wed, 6 Mar 2024 07:19:57 +1100 Subject: chore: fmt --- src/std/str.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/src/std/str.c b/src/std/str.c index 7dafef1..1c687fa 100644 --- a/src/std/str.c +++ b/src/std/str.c @@ -1,6 +1,6 @@ #include "str.h" -#include #include +#include #include "mem.h" str8 str8_create(u8* buf, size_t len) { return (str8){ .buf = buf, .len = len }; } @@ -48,25 +48,15 @@ str8 str8_substr(str8 s, u64 min, u64 max) { assert(min < s.len); assert(max >= 0); assert(max <= s.len); - uint8_t * start = s.buf + (ptrdiff_t)min; + 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); + return (str8){ .buf = start, .len = new_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_take(str8 s, u64 first_n) { return str8_substr(s, 0, first_n); } -str8 str8_chop(str8 s, u64 n) { - return str8_substr(s, 0, s.len - 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); } -- cgit v1.2.3-70-g09d2 From a627f75cc956a463e3910a8f5f615932bad3a418 Mon Sep 17 00:00:00 2001 From: omniscient <17525998+omnisci3nce@users.noreply.github.com> Date: Tue, 5 Mar 2024 21:30:42 +1100 Subject: add string.h include --- src/std/containers/ring_queue.c | 2 ++ 1 file changed, 2 insertions(+) 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 +#include #include "defines.h" ring_queue* ring_queue_new(size_t type_size, size_t capacity, void* memory) { -- cgit v1.2.3-70-g09d2