From 823cd652b91acfa769d551497f1979f162e865fb Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sun, 7 Sep 2025 17:21:52 +0100 Subject: [PATCH] Add to_lower and to_upper functions --- src/primitives/strings/str8/str8.c | 21 +++++++++++++++++++++ src/primitives/strings/str8/str8.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/src/primitives/strings/str8/str8.c b/src/primitives/strings/str8/str8.c index 76c1ddb..f8038aa 100644 --- a/src/primitives/strings/str8/str8.c +++ b/src/primitives/strings/str8/str8.c @@ -4,6 +4,7 @@ #include "../../../common/aliases/aliases.h" #include "../../../common/assert/assert.h" #include "../../mem_allocator/mem_allocator.h" +#include #include #include #include @@ -240,6 +241,26 @@ void wapp_str8_format(Str8 *dst, const char *format, ...) { va_end(args2); } +void wapp_str8_to_lower(Str8 *dst, Str8RO *src) { + wapp_debug_assert(src != NULL && dst != NULL, "`dst` and `src` should not be NULL"); + wapp_debug_assert(dst->capacity >= src->capacity, "`dst` does not have enough capacity"); + + dst->size = src->size; + for (u64 i = 0; i < src->size; ++i) { + wapp_str8_set(dst, i, tolower(wapp_str8_get(src, i))); + } +} + +void wapp_str8_to_upper(Str8 *dst, Str8RO *src) { + wapp_debug_assert(src != NULL && dst != NULL, "`dst` and `src` should not be NULL"); + wapp_debug_assert(dst->capacity >= src->capacity, "`dst` does not have enough capacity"); + + dst->size = src->size; + for (u64 i = 0; i < src->size; ++i) { + wapp_str8_set(dst, i, toupper(wapp_str8_get(src, i))); + } +} + i64 wapp_str8_find(Str8RO *str, Str8RO substr) { if (!str || substr.size > str->size) { return -1; diff --git a/src/primitives/strings/str8/str8.h b/src/primitives/strings/str8/str8.h index b74ffc8..74321d3 100644 --- a/src/primitives/strings/str8/str8.h +++ b/src/primitives/strings/str8/str8.h @@ -97,6 +97,8 @@ 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); void wapp_str8_format(Str8 *dst, const char *format, ...); +void wapp_str8_to_lower(Str8 *dst, Str8RO *src); +void wapp_str8_to_upper(Str8 *dst, Str8RO *src); /** * Str8 find functions