Add wapp_str8_push_back and wapp_str8_list_empty
This commit is contained in:
parent
01f066d20c
commit
ba5e902a1d
@ -120,6 +120,15 @@ void wapp_str8_set(Str8 *str, u64 index, c8 c) {
|
|||||||
str->buf[index] = 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) {
|
bool wapp_str8_equal(Str8RO *s1, Str8RO *s2) {
|
||||||
if (s1->size != s2->size) {
|
if (s1->size != s2->size) {
|
||||||
return false;
|
return false;
|
||||||
@ -608,6 +617,17 @@ RETURN_STR8_LIST_REMOVE:
|
|||||||
return output;
|
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) {
|
internal Str8List node_to_list(Str8Node *node) {
|
||||||
Str8List output = {.first = node, .last = node, .total_size = node->string->size, .node_count = 1};
|
Str8List output = {.first = node, .last = node, .total_size = node->string->size, .node_count = 1};
|
||||||
|
|
||||||
|
@ -77,6 +77,7 @@ void wapp_str8_dealloc_buf(const Allocator *allocator, Str8 **str);
|
|||||||
*/
|
*/
|
||||||
c8 wapp_str8_get(Str8RO *str, u64 index);
|
c8 wapp_str8_get(Str8RO *str, u64 index);
|
||||||
void wapp_str8_set(Str8 *str, u64 index, c8 c);
|
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(Str8RO *s1, Str8RO *s2);
|
||||||
bool wapp_str8_equal_to_count(Str8RO* s1, Str8RO* s2, u64 count);
|
bool wapp_str8_equal_to_count(Str8RO* s1, Str8RO* s2, u64 count);
|
||||||
Str8 wapp_str8_slice(Str8RO *str, u64 start, u64 end);
|
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_front(Str8List *list);
|
||||||
Str8Node *wapp_str8_list_pop_back(Str8List *list);
|
Str8Node *wapp_str8_list_pop_back(Str8List *list);
|
||||||
Str8Node *wapp_str8_list_remove(Str8List *list, u64 index);
|
Str8Node *wapp_str8_list_remove(Str8List *list, u64 index);
|
||||||
|
void wapp_str8_list_empty(Str8List *list);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
END_C_LINKAGE
|
END_C_LINKAGE
|
||||||
|
@ -236,6 +236,28 @@ TestFuncResult test_str8_set(void) {
|
|||||||
return wapp_tester_result(result);
|
return wapp_tester_result(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TestFuncResult test_str8_push_back(void) {
|
||||||
|
bool result;
|
||||||
|
|
||||||
|
Str8 expected = wapp_str8_lit("Abdelrahman");
|
||||||
|
Str8 buf = wapp_str8_buf(64);
|
||||||
|
wapp_str8_push_back(&buf, 'A');
|
||||||
|
wapp_str8_push_back(&buf, 'b');
|
||||||
|
wapp_str8_push_back(&buf, 'd');
|
||||||
|
wapp_str8_push_back(&buf, 'e');
|
||||||
|
wapp_str8_push_back(&buf, 'l');
|
||||||
|
wapp_str8_push_back(&buf, 'r');
|
||||||
|
wapp_str8_push_back(&buf, 'a');
|
||||||
|
wapp_str8_push_back(&buf, 'h');
|
||||||
|
wapp_str8_push_back(&buf, 'm');
|
||||||
|
wapp_str8_push_back(&buf, 'a');
|
||||||
|
wapp_str8_push_back(&buf, 'n');
|
||||||
|
|
||||||
|
result = wapp_str8_equal(&buf, &expected);
|
||||||
|
|
||||||
|
return wapp_tester_result(result);
|
||||||
|
}
|
||||||
|
|
||||||
TestFuncResult test_str8_equal(void) {
|
TestFuncResult test_str8_equal(void) {
|
||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ TestFuncResult test_str8_alloc_concat(void);
|
|||||||
TestFuncResult test_str8_get_index_within_bounds(void);
|
TestFuncResult test_str8_get_index_within_bounds(void);
|
||||||
TestFuncResult test_str8_get_index_out_of_bounds(void);
|
TestFuncResult test_str8_get_index_out_of_bounds(void);
|
||||||
TestFuncResult test_str8_set(void);
|
TestFuncResult test_str8_set(void);
|
||||||
|
TestFuncResult test_str8_push_back(void);
|
||||||
TestFuncResult test_str8_equal(void);
|
TestFuncResult test_str8_equal(void);
|
||||||
TestFuncResult test_str8_slice(void);
|
TestFuncResult test_str8_slice(void);
|
||||||
TestFuncResult test_str8_concat_capped(void);
|
TestFuncResult test_str8_concat_capped(void);
|
||||||
|
@ -246,3 +246,19 @@ TestFuncResult test_str8_list_remove(void) {
|
|||||||
|
|
||||||
return wapp_tester_result(result);
|
return wapp_tester_result(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TestFuncResult test_str8_list_empty(void) {
|
||||||
|
bool result;
|
||||||
|
|
||||||
|
Str8List list = {0};
|
||||||
|
wapp_str8_list_push_back(&list, &wapp_str8_node_from_cstr("Hello"));
|
||||||
|
wapp_str8_list_push_back(&list, &wapp_str8_node_from_cstr("from"));
|
||||||
|
wapp_str8_list_push_back(&list, &wapp_str8_node_from_cstr("wizapp"));
|
||||||
|
wapp_str8_list_push_back(&list, &wapp_str8_node_from_cstr("stdlib"));
|
||||||
|
|
||||||
|
wapp_str8_list_empty(&list);
|
||||||
|
|
||||||
|
result = list.first == NULL && list.last == NULL && list.node_count == 0 && list.total_size == 0;
|
||||||
|
|
||||||
|
return wapp_tester_result(result);
|
||||||
|
}
|
||||||
|
@ -14,6 +14,7 @@ TestFuncResult test_str8_list_insert(void);
|
|||||||
TestFuncResult test_str8_list_pop_front(void);
|
TestFuncResult test_str8_list_pop_front(void);
|
||||||
TestFuncResult test_str8_list_pop_back(void);
|
TestFuncResult test_str8_list_pop_back(void);
|
||||||
TestFuncResult test_str8_list_remove(void);
|
TestFuncResult test_str8_list_remove(void);
|
||||||
|
TestFuncResult test_str8_list_empty(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
END_C_LINKAGE
|
END_C_LINKAGE
|
||||||
|
Loading…
Reference in New Issue
Block a user