[utils] cstring_array (contiguous) to array of malloc'd strings

This commit is contained in:
Al
2015-07-25 12:13:50 -04:00
parent e9277d7339
commit 2adaf475c2
2 changed files with 14 additions and 0 deletions

View File

@@ -695,6 +695,18 @@ cstring_array *cstring_array_split(char *str, const char *separator, size_t sepa
return string_array;
}
char **cstring_array_to_strings(cstring_array *self) {
char **strings = malloc(self->indices->n * sizeof(char *));
for (int i = 0; i < cstring_array_num_strings(self); i++) {
char *str = cstring_array_get_string(self, i);
strings[i] = strdup(str);
}
cstring_array_destroy(self);
return strings;
}
string_tree_t *string_tree_new_size(size_t size) {
string_tree_t *self = malloc(sizeof(string_tree_t));

View File

@@ -141,6 +141,8 @@ void cstring_array_clear(cstring_array *self);
cstring_array *cstring_array_from_char_array(char_array *str);
char **cstring_array_to_strings(cstring_array *self);
cstring_array *cstring_array_split(char *str, const char *separator, size_t separator_len, int *count);
void cstring_array_join_strings(cstring_array *self, char *separator, int count, ...);