Convert the users of for_each_string_list to for_each_string_list_item macro
[git/git.git] / string-list.h
CommitLineData
0afcb5f7
TF
1#ifndef STRING_LIST_H
2#define STRING_LIST_H
c455c87c
JS
3
4struct string_list_item {
5 char *string;
6 void *util;
7};
8struct string_list
9{
10 struct string_list_item *items;
11 unsigned int nr, alloc;
12 unsigned int strdup_strings:1;
13};
14
cb944f6b 15void print_string_list(const struct string_list *p, const char *text);
c455c87c
JS
16void string_list_clear(struct string_list *list, int free_util);
17
cfa1ee6b
MSO
18/* Use this function to call a custom clear function on each util pointer */
19/* The string associated with the util pointer is passed as the second argument */
20typedef void (*string_list_clear_func_t)(void *p, const char *str);
21void string_list_clear_func(struct string_list *list, string_list_clear_func_t clearfunc);
22
8d31635c 23/* Use this function or the macro below to iterate over each item */
c6f5a7a9 24typedef int (*string_list_each_func_t)(struct string_list_item *, void *);
b684e977
JP
25int for_each_string_list(struct string_list *list,
26 string_list_each_func_t, void *cb_data);
8d31635c
AR
27#define for_each_string_list_item(item,list) \
28 for (item = (list)->items; item < (list)->items + (list)->nr; ++item)
c6f5a7a9 29
c455c87c
JS
30/* Use these functions only on sorted lists: */
31int string_list_has_string(const struct string_list *list, const char *string);
cfa1ee6b
MSO
32int string_list_find_insert_index(const struct string_list *list, const char *string,
33 int negative_existing_index);
78a395d3 34struct string_list_item *string_list_insert(struct string_list *list, const char *string);
aadceea6
JP
35struct string_list_item *string_list_insert_at_index(struct string_list *list,
36 int insert_at, const char *string);
e8c8b713 37struct string_list_item *string_list_lookup(struct string_list *list, const char *string);
c455c87c
JS
38
39/* Use these functions only on unsorted lists: */
1d2f80fa 40struct string_list_item *string_list_append(struct string_list *list, const char *string);
c455c87c
JS
41void sort_string_list(struct string_list *list);
42int unsorted_string_list_has_string(struct string_list *list, const char *string);
e2421480
SB
43struct string_list_item *unsorted_string_list_lookup(struct string_list *list,
44 const char *string);
0afcb5f7 45#endif /* STRING_LIST_H */