File utilities and datatype implementation for a C-based code generator #5

Merged
abdelrahman merged 18 commits from ccodegen into main 2025-09-20 13:48:08 +00:00
2 changed files with 23 additions and 0 deletions
Showing only changes of commit 823cd652b9 - Show all commits

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