From: Max Kellermann Date: Wed, 10 Dec 2008 18:47:36 +0000 (+0100) Subject: match: use g_utf8_casefold() in match_line() X-Git-Tag: release-0.13~78 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5a4d4697a6729bd25b9bb0f58f2e5bc930debc9b;p=ncmpc.git 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(). --- diff --git a/src/match.c b/src/match.c index e414d85..c39959d 100644 --- a/src/match.c +++ b/src/match.c @@ -17,12 +17,31 @@ */ #include "match.h" -#include "support.h" +#include "charset.h" +#include #include +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; }