ldb: version 1.5.2
[Samba.git] / lib / util / util_strlist.h
blob116303424c2fb50c8e5092edc0905c4cc909bf9a
1 /*
2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2005
5 Copyright (C) Jelmer Vernooij 2005
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef _SAMBA_UTIL_STRLIST_H
22 #define _SAMBA_UTIL_STRLIST_H
24 #include <talloc.h>
26 /* separators for lists */
27 #ifndef LIST_SEP
28 #define LIST_SEP " \t,\n\r"
29 #endif
31 /**
32 build an empty (only NULL terminated) list of strings (for expansion with str_list_add() etc)
34 char **str_list_make_empty(TALLOC_CTX *mem_ctx);
36 /**
37 place the only element 'entry' into a new, NULL terminated string list
39 char **str_list_make_single(TALLOC_CTX *mem_ctx,
40 const char *entry);
42 /**
43 build a null terminated list of strings from a input string and a
44 separator list. The separator list must contain characters less than
45 or equal to 0x2f for this to work correctly on multi-byte strings
47 char **str_list_make(TALLOC_CTX *mem_ctx, const char *string,
48 const char *sep);
50 /**
51 * build a null terminated list of strings from an argv-like input string
52 * Entries are separated by spaces and can be enclosed by quotes.
53 * Does NOT support escaping
55 char **str_list_make_shell(TALLOC_CTX *mem_ctx, const char *string,
56 const char *sep);
58 /**
59 * join a list back to one string
61 char *str_list_join(TALLOC_CTX *mem_ctx, const char **list,
62 char separator);
64 /** join a list back to one (shell-like) string; entries
65 * separated by spaces, using quotes where necessary */
66 char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list,
67 char sep);
69 /**
70 return the number of elements in a string list
72 size_t str_list_length(const char * const *list);
74 /**
75 copy a string list
77 char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list);
79 /**
80 Return true if all the elements of the list match exactly.
82 bool str_list_equal(const char * const *list1,
83 const char * const *list2);
85 /**
86 add an entry to a string list
88 const char **str_list_add(const char **list, const char *s);
90 /**
91 remove an entry from a string list
93 void str_list_remove(const char **list, const char *s);
95 /**
96 return true if a string is in a list
98 bool str_list_check(const char **list, const char *s);
101 return true if a string is in a list, case insensitively
103 bool str_list_check_ci(const char **list, const char *s);
105 append one list to another - expanding list1
107 const char **str_list_append(const char **list1,
108 const char * const *list2);
111 remove duplicate elements from a list
113 const char **str_list_unique(const char **list);
116 very useful when debugging complex list related code
118 void str_list_show(const char **list);
122 append one list to another - expanding list1
123 this assumes the elements of list2 are const pointers, so we can re-use them
125 const char **str_list_append_const(const char **list1,
126 const char **list2);
129 Add a string to an array of strings.
131 num should be a pointer to an integer that holds the current
132 number of elements in strings. It will be updated by this function.
134 bool add_string_to_array(TALLOC_CTX *mem_ctx,
135 const char *str, const char ***strings, size_t *num);
138 add an entry to a string list
139 this assumes s will not change
141 const char **str_list_add_const(const char **list, const char *s);
144 copy a string list
145 this assumes list will not change
147 const char **str_list_copy_const(TALLOC_CTX *mem_ctx,
148 const char **list);
150 #endif /* _SAMBA_UTIL_STRLIST_H */