]> granicus.if.org Git - taglib/commitdiff
Semantic and style cleanups. render() should be const. Use for() loops to
authorScott Wheeler <wheeler@kde.org>
Thu, 28 Oct 2004 21:22:33 +0000 (21:22 +0000)
committerScott Wheeler <wheeler@kde.org>
Thu, 28 Oct 2004 21:22:33 +0000 (21:22 +0000)
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
ape/apeitem.h
ape/apetag.cpp

index ef94b7ea56cabf46de67169e0ed01bd6400d000c..90643ba5bbaf2f4a0434cc7ab30fc6f041176fe9 100644 (file)
@@ -56,50 +56,60 @@ APE::Item::Item(const Item& item)
   d = new ItemPrivate(*item.d);
 }
 
-ItemAPE::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<const Item *>(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
index ee2b67338191011a6073155b4139277230c5df78..5953d8b5b2e351c90b12ab046f4df563768e0680 100644 (file)
@@ -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
        */
index 0474ee7d1095e672d5b13b109440b2a3b94b98a3..9b63b435214342b155d70bfc410deeecba1ab6b2 100644 (file)
@@ -223,11 +223,11 @@ ByteVector APE::Tag::render() const
   uint itemCount = 0;
 
   {
-    Map<const String,Item>::Iterator i = d->itemListMap.begin();
-    while(i != d->itemListMap.end()) {
-      data.append(i->second.render());
+    for(Map<const String, Item>::ConstIterator it = d->itemListMap.begin();
+        it != d->itemListMap.end(); ++it)
+    {
+      data.append(it->second.render());
       itemCount++;
-      i++;
     }
   }