+
+/* Allocates and returns an array that points to each of the strings in SET.
+ The caller must not free or modify any of the strings. Removing a string
+ from SET invalidates the corresponding element of the returned array. The
+ caller it is responsible for freeing the returned array itself (with
+ free()).
+
+ The returned array is in the same order as observed by stringi_set_first()
+ and stringi_set_next(), that is, no particular order. */
+char **
+stringi_set_get_array (const struct stringi_set *set)
+{
+ const struct stringi_set_node *node;
+ const char *s;
+ char **array;
+ size_t i;
+
+ array = xnmalloc (stringi_set_count (set), sizeof *array);
+
+ i = 0;
+ STRINGI_SET_FOR_EACH (s, node, set)
+ array[i++] = CONST_CAST (char *, s);
+
+ return array;
+}
+
+static int
+compare_strings (const void *a_, const void *b_)
+{
+ const char *const *a = a_;
+ const char *const *b = b_;
+ return strcasecmp (*a, *b);
+}
+
+/* Allocates and returns an array that points to each of the strings in SET.
+ The caller must not free or modify any of the strings. Removing a string
+ from SET invalidates the corresponding element of the returned array. The
+ caller it is responsible for freeing the returned array itself (with
+ free()).
+
+ The returned array is ordered according to strcasecmp(). */
+char **
+stringi_set_get_sorted_array (const struct stringi_set *set)
+{
+ char **array = stringi_set_get_array (set);
+ qsort (array, stringi_set_count (set), sizeof *array, compare_strings);
+ return array;
+}