From 6b39a5621d9c6724db8f03164e350ae6220fa00a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 7 Aug 2012 23:25:42 +0200 Subject: locate: add "casefold" flag to parser Fold the case during construction, without having to create another copy. --- src/locate.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) (limited to 'src/locate.c') 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) { -- cgit v1.2.3