Compare commits

1 Commits

Author SHA1 Message Date
4291248ec1 noh_string_replace: Use arena from source string 2026-08-11 16:22:28 +02:00

View File

@@ -381,6 +381,8 @@ void noh_string_append_cstr(Noh_String *string, const char *cstr);
void noh_string_append_null(Noh_String *string); void noh_string_append_null(Noh_String *string);
// Replace all occurrences of one character with another in a Noh_String. // Replace all occurrences of one character with another in a Noh_String.
// If the string does not use an arena, its original data will be cleared.
// If it does not use an arena, this data will remain orphaned in the arena.
void noh_string_replace(Noh_String *string, const char from, const char to); void noh_string_replace(Noh_String *string, const char from, const char to);
// Frees a Noh_String, freeing the memory used and settings the count and capacity to 0. // Frees a Noh_String, freeing the memory used and settings the count and capacity to 0.
@@ -922,6 +924,7 @@ void noh_string_append_null(Noh_String *string) {
void noh_string_replace(Noh_String *string, const char from, const char to) { void noh_string_replace(Noh_String *string, const char from, const char to) {
Noh_String result = {0}; Noh_String result = {0};
result.arena = string->arena;
for (size_t i = 0; i < string->count; i++) { for (size_t i = 0; i < string->count; i++) {
if (result.arena) { if (result.arena) {
if (string->elems[i] == from) { if (string->elems[i] == from) {