From 589639f80f634190e5d7ea7a4b3a3eddcc02d203 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 6 Jun 2019 13:21:33 +0200 Subject: [PATCH] tag/ParseName: add StringView overloads --- src/tag/ParseName.cxx | 33 ++++++++++++++++++++++++++++++++- src/tag/ParseName.hxx | 12 +++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) 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