[utils] adding cstring_array_extend and string_tree_clear
This commit is contained in:
@@ -1110,6 +1110,18 @@ cstring_array *cstring_array_from_strings(char **strings, size_t n) {
|
|||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cstring_array_extend(cstring_array *array, cstring_array *other) {
|
||||||
|
if (array == NULL || other == NULL) return false;
|
||||||
|
size_t n = cstring_array_num_strings(other);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < n; i++) {
|
||||||
|
char *s_i = cstring_array_get_string(other, i);
|
||||||
|
cstring_array_add_string(array, s_i);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline size_t cstring_array_capacity(cstring_array *self) {
|
inline size_t cstring_array_capacity(cstring_array *self) {
|
||||||
return self->str->m;
|
return self->str->m;
|
||||||
}
|
}
|
||||||
@@ -1318,6 +1330,12 @@ inline void string_tree_finalize_token(string_tree_t *self) {
|
|||||||
uint32_array_push(self->token_indices, (uint32_t)cstring_array_num_strings(self->strings));
|
uint32_array_push(self->token_indices, (uint32_t)cstring_array_num_strings(self->strings));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void string_tree_clear(string_tree_t *self) {
|
||||||
|
uint32_array_clear(self->token_indices);
|
||||||
|
uint32_array_push(self->token_indices, 0);
|
||||||
|
cstring_array_clear(self->strings);
|
||||||
|
}
|
||||||
|
|
||||||
// terminated
|
// terminated
|
||||||
inline void string_tree_add_string(string_tree_t *self, char *str) {
|
inline void string_tree_add_string(string_tree_t *self, char *str) {
|
||||||
cstring_array_add_string(self->strings, str);
|
cstring_array_add_string(self->strings, str);
|
||||||
|
|||||||
@@ -208,6 +208,8 @@ void cstring_array_clear(cstring_array *self);
|
|||||||
cstring_array *cstring_array_from_char_array(char_array *str);
|
cstring_array *cstring_array_from_char_array(char_array *str);
|
||||||
cstring_array *cstring_array_from_strings(char **strings, size_t n);
|
cstring_array *cstring_array_from_strings(char **strings, size_t n);
|
||||||
|
|
||||||
|
bool cstring_array_extend(cstring_array *array, cstring_array *other);
|
||||||
|
|
||||||
// Convert cstring_array to an array of n C strings and destroy the cstring_array
|
// Convert cstring_array to an array of n C strings and destroy the cstring_array
|
||||||
char **cstring_array_to_strings(cstring_array *self);
|
char **cstring_array_to_strings(cstring_array *self);
|
||||||
|
|
||||||
@@ -285,6 +287,8 @@ void string_tree_add_string_len(string_tree_t *self, char *str, size_t len);
|
|||||||
void string_tree_append_string(string_tree_t *self, char *str);
|
void string_tree_append_string(string_tree_t *self, char *str);
|
||||||
void string_tree_append_string_len(string_tree_t *self, char *str, size_t len);
|
void string_tree_append_string_len(string_tree_t *self, char *str, size_t len);
|
||||||
|
|
||||||
|
void string_tree_clear(string_tree_t *self);
|
||||||
|
|
||||||
uint32_t string_tree_num_tokens(string_tree_t *self);
|
uint32_t string_tree_num_tokens(string_tree_t *self);
|
||||||
uint32_t string_tree_num_strings(string_tree_t *self);
|
uint32_t string_tree_num_strings(string_tree_t *self);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user