Add a new function that appends the strings from one string_list onto another string_list. Signed-off-by: Michael Haggerty <mhagger@xxxxxxxxxxxx> --- Documentation/technical/api-string-list.txt | 10 ++++++++-- string-list.c | 9 +++++++++ string-list.h | 8 ++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Documentation/technical/api-string-list.txt b/Documentation/technical/api-string-list.txt index 20be348..2072cf7 100644 --- a/Documentation/technical/api-string-list.txt +++ b/Documentation/technical/api-string-list.txt @@ -22,8 +22,9 @@ member (you need this if you add things later) and you should set the `nr` and `alloc` members in that case, too. . Adds new items to the list, using `string_list_append`, - `string_list_append_nodup`, `string_list_insert`, - `string_list_split`, and/or `string_list_split_in_place`. + `string_list_append_nodup`, `string_list_append_list`, + `string_list_insert`, `string_list_split`, and/or + `string_list_split_in_place`. . Can check if a string is in the list using `string_list_has_string` or `unsorted_string_list_has_string` and get it from the list using @@ -141,6 +142,11 @@ write `string_list_insert(...)->util = ...;`. ownership of a malloc()ed string to a `string_list` that has `strdup_string` set. +`string_list_append_list`:: + + Append the strings from one string_list to the end of another + one. + `sort_string_list`:: Sort the list's entries by string value in `strcmp()` order. diff --git a/string-list.c b/string-list.c index aabb25e..803acd1 100644 --- a/string-list.c +++ b/string-list.c @@ -212,6 +212,15 @@ struct string_list_item *string_list_append(struct string_list *list, list->strdup_strings ? xstrdup(string) : (char *)string); } +void string_list_append_list(struct string_list *dst, struct string_list *src) +{ + struct string_list_item *item; + + ALLOC_GROW(dst->items, dst->nr + src->nr, dst->alloc); + for_each_string_list_item(item, src) + string_list_append(dst, item->string); +} + /* Yuck */ static compare_strings_fn compare_for_qsort; diff --git a/string-list.h b/string-list.h index de6769c..7b0ae86 100644 --- a/string-list.h +++ b/string-list.h @@ -76,6 +76,14 @@ void string_list_remove_duplicates(struct string_list *sorted_list, int free_uti struct string_list_item *string_list_append(struct string_list *list, const char *string); /* + * Add all strings from src to the end of dst. If dst->strdup_string + * is set, then the strings are copied; otherwise the new + * string_list_entries refer to the input strings. src is left + * unchanged. + */ +void string_list_append_list(struct string_list *dst, struct string_list *src); + +/* * Like string_list_append(), except string is never copied. When * list->strdup_strings is set, this function can be used to hand * ownership of a malloc()ed string to list without making an extra -- 1.8.4.3 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html