diff --git a/src/core/strings/str8/str8.c b/src/core/strings/str8/str8.c index dc53ba3..5510285 100644 --- a/src/core/strings/str8/str8.c +++ b/src/core/strings/str8/str8.c @@ -176,6 +176,17 @@ void wapp_str8_copy_str8_capped(Str8 *dst, Str8RO *src) { dst->size = to_copy; } +void wapp_str8_copy_to_cstr(char *dst, Str8RO *src, u64 dst_capacity) { + if (!dst || !src) { + return; + } + + u64 to_copy = src->size < dst_capacity ? src->size : dst_capacity - 1; + + memset(dst, 0, dst_capacity); + memcpy(dst, src->buf, to_copy); +} + i64 wapp_str8_find(Str8RO *str, Str8RO substr) { if (substr.size > str->size) { return -1; @@ -340,7 +351,7 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *d } u64 capacity = list->total_size + (delimiter->size * (list->node_count - 1)); - Str8 *output = wapp_str8_buf_alloc(allocator, capacity); + Str8 *output = wapp_str8_buf_alloc(allocator, capacity * 2); // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // MSVC Spectre mitigation warnings diff --git a/src/core/strings/str8/str8.h b/src/core/strings/str8/str8.h index 84c620a..39644b6 100644 --- a/src/core/strings/str8/str8.h +++ b/src/core/strings/str8/str8.h @@ -72,6 +72,7 @@ Str8 *wapp_str8_concat(const Allocator *allocator, Str8 *dst, Str8RO *src); void wapp_str8_concat_capped(Str8 *dst, Str8RO *src); void wapp_str8_copy_cstr_capped(Str8 *dst, const char *src); void wapp_str8_copy_str8_capped(Str8 *dst, Str8RO *src); +void wapp_str8_copy_to_cstr(char *dst, Str8RO *src, u64 dst_capacity); /** * Str8 find functions @@ -91,6 +92,8 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8R /** * Str8 list utilities */ +#define wapp_str8_node_from_cstr(STRING) ((Str8Node){.string = &wapp_str8_lit(STRING)}) +#define wapp_str8_node_from_str8(STRING) ((Str8Node){.string = &STRING}) Str8Node *wapp_str8_list_get(const Str8List *list, u64 index); void wapp_str8_list_push_front(Str8List *list, Str8Node *node); void wapp_str8_list_push_back(Str8List *list, Str8Node *node);