From 8b2ace4bc265abde352fcd386ce5f88b88461f4d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 3 Oct 2008 11:50:30 +0200 Subject: use g_ascii_strdown() instead of the custom lowerstr() Don't duplicate code which is already provided by glib. --- src/support.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'src/support.c') diff --git a/src/support.c b/src/support.c index 3f30671f9..ca0266c1b 100644 --- a/src/support.c +++ b/src/support.c @@ -43,24 +43,6 @@ remove_trailing_slash(char *path) return path; } -char * -lowerstr(char *str) -{ - gsize i; - gsize len = strlen(str); - - if (str == NULL) - return NULL; - - i = 0; - while (i < len && str[i]) { - str[i] = tolower(str[i]); - i++; - } - return str; -} - - #ifndef HAVE_BASENAME char * basename(char *path) @@ -84,13 +66,21 @@ basename(char *path) #ifndef HAVE_STRCASESTR -char * +const char * strcasestr(const char *haystack, const char *needle) { + char *haystack2 = g_utf8_strdown(haystack, -1); + char *needle2 = g_utf8_strdown(needle, -1); + char *result; + assert(haystack != NULL); assert(needle != NULL); - return strstr(lowerstr(haystack), lowerstr(needle)); + result = strstr(haystack2, needle2); + g_free(haystack2); + g_free(needle2); + + return haystack + (result - haystack2); } #endif /* HAVE_STRCASESTR */ -- cgit v1.2.3