webperimental: killstack decides stack protects.
[freeciv.git] / utility / string_vector.h
blobee8224a2cb7cc3ce7314c19310b885a566d251c0
1 /***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 ***********************************************************************/
13 #ifndef FC__STRING_VECTOR_H
14 #define FC__STRING_VECTOR_H
16 #ifdef __cplusplus
17 extern "C" {
18 #endif /* __cplusplus */
20 /* utility */
21 #include "support.h" /* bool type. */
23 struct astring;
25 struct strvec; /* Opaque. */
27 struct strvec *strvec_new(void);
28 void strvec_destroy(struct strvec *psv);
30 void strvec_reserve(struct strvec *psv, size_t reserve);
31 void strvec_store(struct strvec *psv, const char *const *vec, size_t size);
32 void strvec_from_str(struct strvec *psv, char separator, const char *str);
33 void strvec_clear(struct strvec *psv);
34 void strvec_remove_empty(struct strvec *psv);
35 void strvec_remove_duplicate(struct strvec *psv,
36 int (*cmp_func) (const char *, const char *));
37 void strvec_copy(struct strvec *dest, const struct strvec *src);
38 void strvec_sort(struct strvec *psv, int (*sort_func) (const char *const *,
39 const char *const *));
41 void strvec_prepend(struct strvec *psv, const char *string);
42 void strvec_append(struct strvec *psv, const char *string);
43 void strvec_insert(struct strvec *psv, size_t svindex, const char *string);
44 bool strvec_set(struct strvec *psv, size_t svindex, const char *string);
45 bool strvec_remove(struct strvec *psv, size_t svindex);
47 size_t strvec_size(const struct strvec *psv);
48 bool are_strvecs_equal(const struct strvec *stv1,
49 const struct strvec *stv2);
50 const char *const *strvec_data(const struct strvec *psv);
51 bool strvec_index_valid(const struct strvec *psv, size_t svindex);
52 const char *strvec_get(const struct strvec *psv, size_t svindex);
53 void strvec_to_str(const struct strvec *psv, char separator,
54 char *buf, size_t buf_len);
55 const char *strvec_to_or_list(const struct strvec *psv,
56 struct astring *astr);
57 const char *strvec_to_and_list(const struct strvec *psv,
58 struct astring *astr);
60 /* Iteration macro. */
61 #define strvec_iterate(psv, str) \
62 { \
63 size_t _id; \
64 const char *str; \
65 for (_id = 0; _id < strvec_size((psv)); _id++) { \
66 str = strvec_get((psv), _id);
68 #define strvec_iterate_end \
69 } \
72 #ifdef __cplusplus
74 #endif /* __cplusplus */
76 #endif /* FC__STRING_VECTOR_H */