From 9f840e514ef860ecdfe1337f662b1801287505bf Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Fri, 14 Mar 2008 00:14:27 +0100 Subject: [PATCH] Fixed bug in string_explode function, introduced with previous commit --- src/core/wee-string.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 586d591c7..9e16788bc 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -432,10 +432,10 @@ char ** string_explode (char *string, char *separators, int keep_eol, int num_items_max, int *num_items) { - int i, n_items; + int i, n_items, word_found, separator_found; char **array; char *ptr, *ptr1, *ptr2; - + if (num_items != NULL) *num_items = 0; @@ -445,15 +445,20 @@ string_explode (char *string, char *separators, int keep_eol, /* calculate number of items */ ptr = string; i = 1; + word_found = 0; + separator_found = 0; while ((ptr = strpbrk (ptr, separators))) { + separator_found = 1; while (ptr[0] && (strchr (separators, ptr[0]) != NULL)) { ptr++; + word_found = 1; } - if (ptr[0]) - i++; + i++; } + if ((word_found == 0) && (separator_found == 1)) + i = 0; n_items = i; if ((num_items_max != 0) && (n_items > num_items_max))