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.
This commit is contained in:
Max Kellermann 2008-10-15 19:36:37 +02:00
parent 7366191f0d
commit 047043d2a8
5 changed files with 16 additions and 30 deletions

View File

@ -30,6 +30,8 @@
#include "log.h" #include "log.h"
#include "storedPlaylist.h" #include "storedPlaylist.h"
#include <glib.h>
typedef struct _ListCommandItem { typedef struct _ListCommandItem {
int8_t tagType; int8_t tagType;
int numConditionals; int numConditionals;
@ -103,7 +105,7 @@ int searchForSongsIn(struct client *client, const char *name,
for (i = 0; i < numItems; i++) { for (i = 0; i < numItems; i++) {
originalNeedles[i] = items[i].needle; originalNeedles[i] = items[i].needle;
items[i].needle = strDupToUpper(originalNeedles[i]); items[i].needle = g_utf8_casefold(originalNeedles[i], -1);
} }
data.client = client; data.client = client;
@ -113,7 +115,7 @@ int searchForSongsIn(struct client *client, const char *name,
ret = db_walk(name, searchInDirectory, NULL, &data); ret = db_walk(name, searchInDirectory, NULL, &data);
for (i = 0; i < numItems; i++) { for (i = 0; i < numItems; i++) {
free(items[i].needle); g_free(items[i].needle);
items[i].needle = originalNeedles[i]; items[i].needle = originalNeedles[i];
} }

View File

@ -22,6 +22,8 @@
#include "tag.h" #include "tag.h"
#include "song.h" #include "song.h"
#include <glib.h>
#define LOCATE_TAG_FILE_KEY "file" #define LOCATE_TAG_FILE_KEY "file"
#define LOCATE_TAG_FILE_KEY_OLD "filename" #define LOCATE_TAG_FILE_KEY_OLD "filename"
#define LOCATE_TAG_ANY_KEY "any" #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 }; int8_t visitedTypes[TAG_NUM_OF_ITEM_TYPES] = { 0 };
if (type == LOCATE_TAG_FILE_TYPE || type == LOCATE_TAG_ANY_TYPE) { 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)) if (strstr(path_max_tmp, str))
ret = 1; ret = 1;
g_free(p);
if (ret == 1 || type == LOCATE_TAG_FILE_TYPE) if (ret == 1 || type == LOCATE_TAG_FILE_TYPE)
return ret; return ret;
} }
@ -151,10 +155,10 @@ strstrSearchTag(struct song *song, enum tag_type type, char *str)
continue; continue;
} }
duplicate = strDupToUpper(song->tag->items[i]->value); duplicate = g_utf8_casefold(song->tag->items[i]->value, -1);
if (*str && strstr(duplicate, str)) if (*str && strstr(duplicate, str))
ret = 1; ret = 1;
free(duplicate); g_free(duplicate);
} }
/** If the search critieron was not visited during the sweep /** If the search critieron was not visited during the sweep

View File

@ -37,6 +37,8 @@
#include "idle.h" #include "idle.h"
#include "os_compat.h" #include "os_compat.h"
#include <glib.h>
#define PLAYLIST_STATE_STOP 0 #define PLAYLIST_STATE_STOP 0
#define PLAYLIST_STATE_PLAY 1 #define PLAYLIST_STATE_PLAY 1
@ -1372,7 +1374,7 @@ void searchForSongsInPlaylist(struct client *client,
for (i = 0; i < numItems; i++) { for (i = 0; i < numItems; i++) {
originalNeedles[i] = items[i].needle; 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++) { for (i = 0; i < playlist.length; i++) {
@ -1381,7 +1383,7 @@ void searchForSongsInPlaylist(struct client *client,
} }
for (i = 0; i < numItems; i++) { for (i = 0; i < numItems; i++) {
free(items[i].needle); g_free(items[i].needle);
items[i].needle = originalNeedles[i]; items[i].needle = originalNeedles[i];
} }

View File

@ -24,7 +24,6 @@
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#include <sys/types.h> #include <sys/types.h>
#include <pwd.h> #include <pwd.h>
#include <fcntl.h> #include <fcntl.h>
@ -45,23 +44,6 @@ char *myFgets(char *buffer, int bufferSize, FILE * fp)
return ret; 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) void stripReturnChar(char *string)
{ {
while (string && (string = strchr(string, '\n'))) { while (string && (string = strchr(string, '\n'))) {

View File

@ -31,10 +31,6 @@
char *myFgets(char *buffer, int bufferSize, FILE * fp); 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 stripReturnChar(char *string);
void my_usleep(long usec); void my_usleep(long usec);