From 5a4d4697a6729bd25b9bb0f58f2e5bc930debc9b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 10 Dec 2008 19:47:36 +0100 Subject: [PATCH] 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(). --- src/match.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) 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; } -- 2.30.2