1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2010 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 #ifndef LIBPSPP_STRING_ARRAY_H
18 #define LIBPSPP_STRING_ARRAY_H
23 /* An unordered array of strings.
25 Not opaque by any means. */
33 /* Suitable for use as the initializer for a string_array named ARRAY. Typical
35 struct string_array array = STRING_ARRAY_INITIALIZER (array);
36 STRING_ARRAY_INITIALIZER is an alternative to calling string_array_init. */
37 #define STRING_ARRAY_INITIALIZER(ARRAY) { NULL, 0, 0 }
39 void string_array_init (struct string_array *);
40 void string_array_clone (struct string_array *, const struct string_array *);
41 void string_array_swap (struct string_array *, struct string_array *);
42 void string_array_destroy (struct string_array *);
44 static inline size_t string_array_count (const struct string_array *);
45 static inline bool string_array_is_empty (const struct string_array *);
47 bool string_array_contains (const struct string_array *, const char *);
48 size_t string_array_find (const struct string_array *, const char *);
50 void string_array_append (struct string_array *, const char *);
51 void string_array_append_nocopy (struct string_array *, char *);
52 void string_array_insert (struct string_array *, const char *, size_t before);
53 void string_array_insert_nocopy (struct string_array *, char *, size_t before);
54 void string_array_delete (struct string_array *, size_t idx);
55 char *string_array_delete_nofree (struct string_array *, size_t idx);
57 void string_array_clear (struct string_array *);
59 void string_array_terminate_null (struct string_array *);
60 void string_array_shrink (struct string_array *);
62 void string_array_sort (struct string_array *);
64 char *string_array_join (const struct string_array *, const char *separator);
66 /* Macros for conveniently iterating through a string_array, e.g. to print all
67 of the strings in "my_array":
72 STRING_ARRAY_FOR_EACH (string, idx, &my_array)
75 #define STRING_ARRAY_FOR_EACH(STRING, IDX, ARRAY) \
78 ? ((STRING) = (ARRAY)->strings[IDX], true) \
82 /* Returns the number of strings currently in ARRAY. */
84 string_array_count (const struct string_array *array)
89 /* Returns true if ARRAY currently contains no strings, false otherwise. */
91 string_array_is_empty (const struct string_array *array)
96 #endif /* libpspp/string-array.h */