diff options
author | Max Kellermann <max@duempel.org> | 2008-10-15 19:36:37 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-10-15 19:36:37 +0200 |
commit | 047043d2a8ee4482a845ed9860dbf4cd01540eef (patch) | |
tree | ec8542ca3ea28e255bd857f01b7b8672fb029da5 | |
parent | 7366191f0d0d5c50ee051a3b60fc31ad86bce721 (diff) | |
download | mpd-047043d2a8ee4482a845ed9860dbf4cd01540eef.tar.gz mpd-047043d2a8ee4482a845ed9860dbf4cd01540eef.tar.xz mpd-047043d2a8ee4482a845ed9860dbf4cd01540eef.zip |
locate: use g_utf8_casefold() instead of string_toupper()
string_toupper() and strDupToUpper() were not able to deal with
character sets other than US-ASCII. Use GLib's g_utf8_casefold()
for strings.
-rw-r--r-- | src/dbUtils.c | 6 | ||||
-rw-r--r-- | src/locate.c | 12 | ||||
-rw-r--r-- | src/playlist.c | 6 | ||||
-rw-r--r-- | src/utils.c | 18 | ||||
-rw-r--r-- | src/utils.h | 4 |
5 files changed, 16 insertions, 30 deletions
diff --git a/src/dbUtils.c b/src/dbUtils.c index ddd4a024f..8f063f254 100644 --- a/src/dbUtils.c +++ b/src/dbUtils.c @@ -30,6 +30,8 @@ #include "log.h" #include "storedPlaylist.h" +#include <glib.h> + typedef struct _ListCommandItem { int8_t tagType; int numConditionals; @@ -103,7 +105,7 @@ int searchForSongsIn(struct client *client, const char *name, for (i = 0; i < numItems; i++) { originalNeedles[i] = items[i].needle; - items[i].needle = strDupToUpper(originalNeedles[i]); + items[i].needle = g_utf8_casefold(originalNeedles[i], -1); } data.client = client; @@ -113,7 +115,7 @@ int searchForSongsIn(struct client *client, const char *name, ret = db_walk(name, searchInDirectory, NULL, &data); for (i = 0; i < numItems; i++) { - free(items[i].needle); + g_free(items[i].needle); items[i].needle = originalNeedles[i]; } diff --git a/src/locate.c b/src/locate.c index 05463b5c9..6b8e87734 100644 --- a/src/locate.c +++ b/src/locate.c @@ -22,6 +22,8 @@ #include "tag.h" #include "song.h" +#include <glib.h> + #define LOCATE_TAG_FILE_KEY "file" #define LOCATE_TAG_FILE_KEY_OLD "filename" #define LOCATE_TAG_ANY_KEY "any" @@ -132,11 +134,13 @@ strstrSearchTag(struct song *song, enum tag_type type, char *str) int8_t visitedTypes[TAG_NUM_OF_ITEM_TYPES] = { 0 }; if (type == LOCATE_TAG_FILE_TYPE || type == LOCATE_TAG_ANY_TYPE) { - char path_max_tmp[MPD_PATH_MAX]; + char path_max_tmp[MPD_PATH_MAX], *p; - string_toupper(song_get_url(song, path_max_tmp)); + song_get_url(song, path_max_tmp); + p = g_utf8_casefold(path_max_tmp, -1); if (strstr(path_max_tmp, str)) ret = 1; + g_free(p); if (ret == 1 || type == LOCATE_TAG_FILE_TYPE) return ret; } @@ -151,10 +155,10 @@ strstrSearchTag(struct song *song, enum tag_type type, char *str) continue; } - duplicate = strDupToUpper(song->tag->items[i]->value); + duplicate = g_utf8_casefold(song->tag->items[i]->value, -1); if (*str && strstr(duplicate, str)) ret = 1; - free(duplicate); + g_free(duplicate); } /** If the search critieron was not visited during the sweep diff --git a/src/playlist.c b/src/playlist.c index 3498ae7bb..bfcfb1f7a 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -37,6 +37,8 @@ #include "idle.h" #include "os_compat.h" +#include <glib.h> + #define PLAYLIST_STATE_STOP 0 #define PLAYLIST_STATE_PLAY 1 @@ -1372,7 +1374,7 @@ void searchForSongsInPlaylist(struct client *client, for (i = 0; i < numItems; i++) { originalNeedles[i] = items[i].needle; - items[i].needle = strDupToUpper(originalNeedles[i]); + items[i].needle = g_utf8_casefold(originalNeedles[i], -1); } for (i = 0; i < playlist.length; i++) { @@ -1381,7 +1383,7 @@ void searchForSongsInPlaylist(struct client *client, } for (i = 0; i < numItems; i++) { - free(items[i].needle); + g_free(items[i].needle); items[i].needle = originalNeedles[i]; } diff --git a/src/utils.c b/src/utils.c index 9cd2190ed..57d1f30fa 100644 --- a/src/utils.c +++ b/src/utils.c @@ -24,7 +24,6 @@ #include <assert.h> #include <string.h> -#include <ctype.h> #include <sys/types.h> #include <pwd.h> #include <fcntl.h> @@ -45,23 +44,6 @@ char *myFgets(char *buffer, int bufferSize, FILE * fp) return ret; } -char *string_toupper(char *str) -{ - int i = strlen(str); - char *ret = str; - - for (; --i >= 0; ++str) - *str = toupper((int)(*str)); - - return ret; - -} - -char *strDupToUpper(char *str) -{ - return string_toupper(xstrdup(str)); -} - void stripReturnChar(char *string) { while (string && (string = strchr(string, '\n'))) { diff --git a/src/utils.h b/src/utils.h index 9a83b6f52..5f3b26c5f 100644 --- a/src/utils.h +++ b/src/utils.h @@ -31,10 +31,6 @@ char *myFgets(char *buffer, int bufferSize, FILE * fp); -char *string_toupper(char *str); - -char *strDupToUpper(char *str); /* avoid, use string_toupper instead */ - void stripReturnChar(char *string); void my_usleep(long usec); |