diff options
author | Max Kellermann <max@duempel.org> | 2012-08-07 23:25:42 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2012-08-07 23:27:23 +0200 |
commit | 6b39a5621d9c6724db8f03164e350ae6220fa00a (patch) | |
tree | 1d2284873c2a8bdb1f27703731ed1b6f988fb84c /src/locate.c | |
parent | 0d46e118269689e2a98e8011f52bb4bb0459421a (diff) | |
download | mpd-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/locate.c | 25 |
1 files changed, 7 insertions, 18 deletions
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) { |