From 043d2bbef5c2a16ba3026010835c21881cb5daa0 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Mon, 4 Aug 2014 15:07:35 +0900 Subject: [PATCH 01/10] Fixed a test to work with MSVC. --- tests/test_ogg.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/test_ogg.cpp b/tests/test_ogg.cpp index c89586aa..8d69371e 100644 --- a/tests/test_ogg.cpp +++ b/tests/test_ogg.cpp @@ -88,12 +88,17 @@ public: CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), tags["UNUSUALTAG"].size()); CPPUNIT_ASSERT_EQUAL(String("usual value"), tags["UNUSUALTAG"][0]); CPPUNIT_ASSERT_EQUAL(String("another value"), tags["UNUSUALTAG"][1]); - CPPUNIT_ASSERT_EQUAL(String("öäüoΣø", String::UTF8), tags["UNICODETAG"][0]); + CPPUNIT_ASSERT_EQUAL( + String("\xC3\xB6\xC3\xA4\xC3\xBC\x6F\xCE\xA3\xC3\xB8", String::UTF8), + tags["UNICODETAG"][0]); - tags["UNICODETAG"][0] = String("νεω ναλυε", String::UTF8); + tags["UNICODETAG"][0] = String( + "\xCE\xBD\xCE\xB5\xCF\x89\x20\xCE\xBD\xCE\xB1\xCE\xBB\xCF\x85\xCE\xB5", String::UTF8); tags.erase("UNUSUALTAG"); f->tag()->setProperties(tags); - CPPUNIT_ASSERT_EQUAL(String("νεω ναλυε", String::UTF8), f->tag()->properties()["UNICODETAG"][0]); + CPPUNIT_ASSERT_EQUAL( + String("\xCE\xBD\xCE\xB5\xCF\x89\x20\xCE\xBD\xCE\xB1\xCE\xBB\xCF\x85\xCE\xB5", String::UTF8), + f->tag()->properties()["UNICODETAG"][0]); CPPUNIT_ASSERT_EQUAL(false, f->tag()->properties().contains("UNUSUALTAG")); delete f; From f76d76728d5067dd66a6e416de5be4fcccca72e1 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Mon, 4 Aug 2014 17:40:56 +0900 Subject: [PATCH 02/10] Fixed some mistakes in the CMake module for float types. --- cmake/modules/TestFloatFormat.cmake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmake/modules/TestFloatFormat.cmake b/cmake/modules/TestFloatFormat.cmake index 0e90cde6..c1bc568f 100644 --- a/cmake/modules/TestFloatFormat.cmake +++ b/cmake/modules/TestFloatFormat.cmake @@ -2,12 +2,13 @@ MACRO(TEST_FLOAT_FORMAT FP_IEEE754) IF(NOT FP_IEEE754) - TRY_COMPILE(HAVE_${FP_IEEE754} "${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}/cmake/TestFloatFormat.c" + TRY_COMPILE(HAVE_FLOAT_FORMAT_BIN + "${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}/cmake/TestFloatFormat.c" COPY_FILE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestFloatFormat.bin") SET(FP_IEEE754 0) - IF(HAVE_${FP_IEEE754}) + IF(HAVE_FLOAT_FORMAT_BIN) # dont match first/last letter because of string rounding errors :-) FILE(STRINGS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestFloatFormat.bin" From 286fd2abec484c285497ee8ea78b97479c3e620d Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Wed, 6 Aug 2014 16:13:15 +0900 Subject: [PATCH 03/10] Fixed some debug messages. --- taglib/toolkit/tfilestream.cpp | 24 ++++++++++++------------ taglib/toolkit/tstring.cpp | 20 ++++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/taglib/toolkit/tfilestream.cpp b/taglib/toolkit/tfilestream.cpp index f9895d78..93078ae9 100644 --- a/taglib/toolkit/tfilestream.cpp +++ b/taglib/toolkit/tfilestream.cpp @@ -177,7 +177,7 @@ FileName FileStream::name() const ByteVector FileStream::readBlock(ulong length) { if(!isOpen()) { - debug("File::readBlock() -- invalid file."); + debug("FileStream::readBlock() -- invalid file."); return ByteVector::null; } @@ -199,12 +199,12 @@ ByteVector FileStream::readBlock(ulong length) void FileStream::writeBlock(const ByteVector &data) { if(!isOpen()) { - debug("File::writeBlock() -- invalid file."); + debug("FileStream::writeBlock() -- invalid file."); return; } if(readOnly()) { - debug("File::writeBlock() -- read only file."); + debug("FileStream::writeBlock() -- read only file."); return; } @@ -214,12 +214,12 @@ void FileStream::writeBlock(const ByteVector &data) void FileStream::insert(const ByteVector &data, ulong start, ulong replace) { if(!isOpen()) { - debug("File::insert() -- invalid file."); + debug("FileStream::insert() -- invalid file."); return; } if(readOnly()) { - debug("File::insert() -- read only file."); + debug("FileStream::insert() -- read only file."); return; } @@ -296,7 +296,7 @@ void FileStream::insert(const ByteVector &data, ulong start, ulong replace) void FileStream::removeBlock(ulong start, ulong length) { if(!isOpen()) { - debug("File::removeBlock() -- invalid file."); + debug("FileStream::removeBlock() -- invalid file."); return; } @@ -343,7 +343,7 @@ bool FileStream::isOpen() const void FileStream::seek(long offset, Position p) { if(!isOpen()) { - debug("File::seek() -- invalid file."); + debug("FileStream::seek() -- invalid file."); return; } @@ -372,7 +372,7 @@ void FileStream::seek(long offset, Position p) SetFilePointer(d->file, 0, NULL, FILE_BEGIN); } if(GetLastError() != NO_ERROR) { - debug("File::seek() -- Failed to set the file pointer."); + debug("FileStream::seek() -- Failed to set the file pointer."); } #else @@ -421,7 +421,7 @@ long FileStream::tell() const return static_cast(position); } else { - debug("File::tell() -- Failed to get the file pointer."); + debug("FileStream::tell() -- Failed to get the file pointer."); return 0; } @@ -435,7 +435,7 @@ long FileStream::tell() const long FileStream::length() { if(!isOpen()) { - debug("File::length() -- invalid file."); + debug("FileStream::length() -- invalid file."); return 0; } @@ -447,7 +447,7 @@ long FileStream::length() return static_cast(fileSize); } else { - debug("File::length() -- Failed to get the file size."); + debug("FileStream::length() -- Failed to get the file size."); return 0; } @@ -480,7 +480,7 @@ void FileStream::truncate(long length) SetLastError(NO_ERROR); SetEndOfFile(d->file); if(GetLastError() != NO_ERROR) { - debug("File::truncate() -- Failed to truncate the file."); + debug("FileStream::truncate() -- Failed to truncate the file."); } seek(currentPos); diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index c43d70b6..8287244b 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -70,7 +70,7 @@ namespace st, srcBegin, srcEnd, source, dstBegin, dstEnd, target); if(result != utf8_utf16_t::ok) { - debug("String::copyFromUTF8() - Unicode conversion error."); + debug("String::UTF16toUTF8() - Unicode conversion error."); } #else @@ -88,7 +88,7 @@ namespace &srcBegin, srcEnd, &dstBegin, dstEnd, Unicode::lenientConversion); if(result != Unicode::conversionOK) { - debug("String::to8Bit() - Unicode conversion error."); + debug("String::UTF16toUTF8() - Unicode conversion error."); } #endif @@ -116,7 +116,7 @@ namespace st, srcBegin, srcEnd, source, dstBegin, dstEnd, target); if(result != utf8_utf16_t::ok) { - debug("String::copyFromUTF8() - Unicode conversion error."); + debug("String::UTF8toUTF16() - Unicode conversion error."); } #else @@ -134,7 +134,7 @@ namespace &srcBegin, srcEnd, &dstBegin, dstEnd, Unicode::lenientConversion); if(result != Unicode::conversionOK) { - debug("String::copyFromUTF8() - Unicode conversion error."); + debug("String::UTF8toUTF16() - Unicode conversion error."); } #endif @@ -197,7 +197,7 @@ String::String(const std::string &s, Type t) else if(t == String::UTF8) copyFromUTF8(s.c_str(), s.length()); else { - debug("String::String() -- A std::string should not contain UTF16."); + debug("String::String() -- std::string should not contain UTF16."); } } @@ -215,7 +215,7 @@ String::String(const wstring &s, Type t) copyFromUTF16(s.c_str(), s.length(), t); } else { - debug("String::String() -- A TagLib::wstring should not contain Latin1 or UTF-8."); + debug("String::String() -- TagLib::wstring should not contain Latin1 or UTF-8."); } } @@ -233,7 +233,7 @@ String::String(const wchar_t *s, Type t) copyFromUTF16(s, ::wcslen(s), t); } else { - debug("String::String() -- A const wchar_t * should not contain Latin1 or UTF-8."); + debug("String::String() -- const wchar_t * should not contain Latin1 or UTF-8."); } } @@ -245,7 +245,7 @@ String::String(const char *s, Type t) else if(t == String::UTF8) copyFromUTF8(s, ::strlen(s)); else { - debug("String::String() -- A const char * should not contain UTF16."); + debug("String::String() -- const char * should not contain UTF16."); } } @@ -255,7 +255,7 @@ String::String(wchar_t c, Type t) if(t == UTF16 || t == UTF16BE || t == UTF16LE) copyFromUTF16(&c, 1, t); else { - debug("String::String() -- A const wchar_t should not contain Latin1 or UTF-8."); + debug("String::String() -- wchar_t should not contain Latin1 or UTF-8."); } } @@ -263,7 +263,7 @@ String::String(char c, Type t) : d(new StringPrivate(1, static_cast(c))) { if(t != Latin1 && t != UTF8) { - debug("String::String() -- A char should not contain UTF16."); + debug("String::String() -- char should not contain UTF16."); } } From 590cb29f995d9171c6b535e98e2869690c6b5282 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Wed, 6 Aug 2014 20:57:04 +0900 Subject: [PATCH 04/10] Improved the CMake check for float/double format. (Intel compiler support) --- cmake/TestFloatFormat.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmake/TestFloatFormat.c b/cmake/TestFloatFormat.c index 5f18aafb..4a7b32e4 100644 --- a/cmake/TestFloatFormat.c +++ b/cmake/TestFloatFormat.c @@ -1,5 +1,7 @@ -int main() +int main(int argc, char **argv) { + int ret = 0; + double bin1[] = { // "*TAGLIB*" encoded as a little-endian floating-point number (double)3.9865557444897601e-105, (double)0.0 @@ -8,6 +10,8 @@ int main() // "*TL*" encoded as a little-endian floating-point number (float)1.81480400e-013, (float)0.0 }; + ret += ((int*)bin1)[argc]; + ret += ((int*)bin2)[argc]; - return 0; + return ret; } From 31a74927e4abb9403c5d9b4dcbbc89642f1978c8 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Thu, 7 Aug 2014 18:49:53 +0900 Subject: [PATCH 05/10] Fixed a bug on stripping tags when saving .WAV files. --- taglib/riff/rifffile.cpp | 22 +++++++------ taglib/riff/wav/wavfile.cpp | 32 +++++++++---------- tests/test_riff.cpp | 63 +++++++++++++++++++++++++++++++++++++ tests/test_wav.cpp | 38 ++++++++++++++++++++++ 4 files changed, 129 insertions(+), 26 deletions(-) diff --git a/taglib/riff/rifffile.cpp b/taglib/riff/rifffile.cpp index a39fce61..979ec530 100644 --- a/taglib/riff/rifffile.cpp +++ b/taglib/riff/rifffile.cpp @@ -219,22 +219,24 @@ void RIFF::File::removeChunk(uint i) { if(i >= d->chunks.size()) return; - - removeBlock(d->chunks[i].offset - 8, d->chunks[i].size + 8); - d->chunks.erase(d->chunks.begin() + i); + + std::vector::iterator it = d->chunks.begin(); + std::advance(it, i); + + const uint removeSize = it->size + it->padding + 8; + removeBlock(it->offset - 8, removeSize); + it = d->chunks.erase(it); + + for(; it != d->chunks.end(); ++it) + it->offset -= removeSize; } void RIFF::File::removeChunk(const ByteVector &name) { - std::vector newChunks; - for(size_t i = 0; i < d->chunks.size(); ++i) { + for(int i = d->chunks.size() - 1; i >= 0; --i) { if(d->chunks[i].name == name) - removeBlock(d->chunks[i].offset - 8, d->chunks[i].size + 8); - else - newChunks.push_back(d->chunks[i]); + removeChunk(i); } - - d->chunks.swap(newChunks); } //////////////////////////////////////////////////////////////////////////////// diff --git a/taglib/riff/wav/wavfile.cpp b/taglib/riff/wav/wavfile.cpp index abecea35..c8d0578c 100644 --- a/taglib/riff/wav/wavfile.cpp +++ b/taglib/riff/wav/wavfile.cpp @@ -147,24 +147,20 @@ bool RIFF::WAV::File::save(TagTypes tags, bool stripOthers, int id3v2Version) strip(static_cast(AllTags & ~tags)); ID3v2::Tag *id3v2tag = d->tag.access(ID3v2Index, false); - if(!id3v2tag->isEmpty()) { - if(tags & ID3v2) { - setChunkData(d->tagChunkID, id3v2tag->render(id3v2Version)); - d->hasID3v2 = true; - } + if((tags & ID3v2) && !id3v2tag->isEmpty()) { + setChunkData(d->tagChunkID, id3v2tag->render(id3v2Version)); + d->hasID3v2 = true; } Info::Tag *infotag = d->tag.access(InfoIndex, false); - if(!infotag->isEmpty()) { - if(tags & Info) { - int chunkId = findInfoTagChunk(); - if(chunkId != -1) - setChunkData(chunkId, infotag->render()); - else - setChunkData("LIST", infotag->render(), true); + if((tags & Info) && !infotag->isEmpty()) { + int chunkId = findInfoTagChunk(); + if(chunkId != -1) + setChunkData(chunkId, infotag->render()); + else + setChunkData("LIST", infotag->render(), true); - d->hasInfo = true; - } + d->hasInfo = true; } return true; @@ -222,13 +218,17 @@ void RIFF::WAV::File::read(bool readProperties, Properties::ReadStyle properties void RIFF::WAV::File::strip(TagTypes tags) { - if(tags & ID3v2) + if(tags & ID3v2) { removeChunk(d->tagChunkID); + d->hasID3v2 = false; + } if(tags & Info){ TagLib::uint chunkId = findInfoTagChunk(); - if(chunkId != TagLib::uint(-1)) + if(chunkId != TagLib::uint(-1)) { removeChunk(chunkId); + d->hasInfo = false; + } } } diff --git a/tests/test_riff.cpp b/tests/test_riff.cpp index 8e120d06..9b07a7ce 100644 --- a/tests/test_riff.cpp +++ b/tests/test_riff.cpp @@ -20,12 +20,17 @@ public: TagLib::uint chunkDataSize(TagLib::uint i) { return RIFF::File::chunkDataSize(i); }; ByteVector chunkName(TagLib::uint i) { return RIFF::File::chunkName(i); }; ByteVector chunkData(TagLib::uint i) { return RIFF::File::chunkData(i); }; + void setChunkData(uint i, const ByteVector &data) { + RIFF::File::setChunkData(i, data); + } void setChunkData(const ByteVector &name, const ByteVector &data) { RIFF::File::setChunkData(name, data); }; virtual TagLib::Tag* tag() const { return 0; }; virtual TagLib::AudioProperties* audioProperties() const { return 0;}; virtual bool save() { return false; }; + void removeChunk(uint i) { RIFF::File::removeChunk(i); } + void removeChunk(const ByteVector &name) { RIFF::File::removeChunk(name); } }; class TestRIFF : public CppUnit::TestFixture @@ -35,6 +40,7 @@ class TestRIFF : public CppUnit::TestFixture CPPUNIT_TEST(testLastChunkAtEvenPosition); CPPUNIT_TEST(testLastChunkAtEvenPosition2); CPPUNIT_TEST(testLastChunkAtEvenPosition3); + CPPUNIT_TEST(testChunkOffset); CPPUNIT_TEST_SUITE_END(); public: @@ -193,6 +199,63 @@ public: delete f; } + void testChunkOffset() + { + ScopedFileCopy copy("empty", ".aiff"); + string filename = copy.fileName(); + + PublicRIFF *f = new PublicRIFF(filename.c_str()); + + CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f->chunkName(0)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f->chunkOffset(0)); + CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(1)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0026 + 8), f->chunkOffset(1)); + CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(2)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x1728 + 8), f->chunkOffset(2)); + + const ByteVector data(0x400, ' '); + f->setChunkData("SSND", data); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f->chunkOffset(0)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0026 + 8), f->chunkOffset(1)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x042E + 8), f->chunkOffset(2)); + + f->seek(f->chunkOffset(0) - 8); + CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f->readBlock(4)); + f->seek(f->chunkOffset(1) - 8); + CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->readBlock(4)); + f->seek(f->chunkOffset(2) - 8); + CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->readBlock(4)); + + f->setChunkData(0, data); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f->chunkOffset(0)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0414 + 8), f->chunkOffset(1)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x081C + 8), f->chunkOffset(2)); + + f->seek(f->chunkOffset(0) - 8); + CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f->readBlock(4)); + f->seek(f->chunkOffset(1) - 8); + CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->readBlock(4)); + f->seek(f->chunkOffset(2) - 8); + CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->readBlock(4)); + + f->removeChunk("SSND"); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f->chunkOffset(0)); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x0414 + 8), f->chunkOffset(1)); + + f->seek(f->chunkOffset(0) - 8); + CPPUNIT_ASSERT_EQUAL(ByteVector("COMM"), f->readBlock(4)); + f->seek(f->chunkOffset(1) - 8); + CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->readBlock(4)); + + f->removeChunk(0); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(0x000C + 8), f->chunkOffset(0)); + + f->seek(f->chunkOffset(0) - 8); + CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->readBlock(4)); + + delete f; + } + }; CPPUNIT_TEST_SUITE_REGISTRATION(TestRIFF); diff --git a/tests/test_wav.cpp b/tests/test_wav.cpp index d17ce2cc..518f37cf 100644 --- a/tests/test_wav.cpp +++ b/tests/test_wav.cpp @@ -14,6 +14,7 @@ class TestWAV : public CppUnit::TestFixture CPPUNIT_TEST_SUITE(TestWAV); CPPUNIT_TEST(testLength); CPPUNIT_TEST(testZeroSizeDataChunk); + CPPUNIT_TEST(testStripTags); CPPUNIT_TEST_SUITE_END(); public: @@ -31,6 +32,43 @@ public: CPPUNIT_ASSERT_EQUAL(false, f.isValid()); } + void testStripTags() + { + ScopedFileCopy copy("empty", ".wav"); + string filename = copy.fileName(); + + RIFF::WAV::File *f = new RIFF::WAV::File(filename.c_str()); + f->ID3v2Tag()->setTitle("test title"); + f->InfoTag()->setTitle("test title"); + f->save(); + delete f; + + f = new RIFF::WAV::File(filename.c_str()); + CPPUNIT_ASSERT(f->hasID3v2Tag()); + CPPUNIT_ASSERT(f->hasInfoTag()); + f->save(RIFF::WAV::File::ID3v2, true); + delete f; + + f = new RIFF::WAV::File(filename.c_str()); + CPPUNIT_ASSERT(f->hasID3v2Tag()); + CPPUNIT_ASSERT(!f->hasInfoTag()); + f->ID3v2Tag()->setTitle("test title"); + f->InfoTag()->setTitle("test title"); + f->save(); + delete f; + + f = new RIFF::WAV::File(filename.c_str()); + CPPUNIT_ASSERT(f->hasID3v2Tag()); + CPPUNIT_ASSERT(f->hasInfoTag()); + f->save(RIFF::WAV::File::Info, true); + delete f; + + f = new RIFF::WAV::File(filename.c_str()); + CPPUNIT_ASSERT(!f->hasID3v2Tag()); + CPPUNIT_ASSERT(f->hasInfoTag()); + delete f; + } + }; CPPUNIT_TEST_SUITE_REGISTRATION(TestWAV); From 1944588595483a7341f9533d0955d58f0da0e2f0 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sun, 1 Dec 2013 08:57:26 +0900 Subject: [PATCH 06/10] Added some missing detach()s to List, ByteVector and String. --- taglib/toolkit/tbytevector.cpp | 14 ++++++++------ taglib/toolkit/tlist.tcc | 1 + taglib/toolkit/tstring.cpp | 2 ++ tests/test_bytevector.cpp | 31 +++++++++++++++++++++++++++++++ tests/test_list.cpp | 7 ++++++- tests/test_map.cpp | 20 +++++++++++++++----- tests/test_string.cpp | 19 +++++++++++++++++++ 7 files changed, 82 insertions(+), 12 deletions(-) diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index 3404ab39..abcaffc5 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -714,7 +714,8 @@ ByteVector &ByteVector::resize(uint size, char padding) ByteVector::Iterator ByteVector::begin() { - return d->data->data.begin() + d->offset; + detach(); + return d->data->data.begin(); } ByteVector::ConstIterator ByteVector::begin() const @@ -724,7 +725,8 @@ ByteVector::ConstIterator ByteVector::begin() const ByteVector::Iterator ByteVector::end() { - return d->data->data.begin() + d->offset + d->length; + detach(); + return d->data->data.end(); } ByteVector::ConstIterator ByteVector::end() const @@ -734,8 +736,8 @@ ByteVector::ConstIterator ByteVector::end() const ByteVector::ReverseIterator ByteVector::rbegin() { - std::vector &v = d->data->data; - return v.rbegin() + (v.size() - (d->offset + d->length)); + detach(); + return d->data->data.rbegin(); } ByteVector::ConstReverseIterator ByteVector::rbegin() const @@ -746,8 +748,8 @@ ByteVector::ConstReverseIterator ByteVector::rbegin() const ByteVector::ReverseIterator ByteVector::rend() { - std::vector &v = d->data->data; - return v.rbegin() + (v.size() - d->offset); + detach(); + return d->data->data.rend(); } ByteVector::ConstReverseIterator ByteVector::rend() const diff --git a/taglib/toolkit/tlist.tcc b/taglib/toolkit/tlist.tcc index 72d4767b..34df7fdd 100644 --- a/taglib/toolkit/tlist.tcc +++ b/taglib/toolkit/tlist.tcc @@ -208,6 +208,7 @@ bool List::isEmpty() const template typename List::Iterator List::find(const T &value) { + detach(); return std::find(d->list.begin(), d->list.end(), value); } diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index 8287244b..c410deb4 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -316,6 +316,7 @@ const wchar_t *String::toCWString() const String::Iterator String::begin() { + detach(); return d->data.begin(); } @@ -326,6 +327,7 @@ String::ConstIterator String::begin() const String::Iterator String::end() { + detach(); return d->data.end(); } diff --git a/tests/test_bytevector.cpp b/tests/test_bytevector.cpp index 5614f695..61b39e05 100644 --- a/tests/test_bytevector.cpp +++ b/tests/test_bytevector.cpp @@ -41,6 +41,7 @@ class TestByteVector : public CppUnit::TestFixture CPPUNIT_TEST(testToHex); CPPUNIT_TEST(testNumericCoversion); CPPUNIT_TEST(testReplace); + CPPUNIT_TEST(testIterator); CPPUNIT_TEST_SUITE_END(); public: @@ -290,6 +291,36 @@ public: } } + void testIterator() + { + ByteVector v1("taglib"); + ByteVector v2 = v1; + + ByteVector::Iterator it1 = v1.begin(); + ByteVector::Iterator it2 = v2.begin(); + + CPPUNIT_ASSERT_EQUAL('t', *it1); + CPPUNIT_ASSERT_EQUAL('t', *it2); + + std::advance(it1, 4); + std::advance(it2, 4); + *it2 = 'I'; + CPPUNIT_ASSERT_EQUAL('i', *it1); + CPPUNIT_ASSERT_EQUAL('I', *it2); + + ByteVector::ReverseIterator it3 = v1.rbegin(); + ByteVector::ReverseIterator it4 = v2.rbegin(); + + CPPUNIT_ASSERT_EQUAL('b', *it3); + CPPUNIT_ASSERT_EQUAL('b', *it4); + + std::advance(it3, 4); + std::advance(it4, 4); + *it4 = 'A'; + CPPUNIT_ASSERT_EQUAL('a', *it3); + CPPUNIT_ASSERT_EQUAL('A', *it4); + } + }; CPPUNIT_TEST_SUITE_REGISTRATION(TestByteVector); diff --git a/tests/test_list.cpp b/tests/test_list.cpp index 39cbaf0a..1b3156b5 100644 --- a/tests/test_list.cpp +++ b/tests/test_list.cpp @@ -51,8 +51,13 @@ public: l3.append(3); l3.append(4); CPPUNIT_ASSERT(l1 == l3); + + List l4 = l1; + List::Iterator it = l4.find(3); + *it = 33; + CPPUNIT_ASSERT_EQUAL(l1[2], 3); + CPPUNIT_ASSERT_EQUAL(l4[2], 33); } - }; CPPUNIT_TEST_SUITE_REGISTRATION(TestList); diff --git a/tests/test_map.cpp b/tests/test_map.cpp index b6f77aae..5fdea157 100644 --- a/tests/test_map.cpp +++ b/tests/test_map.cpp @@ -15,11 +15,21 @@ public: void testInsert() { - Map m; - m.insert("foo", 3); - CPPUNIT_ASSERT_EQUAL(3, m["foo"]); - m.insert("foo", 7); - CPPUNIT_ASSERT_EQUAL(7, m["foo"]); + Map m1; + m1.insert("foo", 3); + CPPUNIT_ASSERT_EQUAL(3, m1["foo"]); + m1.insert("foo", 7); + CPPUNIT_ASSERT_EQUAL(7, m1["foo"]); + + m1.insert("alice", 5); + m1.insert("bob", 9); + m1.insert("carol", 11); + + Map m2 = m1; + Map::Iterator it = m2.find("bob"); + (*it).second = 99; + CPPUNIT_ASSERT_EQUAL(m1["bob"], 9); + CPPUNIT_ASSERT_EQUAL(m2["bob"], 99); } }; diff --git a/tests/test_string.cpp b/tests/test_string.cpp index 40a21576..c620c500 100644 --- a/tests/test_string.cpp +++ b/tests/test_string.cpp @@ -44,6 +44,7 @@ class TestString : public CppUnit::TestFixture CPPUNIT_TEST(testSubstr); CPPUNIT_TEST(testNewline); CPPUNIT_TEST(testEncode); + CPPUNIT_TEST(testIterator); CPPUNIT_TEST_SUITE_END(); public: @@ -280,6 +281,24 @@ public: CPPUNIT_ASSERT(empty7.empty()); } + void testIterator() + { + String s1 = "taglib string"; + String s2 = s1; + + String::Iterator it1 = s1.begin(); + String::Iterator it2 = s2.begin(); + + CPPUNIT_ASSERT_EQUAL(L't', *it1); + CPPUNIT_ASSERT_EQUAL(L't', *it2); + + std::advance(it1, 4); + std::advance(it2, 4); + *it2 = L'I'; + CPPUNIT_ASSERT_EQUAL(L'i', *it1); + CPPUNIT_ASSERT_EQUAL(L'I', *it2); + } + }; CPPUNIT_TEST_SUITE_REGISTRATION(TestString); From 3c727e091e19d2713ffa5be2604f5dd1509c9e89 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Tue, 12 Aug 2014 13:42:44 +0900 Subject: [PATCH 07/10] Removed a useless line from ConfigureChecks.cmake. --- ConfigureChecks.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index 23830f93..bd7c5658 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -240,7 +240,6 @@ if(NOT ZLIB_SOURCE) set(HAVE_ZLIB 0) endif() endif() -set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) find_package(CppUnit) if(NOT CppUnit_FOUND AND BUILD_TESTS) From 9bb0eb7ee9df3fa4267ef5246c7c1d8ed134346b Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Tue, 12 Aug 2014 22:54:54 +0900 Subject: [PATCH 08/10] Added some operators to compare String to string literals. --- taglib/toolkit/tstring.cpp | 31 +++++++++++++++++++++++++++++-- taglib/toolkit/tstring.h | 24 ++++++++++++++++++++++++ tests/test_string.cpp | 12 ++++++++++-- 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index 8287244b..5577feef 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -607,12 +607,39 @@ const TagLib::wchar &String::operator[](int i) const bool String::operator==(const String &s) const { - return d == s.d || d->data == s.d->data; + return (d == s.d || d->data == s.d->data); } bool String::operator!=(const String &s) const { - return !operator==(s); + return !(*this == s); +} + +bool String::operator==(const char *s) const +{ + const wchar_t *p = toCWString(); + + while(*p != L'\0' || *s != '\0') + { + if(*p++ != static_cast(*s++)) + return false; + } + return true; +} + +bool String::operator!=(const char *s) const +{ + return !(*this == s); +} + +bool String::operator==(const wchar_t *s) const +{ + return (::wcscmp(toCWString(), s) == 0); +} + +bool String::operator!=(const wchar_t *s) const +{ + return !(*this == s); } String &String::operator+=(const String &s) diff --git a/taglib/toolkit/tstring.h b/taglib/toolkit/tstring.h index 6d3257eb..ab046d8e 100644 --- a/taglib/toolkit/tstring.h +++ b/taglib/toolkit/tstring.h @@ -397,6 +397,30 @@ namespace TagLib { */ bool operator!=(const String &s) const; + /*! + * Compares each character of the String with each character of \a s and + * returns true if the strings match. + */ + bool operator==(const char *s) const; + + /*! + * Compares each character of the String with each character of \a s and + * returns false if the strings match. + */ + bool operator!=(const char *s) const; + + /*! + * Compares each character of the String with each character of \a s and + * returns true if the strings match. + */ + bool operator==(const wchar_t *s) const; + + /*! + * Compares each character of the String with each character of \a s and + * returns false if the strings match. + */ + bool operator!=(const wchar_t *s) const; + /*! * Appends \a s to the end of the String. */ diff --git a/tests/test_string.cpp b/tests/test_string.cpp index 40a21576..2d59bba2 100644 --- a/tests/test_string.cpp +++ b/tests/test_string.cpp @@ -56,6 +56,14 @@ public: char str[] = "taglib string"; CPPUNIT_ASSERT(strcmp(s.toCString(), str) == 0); + CPPUNIT_ASSERT(s == "taglib string"); + CPPUNIT_ASSERT(s != "taglib STRING"); + CPPUNIT_ASSERT(s != "taglib"); + CPPUNIT_ASSERT(s != "taglib string taglib"); + CPPUNIT_ASSERT(s == L"taglib string"); + CPPUNIT_ASSERT(s != L"taglib STRING"); + CPPUNIT_ASSERT(s != L"taglib"); + CPPUNIT_ASSERT(s != L"taglib string taglib"); String unicode("José Carlos", String::UTF8); CPPUNIT_ASSERT(strcmp(unicode.toCString(), "Jos\xe9 Carlos") == 0); @@ -73,8 +81,8 @@ public: String unicode2(unicode.to8Bit(true), String::UTF8); CPPUNIT_ASSERT(unicode == unicode2); - String unicode3(L"\u65E5\u672C\u8A9E"); - CPPUNIT_ASSERT(*(unicode3.toCWString() + 1) == L'\u672C'); + String unicode3(L"\u65E5\u672C\u8A9E"); + CPPUNIT_ASSERT(*(unicode3.toCWString() + 1) == L'\u672C'); String unicode4(L"\u65e5\u672c\u8a9e", String::UTF16BE); CPPUNIT_ASSERT(unicode4[1] == L'\u672c'); From 387890d956a0925c8d673bcf7a79f2e313cc39be Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Sat, 16 Aug 2014 15:33:39 +0900 Subject: [PATCH 09/10] Small fixes in line breaking. --- taglib/toolkit/tbytevector.cpp | 11 ++++------- taglib/toolkit/tstring.cpp | 14 +++++--------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index 3404ab39..5c5221f5 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -161,15 +161,12 @@ int findVector( lastOccurrence[static_cast(*(patternBegin + i))] = patternSize - i - 1; TIterator it = dataBegin + patternSize - 1 + offset; - while(true) - { + while(true) { TIterator itBuffer = it; TIterator itPattern = patternBegin + patternSize - 1; - while(*itBuffer == *itPattern) - { - if(itPattern == patternBegin) - { + while(*itBuffer == *itPattern) { + if(itPattern == patternBegin) { if((itBuffer - dataBegin - offset) % byteAlign == 0) return (itBuffer - dataBegin); else @@ -243,7 +240,7 @@ ByteVector fromNumber(T value, bool mostSignificantByteFirst) template TFloat toFloat(const ByteVector &v, size_t offset) { - if (offset > v.size() - sizeof(TInt)) { + if(offset > v.size() - sizeof(TInt)) { debug("toFloat() - offset is out of range. Returning 0."); return 0.0; } diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index 5577feef..c51a25d6 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -347,16 +347,13 @@ int String::rfind(const String &s, int offset) const StringList String::split(const String &separator) const { StringList list; - for(int index = 0;;) - { + for(int index = 0;;) { int sep = find(separator, index); - if(sep < 0) - { + if(sep < 0) { list.append(substr(index, size() - index)); break; } - else - { + else { list.append(substr(index, sep - index)); index = sep + separator.size(); } @@ -619,8 +616,7 @@ bool String::operator==(const char *s) const { const wchar_t *p = toCWString(); - while(*p != L'\0' || *s != '\0') - { + while(*p != L'\0' || *s != '\0') { if(*p++ != static_cast(*s++)) return false; } @@ -634,7 +630,7 @@ bool String::operator!=(const char *s) const bool String::operator==(const wchar_t *s) const { - return (::wcscmp(toCWString(), s) == 0); + return (d->data == s); } bool String::operator!=(const wchar_t *s) const From 2971891c69b4edc730ec13398c6fe36af7e2eb05 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Thu, 21 Aug 2014 16:35:35 +0900 Subject: [PATCH 10/10] Reduce useless detach operations by making some non-const iterators const. --- bindings/c/tag_c.cpp | 2 +- examples/tagwriter.cpp | 4 ++-- taglib/ape/apetag.cpp | 2 +- taglib/mod/modtag.cpp | 2 +- taglib/mp4/mp4tag.cpp | 6 +++--- taglib/mpeg/id3v2/frames/chapterframe.cpp | 6 +++--- taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp | 6 +++--- .../mpeg/id3v2/frames/textidentificationframe.cpp | 6 +++--- taglib/mpeg/id3v2/frames/urllinkframe.cpp | 2 +- taglib/mpeg/id3v2/id3v2framefactory.cpp | 14 +++++++------- taglib/mpeg/id3v2/id3v2header.cpp | 2 +- taglib/mpeg/id3v2/id3v2tag.cpp | 6 +++--- taglib/ogg/oggfile.cpp | 2 +- taglib/tag.cpp | 2 +- taglib/toolkit/tpropertymap.cpp | 12 ++++++------ taglib/xm/xmfile.cpp | 2 +- 16 files changed, 38 insertions(+), 38 deletions(-) diff --git a/bindings/c/tag_c.cpp b/bindings/c/tag_c.cpp index 2ae8c7dd..d2567fef 100644 --- a/bindings/c/tag_c.cpp +++ b/bindings/c/tag_c.cpp @@ -233,7 +233,7 @@ void taglib_tag_free_strings() if(!stringManagementEnabled) return; - for(List::Iterator it = strings.begin(); it != strings.end(); ++it) + for(List::ConstIterator it = strings.begin(); it != strings.end(); ++it) free(*it); strings.clear(); } diff --git a/examples/tagwriter.cpp b/examples/tagwriter.cpp index 63163fbe..f2896d76 100644 --- a/examples/tagwriter.cpp +++ b/examples/tagwriter.cpp @@ -94,7 +94,7 @@ int main(int argc, char *argv[]) char field = argv[i][1]; TagLib::String value = argv[i + 1]; - TagLib::List::Iterator it; + TagLib::List::ConstIterator it; for(it = fileList.begin(); it != fileList.end(); ++it) { TagLib::Tag *t = (*it).tag(); @@ -131,7 +131,7 @@ int main(int argc, char *argv[]) usage(); } - TagLib::List::Iterator it; + TagLib::List::ConstIterator it; for(it = fileList.begin(); it != fileList.end(); ++it) (*it).file()->save(); diff --git a/taglib/ape/apetag.cpp b/taglib/ape/apetag.cpp index 3a30fd4a..e1252193 100644 --- a/taglib/ape/apetag.cpp +++ b/taglib/ape/apetag.cpp @@ -233,7 +233,7 @@ PropertyMap APE::Tag::setProperties(const PropertyMap &origProps) toRemove.append(remIt->first); } - for (StringList::Iterator removeIt = toRemove.begin(); removeIt != toRemove.end(); removeIt++) + for(StringList::ConstIterator removeIt = toRemove.begin(); removeIt != toRemove.end(); removeIt++) removeItem(*removeIt); // now sync in the "forward direction" diff --git a/taglib/mod/modtag.cpp b/taglib/mod/modtag.cpp index 14c4c741..4ba72117 100644 --- a/taglib/mod/modtag.cpp +++ b/taglib/mod/modtag.cpp @@ -158,7 +158,7 @@ PropertyMap Mod::Tag::setProperties(const PropertyMap &origProps) // for each tag that has been set above, remove the first entry in the corresponding // value list. The others will be returned as unsupported by this format. - for(StringList::Iterator it = oneValueSet.begin(); it != oneValueSet.end(); ++it) { + for(StringList::ConstIterator it = oneValueSet.begin(); it != oneValueSet.end(); ++it) { if(properties[*it].size() == 1) properties.erase(*it); else diff --git a/taglib/mp4/mp4tag.cpp b/taglib/mp4/mp4tag.cpp index 75a16cd4..09630a70 100644 --- a/taglib/mp4/mp4tag.cpp +++ b/taglib/mp4/mp4tag.cpp @@ -612,11 +612,11 @@ MP4::Tag::saveExisting(ByteVector &data, AtomList &path) long length = ilst->length; MP4::Atom *meta = path[path.size() - 2]; - AtomList::Iterator index = meta->children.find(ilst); + AtomList::ConstIterator index = meta->children.find(ilst); // check if there is an atom before 'ilst', and possibly use it as padding if(index != meta->children.begin()) { - AtomList::Iterator prevIndex = index; + AtomList::ConstIterator prevIndex = index; prevIndex--; MP4::Atom *prev = *prevIndex; if(prev->name == "free") { @@ -625,7 +625,7 @@ MP4::Tag::saveExisting(ByteVector &data, AtomList &path) } } // check if there is an atom after 'ilst', and possibly use it as padding - AtomList::Iterator nextIndex = index; + AtomList::ConstIterator nextIndex = index; nextIndex++; if(nextIndex != meta->children.end()) { MP4::Atom *next = *nextIndex; diff --git a/taglib/mpeg/id3v2/frames/chapterframe.cpp b/taglib/mpeg/id3v2/frames/chapterframe.cpp index b1741cd2..3180e1e0 100644 --- a/taglib/mpeg/id3v2/frames/chapterframe.cpp +++ b/taglib/mpeg/id3v2/frames/chapterframe.cpp @@ -68,7 +68,7 @@ ChapterFrame::ChapterFrame(const ByteVector &eID, const uint &sT, const uint &eT d->startOffset = sO; d->endOffset = eO; FrameList l = eF; - for(FrameList::Iterator it = l.begin(); it != l.end(); ++it) + for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) addEmbeddedFrame(*it); d->factory = FrameFactory::instance(); } @@ -169,7 +169,7 @@ void ChapterFrame::removeEmbeddedFrame(Frame *frame, bool del) void ChapterFrame::removeEmbeddedFrames(const ByteVector &id) { FrameList l = d->embeddedFrameListMap[id]; - for(FrameList::Iterator it = l.begin(); it != l.end(); ++it) + for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) removeEmbeddedFrame(*it, true); } @@ -251,7 +251,7 @@ ByteVector ChapterFrame::renderFields() const data.append(ByteVector::fromUInt(d->startOffset, true)); data.append(ByteVector::fromUInt(d->endOffset, true)); FrameList l = d->embeddedFrameList; - for(FrameList::Iterator it = l.begin(); it != l.end(); ++it) + for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) data.append((*it)->render()); return data; diff --git a/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp b/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp index 26f5a541..9ba00227 100644 --- a/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp +++ b/taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp @@ -63,7 +63,7 @@ TableOfContentsFrame::TableOfContentsFrame(const ByteVector &eID, const ByteVect d->elementID = eID; d->childElements = ch; FrameList l = eF; - for(FrameList::Iterator it = l.begin(); it != l.end(); ++it) + for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) addEmbeddedFrame(*it); d->factory = FrameFactory::instance(); } @@ -170,7 +170,7 @@ void TableOfContentsFrame::removeEmbeddedFrame(Frame *frame, bool del) void TableOfContentsFrame::removeEmbeddedFrames(const ByteVector &id) { FrameList l = d->embeddedFrameListMap[id]; - for(FrameList::Iterator it = l.begin(); it != l.end(); ++it) + for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) removeEmbeddedFrame(*it, true); } @@ -278,7 +278,7 @@ ByteVector TableOfContentsFrame::renderFields() const it++; } FrameList l = d->embeddedFrameList; - for(FrameList::Iterator it = l.begin(); it != l.end(); ++it) + for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) data.append((*it)->render()); return data; diff --git a/taglib/mpeg/id3v2/frames/textidentificationframe.cpp b/taglib/mpeg/id3v2/frames/textidentificationframe.cpp index 70ea50f8..b77dd547 100644 --- a/taglib/mpeg/id3v2/frames/textidentificationframe.cpp +++ b/taglib/mpeg/id3v2/frames/textidentificationframe.cpp @@ -211,12 +211,12 @@ void TextIdentificationFrame::parseFields(const ByteVector &data) // append those split values to the list and make sure that the new string's // type is the same specified for this frame - for(ByteVectorList::Iterator it = l.begin(); it != l.end(); it++) { + for(ByteVectorList::ConstIterator it = l.begin(); it != l.end(); it++) { if(!(*it).isEmpty()) { if(d->textEncoding == String::Latin1) d->fieldList.append(Tag::latin1StringHandler()->parse(*it)); else - d->fieldList.append(String(*it, d->textEncoding)); + d->fieldList.append(String(*it, d->textEncoding)); } } } @@ -394,7 +394,7 @@ UserTextIdentificationFrame *UserTextIdentificationFrame::find( ID3v2::Tag *tag, const String &description) // static { FrameList l = tag->frameList("TXXX"); - for(FrameList::Iterator it = l.begin(); it != l.end(); ++it) { + for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) { UserTextIdentificationFrame *f = dynamic_cast(*it); if(f && f->description() == description) return f; diff --git a/taglib/mpeg/id3v2/frames/urllinkframe.cpp b/taglib/mpeg/id3v2/frames/urllinkframe.cpp index 6bcbbda4..1225b524 100644 --- a/taglib/mpeg/id3v2/frames/urllinkframe.cpp +++ b/taglib/mpeg/id3v2/frames/urllinkframe.cpp @@ -169,7 +169,7 @@ PropertyMap UserUrlLinkFrame::asProperties() const UserUrlLinkFrame *UserUrlLinkFrame::find(ID3v2::Tag *tag, const String &description) // static { FrameList l = tag->frameList("WXXX"); - for(FrameList::Iterator it = l.begin(); it != l.end(); ++it) { + for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) { UserUrlLinkFrame *f = dynamic_cast(*it); if(f && f->description() == description) return f; diff --git a/taglib/mpeg/id3v2/id3v2framefactory.cpp b/taglib/mpeg/id3v2/id3v2framefactory.cpp index 9055be56..e2b1d0de 100644 --- a/taglib/mpeg/id3v2/id3v2framefactory.cpp +++ b/taglib/mpeg/id3v2/id3v2framefactory.cpp @@ -268,22 +268,22 @@ Frame *FrameFactory::createFrame(const ByteVector &origData, Header *tagHeader) if(frameID == "PRIV") return new PrivateFrame(data, header); - + // Ownership (frames 4.22) - + if(frameID == "OWNE") { OwnershipFrame *f = new OwnershipFrame(data, header); d->setTextEncoding(f); return f; } - + // Chapter (ID3v2 chapters 1.0) - + if(frameID == "CHAP") return new ChapterFrame(data, header); - + // Table of contents (ID3v2 chapters 1.0) - + if(frameID == "CTOC") return new TableOfContentsFrame(data, header); @@ -458,7 +458,7 @@ void FrameFactory::updateGenre(TextIdentificationFrame *frame) const StringList fields = frame->fieldList(); StringList newfields; - for(StringList::Iterator it = fields.begin(); it != fields.end(); ++it) { + for(StringList::ConstIterator it = fields.begin(); it != fields.end(); ++it) { String s = *it; int end = s.find(")"); diff --git a/taglib/mpeg/id3v2/id3v2header.cpp b/taglib/mpeg/id3v2/id3v2header.cpp index ad6b3aa7..10381053 100644 --- a/taglib/mpeg/id3v2/id3v2header.cpp +++ b/taglib/mpeg/id3v2/id3v2header.cpp @@ -215,7 +215,7 @@ void Header::parse(const ByteVector &data) return; } - for(ByteVector::Iterator it = sizeData.begin(); it != sizeData.end(); it++) { + for(ByteVector::ConstIterator it = sizeData.begin(); it != sizeData.end(); it++) { if(uchar(*it) >= 128) { d->tagSize = 0; debug("TagLib::ID3v2::Header::parse() - One of the size bytes in the id3v2 header was greater than the allowed 128."); diff --git a/taglib/mpeg/id3v2/id3v2tag.cpp b/taglib/mpeg/id3v2/id3v2tag.cpp index 57637a36..715cb1bc 100644 --- a/taglib/mpeg/id3v2/id3v2tag.cpp +++ b/taglib/mpeg/id3v2/id3v2tag.cpp @@ -356,7 +356,7 @@ void ID3v2::Tag::removeFrame(Frame *frame, bool del) void ID3v2::Tag::removeFrames(const ByteVector &id) { FrameList l = d->frameListMap[id]; - for(FrameList::Iterator it = l.begin(); it != l.end(); ++it) + for(FrameList::ConstIterator it = l.begin(); it != l.end(); ++it) removeFrame(*it, true); } @@ -469,7 +469,7 @@ void ID3v2::Tag::downgradeFrames(FrameList *frames, FrameList *newFrames) const ID3v2::TextIdentificationFrame *frameTDRC = 0; ID3v2::TextIdentificationFrame *frameTIPL = 0; ID3v2::TextIdentificationFrame *frameTMCL = 0; - for(FrameList::Iterator it = d->frameList.begin(); it != d->frameList.end(); it++) { + for(FrameList::ConstIterator it = d->frameList.begin(); it != d->frameList.end(); it++) { ID3v2::Frame *frame = *it; ByteVector frameID = frame->header()->frameID(); for(int i = 0; unsupportedFrames[i]; i++) { @@ -583,7 +583,7 @@ ByteVector ID3v2::Tag::render(int version) const downgradeFrames(&frameList, &newFrames); } - for(FrameList::Iterator it = frameList.begin(); it != frameList.end(); it++) { + for(FrameList::ConstIterator it = frameList.begin(); it != frameList.end(); it++) { (*it)->header()->setVersion(version); if((*it)->header()->frameID().size() != 4) { debug("A frame of unsupported or unknown type \'" diff --git a/taglib/ogg/oggfile.cpp b/taglib/ogg/oggfile.cpp index cc30f9ce..dfd81ec6 100644 --- a/taglib/ogg/oggfile.cpp +++ b/taglib/ogg/oggfile.cpp @@ -354,7 +354,7 @@ void Ogg::File::writePageGroup(const List &thePageGroup) // create a gap for the new pages int numberOfNewPages = pages.back()->header()->pageSequenceNumber() - pageGroup.back(); - List::Iterator pageIter = d->pages.begin(); + List::ConstIterator pageIter = d->pages.begin(); for(int i = 0; i < pageGroup.back(); i++) { if(pageIter != d->pages.end()) { ++pageIter; diff --git a/taglib/tag.cpp b/taglib/tag.cpp index 67634081..98c23043 100644 --- a/taglib/tag.cpp +++ b/taglib/tag.cpp @@ -141,7 +141,7 @@ PropertyMap Tag::setProperties(const PropertyMap &origProps) // for each tag that has been set above, remove the first entry in the corresponding // value list. The others will be returned as unsupported by this format. - for(StringList::Iterator it = oneValueSet.begin(); it != oneValueSet.end(); ++it) { + for(StringList::ConstIterator it = oneValueSet.begin(); it != oneValueSet.end(); ++it) { if(properties[*it].size() == 1) properties.erase(*it); else diff --git a/taglib/toolkit/tpropertymap.cpp b/taglib/toolkit/tpropertymap.cpp index 3317cc92..313d7fb4 100644 --- a/taglib/toolkit/tpropertymap.cpp +++ b/taglib/toolkit/tpropertymap.cpp @@ -154,12 +154,12 @@ String PropertyMap::toString() const void PropertyMap::removeEmpty() { - StringList emptyKeys; - for(Iterator it = begin(); it != end(); ++it) - if(it->second.isEmpty()) - emptyKeys.append(it->first); - for(StringList::Iterator emptyIt = emptyKeys.begin(); emptyIt != emptyKeys.end(); emptyIt++ ) - erase(*emptyIt); + PropertyMap m; + for(ConstIterator it = begin(); it != end(); ++it) { + if(!it->second.isEmpty()) + m.insert(it->first, it->second); + } + *this = m; } StringList &PropertyMap::unsupportedData() diff --git a/taglib/xm/xmfile.cpp b/taglib/xm/xmfile.cpp index 50161fe4..7fe6f108 100644 --- a/taglib/xm/xmfile.cpp +++ b/taglib/xm/xmfile.cpp @@ -329,7 +329,7 @@ public: uint read(TagLib::File &file, uint limit) { uint sumcount = 0; - for(List::Iterator i = m_readers.begin(); + for(List::ConstIterator i = m_readers.begin(); limit > 0 && i != m_readers.end(); ++ i) { uint count = (*i)->read(file, limit); limit -= count;