[PATCH 3/4] string-list: add for_each_string_list()

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jay Soffian
Date: Wednesday, February 18, 2009 - 10:14 pm

Give string-list a convenience function for iterating over each of the
items in a string_list.

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
 string-list.c |   10 ++++++++++
 string-list.h |    5 +++++
 2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/string-list.c b/string-list.c
index 15e14cf..1ac536e 100644
--- a/string-list.c
+++ b/string-list.c
@@ -92,6 +92,16 @@ struct string_list_item *string_list_lookup(const char *string, struct string_li
 	return list->items + i;
 }
 
+int for_each_string_list(string_list_each_func_t fn,
+			 struct string_list *list, void *cb_data)
+{
+	int i, ret = 0;
+	for (i = 0; i < list->nr; i++)
+		if ((ret = fn(&list->items[i], cb_data)))
+			break;
+	return ret;
+}
+
 void string_list_clear(struct string_list *list, int free_util)
 {
 	if (list->items) {
diff --git a/string-list.h b/string-list.h
index d32ba05..14bbc47 100644
--- a/string-list.h
+++ b/string-list.h
@@ -20,6 +20,11 @@ void string_list_clear(struct string_list *list, int free_util);
 typedef void (*string_list_clear_func_t)(void *p, const char *str);
 void string_list_clear_func(struct string_list *list, string_list_clear_func_t clearfunc);
 
+/* Use this function to iterate over each item */
+typedef int (*string_list_each_func_t)(struct string_list_item *, void *);
+int for_each_string_list(string_list_each_func_t,
+			 struct string_list *list, void *cb_data);
+
 /* Use these functions only on sorted lists: */
 int string_list_has_string(const struct string_list *list, const char *string);
 int string_list_find_insert_index(const struct string_list *list, const char *string,
-- 
1.6.2.rc1.218.g1b4fab

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/4] Improve &quot;remote show&quot; output, Jay Soffian, (Wed Feb 18, 10:14 pm)
[PATCH 3/4] string-list: add for_each_string_list(), Jay Soffian, (Wed Feb 18, 10:14 pm)
[PATCH 4/4] remote: new show output style, Jay Soffian, (Wed Feb 18, 10:14 pm)
Re: [PATCH 4/4] remote: new show output style, Marc Branchaud, (Thu Feb 19, 9:03 am)
Re: [PATCH 4/4] remote: new show output style, Sverre Rabbelier, (Thu Feb 19, 9:16 am)
Re: [PATCH 4/4] remote: new show output style, Rostislav Svoboda, (Thu Feb 19, 9:17 am)
Re: [PATCH 4/4] remote: new show output style, Marc Branchaud, (Thu Feb 19, 9:31 am)
Re: [PATCH 4/4] remote: new show output style, Sverre Rabbelier, (Thu Feb 19, 9:33 am)
Re: [PATCH 4/4] remote: new show output style, Jay Soffian, (Thu Feb 19, 10:57 am)
Re: [PATCH 4/4] remote: new show output style, Jay Soffian, (Thu Feb 19, 10:59 am)
Re: [PATCH 4/4] remote: new show output style, Julian Phillips, (Thu Feb 19, 11:58 am)
Re: [PATCH 4/4] remote: new show output style, Johannes Sixt, (Thu Feb 19, 12:29 pm)
Re: [PATCH 4/4] remote: new show output style, Jay Soffian, (Thu Feb 19, 12:51 pm)
Re: [PATCH 4/4] remote: new show output style, Marc Branchaud, (Fri Feb 20, 3:34 pm)
Re: [PATCH 4/4] remote: new show output style, Jay Soffian, (Fri Feb 20, 3:55 pm)