X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcutil%2Fsilcstrutil.c;h=3251c2b0a4d47c43255ca71746e17cf899ffedb4;hb=e7b6c157b80152bf9fb9266e6bdd93f9fb0db776;hp=1655f213459470ab4a4765d0d55a12b9ba7c9440;hpb=51558729d89b9f3492b2ca754242ed548a579ca4;p=silc.git diff --git a/lib/silcutil/silcstrutil.c b/lib/silcutil/silcstrutil.c index 1655f213..3251c2b0 100644 --- a/lib/silcutil/silcstrutil.c +++ b/lib/silcutil/silcstrutil.c @@ -121,7 +121,7 @@ int silc_string_compare(char *string1, char *string2) char **silc_string_split(const char *string, char ch, int *ret_count) { - char **splitted = NULL, sep[1], *item, *cp; + char **splitted = NULL, sep[2], *item, *cp; int i = 0, len; if (!string || !ret_count) { @@ -140,9 +140,13 @@ char **silc_string_split(const char *string, char ch, int *ret_count) } sep[0] = ch; + sep[1] = '\0'; cp = (char *)string; - while(cp) { + while (cp) { len = strcspn(cp, sep); + if (!len) + break; + item = silc_memdup(cp, len); if (!item) { silc_free(splitted); @@ -155,10 +159,13 @@ char **silc_string_split(const char *string, char ch, int *ret_count) else cp++; - splitted = silc_realloc(splitted, (i + 1) * sizeof(*splitted)); - if (!splitted) - return NULL; splitted[i++] = item; + + if (cp) { + splitted = silc_realloc(splitted, (i + 1) * sizeof(*splitted)); + if (!splitted) + return NULL; + } } *ret_count = i; @@ -242,26 +249,6 @@ char *silc_string_regex_combine(const char *string1, const char *string2) return tmp; } -/* Matches the two strings and returns TRUE if the strings match. */ - -int silc_string_regex_match(const char *regex, const char *string) -{ - regex_t preg; - int ret = FALSE; - - if (regcomp(&preg, regex, REG_NOSUB | REG_EXTENDED) != 0) { - silc_set_errno(SILC_ERR_INVALID_ARGUMENT); - return FALSE; - } - - if (regexec(&preg, string, 0, NULL, 0) == 0) - ret = TRUE; - - regfree(&preg); - - return ret; -} - /* Do regex match to the two strings `string1' and `string2'. If the `string2' matches the `string1' this returns TRUE. */