Add wapp_str8_push_back and wapp_str8_list_empty

This commit is contained in:
2025-02-22 17:48:04 +00:00
parent 01f066d20c
commit ba5e902a1d
6 changed files with 62 additions and 0 deletions

View File

@@ -120,6 +120,15 @@ void wapp_str8_set(Str8 *str, u64 index, c8 c) {
str->buf[index] = c;
}
void wapp_str8_push_back(Str8 *str, c8 c) {
if (!(str->size < str->capacity)) {
return;
}
u64 index = (str->size)++;
wapp_str8_set(str, index, c);
}
bool wapp_str8_equal(Str8RO *s1, Str8RO *s2) {
if (s1->size != s2->size) {
return false;
@@ -608,6 +617,17 @@ RETURN_STR8_LIST_REMOVE:
return output;
}
void wapp_str8_list_empty(Str8List *list) {
if (!list) {
return;
}
u64 count = list->node_count;
for (u64 i = 0; i < count; ++i) {
wapp_str8_list_pop_back(list);
}
}
internal Str8List node_to_list(Str8Node *node) {
Str8List output = {.first = node, .last = node, .total_size = node->string->size, .node_count = 1};

View File

@@ -77,6 +77,7 @@ void wapp_str8_dealloc_buf(const Allocator *allocator, Str8 **str);
*/
c8 wapp_str8_get(Str8RO *str, u64 index);
void wapp_str8_set(Str8 *str, u64 index, c8 c);
void wapp_str8_push_back(Str8 *str, c8 c);
bool wapp_str8_equal(Str8RO *s1, Str8RO *s2);
bool wapp_str8_equal_to_count(Str8RO* s1, Str8RO* s2, u64 count);
Str8 wapp_str8_slice(Str8RO *str, u64 start, u64 end);
@@ -113,6 +114,7 @@ void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index);
Str8Node *wapp_str8_list_pop_front(Str8List *list);
Str8Node *wapp_str8_list_pop_back(Str8List *list);
Str8Node *wapp_str8_list_remove(Str8List *list, u64 index);
void wapp_str8_list_empty(Str8List *list);
#ifdef __cplusplus
END_C_LINKAGE