Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions bstest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1680,6 +1680,12 @@ static int test21 (void) {
struct tagbstring is = bsStatic ("is");
struct tagbstring ng = bsStatic ("ng");
struct tagbstring commas = bsStatic (",,,,");
struct tagbstring delim = bsStatic ("aa");
struct tagbstring beginWithDelim = bsStatic ("aaabcdaa1");
struct tagbstring endWithDelim = bsStatic ("1aaabcdaa");
struct tagbstring conseqDelim = bsStatic ("1aaaa1");
struct tagbstring oneCharLeft = bsStatic ("aaaaaaa");
struct tagbstring allDelim = bsStatic ("aaaaaa");
int ret = 0;

printf ("TEST: struct bstrList * bsplit (const_bstring str, unsigned char splitChar);\n");
Expand Down Expand Up @@ -1707,6 +1713,16 @@ int ret = 0;
ret += test21_1 (&longBstring, &is, 3);
ret += test21_1 (&longBstring, &ng, 5);

/* corner cases */
ret += test21_1 (&shortBstring, &emptyBstring, shortBstring.slen);
ret += test21_1 (&emptyBstring, &delim, 1);
ret += test21_1 (&delim, &delim, 2);
ret += test21_1 (&beginWithDelim, &delim, 3);
ret += test21_1 (&endWithDelim, &delim, 3);
ret += test21_1 (&conseqDelim, &delim, 3);
ret += test21_1 (&oneCharLeft, &delim, 4);
ret += test21_1 (&allDelim, &delim, 4);

if (0 == ret) {
struct bstrList * l;
unsigned char c;
Expand Down
6 changes: 5 additions & 1 deletion bstrlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2768,13 +2768,17 @@ int i, p, ret;
if (splitStr->slen == 1)
return bsplitcb (str, splitStr->data[0], pos, cb, parm);

for (i=p=pos; i <= str->slen - splitStr->slen; i++) {
i = p = pos;
while (i <= str->slen - splitStr->slen) {
if (0 == bstr__memcmp (splitStr->data, str->data + i,
splitStr->slen)) {
if ((ret = cb (parm, p, i - p)) < 0) return ret;
i += splitStr->slen;
p = i;
}
else {
i++;
}
}
if ((ret = cb (parm, p, str->slen - p)) < 0) return ret;
return BSTR_OK;
Expand Down