From 41a7203c28d2cc7550f1bb05f767950d388326cd Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 12 Jul 2014 17:22:39 +0200 Subject: Tag: add class const_iterator and methods begin(), end() Enables using range-based "for". --- src/output/plugins/RoarOutputPlugin.cxx | 12 +++++++----- src/output/plugins/ShoutOutputPlugin.cxx | 8 ++++---- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'src/output') diff --git a/src/output/plugins/RoarOutputPlugin.cxx b/src/output/plugins/RoarOutputPlugin.cxx index ac4dd8a4e..ae6bdf1b1 100644 --- a/src/output/plugins/RoarOutputPlugin.cxx +++ b/src/output/plugins/RoarOutputPlugin.cxx @@ -374,20 +374,22 @@ RoarOutput::SendTag(const Tag &tag) vals[0].key = const_cast("LENGTH"); vals[0].value = timebuf; - for (unsigned i = 0; i < tag.num_items && cnt < 32; i++) - { + for (const auto &item : tag) { + if (cnt >= 32) + break; + bool is_uuid = false; - const char *key = roar_tag_convert(tag.items[i]->type, + const char *key = roar_tag_convert(item.type, &is_uuid); if (key != nullptr) { vals[cnt].key = const_cast(key); if (is_uuid) { snprintf(uuid_buf[cnt], sizeof(uuid_buf[0]), "{UUID}%s", - tag.items[i]->value); + item.value); vals[cnt].value = uuid_buf[cnt]; } else { - vals[cnt].value = tag.items[i]->value; + vals[cnt].value = const_cast(item.value); } cnt++; diff --git a/src/output/plugins/ShoutOutputPlugin.cxx b/src/output/plugins/ShoutOutputPlugin.cxx index a16c8fecd..0341e1cf7 100644 --- a/src/output/plugins/ShoutOutputPlugin.cxx +++ b/src/output/plugins/ShoutOutputPlugin.cxx @@ -470,13 +470,13 @@ shout_tag_to_metadata(const Tag *tag, char *dest, size_t size) artist[0] = 0; title[0] = 0; - for (unsigned i = 0; i < tag->num_items; i++) { - switch (tag->items[i]->type) { + for (const auto &item : *tag) { + switch (item.type) { case TAG_ARTIST: - strncpy(artist, tag->items[i]->value, size); + strncpy(artist, item.value, size); break; case TAG_TITLE: - strncpy(title, tag->items[i]->value, size); + strncpy(title, item.value, size); break; default: -- cgit v1.2.3