1/* GNU gettext - internationalization aids 2 Copyright (C) 1995-1996, 1998, 2000-2004 Free Software Foundation, Inc. 3 4 This file was written by Peter Miller <millerp@canb.auug.org.au> 5 6 This program is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 18 19#ifndef _STR_LIST_H 20#define _STR_LIST_H 1 21 22/* Get size_t and NULL. */ 23#include <stddef.h> 24 25/* Get bool. */ 26#include <stdbool.h> 27 28 29#ifdef __cplusplus 30extern "C" { 31#endif 32 33 34/* Type describing list of immutable strings, 35 implemented using a dynamic array. */ 36typedef struct string_list_ty string_list_ty; 37struct string_list_ty 38{ 39 const char **item; 40 size_t nitems; 41 size_t nitems_max; 42}; 43 44/* Initialize an empty list of strings. */ 45extern void string_list_init (string_list_ty *slp); 46 47/* Return a fresh, empty list of strings. */ 48extern string_list_ty *string_list_alloc (void); 49 50/* Append a single string to the end of a list of strings. */ 51extern void string_list_append (string_list_ty *slp, const char *s); 52 53/* Append a single string to the end of a list of strings, unless it is 54 already contained in the list. */ 55extern void string_list_append_unique (string_list_ty *slp, const char *s); 56 57/* Destroy a list of strings. */ 58extern void string_list_destroy (string_list_ty *slp); 59 60/* Free a list of strings. */ 61extern void string_list_free (string_list_ty *slp); 62 63/* Return a freshly allocated string obtained by concatenating all the 64 strings in the list. */ 65extern char *string_list_concat (const string_list_ty *slp); 66 67/* Return a freshly allocated string obtained by concatenating all the 68 strings in the list, and destroy the list. */ 69extern char *string_list_concat_destroy (string_list_ty *slp); 70 71/* Return a freshly allocated string obtained by concatenating all the 72 strings in the list, separated by the separator character, terminated 73 by the terminator character. The terminator character is not added if 74 drop_redundant_terminator is true and the last string already ends with 75 the terminator. */ 76extern char *string_list_join (const string_list_ty *slp, char separator, 77 char terminator, bool drop_redundant_terminator); 78 79/* Return 1 if s is contained in the list of strings, 0 otherwise. */ 80extern bool string_list_member (const string_list_ty *slp, const char *s); 81 82 83#ifdef __cplusplus 84} 85#endif 86 87 88#endif /* _STR_LIST_H */ 89