From 970b10d01bbca4bd3c09d37c76531625b3adf0b4 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 9 Jan 2014 19:00:59 +0100 Subject: [PATCH] tag/TagTable: add lookup TagType -> name --- src/tag/TagTable.cxx | 10 ++++++++++ src/tag/TagTable.hxx | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/src/tag/TagTable.cxx b/src/tag/TagTable.cxx index b51bc35ba..5224404a9 100644 --- a/src/tag/TagTable.cxx +++ b/src/tag/TagTable.cxx @@ -51,3 +51,13 @@ tag_table_lookup_i(const struct tag_table *table, const char *name) return TAG_NUM_OF_ITEM_TYPES; } + +const char * +tag_table_lookup(const tag_table *table, TagType type) +{ + for (; table->name != nullptr; ++table) + if (table->type == type) + return table->name; + + return nullptr; +} diff --git a/src/tag/TagTable.hxx b/src/tag/TagTable.hxx index c050f61ac..423a1e6ad 100644 --- a/src/tag/TagTable.hxx +++ b/src/tag/TagTable.hxx @@ -47,4 +47,13 @@ gcc_pure TagType tag_table_lookup_i(const tag_table *table, const char *name); +/** + * Looks up a #TagType in a tag translation table and returns its + * string representation. Returns nullptr if the specified type was + * not found in the table. + */ +gcc_pure +const char * +tag_table_lookup(const tag_table *table, TagType type); + #endif