29 for (
int i =
size()-2; i >= 0; --i) {
30 if (compare(
str[i],
str[i+1], client_data) == 0) {
70 size_t nonsepcount = strcspn(sep, separator);
75 size_t sepcount = strspn(sep, separator);
79 for (
size_t s = 1;
s<sepcount; ++
s) names.
put(sep);
91 char separator_string[] =
"x";
92 separator_string[0] = separator;
110 for (
int n = 1; strings[n]; ++n) {
111 if (separator) out.
put(separator);
121 if (search_for && allocated) {
122 for (
int i = 0;
str[i]; ++i) {
123 if (strcmp(
str[i], search_for) == 0) {
140 if (oidx == -1) oidx = siz-1;
141 if (nidx == -1) nidx = siz-1;
142 else if (nidx >= siz) nidx = 0;
146 if (oidx != nidx && oidx<siz) {
147 if (oidx>nidx)
for (
int i = oidx-1; i>= nidx; --i)
swap(i, i+1);
148 else for (
int i = oidx; i< nidx; ++i)
swap(i, i+1);
158 while (
size_t(i) <
elems) {
171 void TEST_StrArray() {
206 void TEST_StrArray_truncate() {
217 #define TEST_SPLIT_JOIN(str,sep) \
219 ConstStrArray cnames; \
220 GBT_split_string(cnames, str, sep); \
221 TEST_EXPECT_STRARRAY_CONTAINS(cnames, sep, joined); \
224 void TEST_GBT_split_join_names() {
228 size_t count = names.
size();
238 size_t count = names.
size();
253 size_t count = names.
size();
265 size_t count = names.
size();
275 size_t count = names.
size();
281 TEST_SPLIT_JOIN(
"a.b.c",
'.');
282 TEST_SPLIT_JOIN(
"a.b.c",
'*');
284 TEST_SPLIT_JOIN(
"..a.b.c",
'.');
285 TEST_SPLIT_JOIN(
"a.b.c..",
'.');
286 TEST_SPLIT_JOIN(
"a..b..c",
'.');
287 TEST_SPLIT_JOIN(
".",
'.');
288 TEST_SPLIT_JOIN(
"....",
'.');
289 TEST_SPLIT_JOIN(
"",
'.');
292 void TEST_StrArray_index_of() {
306 #define TEST_EXPECT_NAMES_JOIN_TO(names,sep,expected) TEST_EXPECT_STRARRAY_CONTAINS(names,sep,expected)
308 void TEST_StrArray_safe_remove() {
313 TEST_EXPECT_NAMES_JOIN_TO(names, 0,
"abcde");
316 TEST_EXPECT_NAMES_JOIN_TO(names,
'*',
"b*c*d*e");
319 TEST_EXPECT_NAMES_JOIN_TO(names,
'*',
"b*c*d");
322 TEST_EXPECT_NAMES_JOIN_TO(names,
'*',
"b*c*d");
325 TEST_EXPECT_NAMES_JOIN_TO(names,
'*',
"b*c*d");
328 TEST_EXPECT_NAMES_JOIN_TO(names,
'*',
"b*d");
331 void TEST_StrArray_move() {
336 TEST_EXPECT_NAMES_JOIN_TO(names,
'*',
"b*c*dee*a");
338 TEST_EXPECT_NAMES_JOIN_TO(names,
'*',
"a*b*c*dee");
340 TEST_EXPECT_NAMES_JOIN_TO(names,
'*',
"a*b*dee*c");
342 TEST_EXPECT_NAMES_JOIN_TO(names,
'*',
"a*dee*b*c");
346 TEST_EXPECT_NAMES_JOIN_TO(names,
'*',
"dee*b*c*a");
347 names.
move(-1, 99999);
348 TEST_EXPECT_NAMES_JOIN_TO(names,
'*',
"a*dee*b*c");
351 void TEST_StrArray_put_before() {
356 TEST_EXPECT_NAMES_JOIN_TO(names,
'*',
"a*b");
359 TEST_EXPECT_NAMES_JOIN_TO(names,
'*',
"a*b*c");
362 TEST_EXPECT_NAMES_JOIN_TO(names,
'*',
"a*b*c*d");
365 TEST_EXPECT_NAMES_JOIN_TO(names,
'*',
"a*b*b2*c*d");
368 TEST_EXPECT_NAMES_JOIN_TO(names,
'*',
"a0*a*b*b2*c*d");
371 TEST_EXPECT_NAMES_JOIN_TO(names,
'*',
"a0*a*b*b2*c*d0*d");
void put(const char *elem)
#define implicated(hypothesis, conclusion)
int(* CharPtrArray_compare_fun)(const void *p0, const void *p1, void *client_data)
void GB_sort(void **array, size_t first, size_t behind_last, gb_compare_function compare, void *client_data)
char * ARB_strdup(const char *str)
void uniq(CharPtrArray_compare_fun compare, void *client_data)
void cat(const char *from)
void set_memblock(char *block)
#define TEST_PUBLISH(testfunction)
virtual void free_elem(int i)=0
#define TEST_EXPECT(cond)
void swap(int i1, int i2)
int index_of(const char *search_for) const
#define TEST_REJECT(cond)
void put_before(int insert_before, const char *elem)
char * GBT_join_strings(const CharPtrArray &strings, char separator)
#define TEST_EXPECT_NULL(n)
void move(int from, int to)
void sort(CharPtrArray_compare_fun compare, void *client_data)
void GBT_split_string(ConstStrArray &dest, const char *namelist, const char *separator, SplitMode mode)
void GBT_splitNdestroy_string(ConstStrArray &names, char *&namelist, const char *separator, SplitMode mode)
bool elem_index(int i) const
#define TEST_EXPECT_EQUAL(expr, want)
GB_write_int const char s