tag/ParseName: use std::string_view

This commit is contained in:
Max Kellermann 2022-06-30 10:51:33 +02:00
parent c34f3c9b94
commit 1a2b505979
2 changed files with 8 additions and 12 deletions

View File

@ -19,21 +19,19 @@
#include "ParseName.hxx" #include "ParseName.hxx"
#include "util/ASCII.hxx" #include "util/ASCII.hxx"
#include "util/StringView.hxx" #include "util/StringCompare.hxx"
#include <cassert> #include <cassert>
#include <string.h> #include <string.h>
TagType TagType
tag_name_parse(StringView name) noexcept tag_name_parse(std::string_view name) noexcept
{ {
assert(name != nullptr);
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) { for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) {
assert(tag_item_names[i] != nullptr); assert(tag_item_names[i] != nullptr);
if (name.Equals(tag_item_names[i])) if (name == tag_item_names[i])
return (TagType)i; return (TagType)i;
} }
@ -56,14 +54,12 @@ tag_name_parse_i(const char *name) noexcept
} }
TagType TagType
tag_name_parse_i(StringView name) noexcept tag_name_parse_i(std::string_view name) noexcept
{ {
assert(name != nullptr);
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) { for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) {
assert(tag_item_names[i] != nullptr); assert(tag_item_names[i] != nullptr);
if (name.EqualsIgnoreCase(tag_item_names[i])) if (StringIsEqualIgnoreCase(name, tag_item_names[i]))
return (TagType)i; return (TagType)i;
} }

View File

@ -22,7 +22,7 @@
#include "Type.h" #include "Type.h"
struct StringView; #include <string_view>
/** /**
* Parse the string, and convert it into a #TagType. Returns * Parse the string, and convert it into a #TagType. Returns
@ -34,7 +34,7 @@ tag_name_parse(const char *name) noexcept;
[[gnu::pure]] [[gnu::pure]]
TagType TagType
tag_name_parse(StringView name) noexcept; tag_name_parse(std::string_view name) noexcept;
/** /**
* Parse the string, and convert it into a #TagType. Returns * Parse the string, and convert it into a #TagType. Returns
@ -48,6 +48,6 @@ tag_name_parse_i(const char *name) noexcept;
[[gnu::pure]] [[gnu::pure]]
TagType TagType
tag_name_parse_i(StringView name) noexcept; tag_name_parse_i(std::string_view name) noexcept;
#endif #endif