From dab576cb940f48319befac01f67f611f0acabe35 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sat, 14 Aug 2021 19:22:17 +0200 Subject: [PATCH] mp4: Clean up find_standard_meta(). Use ARRAY_SIZE() instead of open-coding it, move the stdmetas array into the function since it is only used there, and make it const. Also replace 0 by NULL, since the function returns a pointer, and remove the pointless comment. Finally, move the function and the declaration of the stdmeta_entry structure closer to its single user. --- mp4.c | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/mp4.c b/mp4.c index 1b935fa8..3167a132 100644 --- a/mp4.c +++ b/mp4.c @@ -1203,29 +1203,6 @@ static unsigned membuffer_write_int32(struct membuffer *buf, uint32_t data) return membuffer_write(buf, temp, 4); } -struct stdmeta_entry { - const char *atom; - const char *name; -}; - -struct stdmeta_entry stdmetas[] = { - {"\xA9" "nam", "title"}, - {"\xA9" "ART", "artist"}, - {"\xA9" "alb", "album"}, - {"\xA9" "day", "date"}, - {"\xA9" "cmt", "comment"}, -}; - -static const char *find_standard_meta(const char *name) //returns atom name if found, 0 if not -{ - unsigned n; - for (n = 0; n < sizeof (stdmetas) / sizeof (stdmetas[0]); n++) { - if (!strcasecmp(name, stdmetas[n].name)) - return stdmetas[n].atom; - } - return 0; -} - static void membuffer_write_std_tag(struct membuffer *buf, const char *name, const char *value) { @@ -1277,6 +1254,27 @@ static void *membuffer_detach(struct membuffer *buf) return ret; } +struct stdmeta_entry { + const char *atom; + const char *name; +}; + +static const char *find_standard_meta(const char *name) +{ + const struct stdmeta_entry stdmetas[] = { + {"\xA9" "nam", "title"}, + {"\xA9" "ART", "artist"}, + {"\xA9" "alb", "album"}, + {"\xA9" "day", "date"}, + {"\xA9" "cmt", "comment"}, + }; + + for (unsigned n = 0; n < ARRAY_SIZE(stdmetas); n++) + if (!strcasecmp(name, stdmetas[n].name)) + return stdmetas[n].atom; + return NULL; +} + static uint32_t create_ilst(const struct mp4_metadata *meta, void **out_buffer, uint32_t * out_size) { -- 2.39.5