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:
parent
7366191f0d
commit
047043d2a8
@ -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];
|
||||
}
|
||||
|
||||
|
12
src/locate.c
12
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
|
||||
|
@ -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];
|
||||
}
|
||||
|
||||
|
18
src/utils.c
18
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'))) {
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user