diff options
-rw-r--r-- | src/core/misc.c | 20 | ||||
-rw-r--r-- | src/core/misc.h | 7 |
2 files changed, 22 insertions, 5 deletions
diff --git a/src/core/misc.c b/src/core/misc.c index 709fd98d..f32151a5 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -339,10 +339,10 @@ char *stristr(const char *data, const char *key) ((unsigned char) (c) < 128 && \ (isspace((int) (c)) || ispunct((int) (c)))) -char *stristr_full(const char *data, const char *key) +char *strstr_full_case(const char *data, const char *key, int icase) { const char *start, *max; - int keylen, datalen, pos; + int keylen, datalen, pos, match; keylen = strlen(key); datalen = strlen(data); @@ -364,8 +364,10 @@ char *stristr_full(const char *data, const char *key) return (char *) data; } - if (toupper(data[pos]) == toupper(key[pos]) && - (pos != 0 || data == start || isbound(data[-1]))) + match = icase ? (toupper(data[pos]) == toupper(key[pos])) : + data[pos] == key[pos]; + + if (match && (pos != 0 || data == start || isbound(data[-1]))) pos++; else { data++; @@ -376,6 +378,16 @@ char *stristr_full(const char *data, const char *key) return NULL; } +char *strstr_full(const char *data, const char *key) +{ + return strstr_full_case(data, key, FALSE); +} + +char *stristr_full(const char *data, const char *key) +{ + return strstr_full_case(data, key, TRUE); +} + int regexp_match(const char *str, const char *regexp) { #ifdef HAVE_REGEX_H diff --git a/src/core/misc.h b/src/core/misc.h index b56e8f97..80cf87be 100644 --- a/src/core/misc.h +++ b/src/core/misc.h @@ -38,8 +38,13 @@ GSList *hashtable_get_keys(GHashTable *hash); /* strstr() with case-ignoring */ char *stristr(const char *data, const char *key); -/* stristr(), but matches only for full words */ + +/* like strstr(), but matches only for full words. + `icase' specifies if match is case sensitive */ +char *strstr_full_case(const char *data, const char *key, int icase); +char *strstr_full(const char *data, const char *key); char *stristr_full(const char *data, const char *key); + /* easy way to check if regexp matches */ int regexp_match(const char *str, const char *regexp); |