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
This commit is contained in:
Scott Wheeler 2004-10-28 21:22:33 +00:00
parent d58cde9eca
commit a92f6b94dd
3 changed files with 43 additions and 23 deletions

View File

@ -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<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

View 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
*/

View 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++;
}
}