Mercurial > hg > th-libs
diff th_string.c @ 414:77fd4f0327dc
Split th_str{case}match() into another file to reduce code duplication.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 09 Mar 2016 13:03:39 +0200 |
parents | 371567cf0a38 |
children | d41cb5983772 |
line wrap: on
line diff
--- a/th_string.c Wed Mar 09 13:03:05 2016 +0200 +++ b/th_string.c Wed Mar 09 13:03:39 2016 +0200 @@ -931,217 +931,16 @@ * wildcards ? and *. "?" matches any character and "*" matches * any number of characters. */ -BOOL th_strmatch(const char *haystack, const char *pattern) -{ - BOOL matched = TRUE, any = FALSE, end = FALSE; - const char *tmp = NULL; - - // Check given pattern and string - if (haystack == NULL || pattern == NULL) - return FALSE; - - // Start comparision - do { - matched = FALSE; - switch (*pattern) - { - case '?': - // Any single character matches - if (*haystack) - { - matched = TRUE; - pattern++; - haystack++; - } - break; - - case '*': - matched = TRUE; - pattern++; - if (!*pattern) - end = TRUE; - any = TRUE; - tmp = pattern; - break; - - case 0: - if (any) - { - if (*haystack) - haystack++; - else - end = TRUE; - } - else - { - if (*haystack) - { - if (tmp) - { - any = TRUE; - pattern = tmp; - } - else - matched = FALSE; - } - else - end = TRUE; - } - break; - - default: - if (any) - { - if (*pattern == *haystack) - { - any = FALSE; - matched = TRUE; - } - else - { - if (*haystack) - { - matched = TRUE; - haystack++; - } - } - } - else - { - if (*pattern == *haystack) - { - matched = TRUE; - if (*pattern) - pattern++; - if (*haystack) - haystack++; - } - else - { - if (tmp) - { - matched = TRUE; - any = TRUE; - pattern = tmp; - } - } - } - - if (!*haystack && !*pattern) - end = TRUE; - break; - - } // switch - } while (matched && !end); - - return matched; -} +#define TH_STRMATCH_FUNC th_strmatch +#define TH_STRMATCH_COLLATE(px) (px) +#include "th_strmatch.c" /* Compare a string to a pattern. Case-INSENSITIVE version. */ -BOOL th_strcasematch(const char *haystack, const char *pattern) -{ - BOOL matched = TRUE, any = FALSE, end = FALSE; - const char *tmp = NULL; - - // Check given pattern and string - if (haystack == NULL || pattern == NULL) - return FALSE; - - // Start comparision - do { - switch (*pattern) { - case '?': - // Any single character matches - if (*haystack) - { - pattern++; - haystack++; - } - else - matched = FALSE; - break; - - case '*': - pattern++; - if (!*pattern || *pattern == '?') - end = TRUE; - any = TRUE; - tmp = pattern; - break; - - case 0: - if (any) - { - if (*haystack) - haystack++; - else - end = TRUE; - } - else - { - if (*haystack) - { - if (tmp) - { - any = TRUE; - pattern = tmp; - } - else - matched = FALSE; - } - else - end = TRUE; - } - break; - - default: - if (any) - { - if (th_tolower(*pattern) == th_tolower(*haystack)) - { - any = FALSE; - } - else - { - if (*haystack) - haystack++; - else - matched = FALSE; - } - } - else - { - if (th_tolower(*pattern) == th_tolower(*haystack)) - { - if (*pattern) - pattern++; - if (*haystack) - haystack++; - } - else - { - if (tmp) - { - any = TRUE; - pattern = tmp; - } - else - matched = FALSE; - } - } - - if (!*haystack && !*pattern) - end = TRUE; - - break; - - } // switch - } while (matched && !end); - - return matched; -} +#define TH_STRMATCH_FUNC th_strcasematch +#define TH_STRMATCH_COLLATE(px) th_tolower(px) +#include "th_strmatch.c" int th_get_hex_triplet(const char *str)