diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2008-03-13 22:50:01 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2008-03-13 22:50:01 +0100 |
commit | 5d740b882cc428017a720e85e437b5a240a30536 (patch) | |
tree | 1cea9dcd09bf8bb605c618ace91982450ff920be /src | |
parent | 88133a7b9a3962a4e81bdf2d8d7f733ff70fde19 (diff) | |
download | weechat-5d740b882cc428017a720e85e437b5a240a30536.zip |
Fixed string_explode function, when string ends with separator(s)
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-string.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 0fdd4d2eb..586d591c7 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -448,16 +448,18 @@ string_explode (char *string, char *separators, int keep_eol, while ((ptr = strpbrk (ptr, separators))) { while (ptr[0] && (strchr (separators, ptr[0]) != NULL)) + { ptr++; - i++; + } + if (ptr[0]) + i++; } n_items = i; if ((num_items_max != 0) && (n_items > num_items_max)) n_items = num_items_max; - array = - (char **)malloc ((n_items + 1) * sizeof (char *)); + array = (char **)malloc ((n_items + 1) * sizeof (char *)); ptr1 = string; ptr2 = string; @@ -465,11 +467,19 @@ string_explode (char *string, char *separators, int keep_eol, for (i = 0; i < n_items; i++) { while (ptr1[0] && (strchr (separators, ptr1[0]) != NULL)) + { ptr1++; + } if (i == (n_items - 1) || (ptr2 = strpbrk (ptr1, separators)) == NULL) + { if ((ptr2 = strchr (ptr1, '\r')) == NULL) + { if ((ptr2 = strchr (ptr1, '\n')) == NULL) + { ptr2 = strchr (ptr1, '\0'); + } + } + } if ((ptr1 == NULL) || (ptr2 == NULL)) { @@ -480,7 +490,9 @@ string_explode (char *string, char *separators, int keep_eol, if (ptr2 - ptr1 > 0) { if (keep_eol) + { array[i] = strdup (ptr1); + } else { array[i] = |