1 /* GNU gettext - internationalization aids 2 Copyright (C) 1995-1996, 1998, 2000-2004, 2009, 2020 Free Software 3 Foundation, Inc. 4 5 This file was written by Peter Miller <millerp@canb.auug.org.au> 6 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. 11 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. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <https://www.gnu.org/licenses/>. */ 19 20 #ifndef _STR_LIST_H 21 #define _STR_LIST_H 1 22 23 /* Get size_t and NULL. */ 24 #include <stddef.h> 25 26 /* Get bool. */ 27 #include <stdbool.h> 28 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 35 /* Type describing list of immutable strings, 36 implemented using a dynamic array. */ 37 typedef struct string_list_ty string_list_ty; 38 struct string_list_ty 39 { 40 const char **item; 41 size_t nitems; 42 size_t nitems_max; 43 }; 44 45 /* Initialize an empty list of strings. */ 46 extern void string_list_init (string_list_ty *slp); 47 48 /* Return a fresh, empty list of strings. */ 49 extern string_list_ty *string_list_alloc (void); 50 51 /* Append a single string to the end of a list of strings. */ 52 extern void string_list_append (string_list_ty *slp, const char *s); 53 54 /* Append a single string to the end of a list of strings, unless it is 55 already contained in the list. */ 56 extern void string_list_append_unique (string_list_ty *slp, const char *s); 57 58 /* Destroy a list of strings. */ 59 extern void string_list_destroy (string_list_ty *slp); 60 61 /* Free a list of strings. */ 62 extern void string_list_free (string_list_ty *slp); 63 64 /* Return a freshly allocated string obtained by concatenating all the 65 strings in the list. */ 66 extern char *string_list_concat (const string_list_ty *slp); 67 68 /* Return a freshly allocated string obtained by concatenating all the 69 strings in the list, and destroy the list. */ 70 extern char *string_list_concat_destroy (string_list_ty *slp); 71 72 /* Return a freshly allocated string obtained by concatenating all the 73 strings in the list, separated by the separator string, terminated 74 by the terminator character. The terminator character is not added if 75 drop_redundant_terminator is true and the last string already ends with 76 the terminator. */ 77 extern char *string_list_join (const string_list_ty *slp, const char *separator, 78 char terminator, bool drop_redundant_terminator); 79 80 /* Return 1 if s is contained in the list of strings, 0 otherwise. */ 81 extern bool string_list_member (const string_list_ty *slp, const char *s); 82 83 /* Remove s from the list of strings. Return the removed string or NULL. */ 84 extern const char * string_list_remove (string_list_ty *slp, const char *s); 85 86 87 #ifdef __cplusplus 88 } 89 #endif 90 91 92 #endif /* _STR_LIST_H */ 93