From a92f6b94ddd6d99f76301f85ba451c2d40f6b193 Mon Sep 17 00:00:00 2001 From: Scott Wheeler Date: Thu, 28 Oct 2004 21:22:33 +0000 Subject: [PATCH] Semantic and style cleanups. render() should be const. Use for() loops to loop through lists rather than while, fix bracket style. git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@358627 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- ape/apeitem.cpp | 48 +++++++++++++++++++++++++++++++----------------- ape/apeitem.h | 10 ++++++++-- ape/apetag.cpp | 8 ++++---- 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/ape/apeitem.cpp b/ape/apeitem.cpp index ef94b7ea..90643ba5 100644 --- a/ape/apeitem.cpp +++ b/ape/apeitem.cpp @@ -56,50 +56,60 @@ APE::Item::Item(const Item& item) d = new ItemPrivate(*item.d); } -Item& APE::Item::operator=(const Item& item) +Item &APE::Item::operator=(const Item& item) { delete d; d = new ItemPrivate(*item.d); return *this; } -void APE::Item::setReadOnly(bool val) { +void APE::Item::setReadOnly(bool val) +{ d->readOnly = val; } -bool APE::Item::isReadOnly() const { +bool APE::Item::isReadOnly() const +{ return d->readOnly; } -void APE::Item::setType(APE::Item::ItemTypes val) { +void APE::Item::setType(APE::Item::ItemTypes val) +{ d->type = val; } -APE::Item::ItemTypes APE::Item::type() const { +APE::Item::ItemTypes APE::Item::type() const +{ return d->type; } -String APE::Item::key() const { +String APE::Item::key() const +{ return d->key; } -ByteVector APE::Item::value() const { +ByteVector APE::Item::value() const +{ return d->value; } -int APE::Item::size() const { - return 8 + d->key.size() + 1 + d->value.size(); +int APE::Item::size() const +{ + return 8 + d->key.size() + 1 + d->value.size(); } -StringList APE::Item::toStringList() const { +StringList APE::Item::toStringList() const +{ return d->text; } -String APE::Item::toString() const { +String APE::Item::toString() const +{ return d->text.front(); } -bool APE::Item::isEmpty() const { +bool APE::Item::isEmpty() const +{ switch(d->type) { case 0: case 1: @@ -113,7 +123,8 @@ bool APE::Item::isEmpty() const { } } -void APE::Item::parse(const ByteVector& data) { +void APE::Item::parse(const ByteVector& data) +{ uint valueLength = data.mid(0, 4).toUInt(false); uint flags = data.mid(4, 4).toUInt(false); @@ -124,14 +135,18 @@ void APE::Item::parse(const ByteVector& data) { setReadOnly(flags & 1); setType(ItemTypes((flags >> 1) & 3)); - if ((int)(d->type) < 2) { + if(int(d->type) < 2) { ByteVectorList bl = ByteVectorList::split(d->value, '\0'); d->text = StringList(bl, String::UTF8); } - } ByteVector APE::Item::render() +{ + return const_cast(this)->render(); +} + +ByteVector APE::Item::render() const { ByteVector data; TagLib::uint flags = ((d->readOnly) ? 1 : 0) | (d->type << 1); @@ -144,10 +159,9 @@ ByteVector APE::Item::render() StringList::ConstIterator it = d->text.begin(); value.append(it->data(String::UTF8)); it++; - while(it != d->text.end()) { + for(; it != d->text.end(); ++it) { value.append('\0'); value.append(it->data(String::UTF8)); - it++; } d->value = value; } else diff --git a/ape/apeitem.h b/ape/apeitem.h index ee2b6733..5953d8b5 100644 --- a/ape/apeitem.h +++ b/ape/apeitem.h @@ -35,8 +35,9 @@ namespace TagLib { /*! * This class provides the features of items in the APEv2 standard. */ - struct Item + class Item { + public: /*! * Enum of types an Item can have. The value of 3 is reserved. */ @@ -93,10 +94,15 @@ namespace TagLib { StringList toStringList() const; /*! - * Render the item to a ByteVector + * \deprecated Use the const version. */ ByteVector render(); + /*! + * Render the item to a ByteVector + */ + ByteVector render() const; + /*! * Parse the item from the ByteVector \a data */ diff --git a/ape/apetag.cpp b/ape/apetag.cpp index 0474ee7d..9b63b435 100644 --- a/ape/apetag.cpp +++ b/ape/apetag.cpp @@ -223,11 +223,11 @@ ByteVector APE::Tag::render() const uint itemCount = 0; { - Map::Iterator i = d->itemListMap.begin(); - while(i != d->itemListMap.end()) { - data.append(i->second.render()); + for(Map::ConstIterator it = d->itemListMap.begin(); + it != d->itemListMap.end(); ++it) + { + data.append(it->second.render()); itemCount++; - i++; } }