Commit 589639f8 authored by Max Kellermann's avatar Max Kellermann

tag/ParseName: add StringView overloads

parent 548aa001
/*
* 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 <assert.h>
#include <string.h>
......@@ -39,6 +40,21 @@ tag_name_parse(const char *name) noexcept
}
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
{
assert(name != nullptr);
......@@ -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;
}
/*
* 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment