tag_id3: use the tag_table library for TXXX

This commit is contained in:
Max Kellermann 2012-02-11 10:37:59 +01:00
parent 767ade02f4
commit 9e5a49b8cb
2 changed files with 26 additions and 15 deletions

View File

@ -19,6 +19,7 @@
#include "config.h" #include "config.h"
#include "tag_id3.h" #include "tag_id3.h"
#include "tag_table.h"
#include "tag.h" #include "tag.h"
#include "riff.h" #include "riff.h"
#include "aiff.h" #include "aiff.h"
@ -242,23 +243,17 @@ tag_id3_import_comment(struct tag *dest, struct id3_tag *tag, const char *id,
static enum tag_type static enum tag_type
tag_id3_parse_txxx_name(const char *name) tag_id3_parse_txxx_name(const char *name)
{ {
static const struct { static const struct tag_table txxx_tags[] = {
enum tag_type type; { "ALBUMARTISTSORT", TAG_ALBUM_ARTIST_SORT },
const char *name; { "MusicBrainz Artist Id", TAG_MUSICBRAINZ_ARTISTID },
} musicbrainz_txxx[] = { { "MusicBrainz Album Id", TAG_MUSICBRAINZ_ALBUMID },
{ TAG_ALBUM_ARTIST_SORT, "ALBUMARTISTSORT" }, { "MusicBrainz Album Artist Id",
{ TAG_MUSICBRAINZ_ARTISTID, "MusicBrainz Artist Id" }, TAG_MUSICBRAINZ_ALBUMARTISTID },
{ TAG_MUSICBRAINZ_ALBUMID, "MusicBrainz Album Id" }, { "MusicBrainz Track Id", TAG_MUSICBRAINZ_TRACKID },
{ TAG_MUSICBRAINZ_ALBUMARTISTID, { NULL, TAG_NUM_OF_ITEM_TYPES }
"MusicBrainz Album Artist Id" },
{ TAG_MUSICBRAINZ_TRACKID, "MusicBrainz Track Id" },
}; };
for (unsigned i = 0; i < G_N_ELEMENTS(musicbrainz_txxx); ++i) return tag_table_lookup(txxx_tags, name);
if (strcmp(name, musicbrainz_txxx[i].name) == 0)
return musicbrainz_txxx[i].type;
return TAG_NUM_OF_ITEM_TYPES;
} }
/** /**

View File

@ -30,6 +30,22 @@ struct tag_table {
enum tag_type type; enum tag_type type;
}; };
/**
* Looks up a string in a tag translation table (case sensitive).
* Returns TAG_NUM_OF_ITEM_TYPES if the specified name was not found
* in the table.
*/
G_GNUC_PURE
static inline enum tag_type
tag_table_lookup(const struct tag_table *table, const char *name)
{
for (; table->name != NULL; ++table)
if (strcmp(name, table->name) == 0)
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