diff options
author | Max Kellermann <max@duempel.org> | 2008-12-10 19:47:36 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-12-10 19:47:36 +0100 |
commit | 5a4d4697a6729bd25b9bb0f58f2e5bc930debc9b (patch) | |
tree | a999f6a20a4b8f094714cda50c05c03607c4ff48 /src/match.c | |
parent | 7a3feb12511fa02361f3cdd0e62396c084b143ad (diff) | |
download | mpd-5a4d4697a6729bd25b9bb0f58f2e5bc930debc9b.tar.gz mpd-5a4d4697a6729bd25b9bb0f58f2e5bc930debc9b.tar.xz mpd-5a4d4697a6729bd25b9bb0f58f2e5bc930debc9b.zip |
match: use g_utf8_casefold() in match_line()
strcasestr() is a non-standard function, and requires setting
_GNU_SOURCE. To avoid this, do wasteful g_utf8_casefold() conversions
and use strstr().
Diffstat (limited to '')
-rw-r--r-- | src/match.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/match.c b/src/match.c index e414d859d..c39959d0d 100644 --- a/src/match.c +++ b/src/match.c @@ -17,12 +17,31 @@ */ #include "match.h" -#include "support.h" +#include "charset.h" +#include <glib.h> #include <string.h> +static char * +locale_casefold(const char *src) +{ + char *utf8 = locale_to_utf8(src); + char *folded = g_utf8_casefold(utf8, -1); + + g_free(utf8); + return folded; +} + bool match_line(const char *line, const char *needle) { - return strcasestr(line, needle) != NULL; + char *line_folded = locale_casefold(line); + char *needle_folded = locale_casefold(needle); + + bool ret = strstr(line_folded, needle_folded) != NULL; + + g_free(line_folded); + g_free(needle_folded); + + return ret; } |