Commit 80ec6f97 authored by Max Kellermann's avatar Max Kellermann

tag/Table: add StringView overloads

parent 589639f8
/* /*
* Copyright 2003-2018 The Music Player Daemon Project * Copyright 2003-2019 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * 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 ...@@ -37,6 +37,16 @@ tag_table_lookup(const struct tag_table *table, const char *name) noexcept
return TAG_NUM_OF_ITEM_TYPES; 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). * Looks up a string in a tag translation table (case insensitive).
* Returns TAG_NUM_OF_ITEM_TYPES if the specified name was not found * 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 ...@@ -52,6 +62,16 @@ tag_table_lookup_i(const struct tag_table *table, const char *name) noexcept
return TAG_NUM_OF_ITEM_TYPES; 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 * const char *
tag_table_lookup(const tag_table *table, TagType type) noexcept tag_table_lookup(const tag_table *table, TagType type) noexcept
{ {
......
/* /*
* Copyright 2003-2018 The Music Player Daemon Project * Copyright 2003-2019 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include "Type.h" #include "Type.h"
#include "util/Compiler.h" #include "util/Compiler.h"
struct StringView;
struct tag_table { struct tag_table {
const char *name; const char *name;
...@@ -38,6 +40,10 @@ gcc_pure ...@@ -38,6 +40,10 @@ gcc_pure
TagType TagType
tag_table_lookup(const tag_table *table, const char *name) noexcept; 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). * Looks up a string in a tag translation table (case insensitive).
* Returns TAG_NUM_OF_ITEM_TYPES if the specified name was not found * Returns TAG_NUM_OF_ITEM_TYPES if the specified name was not found
...@@ -47,6 +53,10 @@ gcc_pure ...@@ -47,6 +53,10 @@ gcc_pure
TagType TagType
tag_table_lookup_i(const tag_table *table, const char *name) noexcept; 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 * Looks up a #TagType in a tag translation table and returns its
* string representation. Returns nullptr if the specified type was * string representation. Returns nullptr if the specified type was
......
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