Add to_lower and to_upper functions

This commit is contained in:
Abdelrahman Said 2025-09-07 17:21:52 +01:00
parent 9ddd0d6113
commit 823cd652b9
2 changed files with 23 additions and 0 deletions

View File

@ -4,6 +4,7 @@
#include "../../../common/aliases/aliases.h"
#include "../../../common/assert/assert.h"
#include "../../mem_allocator/mem_allocator.h"
#include <ctype.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
@ -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;

View File

@ -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