summaryrefslogtreecommitdiff
path: root/src/std
diff options
context:
space:
mode:
Diffstat (limited to 'src/std')
-rw-r--r--src/std/containers/darray.h11
-rw-r--r--src/std/mem.h6
-rw-r--r--src/std/str.c88
-rw-r--r--src/std/str.h36
4 files changed, 68 insertions, 73 deletions
diff --git a/src/std/containers/darray.h b/src/std/containers/darray.h
index b15d269..b3dbd06 100644
--- a/src/std/containers/darray.h
+++ b/src/std/containers/darray.h
@@ -86,6 +86,7 @@
size_t new_capacity = \
d->capacity > 0 ? d->capacity * DARRAY_RESIZE_FACTOR : DARRAY_DEFAULT_CAPACITY; \
T *resized = Type##_darray_resize(d, new_capacity); \
+ (void)resized; \
} \
\
d->data[d->len] = value; \
@@ -97,6 +98,7 @@
size_t new_capacity = \
d->capacity > 0 ? d->capacity * DARRAY_RESIZE_FACTOR : DARRAY_DEFAULT_CAPACITY; \
T *resized = Type##_darray_resize(d, new_capacity); \
+ (void)resized; \
} \
\
T *place = d->data + d->len; \
@@ -116,6 +118,7 @@
size_t new_capacity = \
d->capacity > 0 ? d->capacity * DARRAY_RESIZE_FACTOR : DARRAY_DEFAULT_CAPACITY; \
T *resized = Type##_darray_resize(d, new_capacity); \
+ (void)resized; \
} \
\
/* shift existing data after index */ \
@@ -136,14 +139,6 @@
\
PREFIX size_t Type##_darray_len(Type##_darray *d) { return d->len; } \
\
- PREFIX void Type##_darray_print(Type##_darray *d) { \
- printf("len: %zu ", d->len); \
- printf("capacity: %zu\n", d->capacity); \
- for (int i = 0; i < d->len; i++) { \
- printf("Index %d holds value %d\n", i, d->data[i]); \
- } \
- } \
- \
PREFIX Type##_darray_iter Type##_darray_iter_new(Type##_darray *d) { \
Type##_darray_iter iterator; \
iterator.array = d; \
diff --git a/src/std/mem.h b/src/std/mem.h
index 8ab6f46..789cba3 100644
--- a/src/std/mem.h
+++ b/src/std/mem.h
@@ -80,12 +80,12 @@ void void_pool_dealloc(void_pool* pool, u32 raw_handle);
void_pool p = void_pool_create(a, "\"" #Name "\"", cap, entry_size); \
return (Name##_pool){ .inner = p }; \
} \
- static inline T* Name##_pool_get(Name##_pool* pool, Name##_handle handle) { \
+ static inline T* Name##_pool_get(Name##_pool* pool, Name##Handle handle) { \
return (T*)void_pool_get(&pool->inner, handle.raw); \
} \
- static inline T* Name##_pool_alloc(Name##_pool* pool, Name##_handle* out_handle) { \
+ static inline T* Name##_pool_alloc(Name##_pool* pool, Name##Handle* out_handle) { \
return (T*)void_pool_alloc(&pool->inner, &out_handle->raw); \
} \
- static inline void Name##_pool_dealloc(Name##_pool* pool, Name##_handle handle) { \
+ static inline void Name##_pool_dealloc(Name##_pool* pool, Name##Handle handle) { \
void_pool_dealloc(&pool->inner, handle.raw); \
}\
diff --git a/src/std/str.c b/src/std/str.c
index 07a8e73..e15c38f 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 1ebecac..e9c4098 100644
--- a/src/std/str.h
+++ b/src/std/str.h
@@ -23,30 +23,30 @@
typedef struct {
u8* buf;
size_t len;
-} str8;
+} Str8;
// --- Constructors
/** @brief Take a string literal and turn it into a `str8` */
-#define str8lit(s) \
- (str8) { (u8*)s, ((sizeof(s) / sizeof(*(s)) - 1)) }
+#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);
+char* Str8_to_cstr(arena* a, Str8 s);
-#define cstr(a, s) (str8_to_cstr(a, s)) // Shorthand
+#define cstr(a, s) (Str8_to_cstr(a, s)) // Shorthand
-/** @brief Return a str8 that references a statically allocated string.
+/** @brief Return a Str8 that references a statically allocated string.
`string` therefore must already be null-terminated.
@note The backing `string` cannot be modified. */
-str8 str8_cstr_view(char* string);
+Str8 Str8_cstr_view(char* string);
// --- Comparisons
/** @brief Compare two strings for exact equality */
-bool str8_equals(str8 a, str8 b);
+bool Str8_equals(Str8 a, Str8 b);
/**
* @brief Compare the first `first_nchars` of each string for equality
@@ -55,27 +55,27 @@ bool str8_equals(str8 a, str8 b);
* @returns 0 if they are fully equal up until `first_nchars`, i.e they never differed, else it
returns the index at which the first string differed from the second string.
*/
-size_t str8_nequals(str8 a, str8 b, size_t first_nchars);
+size_t Str8_nequals(Str8 a, Str8 b, size_t first_nchars);
-bool str8_ends_with(str8 input_str, str8 suffix);
+bool Str8_ends_with(Str8 input_str, Str8 suffix);
/// --- Subviews
-str8 str8_substr(str8 s, u64 min, u64 max);
+Str8 Str8_substr(Str8 s, u64 min, u64 max);
/** @brief Keeps only the `first_n` chars of `s` */
-str8 str8_take(str8 s, u64 first_n);
+Str8 Str8_take(Str8 s, u64 first_n);
/** @brief Keeps only the `last_n` chars of `s` */
-str8 str8_drop(str8 s, u64 last_n);
+Str8 Str8_drop(Str8 s, u64 last_n);
/** @brief Keeps everything after the first `n` chars of `s` */
-str8 str8_skip(str8 s, u64 n);
+Str8 Str8_skip(Str8 s, u64 n);
/** @brief Keeps everything before the last `n` chars of `s` */
-str8 str8_chop(str8 s, u64 n);
+Str8 Str8_chop(Str8 s, u64 n);
-str8 str8_concat(arena* a, str8 left, str8 right);
+Str8 Str8_concat(arena* a, Str8 left, Str8 right);
/// --- Misc
-static inline bool str8_is_null_term(str8 a) {
+static inline bool Str8_is_null_term(Str8 a) {
return a.buf[a.len] == 0; // This doesn't seem safe. YOLO
}