summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 12ad417)
raw | patch | inline | side by side (parent: 12ad417)
author | Max Kellermann <max@duempel.org> | |
Fri, 3 Oct 2008 09:50:30 +0000 (11:50 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Fri, 3 Oct 2008 09:50:30 +0000 (11:50 +0200) |
Don't duplicate code which is already provided by glib.
src/conf.c | patch | blob | history | |
src/support.c | patch | blob | history | |
src/support.h | patch | blob | history |
diff --git a/src/conf.c b/src/conf.c
index 05eb28ff7081e9b63d35d750f8b1efb7c3573e58..ff627e0b6612708b38975954806fe0c00ea0d409 100644 (file)
--- a/src/conf.c
+++ b/src/conf.c
i=0;
j=0;
while( tmp && tmp[i] ) {
- tmp[i] = lowerstr(tmp[i]);
- if (screen_lookup_name(tmp[i]) == NULL)
+ char *name = g_ascii_strdown(tmp[i], -1);
+ if (screen_lookup_name(name) == NULL) {
fprintf(stderr,
_("Error: Unsupported screen \"%s\"\n"),
- tmp[i]);
- else {
+ name);
+ free(name);
+ } else {
screen = g_realloc(screen, (j+2)*sizeof(char *));
- screen[j++] = g_strdup(tmp[i]);
+ screen[j++] = name;
screen[j] = NULL;
}
i++;
diff --git a/src/support.c b/src/support.c
index 3f30671f9758d25d52c1bb91a09b39c4300fdc82..ca0266c1be28da9816a65ae6bf2a12c8badb429b 100644 (file)
--- a/src/support.c
+++ b/src/support.c
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)
#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 */
diff --git a/src/support.h b/src/support.h
index 0679ddc8676ba7ac395f52e8cfab2b6f7d92f38b..5d67b8fa7bec91b0e8a1f7b04bad9efb63c6a509 100644 (file)
--- a/src/support.h
+++ b/src/support.h
#define IS_WHITESPACE(c) (c==' ' || c=='\t' || c=='\r' || c=='\n')
char *remove_trailing_slash(char *path);
-char *lowerstr(char *str);
-char *strcasestr(const char *haystack, const char *needle);
+const char *strcasestr(const char *haystack, const char *needle);
typedef struct {
gsize offset;