summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7a3feb1)
raw | patch | inline | side by side (parent: 7a3feb1)
author | Max Kellermann <max@duempel.org> | |
Wed, 10 Dec 2008 18:47:36 +0000 (19:47 +0100) | ||
committer | Max Kellermann <max@duempel.org> | |
Wed, 10 Dec 2008 18:47:36 +0000 (19:47 +0100) |
strcasestr() is a non-standard function, and requires setting
_GNU_SOURCE. To avoid this, do wasteful g_utf8_casefold() conversions
and use strstr().
_GNU_SOURCE. To avoid this, do wasteful g_utf8_casefold() conversions
and use strstr().
src/match.c | patch | blob | history |
diff --git a/src/match.c b/src/match.c
index e414d859d4cf323d03a1d8932f5507218c71bc1f..c39959d0d1ee7b1a7bf533f8859be7df6b78640c 100644 (file)
--- a/src/match.c
+++ b/src/match.c
*/
#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;
}