diff --git a/src/tag/Table.cxx b/src/tag/Table.cxx index 93901c937..04577d8ac 100644 --- a/src/tag/Table.cxx +++ b/src/tag/Table.cxx @@ -1,5 +1,5 @@ /* - * Copyright 2003-2018 The Music Player Daemon Project + * Copyright 2003-2019 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -37,6 +37,16 @@ tag_table_lookup(const struct tag_table *table, const char *name) noexcept return TAG_NUM_OF_ITEM_TYPES; } +TagType +tag_table_lookup(const struct tag_table *table, StringView name) noexcept +{ + for (; table->name != nullptr; ++table) + if (name.Equals(table->name)) + return table->type; + + return TAG_NUM_OF_ITEM_TYPES; +} + /** * Looks up a string in a tag translation table (case insensitive). * Returns TAG_NUM_OF_ITEM_TYPES if the specified name was not found @@ -52,6 +62,16 @@ tag_table_lookup_i(const struct tag_table *table, const char *name) noexcept return TAG_NUM_OF_ITEM_TYPES; } +TagType +tag_table_lookup_i(const struct tag_table *table, StringView name) noexcept +{ + for (; table->name != nullptr; ++table) + if (name.EqualsIgnoreCase(table->name)) + return table->type; + + return TAG_NUM_OF_ITEM_TYPES; +} + const char * tag_table_lookup(const tag_table *table, TagType type) noexcept { diff --git a/src/tag/Table.hxx b/src/tag/Table.hxx index 776a0ed1d..88e46b417 100644 --- a/src/tag/Table.hxx +++ b/src/tag/Table.hxx @@ -1,5 +1,5 @@ /* - * Copyright 2003-2018 The Music Player Daemon Project + * Copyright 2003-2019 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -23,6 +23,8 @@ #include "Type.h" #include "util/Compiler.h" +struct StringView; + struct tag_table { const char *name; @@ -38,6 +40,10 @@ gcc_pure TagType tag_table_lookup(const tag_table *table, const char *name) noexcept; +gcc_pure +TagType +tag_table_lookup(const tag_table *table, StringView name) noexcept; + /** * Looks up a string in a tag translation table (case insensitive). * Returns TAG_NUM_OF_ITEM_TYPES if the specified name was not found @@ -47,6 +53,10 @@ gcc_pure TagType tag_table_lookup_i(const tag_table *table, const char *name) noexcept; +gcc_pure +TagType +tag_table_lookup_i(const tag_table *table, StringView name) noexcept; + /** * Looks up a #TagType in a tag translation table and returns its * string representation. Returns nullptr if the specified type was