l10n: git.pot: v2.5.0 round 1 (65 new, 15 removed)
[gitweb.git] / Documentation / technical / api-string-list.txt
index 1dcad47f7c4f2e06795d0be915920f446e54b181..c08402b12e88930ca37cce6d3b4537d7f360852f 100644 (file)
@@ -1,8 +1,9 @@
 string-list API
 ===============
 
-The string_list API offers a data structure and functions to handle sorted
-and unsorted string lists.
+The string_list API offers a data structure and functions to handle
+sorted and unsorted string lists.  A "sorted" list is one whose
+entries are sorted by string value in `strcmp()` order.
 
 The 'string_list' struct used to be called 'path_list', but was renamed
 because it is not specific to paths.
@@ -28,20 +29,26 @@ member (you need this if you add things later) and you should set the
   `unsorted_string_list_has_string` and get it from the list using
   `string_list_lookup` for sorted lists.
 
-. Can sort an unsorted list using `sort_string_list`.
+. Can sort an unsorted list using `string_list_sort`.
+
+. Can remove duplicate items from a sorted list using
+  `string_list_remove_duplicates`.
 
 . Can remove individual items of an unsorted list using
   `unsorted_string_list_delete_item`.
 
+. Can remove items not matching a criterion from a sorted or unsorted
+  list using `filter_string_list`, or remove empty strings using
+  `string_list_remove_empty_items`.
+
 . Finally it should free the list using `string_list_clear`.
 
 Example:
 
 ----
-struct string_list list;
+struct string_list list = STRING_LIST_INIT_NODUP;
 int i;
 
-memset(&list, 0, sizeof(struct string_list));
 string_list_append(&list, "foo");
 string_list_append(&list, "bar");
 for (i = 0; i < list.nr; i++)
@@ -61,6 +68,25 @@ Functions
 
 * General ones (works with sorted and unsorted lists as well)
 
+`string_list_init`::
+
+       Initialize the members of the string_list, set `strdup_strings`
+       member according to the value of the second parameter.
+
+`filter_string_list`::
+
+       Apply a function to each item in a list, retaining only the
+       items for which the function returns true.  If free_util is
+       true, call free() on the util members of any items that have
+       to be deleted.  Preserve the order of the items that are
+       retained.
+
+`string_list_remove_empty_items`::
+
+       Remove any empty strings from the list.  If free_util is true,
+       call free() on the util members of any items that have to be
+       deleted.  Preserve the order of the items that are retained.
+
 `print_string_list`::
 
        Dump a string_list to stdout, useful mainly for debugging purposes. It
@@ -97,6 +123,12 @@ write `string_list_insert(...)->util = ...;`.
        Look up a given string in the string_list, returning the containing
        string_list_item. If the string is not found, NULL is returned.
 
+`string_list_remove_duplicates`::
+
+       Remove all but the first of consecutive entries that have the
+       same string value.  If free_util is true, call free() on the
+       util members of any items that have to be deleted.
+
 * Functions for unsorted lists only
 
 `string_list_append`::
@@ -114,9 +146,9 @@ write `string_list_insert(...)->util = ...;`.
        ownership of a malloc()ed string to a `string_list` that has
        `strdup_string` set.
 
-`sort_string_list`::
+`string_list_sort`::
 
-       Make an unsorted list sorted.
+       Sort the list's entries by string value in `strcmp()` order.
 
 `unsorted_string_list_has_string`::
 
@@ -173,3 +205,5 @@ Represents the list itself.
   You should not tamper with it.
 . Setting the `strdup_strings` member to 1 will strdup() the strings
   before adding them, see above.
+. The `compare_strings_fn` member is used to specify a custom compare
+  function, otherwise `strcmp()` is used as the default function.