aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-08-07 23:25:42 +0200
committerMax Kellermann <max@duempel.org>2012-08-07 23:27:23 +0200
commit6b39a5621d9c6724db8f03164e350ae6220fa00a (patch)
tree1d2284873c2a8bdb1f27703731ed1b6f988fb84c
parent0d46e118269689e2a98e8011f52bb4bb0459421a (diff)
downloadmpd-6b39a5621d9c6724db8f03164e350ae6220fa00a.tar.gz
mpd-6b39a5621d9c6724db8f03164e350ae6220fa00a.tar.xz
mpd-6b39a5621d9c6724db8f03164e350ae6220fa00a.zip
locate: add "casefold" flag to parser
Fold the case during construction, without having to create another copy.
Diffstat (limited to '')
-rw-r--r--src/DatabaseCommands.cxx16
-rw-r--r--src/DatabasePlaylist.cxx11
-rw-r--r--src/DatabasePrint.cxx11
-rw-r--r--src/DatabaseQueue.cxx11
-rw-r--r--src/command.c4
-rw-r--r--src/locate.c25
-rw-r--r--src/locate.h10
-rw-r--r--src/queue_print.c10
8 files changed, 26 insertions, 72 deletions
diff --git a/src/DatabaseCommands.cxx b/src/DatabaseCommands.cxx
index 40ba88052..618fe0947 100644
--- a/src/DatabaseCommands.cxx
+++ b/src/DatabaseCommands.cxx
@@ -60,7 +60,7 @@ enum command_return
handle_find(struct client *client, int argc, char *argv[])
{
struct locate_item_list *list =
- locate_item_list_parse(argv + 1, argc - 1);
+ locate_item_list_parse(argv + 1, argc - 1, false);
if (list == NULL || list->length == 0) {
if (list != NULL)
@@ -84,7 +84,7 @@ enum command_return
handle_findadd(struct client *client, int argc, char *argv[])
{
struct locate_item_list *list =
- locate_item_list_parse(argv + 1, argc - 1);
+ locate_item_list_parse(argv + 1, argc - 1, false);
if (list == NULL || list->length == 0) {
if (list != NULL)
locate_item_list_free(list);
@@ -108,7 +108,7 @@ enum command_return
handle_search(struct client *client, int argc, char *argv[])
{
struct locate_item_list *list =
- locate_item_list_parse(argv + 1, argc - 1);
+ locate_item_list_parse(argv + 1, argc - 1, true);
if (list == NULL || list->length == 0) {
if (list != NULL)
@@ -132,7 +132,7 @@ enum command_return
handle_searchadd(struct client *client, int argc, char *argv[])
{
struct locate_item_list *list =
- locate_item_list_parse(argv + 1, argc - 1);
+ locate_item_list_parse(argv + 1, argc - 1, true);
if (list == NULL || list->length == 0) {
if (list != NULL)
@@ -159,7 +159,7 @@ handle_searchaddpl(struct client *client, int argc, char *argv[])
const char *playlist = argv[1];
struct locate_item_list *list =
- locate_item_list_parse(argv + 2, argc - 2);
+ locate_item_list_parse(argv + 2, argc - 2, true);
if (list == NULL || list->length == 0) {
if (list != NULL)
@@ -184,7 +184,7 @@ enum command_return
handle_count(struct client *client, int argc, char *argv[])
{
struct locate_item_list *list =
- locate_item_list_parse(argv + 1, argc - 1);
+ locate_item_list_parse(argv + 1, argc - 1, false);
if (list == NULL || list->length == 0) {
if (list != NULL)
@@ -245,14 +245,14 @@ handle_list(struct client *client, int argc, char *argv[])
return COMMAND_RETURN_ERROR;
}
- locate_item_list_parse(argv + 1, argc - 1);
+ locate_item_list_parse(argv + 1, argc - 1, false);
conditionals = locate_item_list_new(1);
conditionals->items[0].tag = TAG_ARTIST;
conditionals->items[0].needle = g_strdup(argv[2]);
} else {
conditionals =
- locate_item_list_parse(argv + 2, argc - 2);
+ locate_item_list_parse(argv + 2, argc - 2, false);
if (conditionals == NULL) {
command_error(client, ACK_ERROR_ARG,
"not able to parse args");
diff --git a/src/DatabasePlaylist.cxx b/src/DatabasePlaylist.cxx
index e8d569877..c1524a335 100644
--- a/src/DatabasePlaylist.cxx
+++ b/src/DatabasePlaylist.cxx
@@ -66,15 +66,8 @@ search_add_to_playlist(const char *uri, const char *playlist_path_utf8,
{
const DatabaseSelection selection(uri, true);
- struct locate_item_list *new_list
- = locate_item_list_casefold(criteria);
-
using namespace std::placeholders;
const auto f = std::bind(SearchAddSong, playlist_path_utf8,
- new_list, _1, _2);
- bool success = GetDatabase()->Visit(selection, f, error_r);
-
- locate_item_list_free(new_list);
-
- return success;
+ criteria, _1, _2);
+ return GetDatabase()->Visit(selection, f, error_r);
}
diff --git a/src/DatabasePrint.cxx b/src/DatabasePrint.cxx
index 318bca8a4..0c5b2bb98 100644
--- a/src/DatabasePrint.cxx
+++ b/src/DatabasePrint.cxx
@@ -155,16 +155,9 @@ searchForSongsIn(struct client *client, const char *uri,
{
const DatabaseSelection selection(uri, true);
- struct locate_item_list *new_list
- = locate_item_list_casefold(criteria);
-
using namespace std::placeholders;
- const auto f = std::bind(SearchPrintSong, client, new_list, _1);
- bool success = GetDatabase()->Visit(selection, f, error_r);
-
- locate_item_list_free(new_list);
-
- return success;
+ const auto f = std::bind(SearchPrintSong, client, criteria, _1);
+ return GetDatabase()->Visit(selection, f, error_r);
}
static bool
diff --git a/src/DatabaseQueue.cxx b/src/DatabaseQueue.cxx
index e9a47a761..7bc18363f 100644
--- a/src/DatabaseQueue.cxx
+++ b/src/DatabaseQueue.cxx
@@ -92,14 +92,7 @@ search_add_songs(struct player_control *pc, const char *uri,
{
const DatabaseSelection selection(uri, true);
- struct locate_item_list *new_list =
- locate_item_list_casefold(criteria);
-
using namespace std::placeholders;
- const auto f = std::bind(SearchAddSong, pc, new_list, _1, _2);
- bool success = GetDatabase()->Visit(selection, f, error_r);
-
- locate_item_list_free(new_list);
-
- return success;
+ const auto f = std::bind(SearchAddSong, pc, criteria, _1, _2);
+ return GetDatabase()->Visit(selection, f, error_r);
}
diff --git a/src/command.c b/src/command.c
index 08d508de7..b1d222250 100644
--- a/src/command.c
+++ b/src/command.c
@@ -677,7 +677,7 @@ static enum command_return
handle_playlistfind(struct client *client, int argc, char *argv[])
{
struct locate_item_list *list =
- locate_item_list_parse(argv + 1, argc - 1);
+ locate_item_list_parse(argv + 1, argc - 1, false);
if (list == NULL || list->length == 0) {
if (list != NULL)
@@ -698,7 +698,7 @@ static enum command_return
handle_playlistsearch(struct client *client, int argc, char *argv[])
{
struct locate_item_list *list =
- locate_item_list_parse(argv + 1, argc - 1);
+ locate_item_list_parse(argv + 1, argc - 1, true);
if (list == NULL || list->length == 0) {
if (list != NULL)
diff --git a/src/locate.c b/src/locate.c
index d4b902538..dd6902e3f 100644
--- a/src/locate.c
+++ b/src/locate.c
@@ -50,14 +50,17 @@ locate_parse_type(const char *str)
static bool
locate_item_init(struct locate_item *item,
- const char *type_string, const char *needle)
+ const char *type_string, const char *needle,
+ bool fold_case)
{
item->tag = locate_parse_type(type_string);
if (item->tag < 0)
return false;
- item->needle = g_strdup(needle);
+ item->needle = fold_case
+ ? g_utf8_casefold(needle, -1)
+ : g_strdup(needle);
return true;
}
@@ -83,7 +86,7 @@ locate_item_list_new(unsigned length)
}
struct locate_item_list *
-locate_item_list_parse(char *argv[], int argc)
+locate_item_list_parse(char *argv[], int argc, bool fold_case)
{
if (argc % 2 != 0)
return NULL;
@@ -92,7 +95,7 @@ locate_item_list_parse(char *argv[], int argc)
for (unsigned i = 0; i < list->length; ++i) {
if (!locate_item_init(&list->items[i], argv[i * 2],
- argv[i * 2 + 1])) {
+ argv[i * 2 + 1], fold_case)) {
locate_item_list_free(list);
return NULL;
}
@@ -101,20 +104,6 @@ locate_item_list_parse(char *argv[], int argc)
return list;
}
-struct locate_item_list *
-locate_item_list_casefold(const struct locate_item_list *list)
-{
- struct locate_item_list *new_list = locate_item_list_new(list->length);
-
- for (unsigned i = 0; i < list->length; i++){
- new_list->items[i].needle =
- g_utf8_casefold(list->items[i].needle, -1);
- new_list->items[i].tag = list->items[i].tag;
- }
-
- return new_list;
-}
-
static bool
locate_tag_search(const struct song *song, enum tag_type type, const char *str)
{
diff --git a/src/locate.h b/src/locate.h
index 9ebb2c4ae..25ca790eb 100644
--- a/src/locate.h
+++ b/src/locate.h
@@ -61,15 +61,7 @@ locate_item_list_new(unsigned length);
/* return number of items or -1 on error */
gcc_nonnull(1)
struct locate_item_list *
-locate_item_list_parse(char *argv[], int argc);
-
-/**
- * Duplicate the struct locate_item_list object and convert all
- * needles with g_utf8_casefold().
- */
-gcc_nonnull(1)
-struct locate_item_list *
-locate_item_list_casefold(const struct locate_item_list *list);
+locate_item_list_parse(char *argv[], int argc, bool fold_case);
gcc_nonnull(1)
void
diff --git a/src/queue_print.c b/src/queue_print.c
index d149e8b6f..032a7dec5 100644
--- a/src/queue_print.c
+++ b/src/queue_print.c
@@ -95,18 +95,12 @@ void
queue_search(struct client *client, const struct queue *queue,
const struct locate_item_list *criteria)
{
- unsigned i;
- struct locate_item_list *new_list =
- locate_item_list_casefold(criteria);
-
- for (i = 0; i < queue_length(queue); i++) {
+ for (unsigned i = 0; i < queue_length(queue); i++) {
const struct song *song = queue_get(queue, i);
- if (locate_song_search(song, new_list))
+ if (locate_song_search(song, criteria))
queue_print_song_info(client, queue, i);
}
-
- locate_item_list_free(new_list);
}
void