diff --git a/src/tag/ParseName.cxx b/src/tag/ParseName.cxx index 0ad34fddd..c7d6166f1 100644 --- a/src/tag/ParseName.cxx +++ b/src/tag/ParseName.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 @@ -19,6 +19,7 @@ #include "ParseName.hxx" #include "util/ASCII.hxx" +#include "util/StringView.hxx" #include #include @@ -38,6 +39,21 @@ tag_name_parse(const char *name) noexcept return TAG_NUM_OF_ITEM_TYPES; } +TagType +tag_name_parse(StringView name) noexcept +{ + assert(name != nullptr); + + for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) { + assert(tag_item_names[i] != nullptr); + + if (name.Equals(tag_item_names[i])) + return (TagType)i; + } + + return TAG_NUM_OF_ITEM_TYPES; +} + TagType tag_name_parse_i(const char *name) noexcept { @@ -52,3 +68,18 @@ tag_name_parse_i(const char *name) noexcept return TAG_NUM_OF_ITEM_TYPES; } + +TagType +tag_name_parse_i(StringView name) noexcept +{ + assert(name != nullptr); + + for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) { + assert(tag_item_names[i] != nullptr); + + if (name.EqualsIgnoreCase(tag_item_names[i])) + return (TagType)i; + } + + return TAG_NUM_OF_ITEM_TYPES; +} diff --git a/src/tag/ParseName.hxx b/src/tag/ParseName.hxx index 4a361763d..c2a3d2e59 100644 --- a/src/tag/ParseName.hxx +++ b/src/tag/ParseName.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; + /** * Parse the string, and convert it into a #TagType. Returns * #TAG_NUM_OF_ITEM_TYPES if the string could not be recognized. @@ -31,6 +33,10 @@ gcc_pure TagType tag_name_parse(const char *name) noexcept; +gcc_pure +TagType +tag_name_parse(StringView name) noexcept; + /** * Parse the string, and convert it into a #TagType. Returns * #TAG_NUM_OF_ITEM_TYPES if the string could not be recognized. @@ -41,4 +47,8 @@ gcc_pure TagType tag_name_parse_i(const char *name) noexcept; +gcc_pure +TagType +tag_name_parse_i(StringView name) noexcept; + #endif