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)
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
18 #endif /* __cplusplus */
21 #include "support.h" /* bool type. */
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 const char *const *strvec_data(const struct strvec
*psv
);
49 bool strvec_index_valid(const struct strvec
*psv
, size_t svindex
);
50 const char *strvec_get(const struct strvec
*psv
, size_t svindex
);
51 void strvec_to_str(const struct strvec
*psv
, char separator
,
52 char *buf
, size_t buf_len
);
53 const char *strvec_to_or_list(const struct strvec
*psv
,
54 struct astring
*astr
);
55 const char *strvec_to_and_list(const struct strvec
*psv
,
56 struct astring
*astr
);
58 /* Iteration macro. */
59 #define strvec_iterate(psv, str) \
63 for (_id = 0; _id < strvec_size((psv)); _id++) { \
64 str = strvec_get((psv), _id);
66 #define strvec_iterate_end \
72 #endif /* __cplusplus */
74 #endif /* FC__STRING_VECTOR_H */