diff --git a/taglib/ape/apefooter.cpp b/taglib/ape/apefooter.cpp index 68864901..25a4ca54 100644 --- a/taglib/ape/apefooter.cpp +++ b/taglib/ape/apefooter.cpp @@ -177,19 +177,19 @@ void APE::Footer::parse(const ByteVector &data) // Read the version number - d->version = data.mid(8, 4).toUInt(false); + d->version = data.mid(8, 4).toUInt32(false); // Read the tag size - d->tagSize = data.mid(12, 4).toUInt(false); + d->tagSize = data.mid(12, 4).toUInt32(false); // Read the item count - d->itemCount = data.mid(16, 4).toUInt(false); + d->itemCount = data.mid(16, 4).toUInt32(false); // Read the flags - std::bitset<32> flags(TAGLIB_CONSTRUCT_BITSET(data.mid(20, 4).toUInt(false))); + std::bitset<32> flags(TAGLIB_CONSTRUCT_BITSET(data.mid(20, 4).toUInt32(false))); d->headerPresent = flags[31]; d->footerPresent = !flags[30]; @@ -208,15 +208,15 @@ ByteVector APE::Footer::render(bool isHeader) const // add the version number -- we always render a 2.000 tag regardless of what // the tag originally was. - v.append(ByteVector::fromUInt(2000, false)); + v.append(ByteVector::fromUInt32(2000, false)); // add the tag size - v.append(ByteVector::fromUInt(d->tagSize, false)); + v.append(ByteVector::fromUInt32(d->tagSize, false)); // add the item count - v.append(ByteVector::fromUInt(d->itemCount, false)); + v.append(ByteVector::fromUInt32(d->itemCount, false)); // render and add the flags @@ -226,11 +226,11 @@ ByteVector APE::Footer::render(bool isHeader) const flags[30] = false; // footer is always present flags[29] = isHeader; - v.append(ByteVector::fromUInt(flags.to_ulong(), false)); + v.append(ByteVector::fromUInt32(flags.to_ulong(), false)); // add the reserved 64bit - v.append(ByteVector::fromLongLong(0)); + v.append(ByteVector::fromUInt64(0)); return v; } diff --git a/taglib/ape/apeitem.cpp b/taglib/ape/apeitem.cpp index 0e27987d..35a7c077 100644 --- a/taglib/ape/apeitem.cpp +++ b/taglib/ape/apeitem.cpp @@ -159,7 +159,7 @@ void APE::Item::appendValues(const StringList &values) int APE::Item::size() const { // SFB: Why is d->key.size() used when size() returns the length in UniChars and not UTF-8? - int result = 8 + d->key.size() /* d->key.data(String::UTF8).size() */ + 1; + size_t result = 8 + d->key.size() /* d->key.data(String::UTF8).size() */ + 1; switch (d->type) { case Text: if(d->text.size()) { @@ -177,7 +177,7 @@ int APE::Item::size() const result += d->value.size(); break; } - return result; + return static_cast(result); } StringList APE::Item::values() const @@ -216,8 +216,8 @@ void APE::Item::parse(const ByteVector &data) return; } - uint valueLength = data.mid(0, 4).toUInt(false); - uint flags = data.mid(4, 4).toUInt(false); + uint valueLength = data.mid(0, 4).toUInt32(false); + uint flags = data.mid(4, 4).toUInt32(false); d->key = String(data.mid(8), String::UTF8); @@ -253,8 +253,8 @@ ByteVector APE::Item::render() const else value.append(d->value); - data.append(ByteVector::fromUInt(value.size(), false)); - data.append(ByteVector::fromUInt(flags, false)); + data.append(ByteVector::fromUInt32(value.size(), false)); + data.append(ByteVector::fromUInt32(flags, false)); data.append(d->key.data(String::UTF8)); data.append(ByteVector('\0')); data.append(value); diff --git a/taglib/ape/apeproperties.cpp b/taglib/ape/apeproperties.cpp index c99996f0..b8b0783e 100644 --- a/taglib/ape/apeproperties.cpp +++ b/taglib/ape/apeproperties.cpp @@ -128,7 +128,7 @@ void APE::Properties::read() ByteVector commonHeader=d->file->readBlock(6); if(!commonHeader.startsWith("MAC ")) return; - d->version = commonHeader.mid(4).toUInt(false); + d->version = commonHeader.mid(4).toUInt32(false); if(d->version >= 3980) { analyzeCurrent(); @@ -182,7 +182,7 @@ void APE::Properties::analyzeCurrent() // Read the descriptor d->file->seek(2, File::Current); ByteVector descriptor = d->file->readBlock(44); - uint descriptorBytes = descriptor.mid(0,4).toUInt(false); + uint descriptorBytes = descriptor.mid(0,4).toUInt32(false); if ((descriptorBytes - 52) > 0) d->file->seek(descriptorBytes - 52, File::Current); @@ -191,14 +191,14 @@ void APE::Properties::analyzeCurrent() ByteVector header = d->file->readBlock(24); // Get the APE info - d->channels = header.mid(18, 2).toShort(false); - d->sampleRate = header.mid(20, 4).toUInt(false); - d->bitsPerSample = header.mid(16, 2).toShort(false); + d->channels = header.mid(18, 2).toInt16(false); + d->sampleRate = header.mid(20, 4).toUInt32(false); + d->bitsPerSample = header.mid(16, 2).toInt16(false); //d->compressionLevel = - uint totalFrames = header.mid(12, 4).toUInt(false); - uint blocksPerFrame = header.mid(4, 4).toUInt(false); - uint finalFrameBlocks = header.mid(8, 4).toUInt(false); + uint totalFrames = header.mid(12, 4).toUInt32(false); + uint blocksPerFrame = header.mid(4, 4).toUInt32(false); + uint finalFrameBlocks = header.mid(8, 4).toUInt32(false); d->sampleFrames = totalFrames > 0 ? (totalFrames - 1) * blocksPerFrame + finalFrameBlocks : 0; d->length = d->sampleRate > 0 ? d->sampleFrames / d->sampleRate : 0; d->bitrate = d->length > 0 ? static_cast(d->streamLength * 8L / d->length / 1000) : 0; @@ -207,13 +207,13 @@ void APE::Properties::analyzeCurrent() void APE::Properties::analyzeOld() { ByteVector header = d->file->readBlock(26); - uint totalFrames = header.mid(18, 4).toUInt(false); + uint totalFrames = header.mid(18, 4).toUInt32(false); // Fail on 0 length APE files (catches non-finalized APE files) if(totalFrames == 0) return; - short compressionLevel = header.mid(0, 2).toShort(false); + short compressionLevel = header.mid(0, 2).toInt16(false); uint blocksPerFrame; if(d->version >= 3950) blocksPerFrame = 73728 * 4; @@ -221,9 +221,9 @@ void APE::Properties::analyzeOld() blocksPerFrame = 73728; else blocksPerFrame = 9216; - d->channels = header.mid(4, 2).toShort(false); - d->sampleRate = header.mid(6, 4).toUInt(false); - uint finalFrameBlocks = header.mid(22, 4).toUInt(false); + d->channels = header.mid(4, 2).toInt16(false); + d->sampleRate = header.mid(6, 4).toUInt32(false); + uint finalFrameBlocks = header.mid(22, 4).toUInt32(false); uint totalBlocks = totalFrames > 0 ? (totalFrames - 1) * blocksPerFrame + finalFrameBlocks : 0; d->length = totalBlocks / d->sampleRate; d->bitrate = d->length > 0 ? static_cast(d->streamLength * 8L / d->length / 1000) : 0; diff --git a/taglib/ape/apetag.cpp b/taglib/ape/apetag.cpp index 31dccc48..dd6095b1 100644 --- a/taglib/ape/apetag.cpp +++ b/taglib/ape/apetag.cpp @@ -360,7 +360,7 @@ ByteVector APE::Tag::render() const } d->footer.setItemCount(itemCount); - d->footer.setTagSize(data.size() + Footer::size()); + d->footer.setTagSize(static_cast(data.size() + Footer::size())); d->footer.setHeaderPresent(true); return d->footer.renderHeader() + data + d->footer.renderFooter(); diff --git a/taglib/asf/asfattribute.cpp b/taglib/asf/asfattribute.cpp index c6f24910..b4d76dbc 100644 --- a/taglib/asf/asfattribute.cpp +++ b/taglib/asf/asfattribute.cpp @@ -288,12 +288,12 @@ int ASF::Attribute::dataSize() const case QWordType: return 5; case UnicodeType: - return d->stringValue.size() * 2 + 2; + return static_cast(d->stringValue.size() * 2 + 2); case BytesType: if(d->pictureValue.isValid()) return d->pictureValue.dataSize(); case GuidType: - return d->byteVectorValue.size(); + return static_cast(d->byteVectorValue.size()); } return 0; } @@ -304,24 +304,24 @@ ByteVector ASF::Attribute::render(const String &name, int kind) const switch (d->type) { case WordType: - data.append(ByteVector::fromShort(d->shortValue, false)); + data.append(ByteVector::fromUInt16(d->shortValue, false)); break; case BoolType: if(kind == 0) { - data.append(ByteVector::fromUInt(d->boolValue ? 1 : 0, false)); + data.append(ByteVector::fromUInt32(d->boolValue ? 1 : 0, false)); } else { - data.append(ByteVector::fromShort(d->boolValue ? 1 : 0, false)); + data.append(ByteVector::fromUInt16(d->boolValue ? 1 : 0, false)); } break; case DWordType: - data.append(ByteVector::fromUInt(d->intValue, false)); + data.append(ByteVector::fromUInt32(d->intValue, false)); break; case QWordType: - data.append(ByteVector::fromLongLong(d->longLongValue, false)); + data.append(ByteVector::fromUInt64(d->longLongValue, false)); break; case UnicodeType: @@ -340,17 +340,17 @@ ByteVector ASF::Attribute::render(const String &name, int kind) const if(kind == 0) { data = File::renderString(name, true) + - ByteVector::fromShort((int)d->type, false) + - ByteVector::fromShort(data.size(), false) + + ByteVector::fromUInt16((int)d->type, false) + + ByteVector::fromUInt16(data.size(), false) + data; } else { ByteVector nameData = File::renderString(name); - data = ByteVector::fromShort(kind == 2 ? d->language : 0, false) + - ByteVector::fromShort(d->stream, false) + - ByteVector::fromShort(nameData.size(), false) + - ByteVector::fromShort((int)d->type, false) + - ByteVector::fromUInt(data.size(), false) + + data = ByteVector::fromUInt16(kind == 2 ? d->language : 0, false) + + ByteVector::fromUInt16(d->stream, false) + + ByteVector::fromUInt16(nameData.size(), false) + + ByteVector::fromUInt16((int)d->type, false) + + ByteVector::fromUInt32(data.size(), false) + nameData + data; } diff --git a/taglib/asf/asffile.cpp b/taglib/asf/asffile.cpp index 6ddf1f9b..fbddf33d 100644 --- a/taglib/asf/asffile.cpp +++ b/taglib/asf/asffile.cpp @@ -167,7 +167,7 @@ void ASF::File::BaseObject::parse(ASF::File *file, unsigned int size) ByteVector ASF::File::BaseObject::render(ASF::File * /*file*/) { - return guid() + ByteVector::fromLongLong(data.size() + 24, false) + data; + return guid() + ByteVector::fromUInt64(data.size() + 24, false) + data; } ASF::File::UnknownObject::UnknownObject(const ByteVector &guid) : myGuid(guid) @@ -187,7 +187,7 @@ ByteVector ASF::File::FilePropertiesObject::guid() void ASF::File::FilePropertiesObject::parse(ASF::File *file, uint size) { BaseObject::parse(file, size); - file->d->properties->setLength((int)(data.mid(40, 8).toLongLong(false) / 10000000L - data.mid(56, 8).toLongLong(false) / 1000L)); + file->d->properties->setLength((int)(data.mid(40, 8).toInt64(false) / 10000000L - data.mid(56, 8).toInt64(false) / 1000L)); } ByteVector ASF::File::StreamPropertiesObject::guid() @@ -198,9 +198,9 @@ ByteVector ASF::File::StreamPropertiesObject::guid() void ASF::File::StreamPropertiesObject::parse(ASF::File *file, uint size) { BaseObject::parse(file, size); - file->d->properties->setChannels(data.mid(56, 2).toShort(false)); - file->d->properties->setSampleRate(data.mid(58, 4).toUInt(false)); - file->d->properties->setBitrate(data.mid(62, 4).toUInt(false) * 8 / 1000); + file->d->properties->setChannels(data.mid(56, 2).toInt16(false)); + file->d->properties->setSampleRate(data.mid(58, 4).toUInt32(false)); + file->d->properties->setBitrate(data.mid(62, 4).toUInt32(false) * 8 / 1000); } ByteVector ASF::File::ContentDescriptionObject::guid() @@ -231,11 +231,11 @@ ByteVector ASF::File::ContentDescriptionObject::render(ASF::File *file) ByteVector v4 = file->renderString(file->d->tag->comment()); ByteVector v5 = file->renderString(file->d->tag->rating()); data.clear(); - data.append(ByteVector::fromShort(v1.size(), false)); - data.append(ByteVector::fromShort(v2.size(), false)); - data.append(ByteVector::fromShort(v3.size(), false)); - data.append(ByteVector::fromShort(v4.size(), false)); - data.append(ByteVector::fromShort(v5.size(), false)); + data.append(ByteVector::fromUInt16(v1.size(), false)); + data.append(ByteVector::fromUInt16(v2.size(), false)); + data.append(ByteVector::fromUInt16(v3.size(), false)); + data.append(ByteVector::fromUInt16(v4.size(), false)); + data.append(ByteVector::fromUInt16(v5.size(), false)); data.append(v1); data.append(v2); data.append(v3); @@ -263,7 +263,7 @@ void ASF::File::ExtendedContentDescriptionObject::parse(ASF::File *file, uint /* ByteVector ASF::File::ExtendedContentDescriptionObject::render(ASF::File *file) { data.clear(); - data.append(ByteVector::fromShort(attributeData.size(), false)); + data.append(ByteVector::fromUInt16(attributeData.size(), false)); data.append(attributeData.toByteVector(ByteVector::null)); return BaseObject::render(file); } @@ -287,7 +287,7 @@ void ASF::File::MetadataObject::parse(ASF::File *file, uint /*size*/) ByteVector ASF::File::MetadataObject::render(ASF::File *file) { data.clear(); - data.append(ByteVector::fromShort(attributeData.size(), false)); + data.append(ByteVector::fromUInt16(attributeData.size(), false)); data.append(attributeData.toByteVector(ByteVector::null)); return BaseObject::render(file); } @@ -311,7 +311,7 @@ void ASF::File::MetadataLibraryObject::parse(ASF::File *file, uint /*size*/) ByteVector ASF::File::MetadataLibraryObject::render(ASF::File *file) { data.clear(); - data.append(ByteVector::fromShort(attributeData.size(), false)); + data.append(ByteVector::fromUInt16(attributeData.size(), false)); data.append(attributeData.toByteVector(ByteVector::null)); return BaseObject::render(file); } @@ -361,7 +361,7 @@ ByteVector ASF::File::HeaderExtensionObject::render(ASF::File *file) for(unsigned int i = 0; i < objects.size(); i++) { data.append(objects[i]->render(file)); } - data = ByteVector("\x11\xD2\xD3\xAB\xBA\xA9\xcf\x11\x8E\xE6\x00\xC0\x0C\x20\x53\x65\x06\x00", 18) + ByteVector::fromUInt(data.size(), false) + data; + data = ByteVector("\x11\xD2\xD3\xAB\xBA\xA9\xcf\x11\x8E\xE6\x00\xC0\x0C\x20\x53\x65\x06\x00", 18) + ByteVector::fromUInt32(data.size(), false) + data; return BaseObject::render(file); } @@ -552,7 +552,7 @@ bool ASF::File::save() for(unsigned int i = 0; i < d->objects.size(); i++) { data.append(d->objects[i]->render(this)); } - data = headerGuid + ByteVector::fromLongLong(data.size() + 30, false) + ByteVector::fromUInt(d->objects.size(), false) + ByteVector("\x01\x02", 2) + data; + data = headerGuid + ByteVector::fromUInt64(data.size() + 30, false) + ByteVector::fromUInt32(d->objects.size(), false) + ByteVector("\x01\x02", 2) + data; insert(data, 0, (uint)d->size); return true; @@ -581,7 +581,7 @@ int ASF::File::readWORD(bool *ok) return 0; } if(ok) *ok = true; - return v.toUShort(false); + return v.toUInt16(false); } unsigned int ASF::File::readDWORD(bool *ok) @@ -592,7 +592,7 @@ unsigned int ASF::File::readDWORD(bool *ok) return 0; } if(ok) *ok = true; - return v.toUInt(false); + return v.toUInt32(false); } long long ASF::File::readQWORD(bool *ok) @@ -603,13 +603,13 @@ long long ASF::File::readQWORD(bool *ok) return 0; } if(ok) *ok = true; - return v.toLongLong(false); + return v.toInt64(false); } String ASF::File::readString(int length) { ByteVector data = readBlock(length); - unsigned int size = data.size(); + size_t size = data.size(); while (size >= 2) { if(data[size - 1] != '\0' || data[size - 2] != '\0') { break; @@ -624,9 +624,9 @@ String ASF::File::readString(int length) ByteVector ASF::File::renderString(const String &str, bool includeLength) { - ByteVector data = str.data(String::UTF16LE) + ByteVector::fromShort(0, false); + ByteVector data = str.data(String::UTF16LE) + ByteVector::fromUInt16(0, false); if(includeLength) { - data = ByteVector::fromShort(data.size(), false) + data; + data = ByteVector::fromUInt16(data.size(), false) + data; } return data; } diff --git a/taglib/asf/asfpicture.cpp b/taglib/asf/asfpicture.cpp index d8f6b23a..aee9e073 100644 --- a/taglib/asf/asfpicture.cpp +++ b/taglib/asf/asfpicture.cpp @@ -131,9 +131,9 @@ void ASF::Picture::setPicture(const ByteVector &p) int ASF::Picture::dataSize() const { - return + return static_cast( 9 + (d->mimeType.length() + d->description.length()) * 2 + - d->picture.size(); + d->picture.size()); } ASF::Picture& ASF::Picture::operator=(const ASF::Picture& other) @@ -173,7 +173,7 @@ ByteVector ASF::Picture::render() const return ByteVector::null; return ByteVector((char)d->type) + - ByteVector::fromUInt(d->picture.size(), false) + + ByteVector::fromUInt32(d->picture.size(), false) + ASF::File::renderString(d->mimeType) + ASF::File::renderString(d->description) + d->picture; @@ -184,20 +184,20 @@ void ASF::Picture::parse(const ByteVector& bytes) d->valid = false; if(bytes.size() < 9) return; - int pos = 0; + size_t pos = 0; d->type = (Type)bytes[0]; ++pos; - uint dataLen = bytes.mid(pos, 4).toUInt(false); pos+=4; + uint dataLen = bytes.mid(pos, 4).toUInt32(false); pos+=4; const ByteVector nullStringTerminator(2, 0); - int endPos = bytes.find(nullStringTerminator, pos, 2); - if(endPos < 0) + size_t endPos = bytes.find(nullStringTerminator, pos, 2); + if(endPos == ByteVector::npos) return; d->mimeType = String(bytes.mid(pos, endPos - pos), String::UTF16LE); pos = endPos+2; endPos = bytes.find(nullStringTerminator, pos, 2); - if(endPos < 0) + if(endPos == ByteVector::npos) return; d->description = String(bytes.mid(pos, endPos - pos), String::UTF16LE); pos = endPos+2; diff --git a/taglib/fileref.cpp b/taglib/fileref.cpp index 4b456a94..cf4a05d3 100644 --- a/taglib/fileref.cpp +++ b/taglib/fileref.cpp @@ -295,8 +295,8 @@ File *FileRef::create(FileName fileName, bool readAudioProperties, #else { String s = fileName; - int pos = s.rfind("."); - if(pos != -1) + const size_t pos = s.rfind("."); + if(pos != String::npos) ext = s.substr(pos + 1).upper(); } #endif diff --git a/taglib/flac/flacfile.cpp b/taglib/flac/flacfile.cpp index 61ac49f2..7900d5bb 100644 --- a/taglib/flac/flacfile.cpp +++ b/taglib/flac/flacfile.cpp @@ -70,8 +70,8 @@ public: ~FilePrivate() { - uint size = blocks.size(); - for(uint i = 0; i < size; i++) { + size_t size = blocks.size(); + for(size_t i = 0; i < size; i++) { delete blocks[i]; } delete properties; @@ -197,7 +197,7 @@ bool FLAC::File::save() for(uint i = 0; i < newBlocks.size(); i++) { FLAC::MetadataBlock *block = newBlocks[i]; ByteVector blockData = block->render(); - ByteVector blockHeader = ByteVector::fromUInt(blockData.size()); + ByteVector blockHeader = ByteVector::fromUInt32(blockData.size()); blockHeader[0] = block->code(); data.append(blockHeader); data.append(blockData); @@ -206,11 +206,11 @@ bool FLAC::File::save() // Adjust the padding block(s) uint originalLength = static_cast(d->streamStart - d->flacStart); - int paddingLength = originalLength - data.size() - 4; + int paddingLength = static_cast(originalLength - data.size() - 4); if (paddingLength < 0) { paddingLength = MinPaddingLength; } - ByteVector padding = ByteVector::fromUInt(paddingLength); + ByteVector padding = ByteVector::fromUInt32(paddingLength); padding.resize(paddingLength + 4); padding[0] = (char)(FLAC::MetadataBlock::Padding | LastBlockFlag); data.append(padding); @@ -361,7 +361,7 @@ void FLAC::File::scan() char blockType = header[0] & 0x7f; bool isLastBlock = (header[0] & 0x80) != 0; - uint length = header.mid(1, 3).toUInt(); + uint length = header.mid(1, 3).toUInt32(); // First block should be the stream_info metadata @@ -381,7 +381,7 @@ void FLAC::File::scan() header = readBlock(4); blockType = header[0] & 0x7f; isLastBlock = (header[0] & 0x80) != 0; - length = header.mid(1, 3).toUInt(); + length = header.mid(1, 3).toUInt32(); ByteVector data = readBlock(length); if(data.size() != length || length == 0) { diff --git a/taglib/flac/flacpicture.cpp b/taglib/flac/flacpicture.cpp index 36019248..a7bcce6d 100644 --- a/taglib/flac/flacpicture.cpp +++ b/taglib/flac/flacpicture.cpp @@ -83,9 +83,9 @@ bool FLAC::Picture::parse(const ByteVector &data) } int pos = 0; - d->type = FLAC::Picture::Type(data.mid(pos, 4).toUInt()); + d->type = FLAC::Picture::Type(data.mid(pos, 4).toUInt32()); pos += 4; - uint mimeTypeLength = data.mid(pos, 4).toUInt(); + uint mimeTypeLength = data.mid(pos, 4).toUInt32(); pos += 4; if(pos + mimeTypeLength + 24 > data.size()) { debug("Invalid picture block."); @@ -93,7 +93,7 @@ bool FLAC::Picture::parse(const ByteVector &data) } d->mimeType = String(data.mid(pos, mimeTypeLength), String::UTF8); pos += mimeTypeLength; - uint descriptionLength = data.mid(pos, 4).toUInt(); + uint descriptionLength = data.mid(pos, 4).toUInt32(); pos += 4; if(pos + descriptionLength + 20 > data.size()) { debug("Invalid picture block."); @@ -101,15 +101,15 @@ bool FLAC::Picture::parse(const ByteVector &data) } d->description = String(data.mid(pos, descriptionLength), String::UTF8); pos += descriptionLength; - d->width = data.mid(pos, 4).toUInt(); + d->width = data.mid(pos, 4).toUInt32(); pos += 4; - d->height = data.mid(pos, 4).toUInt(); + d->height = data.mid(pos, 4).toUInt32(); pos += 4; - d->colorDepth = data.mid(pos, 4).toUInt(); + d->colorDepth = data.mid(pos, 4).toUInt32(); pos += 4; - d->numColors = data.mid(pos, 4).toUInt(); + d->numColors = data.mid(pos, 4).toUInt32(); pos += 4; - uint dataLength = data.mid(pos, 4).toUInt(); + uint dataLength = data.mid(pos, 4).toUInt32(); pos += 4; if(pos + dataLength > data.size()) { debug("Invalid picture block."); @@ -123,18 +123,18 @@ bool FLAC::Picture::parse(const ByteVector &data) ByteVector FLAC::Picture::render() const { ByteVector result; - result.append(ByteVector::fromUInt(d->type)); + result.append(ByteVector::fromUInt32(d->type)); ByteVector mimeTypeData = d->mimeType.data(String::UTF8); - result.append(ByteVector::fromUInt(mimeTypeData.size())); + result.append(ByteVector::fromUInt32(mimeTypeData.size())); result.append(mimeTypeData); ByteVector descriptionData = d->description.data(String::UTF8); - result.append(ByteVector::fromUInt(descriptionData.size())); + result.append(ByteVector::fromUInt32(descriptionData.size())); result.append(descriptionData); - result.append(ByteVector::fromUInt(d->width)); - result.append(ByteVector::fromUInt(d->height)); - result.append(ByteVector::fromUInt(d->colorDepth)); - result.append(ByteVector::fromUInt(d->numColors)); - result.append(ByteVector::fromUInt(d->data.size())); + result.append(ByteVector::fromUInt32(d->width)); + result.append(ByteVector::fromUInt32(d->height)); + result.append(ByteVector::fromUInt32(d->colorDepth)); + result.append(ByteVector::fromUInt32(d->numColors)); + result.append(ByteVector::fromUInt32(d->data.size())); result.append(d->data); return result; } diff --git a/taglib/flac/flacproperties.cpp b/taglib/flac/flacproperties.cpp index 92f69bdc..2a8c8e94 100644 --- a/taglib/flac/flacproperties.cpp +++ b/taglib/flac/flacproperties.cpp @@ -132,7 +132,7 @@ void FLAC::Properties::read() // Maximum frame size (in bytes) pos += 3; - uint flags = d->data.mid(pos, 4).toUInt(true); + uint flags = d->data.mid(pos, 4).toUInt32(true); pos += 4; d->sampleRate = flags >> 12; @@ -143,7 +143,7 @@ void FLAC::Properties::read() // stream length in samples. (Audio files measured in days) unsigned long long hi = flags & 0xf; - unsigned long long lo = d->data.mid(pos, 4).toUInt(true); + unsigned long long lo = d->data.mid(pos, 4).toUInt32(true); pos += 4; d->sampleFrames = (hi << 32) | lo; diff --git a/taglib/it/itfile.cpp b/taglib/it/itfile.cpp index cc466582..f0e84e85 100644 --- a/taglib/it/itfile.cpp +++ b/taglib/it/itfile.cpp @@ -166,7 +166,7 @@ bool IT::File::save() if(messageOffset + messageLength >= fileSize) { // append new message seek(54); - writeU16L(message.size()); + writeU16L(static_cast(message.size())); writeU32L(messageOffset); seek(messageOffset); writeBlock(message); @@ -224,8 +224,8 @@ void IT::File::read(bool) seek(messageOffset); ByteVector messageBytes = readBlock(messageLength); READ_ASSERT(messageBytes.size() == messageLength); - int index = messageBytes.find((char) 0); - if(index > -1) + const size_t index = messageBytes.find((char) 0); + if(index != ByteVector::npos) messageBytes.resize(index, 0); messageBytes.replace('\r', '\n'); message = messageBytes; diff --git a/taglib/mod/modfile.cpp b/taglib/mod/modfile.cpp index 455b1238..aad2e138 100644 --- a/taglib/mod/modfile.cpp +++ b/taglib/mod/modfile.cpp @@ -82,7 +82,7 @@ bool Mod::File::save() seek(0); writeString(d->tag.title(), 20); StringList lines = d->tag.comment().split("\n"); - uint n = std::min(lines.size(), d->properties.instrumentCount()); + uint n = std::min(static_cast(lines.size()), d->properties.instrumentCount()); for(uint i = 0; i < n; ++ i) { writeString(lines[i], 22); seek(8, Current); diff --git a/taglib/mod/modfilebase.cpp b/taglib/mod/modfilebase.cpp index 0d19aa89..ca97e75d 100644 --- a/taglib/mod/modfilebase.cpp +++ b/taglib/mod/modfilebase.cpp @@ -44,8 +44,8 @@ bool Mod::FileBase::readString(String &s, uint size) { ByteVector data(readBlock(size)); if(data.size() < size) return false; - int index = data.find((char) 0); - if(index > -1) + const size_t index = data.find((char) 0); + if(index != ByteVector::npos) { data.resize(index); } @@ -63,22 +63,22 @@ void Mod::FileBase::writeByte(uchar byte) void Mod::FileBase::writeU16L(ushort number) { - writeBlock(ByteVector::fromShort(number, false)); + writeBlock(ByteVector::fromUInt16(number, false)); } void Mod::FileBase::writeU32L(uint number) { - writeBlock(ByteVector::fromUInt(number, false)); + writeBlock(ByteVector::fromUInt32(number, false)); } void Mod::FileBase::writeU16B(ushort number) { - writeBlock(ByteVector::fromShort(number, true)); + writeBlock(ByteVector::fromUInt16(number, true)); } void Mod::FileBase::writeU32B(uint number) { - writeBlock(ByteVector::fromUInt(number, true)); + writeBlock(ByteVector::fromUInt32(number, true)); } bool Mod::FileBase::readByte(uchar &byte) @@ -93,14 +93,14 @@ bool Mod::FileBase::readU16L(ushort &number) { ByteVector data(readBlock(2)); if(data.size() < 2) return false; - number = data.toUShort(false); + number = data.toUInt16(false); return true; } bool Mod::FileBase::readU32L(uint &number) { ByteVector data(readBlock(4)); if(data.size() < 4) return false; - number = data.toUInt(false); + number = data.toUInt32(false); return true; } @@ -108,13 +108,13 @@ bool Mod::FileBase::readU16B(ushort &number) { ByteVector data(readBlock(2)); if(data.size() < 2) return false; - number = data.toUShort(true); + number = data.toUInt16(true); return true; } bool Mod::FileBase::readU32B(uint &number) { ByteVector data(readBlock(4)); if(data.size() < 4) return false; - number = data.toUInt(true); + number = data.toUInt32(true); return true; } diff --git a/taglib/mp4/mp4atom.cpp b/taglib/mp4/mp4atom.cpp index 92e0c17f..482e495f 100644 --- a/taglib/mp4/mp4atom.cpp +++ b/taglib/mp4/mp4atom.cpp @@ -52,10 +52,10 @@ MP4::Atom::Atom(File *file) return; } - length = header.mid(0, 4).toUInt(); + length = header.mid(0, 4).toUInt32(); if (length == 1) { - long long longLength = file->readBlock(8).toLongLong(); + long long longLength = file->readBlock(8).toInt64(); if (longLength >= 8 && longLength <= 0xFFFFFFFF) { // The atom has a 64-bit length, but it's actually a 32-bit value length = (long)longLength; diff --git a/taglib/mp4/mp4item.cpp b/taglib/mp4/mp4item.cpp index bc918fe9..cb6523e8 100644 --- a/taglib/mp4/mp4item.cpp +++ b/taglib/mp4/mp4item.cpp @@ -289,13 +289,13 @@ MP4::Item::toString() const return d->m_stringList.toString(" / "); case TypeByteVectorList: for(TagLib::uint i = 0; i < d->m_byteVectorList.size(); i++) { - SPRINTF(tmp, "[%d bytes of data]", d->m_byteVectorList[i].size()); + SPRINTF(tmp, "[%d bytes of data]", static_cast(d->m_byteVectorList[i].size())); desc.append(tmp); } return desc.toString(", "); case TypeCoverArtList: for(TagLib::uint i = 0; i < d->m_coverArtList.size(); i++) { - SPRINTF(tmp, "[%d bytes of data]", d->m_coverArtList[i].data().size()); + SPRINTF(tmp, "[%d bytes of data]", static_cast(d->m_coverArtList[i].data().size())); desc.append(tmp); } return desc.toString(", "); diff --git a/taglib/mp4/mp4properties.cpp b/taglib/mp4/mp4properties.cpp index 35830bb9..3353b494 100644 --- a/taglib/mp4/mp4properties.cpp +++ b/taglib/mp4/mp4properties.cpp @@ -103,8 +103,8 @@ MP4::Properties::Properties(File *file, MP4::Atoms *atoms, ReadStyle style) debug("MP4: Atom 'trak.mdia.mdhd' is smaller than expected"); return; } - long long unit = data.mid(28, 8).toLongLong(); - long long length = data.mid(36, 8).toLongLong(); + long long unit = data.mid(28, 8).toInt64(); + long long length = data.mid(36, 8).toInt64(); d->length = unit ? int(length / unit) : 0; } else { @@ -112,8 +112,8 @@ MP4::Properties::Properties(File *file, MP4::Atoms *atoms, ReadStyle style) debug("MP4: Atom 'trak.mdia.mdhd' is smaller than expected"); return; } - unsigned int unit = data.mid(20, 4).toUInt(); - unsigned int length = data.mid(24, 4).toUInt(); + unsigned int unit = data.mid(20, 4).toUInt32(); + unsigned int length = data.mid(24, 4).toUInt32(); d->length = unit ? length / unit : 0; } @@ -126,9 +126,9 @@ MP4::Properties::Properties(File *file, MP4::Atoms *atoms, ReadStyle style) data = file->readBlock(atom->length); if(data.mid(20, 4) == "mp4a") { d->format = PropertiesPrivate::AAC; - d->channels = data.mid(40, 2).toShort(); - d->bitsPerSample = data.mid(42, 2).toShort(); - d->sampleRate = data.mid(46, 4).toUInt(); + d->channels = data.mid(40, 2).toInt16(); + d->bitsPerSample = data.mid(42, 2).toInt16(); + d->sampleRate = data.mid(46, 4).toUInt32(); if(data.mid(56, 4) == "esds" && data[64] == 0x03) { long pos = 65; if(data.mid(pos, 3) == "\x80\x80\x80") { @@ -141,7 +141,7 @@ MP4::Properties::Properties(File *file, MP4::Atoms *atoms, ReadStyle style) pos += 3; } pos += 10; - d->bitrate = (data.mid(pos, 4).toUInt() + 500) / 1000; + d->bitrate = (data.mid(pos, 4).toUInt32() + 500) / 1000; } } } @@ -150,8 +150,8 @@ MP4::Properties::Properties(File *file, MP4::Atoms *atoms, ReadStyle style) if (atom->length == 88 && data.mid(56, 4) == "alac") { d->bitsPerSample = data.at(69); d->channels = data.at(73); - d->bitrate = data.mid(80, 4).toUInt() / 1000; - d->sampleRate = data.mid(84, 4).toUInt(); + d->bitrate = data.mid(80, 4).toUInt32() / 1000; + d->sampleRate = data.mid(84, 4).toUInt32(); } } diff --git a/taglib/mp4/mp4tag.cpp b/taglib/mp4/mp4tag.cpp index 26e2e381..c10dbb86 100644 --- a/taglib/mp4/mp4tag.cpp +++ b/taglib/mp4/mp4tag.cpp @@ -114,9 +114,9 @@ MP4::Tag::parseData2(MP4::Atom *atom, TagLib::File *file, int expectedFlags, boo int i = 0; unsigned int pos = 0; while(pos < data.size()) { - int length = data.mid(pos, 4).toUInt(); + int length = data.mid(pos, 4).toUInt32(); ByteVector name = data.mid(pos + 4, 4); - int flags = data.mid(pos + 8, 4).toUInt(); + int flags = data.mid(pos + 8, 4).toUInt32(); if(freeForm && i < 2) { if(i == 0 && name != "mean") { debug("MP4: Unexpected atom \"" + name + "\", expecting \"mean\""); @@ -159,7 +159,7 @@ MP4::Tag::parseInt(MP4::Atom *atom, TagLib::File *file) { ByteVectorList data = parseData(atom, file); if(data.size()) { - d->items.insert(atom->name, (int)data[0].toShort()); + d->items.insert(atom->name, (int)data[0].toInt16()); } } @@ -168,7 +168,7 @@ MP4::Tag::parseUInt(MP4::Atom *atom, TagLib::File *file) { ByteVectorList data = parseData(atom, file); if(data.size()) { - d->items.insert(atom->name, data[0].toUInt()); + d->items.insert(atom->name, data[0].toUInt32()); } } @@ -177,7 +177,7 @@ MP4::Tag::parseLongLong(MP4::Atom *atom, TagLib::File *file) { ByteVectorList data = parseData(atom, file); if(data.size()) { - d->items.insert(atom->name, data[0].toLongLong()); + d->items.insert(atom->name, data[0].toInt64()); } } @@ -195,7 +195,7 @@ MP4::Tag::parseGnre(MP4::Atom *atom, TagLib::File *file) { ByteVectorList data = parseData(atom, file); if(data.size()) { - int idx = (int)data[0].toShort(); + int idx = (int)data[0].toInt16(); if(!d->items.contains("\251gen") && idx > 0) { d->items.insert("\251gen", StringList(ID3v1::genre(idx - 1))); } @@ -207,8 +207,8 @@ MP4::Tag::parseIntPair(MP4::Atom *atom, TagLib::File *file) { ByteVectorList data = parseData(atom, file); if(data.size()) { - int a = data[0].mid(2, 2).toShort(); - int b = data[0].mid(4, 2).toShort(); + int a = data[0].mid(2, 2).toInt16(); + int b = data[0].mid(4, 2).toInt16(); d->items.insert(atom->name, MP4::Item(a, b)); } } @@ -277,9 +277,9 @@ MP4::Tag::parseCovr(MP4::Atom *atom, TagLib::File *file) ByteVector data = file->readBlock(atom->length - 8); unsigned int pos = 0; while(pos < data.size()) { - int length = data.mid(pos, 4).toUInt(); + int length = data.mid(pos, 4).toUInt32(); ByteVector name = data.mid(pos + 4, 4); - int flags = data.mid(pos + 8, 4).toUInt(); + int flags = data.mid(pos + 8, 4).toUInt32(); if(name != "data") { debug("MP4: Unexpected atom \"" + name + "\", expecting \"data\""); break; @@ -301,7 +301,7 @@ ByteVector MP4::Tag::padIlst(const ByteVector &data, int length) { if (length == -1) { - length = ((data.size() + 1023) & ~1023) - data.size(); + length = static_cast(((data.size() + 1023) & ~1023) - data.size()); } return renderAtom("free", ByteVector(length, '\1')); } @@ -309,7 +309,7 @@ MP4::Tag::padIlst(const ByteVector &data, int length) ByteVector MP4::Tag::renderAtom(const ByteVector &name, const ByteVector &data) { - return ByteVector::fromUInt(data.size() + 8) + name + data; + return ByteVector::fromUInt32(data.size() + 8) + name + data; } ByteVector @@ -317,7 +317,7 @@ MP4::Tag::renderData(const ByteVector &name, int flags, const ByteVectorList &da { ByteVector result; for(unsigned int i = 0; i < data.size(); i++) { - result.append(renderAtom("data", ByteVector::fromUInt(flags) + ByteVector(4, '\0') + data[i])); + result.append(renderAtom("data", ByteVector::fromUInt32(flags) + ByteVector(4, '\0') + data[i])); } return renderAtom(name, result); } @@ -334,7 +334,7 @@ ByteVector MP4::Tag::renderInt(const ByteVector &name, MP4::Item &item) { ByteVectorList data; - data.append(ByteVector::fromShort(item.toInt())); + data.append(ByteVector::fromUInt16(item.toInt())); return renderData(name, TypeInteger, data); } @@ -342,7 +342,7 @@ ByteVector MP4::Tag::renderUInt(const ByteVector &name, MP4::Item &item) { ByteVectorList data; - data.append(ByteVector::fromUInt(item.toUInt())); + data.append(ByteVector::fromUInt32(item.toUInt())); return renderData(name, TypeInteger, data); } @@ -350,7 +350,7 @@ ByteVector MP4::Tag::renderLongLong(const ByteVector &name, MP4::Item &item) { ByteVectorList data; - data.append(ByteVector::fromLongLong(item.toLongLong())); + data.append(ByteVector::fromUInt64(item.toLongLong())); return renderData(name, TypeInteger, data); } @@ -367,8 +367,8 @@ MP4::Tag::renderIntPair(const ByteVector &name, MP4::Item &item) { ByteVectorList data; data.append(ByteVector(2, '\0') + - ByteVector::fromShort(item.toIntPair().first) + - ByteVector::fromShort(item.toIntPair().second) + + ByteVector::fromUInt16(item.toIntPair().first) + + ByteVector::fromUInt16(item.toIntPair().second) + ByteVector(2, '\0')); return renderData(name, TypeImplicit, data); } @@ -378,8 +378,8 @@ MP4::Tag::renderIntPairNoTrailing(const ByteVector &name, MP4::Item &item) { ByteVectorList data; data.append(ByteVector(2, '\0') + - ByteVector::fromShort(item.toIntPair().first) + - ByteVector::fromShort(item.toIntPair().second)); + ByteVector::fromUInt16(item.toIntPair().first) + + ByteVector::fromUInt16(item.toIntPair().second)); return renderData(name, TypeImplicit, data); } @@ -400,7 +400,7 @@ MP4::Tag::renderCovr(const ByteVector &name, MP4::Item &item) ByteVector data; MP4::CoverArtList value = item.toCoverArtList(); for(unsigned int i = 0; i < value.size(); i++) { - data.append(renderAtom("data", ByteVector::fromUInt(value[i].format()) + + data.append(renderAtom("data", ByteVector::fromUInt32(value[i].format()) + ByteVector(4, '\0') + value[i].data())); } return renderAtom(name, data); @@ -415,8 +415,8 @@ MP4::Tag::renderFreeForm(const String &name, MP4::Item &item) return ByteVector::null; } ByteVector data; - data.append(renderAtom("mean", ByteVector::fromUInt(0) + header[1].data(String::UTF8))); - data.append(renderAtom("name", ByteVector::fromUInt(0) + header[2].data(String::UTF8))); + data.append(renderAtom("mean", ByteVector::fromUInt32(0) + header[1].data(String::UTF8))); + data.append(renderAtom("name", ByteVector::fromUInt32(0) + header[2].data(String::UTF8))); AtomDataType type = item.atomDataType(); if(type == TypeUndefined) { if(!item.toStringList().isEmpty()) { @@ -429,13 +429,13 @@ MP4::Tag::renderFreeForm(const String &name, MP4::Item &item) if(type == TypeUTF8) { StringList value = item.toStringList(); for(unsigned int i = 0; i < value.size(); i++) { - data.append(renderAtom("data", ByteVector::fromUInt(type) + ByteVector(4, '\0') + value[i].data(String::UTF8))); + data.append(renderAtom("data", ByteVector::fromUInt32(type) + ByteVector(4, '\0') + value[i].data(String::UTF8))); } } else { ByteVectorList value = item.toByteVectorList(); for(unsigned int i = 0; i < value.size(); i++) { - data.append(renderAtom("data", ByteVector::fromUInt(type) + ByteVector(4, '\0') + value[i])); + data.append(renderAtom("data", ByteVector::fromUInt32(type) + ByteVector(4, '\0') + value[i])); } } return renderAtom("----", data); @@ -500,19 +500,19 @@ MP4::Tag::updateParents(AtomList &path, long delta, int ignore) { for(unsigned int i = 0; i < path.size() - ignore; i++) { d->file->seek(path[i]->offset); - long size = d->file->readBlock(4).toUInt(); + long size = d->file->readBlock(4).toUInt32(); // 64-bit if (size == 1) { d->file->seek(4, File::Current); // Skip name - long long longSize = d->file->readBlock(8).toLongLong(); + long long longSize = d->file->readBlock(8).toInt64(); // Seek the offset of the 64-bit size d->file->seek(path[i]->offset + 8); - d->file->writeBlock(ByteVector::fromLongLong(longSize + delta)); + d->file->writeBlock(ByteVector::fromUInt64(longSize + delta)); } // 32-bit else { d->file->seek(path[i]->offset); - d->file->writeBlock(ByteVector::fromUInt(size + delta)); + d->file->writeBlock(ByteVector::fromUInt32(size + delta)); } } } @@ -530,15 +530,15 @@ MP4::Tag::updateOffsets(long delta, offset_t offset) } d->file->seek(atom->offset + 12); ByteVector data = d->file->readBlock(atom->length - 12); - unsigned int count = data.mid(0, 4).toUInt(); + unsigned int count = data.mid(0, 4).toUInt32(); d->file->seek(atom->offset + 16); int pos = 4; while(count--) { - long o = data.mid(pos, 4).toUInt(); + long o = data.mid(pos, 4).toUInt32(); if(o > offset) { o += delta; } - d->file->writeBlock(ByteVector::fromUInt(o)); + d->file->writeBlock(ByteVector::fromUInt32(o)); pos += 4; } } @@ -551,15 +551,15 @@ MP4::Tag::updateOffsets(long delta, offset_t offset) } d->file->seek(atom->offset + 12); ByteVector data = d->file->readBlock(atom->length - 12); - unsigned int count = data.mid(0, 4).toUInt(); + unsigned int count = data.mid(0, 4).toUInt32(); d->file->seek(atom->offset + 16); int pos = 4; while(count--) { - long long o = data.mid(pos, 8).toLongLong(); + long long o = data.mid(pos, 8).toInt64(); if(o > offset) { o += delta; } - d->file->writeBlock(ByteVector::fromLongLong(o)); + d->file->writeBlock(ByteVector::fromUInt64(o)); pos += 8; } } @@ -575,14 +575,14 @@ MP4::Tag::updateOffsets(long delta, offset_t offset) } d->file->seek(atom->offset + 9); ByteVector data = d->file->readBlock(atom->length - 9); - unsigned int flags = (ByteVector(1, '\0') + data.mid(0, 3)).toUInt(); + unsigned int flags = (ByteVector(1, '\0') + data.mid(0, 3)).toUInt32(); if(flags & 1) { - long long o = data.mid(7, 8).toLongLong(); + long long o = data.mid(7, 8).toInt64(); if(o > offset) { o += delta; } d->file->seek(atom->offset + 16); - d->file->writeBlock(ByteVector::fromLongLong(o)); + d->file->writeBlock(ByteVector::fromUInt64(o)); } } } @@ -604,8 +604,8 @@ MP4::Tag::saveNew(ByteVector &data) offset_t offset = path[path.size() - 1]->offset + 8; d->file->insert(data, offset, 0); - updateParents(path, data.size()); - updateOffsets(data.size(), offset); + updateParents(path, static_cast(data.size())); + updateOffsets(static_cast(data.size()), offset); } void @@ -638,10 +638,10 @@ MP4::Tag::saveExisting(ByteVector &data, AtomList &path) } } - long delta = data.size() - length; + long delta = static_cast(data.size()) - length; if(delta > 0 || (delta < 0 && delta > -8)) { data.append(padIlst(data)); - delta = data.size() - length; + delta = static_cast(data.size()) - length; } else if(delta < 0) { data.append(padIlst(data, -delta - 8)); diff --git a/taglib/mpc/mpcproperties.cpp b/taglib/mpc/mpcproperties.cpp index 1bc24090..440c5dd2 100644 --- a/taglib/mpc/mpcproperties.cpp +++ b/taglib/mpc/mpcproperties.cpp @@ -207,7 +207,7 @@ void MPC::Properties::readSV8(File *file) d->sampleFrames = readSize(data.mid(pos), pos); uint begSilence = readSize(data.mid(pos), pos); - std::bitset<16> flags(TAGLIB_CONSTRUCT_BITSET(data.mid(pos, 2).toUShort(true))); + std::bitset<16> flags(TAGLIB_CONSTRUCT_BITSET(data.mid(pos, 2).toUInt16(true))); pos += 2; d->sampleRate = sftable[flags[15] * 4 + flags[14] * 2 + flags[13]]; @@ -228,10 +228,10 @@ void MPC::Properties::readSV8(File *file) int replayGainVersion = data[0]; if(replayGainVersion == 1) { - d->trackGain = data.mid(1, 2).toUInt(true); - d->trackPeak = data.mid(3, 2).toUInt(true); - d->albumGain = data.mid(5, 2).toUInt(true); - d->albumPeak = data.mid(7, 2).toUInt(true); + d->trackGain = data.mid(1, 2).toUInt32(true); + d->trackPeak = data.mid(3, 2).toUInt32(true); + d->albumGain = data.mid(5, 2).toUInt32(true); + d->albumPeak = data.mid(7, 2).toUInt32(true); } } @@ -252,18 +252,18 @@ void MPC::Properties::readSV7(const ByteVector &data) if(d->version < 7) return; - d->totalFrames = data.mid(4, 4).toUInt(false); + d->totalFrames = data.mid(4, 4).toUInt32(false); - std::bitset<32> flags(TAGLIB_CONSTRUCT_BITSET(data.mid(8, 4).toUInt(false))); + std::bitset<32> flags(TAGLIB_CONSTRUCT_BITSET(data.mid(8, 4).toUInt32(false))); d->sampleRate = sftable[flags[17] * 2 + flags[16]]; d->channels = 2; - uint gapless = data.mid(5, 4).toUInt(false); + uint gapless = data.mid(5, 4).toUInt32(false); - d->trackGain = data.mid(14,2).toShort(false); - d->trackPeak = data.mid(12,2).toUInt(false); - d->albumGain = data.mid(18,2).toShort(false); - d->albumPeak = data.mid(16,2).toUInt(false); + d->trackGain = data.mid(14,2).toInt16(false); + d->trackPeak = data.mid(12,2).toUInt32(false); + d->albumGain = data.mid(18,2).toInt16(false); + d->albumPeak = data.mid(16,2).toUInt32(false); // convert gain info if(d->trackGain != 0) { @@ -293,7 +293,7 @@ void MPC::Properties::readSV7(const ByteVector &data) d->sampleFrames = d->totalFrames * 1152 - 576; } else { - uint headerData = data.mid(0, 4).toUInt(false); + uint headerData = data.mid(0, 4).toUInt32(false); d->bitrate = (headerData >> 23) & 0x01ff; d->version = (headerData >> 11) & 0x03ff; @@ -301,9 +301,9 @@ void MPC::Properties::readSV7(const ByteVector &data) d->channels = 2; if(d->version >= 5) - d->totalFrames = data.mid(4, 4).toUInt(false); + d->totalFrames = data.mid(4, 4).toUInt32(false); else - d->totalFrames = data.mid(6, 2).toUInt(false); + d->totalFrames = data.mid(6, 2).toUInt32(false); d->sampleFrames = d->totalFrames * 1152 - 576; } diff --git a/taglib/mpeg/id3v2/frames/popularimeterframe.cpp b/taglib/mpeg/id3v2/frames/popularimeterframe.cpp index cfe8c9f4..cbc3c7c5 100644 --- a/taglib/mpeg/id3v2/frames/popularimeterframe.cpp +++ b/taglib/mpeg/id3v2/frames/popularimeterframe.cpp @@ -109,7 +109,7 @@ void PopularimeterFrame::parseFields(const ByteVector &data) if(pos < size) { d->rating = (unsigned char)(data[pos++]); if(pos < size) { - d->counter = data.mid(pos, 4).toUInt(); + d->counter = data.mid(pos, 4).toUInt32(); } } } @@ -121,7 +121,7 @@ ByteVector PopularimeterFrame::renderFields() const data.append(d->email.data(String::Latin1)); data.append(textDelimiter(String::Latin1)); data.append(char(d->rating)); - data.append(ByteVector::fromUInt(d->counter)); + data.append(ByteVector::fromUInt32(d->counter)); return data; } diff --git a/taglib/mpeg/id3v2/frames/privateframe.cpp b/taglib/mpeg/id3v2/frames/privateframe.cpp index 24ee0f35..e70f831a 100644 --- a/taglib/mpeg/id3v2/frames/privateframe.cpp +++ b/taglib/mpeg/id3v2/frames/privateframe.cpp @@ -99,8 +99,7 @@ void PrivateFrame::parseFields(const ByteVector &data) // Owner identifier is assumed to be Latin1 - const int byteAlign = 1; - const int endOfOwner = data.find(textDelimiter(String::Latin1), 0, byteAlign); + const size_t endOfOwner = data.find(textDelimiter(String::Latin1), 0, 1); d->owner = String(data.mid(0, endOfOwner)); d->data = data.mid(endOfOwner + 1); diff --git a/taglib/mpeg/id3v2/frames/relativevolumeframe.cpp b/taglib/mpeg/id3v2/frames/relativevolumeframe.cpp index 33254ede..8dd8b366 100644 --- a/taglib/mpeg/id3v2/frames/relativevolumeframe.cpp +++ b/taglib/mpeg/id3v2/frames/relativevolumeframe.cpp @@ -161,7 +161,7 @@ void RelativeVolumeFrame::parseFields(const ByteVector &data) ChannelData &channel = d->channels[type]; - channel.volumeAdjustment = data.mid(pos, 2).toShort(); + channel.volumeAdjustment = data.mid(pos, 2).toInt16(); pos += 2; channel.peakVolume.bitsRepresentingPeak = data[pos]; @@ -187,7 +187,7 @@ ByteVector RelativeVolumeFrame::renderFields() const const ChannelData &channel = (*it).second; data.append(char(type)); - data.append(ByteVector::fromShort(channel.volumeAdjustment)); + data.append(ByteVector::fromUInt16(channel.volumeAdjustment)); data.append(char(channel.peakVolume.bitsRepresentingPeak)); data.append(channel.peakVolume.peakVolume); } diff --git a/taglib/mpeg/id3v2/frames/textidentificationframe.cpp b/taglib/mpeg/id3v2/frames/textidentificationframe.cpp index 70ea50f8..2849a873 100644 --- a/taglib/mpeg/id3v2/frames/textidentificationframe.cpp +++ b/taglib/mpeg/id3v2/frames/textidentificationframe.cpp @@ -164,8 +164,8 @@ PropertyMap TextIdentificationFrame::asProperties() const for(StringList::Iterator it = values.begin(); it != values.end(); ++it) { // ID3v2 specifies ISO8601 timestamps which contain a 'T' as separator between date and time. // Since this is unusual in other formats, the T is removed. - int tpos = it->find("T"); - if(tpos != -1) + const size_t tpos = it->find("T"); + if(tpos != String::npos) (*it)[tpos] = ' '; } } @@ -196,7 +196,7 @@ void TextIdentificationFrame::parseFields(const ByteVector &data) // build a small counter to strip nulls off the end of the field - int dataLength = data.size() - 1; + int dataLength = static_cast(data.size()) - 1; while(dataLength > 0 && data[dataLength] == 0) dataLength--; @@ -414,7 +414,7 @@ UserTextIdentificationFrame::UserTextIdentificationFrame(const ByteVector &data, void UserTextIdentificationFrame::checkFields() { - int fields = fieldList().size(); + const size_t fields = fieldList().size(); if(fields == 0) setDescription(String::null); diff --git a/taglib/mpeg/id3v2/frames/urllinkframe.cpp b/taglib/mpeg/id3v2/frames/urllinkframe.cpp index 6bcbbda4..fe5b04ee 100644 --- a/taglib/mpeg/id3v2/frames/urllinkframe.cpp +++ b/taglib/mpeg/id3v2/frames/urllinkframe.cpp @@ -184,22 +184,22 @@ void UserUrlLinkFrame::parseFields(const ByteVector &data) return; } - int pos = 0; + size_t pos = 0; d->textEncoding = String::Type(data[0]); pos += 1; if(d->textEncoding == String::Latin1 || d->textEncoding == String::UTF8) { - int offset = data.find(textDelimiter(d->textEncoding), pos); - if(offset < pos) + const size_t offset = data.find(textDelimiter(d->textEncoding), pos); + if(offset == ByteVector::npos || offset < pos) return; d->description = String(data.mid(pos, offset - pos), d->textEncoding); pos = offset + 1; } else { - int len = data.mid(pos).find(textDelimiter(d->textEncoding), 0, 2); - if(len < 0) + const size_t len = data.mid(pos).find(textDelimiter(d->textEncoding), 0, 2); + if(len == ByteVector::npos) return; d->description = String(data.mid(pos, len), d->textEncoding); diff --git a/taglib/mpeg/id3v2/id3v2frame.cpp b/taglib/mpeg/id3v2/id3v2frame.cpp index e2b84311..89b1d0af 100644 --- a/taglib/mpeg/id3v2/id3v2frame.cpp +++ b/taglib/mpeg/id3v2/id3v2frame.cpp @@ -193,7 +193,7 @@ void Frame::setText(const String &) ByteVector Frame::render() const { ByteVector fieldData = renderFields(); - d->header->setFrameSize(fieldData.size()); + d->header->setFrameSize(static_cast(fieldData.size())); ByteVector headerData = d->header->render(); return headerData + fieldData; @@ -240,10 +240,10 @@ void Frame::parse(const ByteVector &data) ByteVector Frame::fieldData(const ByteVector &frameData) const { - uint headerSize = Header::size(d->header->version()); + const size_t headerSize = Header::size(d->header->version()); - uint frameDataOffset = headerSize; - uint frameDataLength = size(); + size_t frameDataOffset = headerSize; + size_t frameDataLength = size(); if(d->header->compression() || d->header->dataLengthIndicator()) { frameDataLength = SynchData::toUInt(frameData.mid(headerSize, 4)); @@ -255,7 +255,7 @@ ByteVector Frame::fieldData(const ByteVector &frameData) const !d->header->encryption()) { ByteVector data(frameDataLength); - uLongf uLongTmp = frameDataLength; + uLongf uLongTmp = static_cast(frameDataLength); ::uncompress((Bytef *) data.data(), (uLongf *) &uLongTmp, (Bytef *) frameData.data() + frameDataOffset, @@ -276,9 +276,8 @@ String Frame::readStringField(const ByteVector &data, String::Type encoding, int ByteVector delimiter = textDelimiter(encoding); - int end = data.find(delimiter, *position, delimiter.size()); - - if(end < *position) + const size_t end = data.find(delimiter, *position, delimiter.size()); + if(end == ByteVector::npos || end < static_cast(*position)) return String::null; String str; @@ -287,7 +286,7 @@ String Frame::readStringField(const ByteVector &data, String::Type encoding, int else str = String(data.mid(*position, end - *position), encoding); - *position = end + delimiter.size(); + *position = static_cast(end + delimiter.size()); return str; } @@ -642,7 +641,7 @@ void Frame::Header::setData(const ByteVector &data, uint version) return; } - d->frameSize = data.mid(3, 3).toUInt(); + d->frameSize = data.mid(3, 3).toUInt32(); break; } @@ -670,7 +669,7 @@ void Frame::Header::setData(const ByteVector &data, uint version) // Set the size -- the frame size is the four bytes starting at byte four in // the frame header (structure 4) - d->frameSize = data.mid(4, 4).toUInt(); + d->frameSize = data.mid(4, 4).toUInt32(); { // read the first byte of flags std::bitset<8> flags(data[8]); @@ -717,7 +716,7 @@ void Frame::Header::setData(const ByteVector &data, uint version) // iTunes writes v2.4 tags with v2.3-like frame sizes if(d->frameSize > 127) { if(!isValidFrameID(data.mid(d->frameSize + 10, 4))) { - unsigned int uintSize = data.mid(4, 4).toUInt(); + unsigned int uintSize = data.mid(4, 4).toUInt32(); if(isValidFrameID(data.mid(uintSize + 10, 4))) { d->frameSize = uintSize; } @@ -831,7 +830,7 @@ ByteVector Frame::Header::render() const ByteVector v = d->frameID + (d->version == 3 - ? ByteVector::fromUInt(d->frameSize) + ? ByteVector::fromUInt32(d->frameSize) : SynchData::fromUInt(d->frameSize)) + flags; diff --git a/taglib/mpeg/id3v2/id3v2framefactory.cpp b/taglib/mpeg/id3v2/id3v2framefactory.cpp index c7d74214..0ac17090 100644 --- a/taglib/mpeg/id3v2/id3v2framefactory.cpp +++ b/taglib/mpeg/id3v2/id3v2framefactory.cpp @@ -432,9 +432,9 @@ void FrameFactory::updateGenre(TextIdentificationFrame *frame) const for(StringList::Iterator it = fields.begin(); it != fields.end(); ++it) { String s = *it; - int end = s.find(")"); + const size_t end = s.find(")"); - if(s.startsWith("(") && end > 0) { + if(s.startsWith("(") && end != String::npos) { // "(12)Genre" String text = s.substr(end + 1); bool ok; diff --git a/taglib/mpeg/id3v2/id3v2synchdata.cpp b/taglib/mpeg/id3v2/id3v2synchdata.cpp index d4bab679..05d17a1f 100644 --- a/taglib/mpeg/id3v2/id3v2synchdata.cpp +++ b/taglib/mpeg/id3v2/id3v2synchdata.cpp @@ -34,7 +34,7 @@ TagLib::uint SynchData::toUInt(const ByteVector &data) { uint sum = 0; bool notSynchSafe = false; - int last = data.size() > 4 ? 3 : data.size() - 1; + const int last = data.size() > 4 ? 3 : static_cast(data.size()) - 1; for(int i = 0; i <= last; i++) { if(data[i] & 0x80) { @@ -49,7 +49,7 @@ TagLib::uint SynchData::toUInt(const ByteVector &data) // Invalid data; assume this was created by some buggy software that just // put normal integers here rather than syncsafe ones, and try it that // way. - sum = (data.size() > 4) ? data.mid(0, 4).toUInt() : data.toUInt(); + sum = (data.size() > 4) ? data.mid(0, 4).toUInt32() : data.toUInt32(); } return sum; diff --git a/taglib/mpeg/id3v2/id3v2tag.cpp b/taglib/mpeg/id3v2/id3v2tag.cpp index 7180ece1..5587db35 100644 --- a/taglib/mpeg/id3v2/id3v2tag.cpp +++ b/taglib/mpeg/id3v2/id3v2tag.cpp @@ -593,8 +593,8 @@ ByteVector ID3v2::Tag::render(int version) const // Compute the amount of padding, and append that to tagData. - uint paddingSize = 0; - uint originalSize = d->header.tagSize(); + size_t paddingSize = 0; + const size_t originalSize = d->header.tagSize(); if(tagData.size() < originalSize) paddingSize = originalSize - tagData.size(); @@ -605,7 +605,7 @@ ByteVector ID3v2::Tag::render(int version) const // Set the version and data size. d->header.setMajorVersion(version); - d->header.setTagSize(tagData.size()); + d->header.setTagSize(static_cast(tagData.size())); // TODO: This should eventually include d->footer->render(). return d->header.render() + tagData; @@ -652,8 +652,8 @@ void ID3v2::Tag::parse(const ByteVector &origData) if(d->header.unsynchronisation() && d->header.majorVersion() <= 3) data = SynchData::decode(data); - uint frameDataPosition = 0; - uint frameDataLength = data.size(); + size_t frameDataPosition = 0; + size_t frameDataLength = data.size(); // check for extended header @@ -689,7 +689,7 @@ void ID3v2::Tag::parse(const ByteVector &origData) debug("Padding *and* a footer found. This is not allowed by the spec."); } - d->paddingSize = frameDataLength - frameDataPosition; + d->paddingSize = static_cast(frameDataLength - frameDataPosition); return; } diff --git a/taglib/mpeg/mpegfile.cpp b/taglib/mpeg/mpegfile.cpp index 21cf9162..2446be56 100644 --- a/taglib/mpeg/mpegfile.cpp +++ b/taglib/mpeg/mpegfile.cpp @@ -370,13 +370,13 @@ offset_t MPEG::File::previousFrameOffset(offset_t position) seek(position); buffer = readBlock(size); - if(buffer.size() <= 0) + if(buffer.isEmpty()) break; if(foundFirstSyncPattern && uchar(buffer[buffer.size() - 1]) == 0xff) return position + buffer.size() - 1; - for(int i = buffer.size() - 2; i >= 0; i--) { + for(int i = static_cast(buffer.size()) - 2; i >= 0; i--) { if(uchar(buffer[i]) == 0xff && secondSynchByte(buffer[i + 1])) return position + i; } @@ -478,18 +478,17 @@ offset_t MPEG::File::findID3v2() // The position in the file that the current buffer starts at. offset_t bufferOffset = 0; - ByteVector buffer; // These variables are used to keep track of a partial match that happens at // the end of a buffer. - int previousPartialMatch = -1; + size_t previousPartialMatch = ByteVector::npos; bool previousPartialSynchMatch = false; // Save the location of the current read pointer. We will restore the // position using seek() before all returns. - offset_t originalPosition = tell(); + const offset_t originalPosition = tell(); // Start the search at the beginning of the file. @@ -507,15 +506,19 @@ offset_t MPEG::File::findID3v2() // note this for use in the next itteration, where we will check for the rest // of the pattern. - for(buffer = readBlock(bufferSize()); buffer.size() > 0; buffer = readBlock(bufferSize())) { + while(true) + { + ByteVector buffer = readBlock(bufferSize()); + if(buffer.isEmpty()) + break; // (1) previous partial match if(previousPartialSynchMatch && secondSynchByte(buffer[0])) return -1; - if(previousPartialMatch >= 0 && int(bufferSize()) > previousPartialMatch) { - const int patternOffset = (bufferSize() - previousPartialMatch); + if(previousPartialMatch != ByteVector::npos && bufferSize() > previousPartialMatch) { + const size_t patternOffset = (bufferSize() - previousPartialMatch); if(buffer.containsAt(ID3v2::Header::fileIdentifier(), 0, patternOffset)) { seek(originalPosition); return bufferOffset - bufferSize() + previousPartialMatch; @@ -524,23 +527,23 @@ offset_t MPEG::File::findID3v2() // (2) pattern contained in current buffer - long location = buffer.find(ID3v2::Header::fileIdentifier()); - if(location >= 0) { + const size_t location = buffer.find(ID3v2::Header::fileIdentifier()); + if(location != ByteVector::npos) { seek(originalPosition); return bufferOffset + location; } - int firstSynchByte = buffer.find(char(uchar(255))); + size_t firstSynchByte = buffer.find(char(uchar(255))); // Here we have to loop because there could be several of the first // (11111111) byte, and we want to check all such instances until we find // a full match (11111111 111) or hit the end of the buffer. - while(firstSynchByte >= 0) { + while(firstSynchByte != ByteVector::npos) { // if this *is not* at the end of the buffer - if(firstSynchByte < int(buffer.size()) - 1) { + if(firstSynchByte < buffer.size() - 1) { if(secondSynchByte(buffer[firstSynchByte + 1])) { // We've found the frame synch pattern. seek(originalPosition); diff --git a/taglib/mpeg/mpegheader.cpp b/taglib/mpeg/mpegheader.cpp index c120b2b9..57b143c0 100644 --- a/taglib/mpeg/mpegheader.cpp +++ b/taglib/mpeg/mpegheader.cpp @@ -205,7 +205,7 @@ void MPEG::Header::parse(const ByteVector &data) return; } - std::bitset<32> flags(TAGLIB_CONSTRUCT_BITSET(data.toUInt())); + std::bitset<32> flags(TAGLIB_CONSTRUCT_BITSET(data.toUInt32())); // Check for the second byte's part of the MPEG synch diff --git a/taglib/mpeg/xingheader.cpp b/taglib/mpeg/xingheader.cpp index b34082a5..aafcdf86 100644 --- a/taglib/mpeg/xingheader.cpp +++ b/taglib/mpeg/xingheader.cpp @@ -108,8 +108,8 @@ void MPEG::XingHeader::parse(const ByteVector &data) return; } - d->frames = data.mid(8, 4).toUInt(); - d->size = data.mid(12, 4).toUInt(); + d->frames = data.mid(8, 4).toUInt32(); + d->size = data.mid(12, 4).toUInt32(); d->valid = true; } diff --git a/taglib/ogg/flac/oggflacfile.cpp b/taglib/ogg/flac/oggflacfile.cpp index 53139bba..5f976ef2 100644 --- a/taglib/ogg/flac/oggflacfile.cpp +++ b/taglib/ogg/flac/oggflacfile.cpp @@ -108,7 +108,7 @@ bool Ogg::FLAC::File::save() // Put the size in the first 32 bit (I assume no more than 24 bit are used) - ByteVector v = ByteVector::fromUInt(d->xiphCommentData.size()); + ByteVector v = ByteVector::fromUInt32(d->xiphCommentData.size()); // Set the type of the metadata-block to be a Xiph / Vorbis comment @@ -230,7 +230,7 @@ void Ogg::FLAC::File::scan() char blockType = header[0] & 0x7f; bool lastBlock = (header[0] & 0x80) != 0; - uint length = header.mid(1, 3).toUInt(); + uint length = header.mid(1, 3).toUInt32(); overhead += length; // Sanity: First block should be the stream_info metadata @@ -253,7 +253,7 @@ void Ogg::FLAC::File::scan() header = metadataHeader.mid(0, 4); blockType = header[0] & 0x7f; lastBlock = (header[0] & 0x80) != 0; - length = header.mid(1, 3).toUInt(); + length = header.mid(1, 3).toUInt32(); overhead += length; if(blockType == 1) { diff --git a/taglib/ogg/oggfile.cpp b/taglib/ogg/oggfile.cpp index b8047070..bf857080 100644 --- a/taglib/ogg/oggfile.cpp +++ b/taglib/ogg/oggfile.cpp @@ -269,7 +269,7 @@ bool Ogg::File::nextPage() uint currentPacket = d->currentPage->firstPacketIndex() + i; if(d->packetToPageMap.size() <= currentPacket) d->packetToPageMap.push_back(List()); - d->packetToPageMap[currentPacket].append(d->pages.size() - 1); + d->packetToPageMap[currentPacket].append(static_cast(d->pages.size()) - 1); } return true; diff --git a/taglib/ogg/oggpage.cpp b/taglib/ogg/oggpage.cpp index 86d788e5..4a1aea8e 100644 --- a/taglib/ogg/oggpage.cpp +++ b/taglib/ogg/oggpage.cpp @@ -133,7 +133,7 @@ Ogg::Page::ContainsPacketFlags Ogg::Page::containsPacket(int index) const TagLib::uint Ogg::Page::packetCount() const { - return d->header.packetSizes().size(); + return static_cast(d->header.packetSizes().size()); } ByteVectorList Ogg::Page::packets() const @@ -188,7 +188,7 @@ ByteVector Ogg::Page::render() const // the entire page with the 4 bytes reserved for the checksum zeroed and then // inserted in bytes 22-25 of the page header. - ByteVector checksum = ByteVector::fromUInt(data.checksum(), false); + ByteVector checksum = ByteVector::fromUInt32(data.checksum(), false); for(int i = 0; i < 4; i++) data[i + 22] = checksum[i]; @@ -205,7 +205,7 @@ List Ogg::Page::paginate(const ByteVectorList &packets, { List l; - int totalSize = 0; + size_t totalSize = 0; for(ByteVectorList::ConstIterator it = packets.begin(); it != packets.end(); ++it) totalSize += (*it).size(); @@ -331,7 +331,7 @@ Ogg::Page::Page(const ByteVectorList &packets, // Build a page from the list of packets. for(ByteVectorList::ConstIterator it = packets.begin(); it != packets.end(); ++it) { - packetSizes.append((*it).size()); + packetSizes.append(static_cast((*it).size())); data.append(*it); } d->packets = packets; diff --git a/taglib/ogg/oggpageheader.cpp b/taglib/ogg/oggpageheader.cpp index 9ac88ef6..2024464f 100644 --- a/taglib/ogg/oggpageheader.cpp +++ b/taglib/ogg/oggpageheader.cpp @@ -203,15 +203,15 @@ ByteVector Ogg::PageHeader::render() const // absolute granular position - data.append(ByteVector::fromLongLong(d->absoluteGranularPosition, false)); + data.append(ByteVector::fromUInt64(d->absoluteGranularPosition, false)); // stream serial number - data.append(ByteVector::fromUInt(d->streamSerialNumber, false)); + data.append(ByteVector::fromUInt32(d->streamSerialNumber, false)); // page sequence number - data.append(ByteVector::fromUInt(d->pageSequenceNumber, false)); + data.append(ByteVector::fromUInt32(d->pageSequenceNumber, false)); // checksum -- this is left empty and should be filled in by the Ogg::Page // class @@ -255,9 +255,9 @@ void Ogg::PageHeader::read() d->firstPageOfStream = flags.test(1); d->lastPageOfStream = flags.test(2); - d->absoluteGranularPosition = data.mid(6, 8).toLongLong(false); - d->streamSerialNumber = data.mid(14, 4).toUInt(false); - d->pageSequenceNumber = data.mid(18, 4).toUInt(false); + d->absoluteGranularPosition = data.mid(6, 8).toInt64(false); + d->streamSerialNumber = data.mid(14, 4).toUInt32(false); + d->pageSequenceNumber = data.mid(18, 4).toUInt32(false); // Byte number 27 is the number of page segments, which is the only variable // length portion of the page header. After reading the number of page diff --git a/taglib/ogg/opus/opusproperties.cpp b/taglib/ogg/opus/opusproperties.cpp index 70679d4c..9caf2bc0 100644 --- a/taglib/ogg/opus/opusproperties.cpp +++ b/taglib/ogg/opus/opusproperties.cpp @@ -129,11 +129,11 @@ void Opus::Properties::read() pos += 1; // *Pre-skip* (16 bits, unsigned, little endian) - ushort preSkip = data.mid(pos, 2).toUShort(false); + ushort preSkip = data.mid(pos, 2).toUInt16(false); pos += 2; // *Input Sample Rate* (32 bits, unsigned, little endian) - d->inputSampleRate = data.mid(pos, 4).toUInt(false); + d->inputSampleRate = data.mid(pos, 4).toUInt32(false); pos += 4; // *Output Gain* (16 bits, signed, little endian) diff --git a/taglib/ogg/speex/speexproperties.cpp b/taglib/ogg/speex/speexproperties.cpp index 980f12df..49560b61 100644 --- a/taglib/ogg/speex/speexproperties.cpp +++ b/taglib/ogg/speex/speexproperties.cpp @@ -116,29 +116,29 @@ void Speex::Properties::read() int pos = 28; // speex_version_id; /**< Version for Speex (for checking compatibility) */ - d->speexVersion = data.mid(pos, 4).toUInt(false); + d->speexVersion = data.mid(pos, 4).toUInt32(false); pos += 4; // header_size; /**< Total size of the header ( sizeof(SpeexHeader) ) */ pos += 4; // rate; /**< Sampling rate used */ - d->sampleRate = data.mid(pos, 4).toUInt(false); + d->sampleRate = data.mid(pos, 4).toUInt32(false); pos += 4; // mode; /**< Mode used (0 for narrowband, 1 for wideband) */ - d->mode = data.mid(pos, 4).toUInt(false); + d->mode = data.mid(pos, 4).toUInt32(false); pos += 4; // mode_bitstream_version; /**< Version ID of the bit-stream */ pos += 4; // nb_channels; /**< Number of channels encoded */ - d->channels = data.mid(pos, 4).toUInt(false); + d->channels = data.mid(pos, 4).toUInt32(false); pos += 4; // bitrate; /**< Bit-rate used */ - d->bitrate = data.mid(pos, 4).toUInt(false); + d->bitrate = data.mid(pos, 4).toUInt32(false); pos += 4; // frame_size; /**< Size of frames */ @@ -146,7 +146,7 @@ void Speex::Properties::read() pos += 4; // vbr; /**< 1 for a VBR encoding, 0 otherwise */ - d->vbr = data.mid(pos, 4).toUInt(false) == 1; + d->vbr = data.mid(pos, 4).toUInt32(false) == 1; pos += 4; // frames_per_packet; /**< Number of frames stored per Ogg packet */ diff --git a/taglib/ogg/vorbis/vorbisproperties.cpp b/taglib/ogg/vorbis/vorbisproperties.cpp index fd9c527b..15b89017 100644 --- a/taglib/ogg/vorbis/vorbisproperties.cpp +++ b/taglib/ogg/vorbis/vorbisproperties.cpp @@ -151,22 +151,22 @@ void Ogg::Vorbis::Properties::read() pos += 7; - d->vorbisVersion = data.mid(pos, 4).toUInt(false); + d->vorbisVersion = data.mid(pos, 4).toUInt32(false); pos += 4; d->channels = uchar(data[pos]); pos += 1; - d->sampleRate = data.mid(pos, 4).toUInt(false); + d->sampleRate = data.mid(pos, 4).toUInt32(false); pos += 4; - d->bitrateMaximum = data.mid(pos, 4).toUInt(false); + d->bitrateMaximum = data.mid(pos, 4).toUInt32(false); pos += 4; - d->bitrateNominal = data.mid(pos, 4).toUInt(false); + d->bitrateNominal = data.mid(pos, 4).toUInt32(false); pos += 4; - d->bitrateMinimum = data.mid(pos, 4).toUInt(false); + d->bitrateMinimum = data.mid(pos, 4).toUInt32(false); // TODO: Later this should be only the "fast" mode. d->bitrate = d->bitrateNominal; diff --git a/taglib/ogg/xiphcomment.cpp b/taglib/ogg/xiphcomment.cpp index 84d206b1..aaa75774 100644 --- a/taglib/ogg/xiphcomment.cpp +++ b/taglib/ogg/xiphcomment.cpp @@ -179,7 +179,7 @@ TagLib::uint Ogg::XiphComment::fieldCount() const FieldListMap::ConstIterator it = d->fieldListMap.begin(); for(; it != d->fieldListMap.end(); ++it) - count += (*it).second.size(); + count += static_cast((*it).second.size()); return count; } @@ -286,12 +286,12 @@ ByteVector Ogg::XiphComment::render(bool addFramingBit) const ByteVector vendorData = d->vendorID.data(String::UTF8); - data.append(ByteVector::fromUInt(vendorData.size(), false)); + data.append(ByteVector::fromUInt32(vendorData.size(), false)); data.append(vendorData); // Add the number of fields. - data.append(ByteVector::fromUInt(fieldCount(), false)); + data.append(ByteVector::fromUInt32(fieldCount(), false)); // Iterate over the the field lists. Our iterator returns a // std::pair where the first String is the field name and @@ -311,7 +311,7 @@ ByteVector Ogg::XiphComment::render(bool addFramingBit) const fieldData.append('='); fieldData.append((*valuesIt).data(String::UTF8)); - data.append(ByteVector::fromUInt(fieldData.size(), false)); + data.append(ByteVector::fromUInt32(fieldData.size(), false)); data.append(fieldData); } } @@ -346,7 +346,7 @@ void Ogg::XiphComment::parse(const ByteVector &data) uint pos = 0; - uint vendorLength = data.mid(0, 4).toUInt(false); + uint vendorLength = data.mid(0, 4).toUInt32(false); pos += 4; d->vendorID = String(data.mid(pos, vendorLength), String::UTF8); @@ -354,7 +354,7 @@ void Ogg::XiphComment::parse(const ByteVector &data) // Next the number of fields in the comment vector. - uint commentFields = data.mid(pos, 4).toUInt(false); + uint commentFields = data.mid(pos, 4).toUInt32(false); pos += 4; if(commentFields > (data.size() - 8) / 4) { @@ -366,7 +366,7 @@ void Ogg::XiphComment::parse(const ByteVector &data) // Each comment field is in the format "KEY=value" in a UTF8 string and has // 4 bytes before the text starts that gives the length. - uint commentLength = data.mid(pos, 4).toUInt(false); + uint commentLength = data.mid(pos, 4).toUInt32(false); pos += 4; String comment = String(data.mid(pos, commentLength), String::UTF8); @@ -375,8 +375,8 @@ void Ogg::XiphComment::parse(const ByteVector &data) break; } - int commentSeparatorPosition = comment.find("="); - if(commentSeparatorPosition == -1) { + const size_t commentSeparatorPosition = comment.find("="); + if(commentSeparatorPosition == String::npos) { break; } diff --git a/taglib/riff/aiff/aiffproperties.cpp b/taglib/riff/aiff/aiffproperties.cpp index 3ea27582..c88cc602 100644 --- a/taglib/riff/aiff/aiffproperties.cpp +++ b/taglib/riff/aiff/aiffproperties.cpp @@ -150,9 +150,9 @@ TagLib::uint RIFF::AIFF::Properties::sampleFrames() const void RIFF::AIFF::Properties::read(const ByteVector &data) { - d->channels = data.mid(0, 2).toShort(); - d->sampleFrames = data.mid(2, 4).toUInt(); - d->sampleWidth = data.mid(6, 2).toShort(); + d->channels = data.mid(0, 2).toInt16(); + d->sampleFrames = data.mid(2, 4).toUInt32(); + d->sampleWidth = data.mid(6, 2).toInt16(); double sampleRate = ConvertFromIeeeExtended(reinterpret_cast(data.mid(8, 10).data())); d->sampleRate = (int)sampleRate; d->bitrate = (int)((sampleRate * d->sampleWidth * d->channels) / 1000.0); diff --git a/taglib/riff/rifffile.cpp b/taglib/riff/rifffile.cpp index 9b1d6613..4dcef6ab 100644 --- a/taglib/riff/rifffile.cpp +++ b/taglib/riff/rifffile.cpp @@ -143,13 +143,13 @@ void RIFF::File::setChunkData(uint i, const ByteVector &data) // First we update the global size d->size += ((data.size() + 1) & ~1) - (d->chunks[i].size + d->chunks[i].padding); - insert(ByteVector::fromUInt(d->size, d->endianness == BigEndian), 4, 4); + insert(ByteVector::fromUInt32(d->size, d->endianness == BigEndian), 4, 4); // Now update the specific chunk writeChunk(chunkName(i), data, d->chunks[i].offset - 8, d->chunks[i].size + d->chunks[i].padding + 8); - d->chunks[i].size = data.size(); + d->chunks[i].size = static_cast(data.size()); d->chunks[i].padding = (data.size() & 0x01) ? 1 : 0; // Now update the internal offsets @@ -185,8 +185,8 @@ void RIFF::File::setChunkData(const ByteVector &name, const ByteVector &data, bo // First we update the global size - d->size += static_cast(offset & 1) + data.size() + 8; - insert(ByteVector::fromUInt(d->size, d->endianness == BigEndian), 4, 4); + d->size += static_cast((offset & 1) + data.size() + 8); + insert(ByteVector::fromUInt32(d->size, d->endianness == BigEndian), 4, 4); // Now add the chunk to the file @@ -206,7 +206,7 @@ void RIFF::File::setChunkData(const ByteVector &name, const ByteVector &data, bo Chunk chunk; chunk.name = name; - chunk.size = data.size(); + chunk.size = static_cast(data.size()); chunk.offset = offset + 8; chunk.padding = static_cast(data.size() & 1); @@ -257,13 +257,13 @@ void RIFF::File::read() bool bigEndian = (d->endianness == BigEndian); d->type = readBlock(4); - d->size = readBlock(4).toUInt(bigEndian); + d->size = readBlock(4).toUInt32(bigEndian); d->format = readBlock(4); // + 8: chunk header at least, fix for additional junk bytes while(tell() + 8 <= length()) { ByteVector chunkName = readBlock(4); - uint chunkSize = readBlock(4).toUInt(bigEndian); + uint chunkSize = readBlock(4).toUInt32(bigEndian); if(!isValidChunkID(chunkName)) { debug("RIFF::File::read() -- Chunk '" + chunkName + "' has invalid ID"); @@ -310,7 +310,7 @@ void RIFF::File::writeChunk(const ByteVector &name, const ByteVector &data, combined.append(ByteVector(leadingPadding, '\x00')); } combined.append(name); - combined.append(ByteVector::fromUInt(data.size(), d->endianness == BigEndian)); + combined.append(ByteVector::fromUInt32(data.size(), d->endianness == BigEndian)); combined.append(data); if((data.size() & 0x01) != 0) { combined.append('\x00'); diff --git a/taglib/riff/wav/infotag.cpp b/taglib/riff/wav/infotag.cpp index a4d7efdb..7f54b286 100644 --- a/taglib/riff/wav/infotag.cpp +++ b/taglib/riff/wav/infotag.cpp @@ -215,7 +215,7 @@ ByteVector RIFF::Info::Tag::render() const continue; data.append(it->first); - data.append(ByteVector::fromUInt(text.size() + 1, false)); + data.append(ByteVector::fromUInt32(text.size() + 1, false)); data.append(text); do { @@ -245,7 +245,7 @@ void RIFF::Info::Tag::parse(const ByteVector &data) { uint p = 4; while(p < data.size()) { - uint size = data.mid(p + 4, 4).toUInt(false); + uint size = data.mid(p + 4, 4).toUInt32(false); d->fieldListMap[data.mid(p, 4)] = TagPrivate::stringHandler->parse(data.mid(p + 8, size)); p += ((size + 1) & ~1) + 8; diff --git a/taglib/riff/wav/wavproperties.cpp b/taglib/riff/wav/wavproperties.cpp index 9e7ea70c..3eb9a71f 100644 --- a/taglib/riff/wav/wavproperties.cpp +++ b/taglib/riff/wav/wavproperties.cpp @@ -115,12 +115,12 @@ TagLib::uint RIFF::WAV::Properties::sampleFrames() const void RIFF::WAV::Properties::read(const ByteVector &data) { - d->format = data.mid(0, 2).toShort(false); - d->channels = data.mid(2, 2).toShort(false); - d->sampleRate = data.mid(4, 4).toUInt(false); - d->sampleWidth = data.mid(14, 2).toShort(false); + d->format = data.mid(0, 2).toInt16(false); + d->channels = data.mid(2, 2).toInt16(false); + d->sampleRate = data.mid(4, 4).toUInt32(false); + d->sampleWidth = data.mid(14, 2).toInt16(false); - uint byteRate = data.mid(8, 4).toUInt(false); + uint byteRate = data.mid(8, 4).toUInt32(false); d->bitrate = byteRate * 8 / 1000; d->length = byteRate > 0 ? d->streamLength / byteRate : 0; diff --git a/taglib/toolkit/taglib.h b/taglib/toolkit/taglib.h index 0338dd56..987bd0cf 100755 --- a/taglib/toolkit/taglib.h +++ b/taglib/toolkit/taglib.h @@ -127,10 +127,11 @@ namespace TagLib { class String; - typedef wchar_t wchar; - typedef unsigned char uchar; - typedef unsigned short ushort; - typedef unsigned int uint; + typedef wchar_t wchar; + typedef unsigned char uchar; + typedef unsigned short ushort; + typedef unsigned int uint; + typedef unsigned long long ulonglong; // long/ulong can be either 32-bit or 64-bit wide. typedef unsigned long ulong; diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index 313e2a90..82aeb05e 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -105,25 +105,25 @@ namespace TagLib { * std::vector::iterator and std::vector::reverse_iterator. */ template - int findChar( + size_t findChar( const TIterator dataBegin, const TIterator dataEnd, char c, size_t offset, size_t byteAlign) { const size_t dataSize = dataEnd - dataBegin; if(dataSize == 0 || offset > dataSize - 1) - return -1; + return ByteVector::npos; // n % 0 is invalid if(byteAlign == 0) - return -1; + return ByteVector::npos; for(TIterator it = dataBegin + offset; it < dataEnd; it += byteAlign) { if(*it == c) return (it - dataBegin); } - return -1; + return ByteVector::npos; } /*! @@ -131,7 +131,7 @@ namespace TagLib { * std::vector::iterator and std::vector::reverse_iterator. */ template - int findVector( + size_t findVector( const TIterator dataBegin, const TIterator dataEnd, const TIterator patternBegin, const TIterator patternEnd, size_t offset, size_t byteAlign) @@ -139,12 +139,12 @@ namespace TagLib { const size_t dataSize = dataEnd - dataBegin; const size_t patternSize = patternEnd - patternBegin; if(patternSize > dataSize || offset > dataSize - 1) - return -1; + return ByteVector::npos; // n % 0 is invalid if(byteAlign == 0) - return -1; + return ByteVector::npos; // Special case that pattern has single char. @@ -175,7 +175,7 @@ namespace TagLib { return (itBuffer - dataBegin + 1); } - return -1; + return ByteVector::npos; } #if defined(TAGLIB_MSC_BYTESWAP) || defined(TAGLIB_GCC_BYTESWAP) @@ -294,26 +294,22 @@ class ByteVector::ByteVectorPrivate : public RefCounter { public: ByteVectorPrivate() - : RefCounter(), size(0) {} + : RefCounter() {} ByteVectorPrivate(const std::vector &v) - : RefCounter(), data(v), size(static_cast(v.size())) {} + : RefCounter(), data(v) {} #ifdef TAGLIB_USE_CXX11 ByteVectorPrivate(std::vector &&v) - : RefCounter(), data(v), size(static_cast(v.size())) {} + : RefCounter(), data(v) {} #endif - ByteVectorPrivate(TagLib::uint len, char value) - : RefCounter(), data(len, value), size(len) {} + ByteVectorPrivate(size_t size, char value) + : RefCounter(), data(size, value) {} std::vector data; - - // std::vector::size() is very slow, so we'll cache the value - - TagLib::uint size; }; //////////////////////////////////////////////////////////////////////////////// @@ -322,29 +318,27 @@ public: const ByteVector ByteVector::null; -ByteVector ByteVector::fromCString(const char *s, uint length) -{ - ByteVector v; +const size_t ByteVector::npos = static_cast(-1); - if(length == 0xffffffff) - v.setData(s); +ByteVector ByteVector::fromCString(const char *s, size_t length) +{ + if(length == npos) + return ByteVector(s); else - v.setData(s, length); - - return v; + return ByteVector(s, length); } -ByteVector ByteVector::fromUInt(uint value, bool mostSignificantByteFirst) +ByteVector ByteVector::fromUInt16(size_t value, bool mostSignificantByteFirst) { - return fromNumber(value, mostSignificantByteFirst); + return fromNumber(static_cast(value), mostSignificantByteFirst); } -ByteVector ByteVector::fromShort(short value, bool mostSignificantByteFirst) +ByteVector ByteVector::fromUInt32(size_t value, bool mostSignificantByteFirst) { - return fromNumber(value, mostSignificantByteFirst); + return fromNumber(static_cast(value), mostSignificantByteFirst); } -ByteVector ByteVector::fromLongLong(long long value, bool mostSignificantByteFirst) +ByteVector ByteVector::fromUInt64(ulonglong value, bool mostSignificantByteFirst) { return fromNumber(value, mostSignificantByteFirst); } @@ -358,7 +352,7 @@ ByteVector::ByteVector() { } -ByteVector::ByteVector(uint size, char value) +ByteVector::ByteVector(size_t size, char value) : d(new ByteVectorPrivate(size, value)) { } @@ -383,22 +377,18 @@ ByteVector::ByteVector(ByteVector &&v) #endif ByteVector::ByteVector(char c) - : d(new ByteVectorPrivate()) + : d(new ByteVectorPrivate(1, c)) { - d->data.push_back(c); - d->size = 1; } -ByteVector::ByteVector(const char *data, uint length) - : d(new ByteVectorPrivate()) +ByteVector::ByteVector(const char *data, size_t length) + : d(new ByteVectorPrivate(std::vector(data, data + length))) { - setData(data, length); } ByteVector::ByteVector(const char *data) - : d(new ByteVectorPrivate()) + : d(new ByteVectorPrivate(std::vector(data, data + ::strlen(data)))) { - setData(data); } ByteVector::~ByteVector() @@ -411,72 +401,61 @@ ByteVector::~ByteVector() #endif } -ByteVector &ByteVector::setData(const char *data, uint length) +ByteVector &ByteVector::setData(const char *data, size_t length) { detach(); resize(length); - - if(length > 0) - ::memcpy(DATA(d), data, length); + ::memcpy(DATA(d), data, length); return *this; } ByteVector &ByteVector::setData(const char *data) { - return setData(data, static_cast(::strlen(data))); + return setData(data, ::strlen(data)); } char *ByteVector::data() { detach(); - return size() > 0 ? DATA(d) : 0; + return d->data.empty() ? 0 : DATA(d); } const char *ByteVector::data() const { - return size() > 0 ? DATA(d) : 0; + return d->data.empty() ? 0 : DATA(d); } -ByteVector ByteVector::mid(uint index, uint length) const +ByteVector ByteVector::mid(size_t index, size_t length) const { - ByteVector v; + if(index >= size()) + return ByteVector::null; - if(index > size()) - return v; + if(length > size() - index) + length = size() - index; - ConstIterator endIt; - - if(length < size() - index) - endIt = d->data.begin() + index + length; - else - endIt = d->data.end(); - - v.d->data.insert(v.d->data.begin(), ConstIterator(d->data.begin() + index), endIt); - v.d->size = static_cast(v.d->data.size()); - - return v; + return ByteVector(DATA(d) + index, length); } -char ByteVector::at(uint index) const +char ByteVector::at(size_t index) const { return index < size() ? d->data[index] : 0; } -int ByteVector::find(const ByteVector &pattern, uint offset, int byteAlign) const +size_t ByteVector::find(const ByteVector &pattern, size_t offset, size_t byteAlign) const { return findVector::iterator>( d->data.begin(), d->data.end(), pattern.d->data.begin(), pattern.d->data.end(), offset, byteAlign); } -int ByteVector::find(char c, uint offset, int byteAlign) const +size_t ByteVector::find(char c, size_t offset, size_t byteAlign) const { return findChar::iterator>( d->data.begin(), d->data.end(), c, offset, byteAlign); } -int ByteVector::rfind(const ByteVector &pattern, uint offset, int byteAlign) const +size_t ByteVector::rfind(const ByteVector &pattern, size_t offset, size_t byteAlign) const { if(offset > 0) { offset = size() - offset - pattern.size(); @@ -484,33 +463,27 @@ int ByteVector::rfind(const ByteVector &pattern, uint offset, int byteAlign) con offset = 0; } - const int pos = findVector::reverse_iterator>( + const size_t pos = findVector::reverse_iterator>( d->data.rbegin(), d->data.rend(), pattern.d->data.rbegin(), pattern.d->data.rend(), offset, byteAlign); - if(pos == -1) - return -1; + if(pos == npos) + return npos; else return size() - pos - pattern.size(); } -bool ByteVector::containsAt(const ByteVector &pattern, uint offset, uint patternOffset, uint patternLength) const +bool ByteVector::containsAt( + const ByteVector &pattern, size_t offset, size_t patternOffset, size_t patternLength) const { if(pattern.size() < patternLength) patternLength = pattern.size(); // do some sanity checking -- all of these things are needed for the search to be valid - if(patternLength > size() || offset >= size() || patternOffset >= pattern.size() || patternLength == 0) + if(offset + patternLength > size() || patternOffset >= pattern.size() || patternLength == 0) return false; - // loop through looking for a mismatch - - for(uint i = 0; i < patternLength - patternOffset; i++) { - if(at(i + offset) != pattern[i + patternOffset]) - return false; - } - - return true; + return (::memcmp(DATA(d) + offset, DATA(pattern.d) + patternOffset, patternLength - patternOffset) == 0); } bool ByteVector::startsWith(const ByteVector &pattern) const @@ -528,26 +501,26 @@ ByteVector &ByteVector::replace(const ByteVector &pattern, const ByteVector &wit if(pattern.size() == 0 || pattern.size() > size()) return *this; - const uint withSize = with.size(); - const uint patternSize = pattern.size(); - int offset = 0; + const size_t withSize = with.size(); + const size_t patternSize = pattern.size(); + size_t offset = 0; if(withSize == patternSize) { // I think this case might be common enough to optimize it detach(); offset = find(pattern); - while(offset >= 0) { - ::memcpy(data() + offset, with.data(), withSize); + while(offset != npos) { + ::memcpy(DATA(d) + offset, DATA(with.d), withSize); offset = find(pattern, offset + withSize); } return *this; } // calculate new size: - uint newSize = 0; + size_t newSize = 0; for(;;) { - int next = find(pattern, offset); - if(next < 0) { + const size_t next = find(pattern, offset); + if(next == npos) { if(offset == 0) // pattern not found, do nothing: return *this; @@ -561,20 +534,20 @@ ByteVector &ByteVector::replace(const ByteVector &pattern, const ByteVector &wit // new private data of appropriate size: ByteVectorPrivate *newData = new ByteVectorPrivate(newSize, 0); char *target = DATA(newData); - const char *source = data(); + const char *source = DATA(d); // copy modified data into new private data: offset = 0; for(;;) { - int next = find(pattern, offset); - if(next < 0) { + const size_t next = find(pattern, offset); + if(next == npos) { ::memcpy(target, source + offset, size() - offset); break; } - int chunkSize = next - offset; + const size_t chunkSize = next - offset; ::memcpy(target, source + offset, chunkSize); target += chunkSize; - ::memcpy(target, with.data(), withSize); + ::memcpy(target, DATA(with.d), withSize); target += withSize; offset += chunkSize + patternSize; } @@ -596,33 +569,33 @@ ByteVector &ByteVector::replace(const ByteVector &pattern, const ByteVector &wit return *this; } -int ByteVector::endsWithPartialMatch(const ByteVector &pattern) const +size_t ByteVector::endsWithPartialMatch(const ByteVector &pattern) const { if(pattern.size() > size()) - return -1; + return npos; - const int startIndex = size() - pattern.size(); + const size_t startIndex = size() - pattern.size(); // try to match the last n-1 bytes from the vector (where n is the pattern // size) -- continue trying to match n-2, n-3...1 bytes - for(uint i = 1; i < pattern.size(); i++) { + for(size_t i = 1; i < pattern.size(); i++) { if(containsAt(pattern, startIndex + i, 0, pattern.size() - i)) return startIndex + i; } - return -1; + return npos; } ByteVector &ByteVector::append(const ByteVector &v) { - if(v.d->size == 0) + if(v.isEmpty()) return *this; // Simply return if appending nothing. detach(); - uint originalSize = d->size; - resize(d->size + v.d->size); + size_t originalSize = size(); + resize(originalSize + v.size()); ::memcpy(DATA(d) + originalSize, DATA(v.d), v.size()); return *this; @@ -631,28 +604,19 @@ ByteVector &ByteVector::append(const ByteVector &v) ByteVector &ByteVector::clear() { detach(); - d->data.clear(); - d->size = 0; + std::vector().swap(d->data); return *this; } -TagLib::uint ByteVector::size() const +size_t ByteVector::size() const { - return d->size; + return d->data.size(); } -ByteVector &ByteVector::resize(uint size, char padding) +ByteVector &ByteVector::resize(size_t size, char padding) { - if(d->size < size) { - d->data.reserve(size); - d->data.insert(d->data.end(), size - d->size, padding); - } - else - d->data.erase(d->data.begin() + size, d->data.end()); - - d->size = size; - + d->data.resize(size, padding); return *this; } @@ -683,7 +647,7 @@ bool ByteVector::isNull() const bool ByteVector::isEmpty() const { - return d->data.size() == 0; + return d->data.empty(); } TagLib::uint ByteVector::checksum() const @@ -694,44 +658,43 @@ TagLib::uint ByteVector::checksum() const return sum; } -TagLib::uint ByteVector::toUInt(bool mostSignificantByteFirst) const +TagLib::uint ByteVector::toUInt32(bool mostSignificantByteFirst) const { return toNumber(d->data, mostSignificantByteFirst); } -short ByteVector::toShort(bool mostSignificantByteFirst) const +short ByteVector::toInt16(bool mostSignificantByteFirst) const { return toNumber(d->data, mostSignificantByteFirst); } -unsigned short ByteVector::toUShort(bool mostSignificantByteFirst) const +unsigned short ByteVector::toUInt16(bool mostSignificantByteFirst) const { return toNumber(d->data, mostSignificantByteFirst); } -long long ByteVector::toLongLong(bool mostSignificantByteFirst) const +long long ByteVector::toInt64(bool mostSignificantByteFirst) const { return toNumber(d->data, mostSignificantByteFirst); } -const char &ByteVector::operator[](int index) const +const char &ByteVector::operator[](size_t index) const { return d->data[index]; } -char &ByteVector::operator[](int index) +char &ByteVector::operator[](size_t index) { detach(); - return d->data[index]; } bool ByteVector::operator==(const ByteVector &v) const { - if(d->size != v.d->size) + if(size() != v.size()) return false; - return ::memcmp(data(), v.data(), size()) == 0; + return (::memcmp(DATA(d), DATA(v.d), size()) == 0); } bool ByteVector::operator!=(const ByteVector &v) const @@ -741,10 +704,10 @@ bool ByteVector::operator!=(const ByteVector &v) const bool ByteVector::operator==(const char *s) const { - if(d->size != ::strlen(s)) + if(size() != ::strlen(s)) return false; - return ::memcmp(data(), s, d->size) == 0; + return (::memcmp(DATA(d), s, size()) == 0); } bool ByteVector::operator!=(const char *s) const @@ -754,8 +717,7 @@ bool ByteVector::operator!=(const char *s) const bool ByteVector::operator<(const ByteVector &v) const { - int result = ::memcmp(data(), v.data(), d->size < v.d->size ? d->size : v.d->size); - + int result = ::memcmp(DATA(d), DATA(v.d), std::min(size(), v.size())); if(result != 0) return result < 0; else diff --git a/taglib/toolkit/tbytevector.h b/taglib/toolkit/tbytevector.h index fc4b6039..304a14f4 100644 --- a/taglib/toolkit/tbytevector.h +++ b/taglib/toolkit/tbytevector.h @@ -59,7 +59,7 @@ namespace TagLib { * Construct a vector of size \a size with all values set to \a value by * default. */ - ByteVector(uint size, char value = 0); + ByteVector(size_t size, char value = 0); /*! * Constructs a byte vector that is a copy of \a v. @@ -85,7 +85,7 @@ namespace TagLib { /*! * Constructs a byte vector that copies \a data for up to \a length bytes. */ - ByteVector(const char *data, uint length); + ByteVector(const char *data, size_t length); /*! * Constructs a byte vector that copies \a data up to the first null @@ -103,7 +103,7 @@ namespace TagLib { /*! * Sets the data for the byte array using the first \a length bytes of \a data */ - ByteVector &setData(const char *data, uint length); + ByteVector &setData(const char *data, size_t length); /*! * Sets the data for the byte array copies \a data up to the first null @@ -130,37 +130,37 @@ namespace TagLib { * for \a length bytes. If \a length is not specified it will return the bytes * from \a index to the end of the vector. */ - ByteVector mid(uint index, uint length = 0xffffffff) const; + ByteVector mid(size_t index, size_t length = npos) const; /*! * This essentially performs the same as operator[](), but instead of causing * a runtime error if the index is out of bounds, it will return a null byte. */ - char at(uint index) const; + char at(size_t index) const; /*! * Searches the ByteVector for \a pattern starting at \a offset and returns - * the offset. Returns -1 if the pattern was not found. If \a byteAlign is + * the offset. Returns \a npos if the pattern was not found. If \a byteAlign is * specified the pattern will only be matched if it starts on a byte divisible * by \a byteAlign (starting from \a offset). */ - int find(const ByteVector &pattern, uint offset = 0, int byteAlign = 1) const; + size_t find(const ByteVector &pattern, size_t offset = 0, size_t byteAlign = 1) const; /*! * Searches the char for \a c starting at \a offset and returns - * the offset. Returns -1 if the pattern was not found. If \a byteAlign is + * the offset. Returns \a npos if the pattern was not found. If \a byteAlign is * specified the pattern will only be matched if it starts on a byte divisible * by \a byteAlign (starting from \a offset). */ - int find(char c, uint offset = 0, int byteAlign = 1) const; + size_t find(char c, size_t offset = 0, size_t byteAlign = 1) const; /*! * Searches the ByteVector for \a pattern starting from either the end of the - * vector or \a offset and returns the offset. Returns -1 if the pattern was + * vector or \a offset and returns the offset. Returns \ npos if the pattern was * not found. If \a byteAlign is specified the pattern will only be matched * if it starts on a byte divisible by \a byteAlign (starting from \a offset). */ - int rfind(const ByteVector &pattern, uint offset = 0, int byteAlign = 1) const; + size_t rfind(const ByteVector &pattern, size_t offset = 0, size_t byteAlign = 1) const; /*! * Checks to see if the vector contains the \a pattern starting at position @@ -169,7 +169,8 @@ namespace TagLib { * specify to only check for the first \a patternLength bytes of \a pattern with * the \a patternLength argument. */ - bool containsAt(const ByteVector &pattern, uint offset, uint patternOffset = 0, uint patternLength = 0xffffffff) const; + bool containsAt( + const ByteVector &pattern, size_t offset, size_t patternOffset = 0, size_t patternLength = npos) const; /*! * Returns true if the vector starts with \a pattern. @@ -189,7 +190,7 @@ namespace TagLib { /*! * Checks for a partial match of \a pattern at the end of the vector. It - * returns the offset of the partial match within the vector, or -1 if the + * returns the offset of the partial match within the vector, or \a npos if the * pattern is not found. This method is particularly useful when searching for * patterns that start in one vector and end in another. When combined with * startsWith() it can be used to find a pattern that overlaps two buffers. @@ -197,7 +198,7 @@ namespace TagLib { * \note This will not match the complete pattern at the end of the string; use * endsWith() for that. */ - int endsWithPartialMatch(const ByteVector &pattern) const; + size_t endsWithPartialMatch(const ByteVector &pattern) const; /*! * Appends \a v to the end of the ByteVector. @@ -212,14 +213,14 @@ namespace TagLib { /*! * Returns the size of the array. */ - uint size() const; + size_t size() const; /*! * Resize the vector to \a size. If the vector is currently less than * \a size, pad the remaining spaces with \a padding. Returns a reference * to the resized vector. */ - ByteVector &resize(uint size, char padding = 0); + ByteVector &resize(size_t size, char padding = 0); /*! * Returns an Iterator that points to the front of the vector. @@ -262,18 +263,6 @@ namespace TagLib { */ uint checksum() const; - /*! - * Converts the first 4 bytes of the vector to an unsigned integer. - * - * If \a mostSignificantByteFirst is true this will operate left to right - * evaluating the integer. For example if \a mostSignificantByteFirst is - * true then $00 $00 $00 $01 == 0x00000001 == 1, if false, $01 00 00 00 == - * 0x01000000 == 1. - * - * \see fromUInt() - */ - uint toUInt(bool mostSignificantByteFirst = true) const; - /*! * Converts the first 2 bytes of the vector to a short. * @@ -281,9 +270,9 @@ namespace TagLib { * evaluating the integer. For example if \a mostSignificantByteFirst is * true then $00 $01 == 0x0001 == 1, if false, $01 00 == 0x01000000 == 1. * - * \see fromShort() + * \see fromUInt16() */ - short toShort(bool mostSignificantByteFirst = true) const; + short toInt16(bool mostSignificantByteFirst = true) const; /*! * Converts the first 2 bytes of the vector to a unsigned short. @@ -292,9 +281,21 @@ namespace TagLib { * evaluating the integer. For example if \a mostSignificantByteFirst is * true then $00 $01 == 0x0001 == 1, if false, $01 00 == 0x01000000 == 1. * - * \see fromShort() + * \see fromUInt16() */ - unsigned short toUShort(bool mostSignificantByteFirst = true) const; + unsigned short toUInt16(bool mostSignificantByteFirst = true) const; + + /*! + * Converts the first 4 bytes of the vector to an unsigned integer. + * + * If \a mostSignificantByteFirst is true this will operate left to right + * evaluating the integer. For example if \a mostSignificantByteFirst is + * true then $00 $00 $00 $01 == 0x00000001 == 1, if false, $01 00 00 00 == + * 0x01000000 == 1. + * + * \see fromUInt32() + */ + uint toUInt32(bool mostSignificantByteFirst = true) const; /*! * Converts the first 8 bytes of the vector to a (signed) long long. @@ -304,9 +305,20 @@ namespace TagLib { * true then $00 00 00 00 00 00 00 01 == 0x0000000000000001 == 1, * if false, $01 00 00 00 00 00 00 00 == 0x0100000000000000 == 1. * - * \see fromUInt() + * \see fromUInt64() */ - long long toLongLong(bool mostSignificantByteFirst = true) const; + long long toInt64(bool mostSignificantByteFirst = true) const; + + /*! + * Creates a 2 byte ByteVector based on \a value. If + * \a mostSignificantByteFirst is true, then this will operate left to right + * in building the ByteVector. For example if \a mostSignificantByteFirst is + * true then $00 01 == 0x0001 == 1, if false, $01 00 == 0x0100 == 1. + * + * \note If \a value is larger than 16-bit, the lowest 16 bits are used. + * \see toInt16() + */ + static ByteVector fromUInt16(size_t value, bool mostSignificantByteFirst = true); /*! * Creates a 4 byte ByteVector based on \a value. If @@ -315,19 +327,10 @@ namespace TagLib { * true then $00 00 00 01 == 0x00000001 == 1, if false, $01 00 00 00 == * 0x01000000 == 1. * - * \see toUInt() + * \note If \a value is larger than 32-bit, the lowest 32 bits are used. + * \see toUInt32() */ - static ByteVector fromUInt(uint value, bool mostSignificantByteFirst = true); - - /*! - * Creates a 2 byte ByteVector based on \a value. If - * \a mostSignificantByteFirst is true, then this will operate left to right - * in building the ByteVector. For example if \a mostSignificantByteFirst is - * true then $00 01 == 0x0001 == 1, if false, $01 00 == 0x0100 == 1. - * - * \see toShort() - */ - static ByteVector fromShort(short value, bool mostSignificantByteFirst = true); + static ByteVector fromUInt32(size_t value, bool mostSignificantByteFirst = true); /*! * Creates a 8 byte ByteVector based on \a value. If @@ -336,24 +339,24 @@ namespace TagLib { * true then $00 00 00 01 == 0x0000000000000001 == 1, if false, * $01 00 00 00 00 00 00 00 == 0x0100000000000000 == 1. * - * \see toLongLong() + * \see toInt64() */ - static ByteVector fromLongLong(long long value, bool mostSignificantByteFirst = true); + static ByteVector fromUInt64(ulonglong value, bool mostSignificantByteFirst = true); /*! * Returns a ByteVector based on the CString \a s. */ - static ByteVector fromCString(const char *s, uint length = 0xffffffff); + static ByteVector fromCString(const char *s, size_t length = npos); /*! - * Returns a const refernence to the byte at \a index. + * Returns a const reference to the byte at \a index. */ - const char &operator[](int index) const; + const char &operator[](size_t index) const; /*! * Returns a reference to the byte at \a index. */ - char &operator[](int index); + char &operator[](size_t index); /*! * Returns true if this ByteVector and \a v are equal. @@ -426,6 +429,12 @@ namespace TagLib { */ static const ByteVector null; + /*! + * When used as the value for a \a length or \a patternLength parameter + * in ByteVector's member functions, means "until the end of the data". + * As a return value, it is usually used to indicate no matches. + */ + static const size_t npos; /*! * Returns a hex-encoded copy of the byte vector. diff --git a/taglib/toolkit/tbytevectorlist.cpp b/taglib/toolkit/tbytevectorlist.cpp index 3a399aba..e5282b84 100644 --- a/taglib/toolkit/tbytevectorlist.cpp +++ b/taglib/toolkit/tbytevectorlist.cpp @@ -36,14 +36,14 @@ class ByteVectorListPrivate // static members //////////////////////////////////////////////////////////////////////////////// -ByteVectorList ByteVectorList::split(const ByteVector &v, const ByteVector &pattern, - int byteAlign, int max) +ByteVectorList ByteVectorList::split( + const ByteVector &v, const ByteVector &pattern, size_t byteAlign, size_t max) { ByteVectorList l; - uint previousOffset = 0; - for(int offset = v.find(pattern, 0, byteAlign); - offset != -1 && (max == 0 || max > int(l.size()) + 1); + size_t previousOffset = 0; + for(size_t offset = v.find(pattern, 0, byteAlign); + offset != ByteVector::npos && (max == 0 || max > l.size() + 1); offset = v.find(pattern, offset + pattern.size(), byteAlign)) { if(offset - previousOffset >= 1) diff --git a/taglib/toolkit/tbytevectorlist.h b/taglib/toolkit/tbytevectorlist.h index 3aa87a43..dc26f269 100644 --- a/taglib/toolkit/tbytevectorlist.h +++ b/taglib/toolkit/tbytevectorlist.h @@ -96,8 +96,8 @@ namespace TagLib { * is 2 then a maximum of 1 match will be found and the vector will be split * on that match. */ - static ByteVectorList split(const ByteVector &v, const ByteVector &pattern, - int byteAlign = 1, int max = 0); + static ByteVectorList split( + const ByteVector &v, const ByteVector &pattern, size_t byteAlign = 1, size_t max = 0); }; } diff --git a/taglib/toolkit/tbytevectorstream.cpp b/taglib/toolkit/tbytevectorstream.cpp index 9a3ace03..6ee3f3e0 100644 --- a/taglib/toolkit/tbytevectorstream.cpp +++ b/taglib/toolkit/tbytevectorstream.cpp @@ -68,52 +68,53 @@ FileName ByteVectorStream::name() const return FileName(""); // XXX do we need a name? } -ByteVector ByteVectorStream::readBlock(uint length) +ByteVector ByteVectorStream::readBlock(size_t length) { if(length == 0) return ByteVector::null; - ByteVector v = d->data.mid(static_cast(d->position), length); + ByteVector v = d->data.mid(static_cast(d->position), length); d->position += v.size(); return v; } void ByteVectorStream::writeBlock(const ByteVector &data) { - uint size = data.size(); + const size_t size = data.size(); if(static_cast(d->position + size) > length()) truncate(d->position + size); - memcpy(d->data.data() + d->position, data.data(), size); + ::memcpy(d->data.data() + d->position, data.data(), size); d->position += size; } -void ByteVectorStream::insert(const ByteVector &data, offset_t start, uint replace) +void ByteVectorStream::insert(const ByteVector &data, offset_t start, size_t replace) { - long sizeDiff = data.size() - replace; - if(sizeDiff < 0) { - removeBlock(start + data.size(), -sizeDiff); + if(data.size() < replace) { + removeBlock(start + data.size(), replace - data.size()); } - else if(sizeDiff > 0) { + else if(data.size() > replace) { + const size_t sizeDiff = data.size() - replace; truncate(length() + sizeDiff); - offset_t readPosition = start + replace; - offset_t writePosition = start + data.size(); - memmove( - d->data.data() + static_cast(writePosition), - d->data.data() + static_cast(readPosition), + + const size_t readPosition = static_cast(start + replace); + const size_t writePosition = static_cast(start + data.size()); + ::memmove( + d->data.data() + writePosition, + d->data.data() + readPosition, static_cast(length() - sizeDiff - readPosition)); } seek(start); writeBlock(data); } -void ByteVectorStream::removeBlock(offset_t start, uint length) +void ByteVectorStream::removeBlock(offset_t start, size_t length) { - offset_t readPosition = start + length; + const offset_t readPosition = start + length; offset_t writePosition = start; if(readPosition < ByteVectorStream::length()) { size_t bytesToMove = static_cast(ByteVectorStream::length() - readPosition); - memmove( + ::memmove( d->data.data() + static_cast(writePosition), d->data.data() + static_cast(readPosition), bytesToMove); diff --git a/taglib/toolkit/tbytevectorstream.h b/taglib/toolkit/tbytevectorstream.h index 7b455c82..036d9970 100644 --- a/taglib/toolkit/tbytevectorstream.h +++ b/taglib/toolkit/tbytevectorstream.h @@ -61,7 +61,7 @@ namespace TagLib { /*! * Reads a block of size \a length at the current get pointer. */ - ByteVector readBlock(uint length); + ByteVector readBlock(size_t length); /*! * Attempts to write the block \a data at the current get pointer. If the @@ -81,7 +81,7 @@ namespace TagLib { * \note This method is slow since it requires rewriting all of the file * after the insertion point. */ - void insert(const ByteVector &data, offset_t start = 0, uint replace = 0); + void insert(const ByteVector &data, offset_t start = 0, size_t replace = 0); /*! * Removes a block of the file starting a \a start and continuing for @@ -90,7 +90,7 @@ namespace TagLib { * \note This method is slow since it involves rewriting all of the file * after the removed portion. */ - void removeBlock(offset_t start = 0, uint length = 0); + void removeBlock(offset_t start = 0, size_t length = 0); /*! * Returns true if the file is read only (or if the file can not be opened). diff --git a/taglib/toolkit/tfile.cpp b/taglib/toolkit/tfile.cpp index db75f228..86de3128 100644 --- a/taglib/toolkit/tfile.cpp +++ b/taglib/toolkit/tfile.cpp @@ -81,7 +81,16 @@ public: IOStream *stream; bool streamOwner; bool valid; - static const uint bufferSize = 1024; + +#ifdef _WIN32 + + static const size_t bufferSize = 8192; + +#else + + static const size_t bufferSize = 1024; + +#endif }; File::FilePrivate::FilePrivate(IOStream *stream, bool owner) : @@ -133,7 +142,7 @@ PropertyMap File::setProperties(const PropertyMap &properties) return tag()->setProperties(properties); } -ByteVector File::readBlock(uint length) +ByteVector File::readBlock(size_t length) { return d->stream->readBlock(length); } @@ -151,13 +160,12 @@ offset_t File::find(const ByteVector &pattern, offset_t fromOffset, const ByteVe // The position in the file that the current buffer starts at. offset_t bufferOffset = fromOffset; - ByteVector buffer; // These variables are used to keep track of a partial match that happens at // the end of a buffer. - int previousPartialMatch = -1; - int beforePreviousPartialMatch = -1; + size_t previousPartialMatch = ByteVector::npos; + size_t beforePreviousPartialMatch = ByteVector::npos; // Save the location of the current read pointer. We will restore the // position using seek() before all returns. @@ -186,20 +194,29 @@ offset_t File::find(const ByteVector &pattern, offset_t fromOffset, const ByteVe // then check for "before". The order is important because it gives priority // to "real" matches. - for(buffer = readBlock(d->bufferSize); buffer.size() > 0; buffer = readBlock(d->bufferSize)) { + while(true) + { + ByteVector buffer = readBlock(bufferSize()); + if(buffer.isEmpty()) + break; // (1) previous partial match - if(previousPartialMatch >= 0 && int(d->bufferSize) > previousPartialMatch) { - const int patternOffset = (d->bufferSize - previousPartialMatch); + if(previousPartialMatch != ByteVector::npos + && d->bufferSize > previousPartialMatch) + { + const size_t patternOffset = (d->bufferSize - previousPartialMatch); if(buffer.containsAt(pattern, 0, patternOffset)) { seek(originalPosition); return bufferOffset - d->bufferSize + previousPartialMatch; } } - if(!before.isNull() && beforePreviousPartialMatch >= 0 && int(d->bufferSize) > beforePreviousPartialMatch) { - const int beforeOffset = (d->bufferSize - beforePreviousPartialMatch); + if(!before.isNull() + && beforePreviousPartialMatch != ByteVector::npos + && d->bufferSize > beforePreviousPartialMatch) + { + const size_t beforeOffset = (d->bufferSize - beforePreviousPartialMatch); if(buffer.containsAt(before, 0, beforeOffset)) { seek(originalPosition); return -1; @@ -208,13 +225,13 @@ offset_t File::find(const ByteVector &pattern, offset_t fromOffset, const ByteVe // (2) pattern contained in current buffer - long location = buffer.find(pattern); - if(location >= 0) { + size_t location = buffer.find(pattern); + if(location != ByteVector::npos) { seek(originalPosition); return bufferOffset + location; } - if(!before.isNull() && buffer.find(before) >= 0) { + if(!before.isNull() && buffer.find(before) != ByteVector::npos) { seek(originalPosition); return -1; } @@ -281,13 +298,13 @@ offset_t File::rfind(const ByteVector &pattern, offset_t fromOffset, const ByteV // (2) pattern contained in current buffer - long location = buffer.rfind(pattern); - if(location >= 0) { + const size_t location = buffer.rfind(pattern); + if(location != ByteVector::npos) { seek(originalPosition); return bufferOffset + location; } - if(!before.isNull() && buffer.find(before) >= 0) { + if(!before.isNull() && buffer.find(before) != ByteVector::npos) { seek(originalPosition); return -1; } @@ -307,12 +324,12 @@ offset_t File::rfind(const ByteVector &pattern, offset_t fromOffset, const ByteV return -1; } -void File::insert(const ByteVector &data, offset_t start, uint replace) +void File::insert(const ByteVector &data, offset_t start, size_t replace) { d->stream->insert(data, start, replace); } -void File::removeBlock(offset_t start, uint length) +void File::removeBlock(offset_t start, size_t length) { d->stream->removeBlock(start, length); } @@ -405,7 +422,7 @@ String File::toString() const // protected members //////////////////////////////////////////////////////////////////////////////// -TagLib::uint File::bufferSize() +size_t File::bufferSize() { return FilePrivate::bufferSize; } diff --git a/taglib/toolkit/tfile.h b/taglib/toolkit/tfile.h index 3e8dd5fc..c1227e8b 100644 --- a/taglib/toolkit/tfile.h +++ b/taglib/toolkit/tfile.h @@ -135,7 +135,7 @@ namespace TagLib { /*! * Reads a block of size \a length at the current get pointer. */ - ByteVector readBlock(uint length); + ByteVector readBlock(size_t length); /*! * Attempts to write the block \a data at the current get pointer. If the @@ -187,7 +187,7 @@ namespace TagLib { * \note This method is slow since it requires rewriting all of the file * after the insertion point. */ - void insert(const ByteVector &data, offset_t start = 0, uint replace = 0); + void insert(const ByteVector &data, offset_t start = 0, size_t replace = 0); /*! * Removes a block of the file starting a \a start and continuing for @@ -196,7 +196,7 @@ namespace TagLib { * \note This method is slow since it involves rewriting all of the file * after the removed portion. */ - void removeBlock(offset_t start = 0, uint length = 0); + void removeBlock(offset_t start = 0, size_t length = 0); /*! * Returns true if the file is read only (or if the file can not be opened). diff --git a/taglib/toolkit/tfilestream.cpp b/taglib/toolkit/tfilestream.cpp index 7c90ed6d..f8180a21 100644 --- a/taglib/toolkit/tfilestream.cpp +++ b/taglib/toolkit/tfilestream.cpp @@ -116,7 +116,16 @@ public: bool readOnly; offset_t size; - static const uint bufferSize = 1024; + +#ifdef _WIN32 + + static const size_t bufferSize = 8196; + +#else + + static const size_t bufferSize = 1024; + +#endif }; FileStream::FileStreamPrivate::FileStreamPrivate(FileName fileName, bool openReadOnly) : @@ -181,7 +190,7 @@ FileName FileStream::name() const return d->name; } -ByteVector FileStream::readBlock(uint length) +ByteVector FileStream::readBlock(size_t length) { if(!d->file) { debug("FileStream::readBlock() -- Invalid File"); @@ -191,15 +200,12 @@ ByteVector FileStream::readBlock(uint length) if(length == 0) return ByteVector::null; - if(length > FileStreamPrivate::bufferSize && - static_cast(length) > FileStream::length()) - { - length = static_cast(FileStream::length()); - } + if(length > FileStreamPrivate::bufferSize && static_cast(length) > FileStream::length()) + length = static_cast(FileStream::length()); - ByteVector v(length); + ByteVector v(length, 0); const size_t count = fread(v.data(), sizeof(char), length, d->file); - v.resize(static_cast(count)); + v.resize(count); return v; } @@ -216,7 +222,7 @@ void FileStream::writeBlock(const ByteVector &data) fwrite(data.data(), sizeof(char), data.size(), d->file); } -void FileStream::insert(const ByteVector &data, offset_t start, uint replace) +void FileStream::insert(const ByteVector &data, offset_t start, size_t replace) { if(!d->file) return; @@ -243,10 +249,10 @@ void FileStream::insert(const ByteVector &data, offset_t start, uint replace) // the *differnce* in the tag sizes. We want to avoid overwriting parts // that aren't yet in memory, so this is necessary. - size_t bufferLength = bufferSize(); + size_t bufferLength = FileStreamPrivate::bufferSize; while(data.size() - replace > bufferLength) - bufferLength += bufferSize(); + bufferLength += FileStreamPrivate::bufferSize; // Set where to start the reading and writing. @@ -254,7 +260,7 @@ void FileStream::insert(const ByteVector &data, offset_t start, uint replace) offset_t writePosition = start; ByteVector buffer; - ByteVector aboutToOverwrite(static_cast(bufferLength)); + ByteVector aboutToOverwrite(bufferLength, 0); // This is basically a special case of the loop below. Here we're just // doing the same steps as below, but since we aren't using the same buffer @@ -274,7 +280,7 @@ void FileStream::insert(const ByteVector &data, offset_t start, uint replace) // In case we've already reached the end of file... - buffer.resize(static_cast(bytesRead)); + buffer.resize(bytesRead); // Ok, here's the main loop. We want to loop until the read fails, which // means that we hit the end of the file. @@ -317,17 +323,17 @@ void FileStream::insert(const ByteVector &data, offset_t start, uint replace) d->size = 0; } -void FileStream::removeBlock(offset_t start, uint length) +void FileStream::removeBlock(offset_t start, size_t length) { if(!d->file) return; - size_t bufferLength = bufferSize(); + size_t bufferLength = FileStreamPrivate::bufferSize; offset_t readPosition = start + length; offset_t writePosition = start; - ByteVector buffer(static_cast(bufferLength)); + ByteVector buffer(bufferLength, 0); size_t bytesRead = 1; @@ -505,8 +511,3 @@ void FileStream::truncate(offset_t length) #endif } - -TagLib::uint FileStream::bufferSize() -{ - return FileStreamPrivate::bufferSize; -} diff --git a/taglib/toolkit/tfilestream.h b/taglib/toolkit/tfilestream.h index d3a6179e..f5b5190b 100644 --- a/taglib/toolkit/tfilestream.h +++ b/taglib/toolkit/tfilestream.h @@ -67,7 +67,7 @@ namespace TagLib { /*! * Reads a block of size \a length at the current get pointer. */ - ByteVector readBlock(uint length); + ByteVector readBlock(size_t length); /*! * Attempts to write the block \a data at the current get pointer. If the @@ -87,7 +87,7 @@ namespace TagLib { * \note This method is slow since it requires rewriting all of the file * after the insertion point. */ - void insert(const ByteVector &data, offset_t start = 0, uint replace = 0); + void insert(const ByteVector &data, offset_t start = 0, size_t replace = 0); /*! * Removes a block of the file starting a \a start and continuing for @@ -96,7 +96,7 @@ namespace TagLib { * \note This method is slow since it involves rewriting all of the file * after the removed portion. */ - void removeBlock(offset_t start = 0, uint length = 0); + void removeBlock(offset_t start = 0, size_t length = 0); /*! * Returns true if the file is read only (or if the file can not be opened). @@ -137,13 +137,6 @@ namespace TagLib { */ void truncate(offset_t length); - protected: - - /*! - * Returns the buffer size that is used for internal buffering. - */ - static uint bufferSize(); - private: class FileStreamPrivate; FileStreamPrivate *d; diff --git a/taglib/toolkit/tiostream.h b/taglib/toolkit/tiostream.h index d418810e..5448487d 100644 --- a/taglib/toolkit/tiostream.h +++ b/taglib/toolkit/tiostream.h @@ -87,7 +87,7 @@ namespace TagLib { /*! * Reads a block of size \a length at the current get pointer. */ - virtual ByteVector readBlock(uint length) = 0; + virtual ByteVector readBlock(size_t length) = 0; /*! * Attempts to write the block \a data at the current get pointer. If the @@ -107,7 +107,7 @@ namespace TagLib { * \note This method is slow since it requires rewriting all of the file * after the insertion point. */ - virtual void insert(const ByteVector &data, offset_t start = 0, uint replace = 0) = 0; + virtual void insert(const ByteVector &data, offset_t start = 0, size_t replace = 0) = 0; /*! * Removes a block of the file starting a \a start and continuing for @@ -116,7 +116,7 @@ namespace TagLib { * \note This method is slow since it involves rewriting all of the file * after the removed portion. */ - virtual void removeBlock(offset_t start = 0, uint length = 0) = 0; + virtual void removeBlock(offset_t start = 0, size_t length = 0) = 0; /*! * Returns true if the file is read only (or if the file can not be opened). diff --git a/taglib/toolkit/tlist.h b/taglib/toolkit/tlist.h index b1067f23..0d3a0d3a 100644 --- a/taglib/toolkit/tlist.h +++ b/taglib/toolkit/tlist.h @@ -198,7 +198,7 @@ namespace TagLib { /*! * Returns the number of elements in the list. */ - uint size() const; + size_t size() const; bool isEmpty() const; /*! @@ -256,14 +256,14 @@ namespace TagLib { * * \warning This method is slow. Use iterators to loop through the list. */ - T &operator[](uint i); + T &operator[](size_t i); /*! * Returns a const reference to item \a i in the list. * * \warning This method is slow. Use iterators to loop through the list. */ - const T &operator[](uint i) const; + const T &operator[](size_t i) const; /*! * Make a shallow, implicitly shared, copy of \a l. Because this is diff --git a/taglib/toolkit/tlist.tcc b/taglib/toolkit/tlist.tcc index 3b7e5808..dad0f347 100644 --- a/taglib/toolkit/tlist.tcc +++ b/taglib/toolkit/tlist.tcc @@ -88,7 +88,7 @@ public: void clear() { deletePointers(); - std::list().swap(list); + std::list().swap(list); } std::list list; @@ -96,9 +96,9 @@ public: private: void deletePointers() { if(!autoDelete) - return; + return; - typename std::list::const_iterator it = list.begin(); + typename std::list::const_iterator it = list.begin(); for(; it != list.end(); ++it) delete *it; } @@ -279,9 +279,9 @@ List &List::clear() } template -TagLib::uint List::size() const +size_t List::size() const { - return static_cast(d->list.size()); + return d->list.size(); } template @@ -347,7 +347,7 @@ T &List::back() } template -T &List::operator[](uint i) +T &List::operator[](size_t i) { Iterator it = d->list.begin(); @@ -358,7 +358,7 @@ T &List::operator[](uint i) } template -const T &List::operator[](uint i) const +const T &List::operator[](size_t i) const { ConstIterator it = d->list.begin(); diff --git a/taglib/toolkit/tmap.h b/taglib/toolkit/tmap.h index 3f0bfc0b..93b7bb95 100644 --- a/taglib/toolkit/tmap.h +++ b/taglib/toolkit/tmap.h @@ -142,7 +142,7 @@ namespace TagLib { * * \see isEmpty() */ - uint size() const; + size_t size() const; /*! * Returns true if the map is empty. diff --git a/taglib/toolkit/tmap.tcc b/taglib/toolkit/tmap.tcc index 9266a21d..09130c18 100644 --- a/taglib/toolkit/tmap.tcc +++ b/taglib/toolkit/tmap.tcc @@ -207,7 +207,7 @@ Map &Map::erase(const Key &key) } template -TagLib::uint Map::size() const +size_t Map::size() const { return d->map.size(); } diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index 1efdeac4..358d7975 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -126,6 +126,9 @@ public: const String String::null; +// Actual value is -1. +const size_t String::npos = wstring::npos; + //////////////////////////////////////////////////////////////////////////////// String::String() @@ -325,35 +328,23 @@ String::ConstIterator String::end() const return d->data.end(); } -int String::find(const String &s, int offset) const +size_t String::find(const String &s, size_t offset) const { - const size_t position - = d->data.find(s.d->data, offset == -1 ? wstring::npos : offset); - - if(position != wstring::npos) - return static_cast(position); - else - return -1; + return d->data.find(s.d->data, offset); } -int String::rfind(const String &s, int offset) const +size_t String::rfind(const String &s, size_t offset) const { - const size_t position = - d->data.rfind(s.d->data, offset == -1 ? wstring::npos : offset); - - if(position != wstring::npos) - return static_cast(position); - else - return -1; + return d->data.rfind(s.d->data, offset); } StringList String::split(const String &separator) const { StringList list; - for(int index = 0;;) + for(size_t index = 0;;) { - const int sep = find(separator, index); - if(sep < 0) + const size_t sep = find(separator, index); + if(sep == npos) { list.append(substr(index, size() - index)); break; @@ -375,11 +366,9 @@ bool String::startsWith(const String &s) const return substr(0, s.length()) == s; } -String String::substr(uint position, uint n) const +String String::substr(size_t position, size_t length) const { - String s; - s.d->data = d->data.substr(position, n); - return s; + return String(d->data.substr(position, length)); } String &String::append(const String &s) @@ -394,31 +383,32 @@ String String::upper() const static const int shift = 'A' - 'a'; String s; - s.d->data.reserve(d->data.size()); + s.d->data.resize(d->data.size()); + wchar_t *p = &s.d->data[0]; for(wstring::const_iterator it = d->data.begin(); it != d->data.end(); ++it) { if(*it >= 'a' && *it <= 'z') - s.d->data.push_back(*it + shift); + *p++ = *it + shift; else - s.d->data.push_back(*it); + *p++ = *it; } return s; } -TagLib::uint String::size() const +size_t String::size() const { - return static_cast(d->data.size()); + return d->data.size(); } -TagLib::uint String::length() const +size_t String::length() const { return size(); } bool String::isEmpty() const { - return (d->data.size() == 0); + return d->data.empty(); } bool String::isNull() const @@ -432,7 +422,7 @@ ByteVector String::data(Type t) const { case Latin1: { - ByteVector v(size()); + ByteVector v(size(), 0); char *p = v.data(); for(wstring::const_iterator it = d->data.begin(); it != d->data.end(); it++) @@ -442,7 +432,7 @@ ByteVector String::data(Type t) const } case UTF8: { - ByteVector v(size() * 4 + 1); + ByteVector v(size() * 4 + 1, 0); #ifdef TAGLIB_USE_CODECVT @@ -478,7 +468,7 @@ ByteVector String::data(Type t) const } case UTF16: { - ByteVector v(2 + size() * 2); + ByteVector v(2 + size() * 2, 0); char *p = v.data(); // Assume that if we're doing UTF16 and not UTF16BE that we want little @@ -496,7 +486,7 @@ ByteVector String::data(Type t) const } case UTF16BE: { - ByteVector v(size() * 2); + ByteVector v(size() * 2, 0); char *p = v.data(); for(wstring::const_iterator it = d->data.begin(); it != d->data.end(); it++) { @@ -508,7 +498,7 @@ ByteVector String::data(Type t) const } case UTF16LE: { - ByteVector v(size() * 2); + ByteVector v(size() * 2, 0); char *p = v.data(); for(wstring::const_iterator it = d->data.begin(); it != d->data.end(); it++) { @@ -614,7 +604,7 @@ String String::number(int n) // static if(negative) s += '-'; - for(int i = charStack.d->data.size() - 1; i >= 0; i--) + for(int i = static_cast(charStack.d->data.size()) - 1; i >= 0; i--) s += charStack.d->data[i]; return s; diff --git a/taglib/toolkit/tstring.h b/taglib/toolkit/tstring.h index 43f2643c..780b5e7b 100644 --- a/taglib/toolkit/tstring.h +++ b/taglib/toolkit/tstring.h @@ -240,16 +240,16 @@ namespace TagLib { /*! * Finds the first occurrence of pattern \a s in this string starting from - * \a offset. If the pattern is not found, -1 is returned. + * \a offset. If the pattern is not found, \a npos is returned. */ - int find(const String &s, int offset = 0) const; + size_t find(const String &s, size_t offset = 0) const; /*! * Finds the last occurrence of pattern \a s in this string, searched backwards, * either from the end of the string or starting from \a offset. If the pattern - * is not found, -1 is returned. + * is not found, \a npos is returned. */ - int rfind(const String &s, int offset = -1) const; + size_t rfind(const String &s, size_t offset = npos) const; /*! * Splits the string on each occurrence of \a separator. @@ -265,7 +265,7 @@ namespace TagLib { * Extract a substring from this string starting at \a position and * continuing for \a n characters. */ - String substr(uint position, uint n = 0xffffffff) const; + String substr(size_t position, size_t n = npos) const; /*! * Append \a s to the current string and return a reference to the current @@ -283,12 +283,12 @@ namespace TagLib { /*! * Returns the size of the string. */ - uint size() const; + size_t size() const; /*! * Returns the length of the string. Equivalent to size(). */ - uint length() const; + size_t length() const; /*! * Returns true if the string is empty. @@ -476,6 +476,13 @@ namespace TagLib { */ static const String null; + /*! + * When used as the value for a \a length parameter in String's member + * functions, means "until the end of the string". + * As a return value, it is usually used to indicate no matches. + */ + static const size_t npos; + protected: /*! * If this String is being shared via implicit sharing, do a deep copy of the diff --git a/taglib/toolkit/tstringlist.cpp b/taglib/toolkit/tstringlist.cpp index 910de970..0220a012 100644 --- a/taglib/toolkit/tstringlist.cpp +++ b/taglib/toolkit/tstringlist.cpp @@ -35,8 +35,11 @@ StringList StringList::split(const String &s, const String &pattern) { StringList l; - int previousOffset = 0; - for(int offset = s.find(pattern); offset != -1; offset = s.find(pattern, offset + 1)) { + size_t previousOffset = 0; + for(size_t offset = s.find(pattern); + offset != String::npos; + offset = s.find(pattern, offset + 1)) + { l.append(s.substr(previousOffset, offset - previousOffset)); previousOffset = offset + 1; } diff --git a/taglib/trueaudio/trueaudiofile.cpp b/taglib/trueaudio/trueaudiofile.cpp index f1c3c35d..66023001 100644 --- a/taglib/trueaudio/trueaudiofile.cpp +++ b/taglib/trueaudio/trueaudiofile.cpp @@ -162,7 +162,7 @@ bool TrueAudio::File::save() ByteVector data = ID3v2Tag()->render(); insert(data, d->ID3v2Location, d->ID3v2OriginalSize); d->ID3v1Location -= d->ID3v2OriginalSize - data.size(); - d->ID3v2OriginalSize = data.size(); + d->ID3v2OriginalSize = static_cast(data.size()); d->hasID3v2 = true; } else if(d->hasID3v2) { diff --git a/taglib/trueaudio/trueaudioproperties.cpp b/taglib/trueaudio/trueaudioproperties.cpp index 43423d9c..ea873532 100644 --- a/taglib/trueaudio/trueaudioproperties.cpp +++ b/taglib/trueaudio/trueaudioproperties.cpp @@ -133,16 +133,16 @@ void TrueAudio::Properties::read() // Skip the audio format pos += 2; - d->channels = d->data.mid(pos, 2).toShort(false); + d->channels = d->data.mid(pos, 2).toInt16(false); pos += 2; - d->bitsPerSample = d->data.mid(pos, 2).toShort(false); + d->bitsPerSample = d->data.mid(pos, 2).toInt16(false); pos += 2; - d->sampleRate = d->data.mid(pos, 4).toUInt(false); + d->sampleRate = d->data.mid(pos, 4).toUInt32(false); pos += 4; - d->sampleFrames = d->data.mid(pos, 4).toUInt(false); + d->sampleFrames = d->data.mid(pos, 4).toUInt32(false); d->length = d->sampleRate > 0 ? d->sampleFrames / d->sampleRate : 0; d->bitrate = d->length > 0 ? static_cast(d->streamLength * 8L / d->length / 1000) : 0; diff --git a/taglib/wavpack/wavpackproperties.cpp b/taglib/wavpack/wavpackproperties.cpp index 9ddabe1e..dab34cb8 100644 --- a/taglib/wavpack/wavpackproperties.cpp +++ b/taglib/wavpack/wavpackproperties.cpp @@ -141,17 +141,17 @@ void WavPack::Properties::read() if(!d->data.startsWith("wvpk")) return; - d->version = d->data.mid(8, 2).toShort(false); + d->version = d->data.mid(8, 2).toInt16(false); if(d->version < MIN_STREAM_VERS || d->version > MAX_STREAM_VERS) return; - unsigned int flags = d->data.mid(24, 4).toUInt(false); + unsigned int flags = d->data.mid(24, 4).toUInt32(false); d->bitsPerSample = ((flags & BYTES_STORED) + 1) * 8 - ((flags & SHIFT_MASK) >> SHIFT_LSB); d->sampleRate = sample_rates[(flags & SRATE_MASK) >> SRATE_LSB]; d->channels = (flags & MONO_FLAG) ? 1 : 2; - unsigned int samples = d->data.mid(12, 4).toUInt(false); + unsigned int samples = d->data.mid(12, 4).toUInt32(false); if(samples == ~0u) { if(d->style != Fast) { samples = seekFinalIndex(); @@ -179,14 +179,14 @@ unsigned int WavPack::Properties::seekFinalIndex() ByteVector data = d->file->readBlock(32); if(data.size() != 32) return 0; - int version = data.mid(8, 2).toShort(false); + int version = data.mid(8, 2).toInt16(false); if(version < MIN_STREAM_VERS || version > MAX_STREAM_VERS) continue; - unsigned int flags = data.mid(24, 4).toUInt(false); + unsigned int flags = data.mid(24, 4).toUInt32(false); if(!(flags & FINAL_BLOCK)) return 0; - unsigned int blockIndex = data.mid(16, 4).toUInt(false); - unsigned int blockSamples = data.mid(20, 4).toUInt(false); + unsigned int blockIndex = data.mid(16, 4).toUInt32(false); + unsigned int blockSamples = data.mid(20, 4).toUInt32(false); return blockIndex + blockSamples; } diff --git a/taglib/xm/xmfile.cpp b/taglib/xm/xmfile.cpp index 71a53406..c315011d 100644 --- a/taglib/xm/xmfile.cpp +++ b/taglib/xm/xmfile.cpp @@ -127,14 +127,14 @@ public: uint read(TagLib::File &file, uint limit) { ByteVector data = file.readBlock(std::min(m_size, limit)); - uint count = data.size(); - int index = data.find((char) 0); - if(index > -1) { + size_t count = data.size(); + const size_t index = data.find((char) 0); + if(index != ByteVector::npos) { data.resize(index); } data.replace((char) 0xff, ' '); value = data; - return count; + return static_cast(count); } uint size() const @@ -157,7 +157,7 @@ public: if(data.size() > 0) { value = data[0]; } - return data.size(); + return static_cast(data.size()); } uint size() const @@ -188,8 +188,8 @@ public: uint read(TagLib::File &file, uint limit) { ByteVector data = file.readBlock(std::min(2U,limit)); - value = data.toUShort(bigEndian); - return data.size(); + value = data.toUInt16(bigEndian); + return static_cast(data.size()); } uint size() const @@ -209,8 +209,8 @@ public: uint read(TagLib::File &file, uint limit) { ByteVector data = file.readBlock(std::min(4U,limit)); - value = data.toUInt(bigEndian); - return data.size(); + value = data.toUInt32(bigEndian); + return static_cast(data.size()); } uint size() const diff --git a/tests/test_apetag.cpp b/tests/test_apetag.cpp index c93b2a7e..5d2df9b6 100644 --- a/tests/test_apetag.cpp +++ b/tests/test_apetag.cpp @@ -50,7 +50,7 @@ public: dict["TRACKNUMBER"].append("17"); tag.setProperties(dict); CPPUNIT_ASSERT_EQUAL(String("17"), tag.itemListMap()["TRACK"].values()[0]); - CPPUNIT_ASSERT_EQUAL(2u, tag.itemListMap()["ARTIST"].values().size()); + CPPUNIT_ASSERT_EQUAL((size_t)2u, tag.itemListMap()["ARTIST"].values().size()); CPPUNIT_ASSERT_EQUAL(String("artist 1"), tag.artist()); CPPUNIT_ASSERT_EQUAL(17u, tag.track()); } @@ -66,7 +66,7 @@ public: tag.setItem("TESTBINARY", item2); PropertyMap properties = tag.properties(); - CPPUNIT_ASSERT_EQUAL(1u, properties.unsupportedData().size()); + CPPUNIT_ASSERT_EQUAL((size_t)1u, properties.unsupportedData().size()); CPPUNIT_ASSERT(properties.contains("TRACKNUMBER")); CPPUNIT_ASSERT(!properties.contains("TRACK")); CPPUNIT_ASSERT(tag.itemListMap().contains("TESTBINARY")); @@ -77,7 +77,7 @@ public: APE::Item item3 = APE::Item("TRACKNUMBER", "29"); tag.setItem("TRACKNUMBER", item3); properties = tag.properties(); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), properties["TRACKNUMBER"].size()); + CPPUNIT_ASSERT_EQUAL((size_t)2, properties["TRACKNUMBER"].size()); CPPUNIT_ASSERT_EQUAL(String("17"), properties["TRACKNUMBER"][0]); CPPUNIT_ASSERT_EQUAL(String("29"), properties["TRACKNUMBER"][1]); @@ -93,7 +93,7 @@ public: APE::Tag tag; PropertyMap unsuccessful = tag.setProperties(properties); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), unsuccessful.size()); + CPPUNIT_ASSERT_EQUAL(size_t(2), unsuccessful.size()); CPPUNIT_ASSERT(unsuccessful.contains("A")); CPPUNIT_ASSERT(unsuccessful.contains("MP+")); } diff --git a/tests/test_asf.cpp b/tests/test_asf.cpp index 8610c24b..2876bfea 100644 --- a/tests/test_asf.cpp +++ b/tests/test_asf.cpp @@ -165,7 +165,7 @@ public: f = new ASF::File(newname.c_str()); ASF::AttributeList values2 = f->tag()->attributeListMap()["WM/Picture"]; - CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), values2.size()); + CPPUNIT_ASSERT_EQUAL(size_t(1), values2.size()); ASF::Attribute attr2 = values2.front(); ASF::Picture picture2 = attr2.toPicture(); CPPUNIT_ASSERT(picture2.isValid()); @@ -201,7 +201,7 @@ public: f = new ASF::File(newname.c_str()); ASF::AttributeList values2 = f->tag()->attributeListMap()["WM/Picture"]; - CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), values2.size()); + CPPUNIT_ASSERT_EQUAL(size_t(2), values2.size()); ASF::Picture picture3 = values2[1].toPicture(); CPPUNIT_ASSERT(picture3.isValid()); CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), picture3.mimeType()); @@ -235,17 +235,17 @@ public: CPPUNIT_ASSERT_EQUAL(StringList("Foo Bar"), tags["ARTIST"]); CPPUNIT_ASSERT(f.tag()->attributeListMap().contains("WM/BeatsPerMinute")); - CPPUNIT_ASSERT_EQUAL(1u, f.tag()->attributeListMap()["WM/BeatsPerMinute"].size()); + CPPUNIT_ASSERT_EQUAL((size_t)1u, f.tag()->attributeListMap()["WM/BeatsPerMinute"].size()); CPPUNIT_ASSERT_EQUAL(String("123"), f.tag()->attributeListMap()["WM/BeatsPerMinute"].front().toString()); CPPUNIT_ASSERT_EQUAL(StringList("123"), tags["BPM"]); CPPUNIT_ASSERT(f.tag()->attributeListMap().contains("WM/TrackNumber")); - CPPUNIT_ASSERT_EQUAL(1u, f.tag()->attributeListMap()["WM/TrackNumber"].size()); + CPPUNIT_ASSERT_EQUAL((size_t)1u, f.tag()->attributeListMap()["WM/TrackNumber"].size()); CPPUNIT_ASSERT_EQUAL(String("2"), f.tag()->attributeListMap()["WM/TrackNumber"].front().toString()); CPPUNIT_ASSERT_EQUAL(StringList("2"), tags["TRACKNUMBER"]); CPPUNIT_ASSERT(f.tag()->attributeListMap().contains("WM/PartOfSet")); - CPPUNIT_ASSERT_EQUAL(1u, f.tag()->attributeListMap()["WM/PartOfSet"].size()); + CPPUNIT_ASSERT_EQUAL((size_t)1u, f.tag()->attributeListMap()["WM/PartOfSet"].size()); CPPUNIT_ASSERT_EQUAL(String("3"), f.tag()->attributeListMap()["WM/PartOfSet"].front().toString()); CPPUNIT_ASSERT_EQUAL(StringList("3"), tags["DISCNUMBER"]); } diff --git a/tests/test_bytevector.cpp b/tests/test_bytevector.cpp index dd433456..1ea5b070 100644 --- a/tests/test_bytevector.cpp +++ b/tests/test_bytevector.cpp @@ -52,13 +52,13 @@ public: v[2] = b; v[1] = c; v[0] = d; - CPPUNIT_ASSERT(v.toUInt(false) == i); + CPPUNIT_ASSERT(v.toUInt32(false) == i); v[0] = a; v[1] = b; v[2] = c; v[3] = d; - CPPUNIT_ASSERT(v.toUInt() == i); + CPPUNIT_ASSERT(v.toUInt32() == i); } void testByteVector() @@ -70,12 +70,12 @@ public: ByteVector n(4, 0); n[0] = 1; - CPPUNIT_ASSERT(n.toUInt(true) == 16777216); - CPPUNIT_ASSERT(n.toUInt(false) == 1); - CPPUNIT_ASSERT(ByteVector::fromUInt(16777216, true) == n); - CPPUNIT_ASSERT(ByteVector::fromUInt(1, false) == n); + CPPUNIT_ASSERT(n.toUInt32(true) == 16777216); + CPPUNIT_ASSERT(n.toUInt32(false) == 1); + CPPUNIT_ASSERT(ByteVector::fromUInt32(16777216, true) == n); + CPPUNIT_ASSERT(ByteVector::fromUInt32(1, false) == n); - CPPUNIT_ASSERT(ByteVector::fromUInt(0xa0).toUInt() == 0xa0); + CPPUNIT_ASSERT(ByteVector::fromUInt32(0xa0).toUInt32() == 0xa0); testConversion(0x000000a0, 0x00, 0x00, 0x00, 0xa0); testConversion(0xd50bf072, 0xd5, 0x0b, 0xf0, 0x72); @@ -83,16 +83,16 @@ public: ByteVector intVector(2, 0); intVector[0] = char(0xfc); intVector[1] = char(0x00); - CPPUNIT_ASSERT(intVector.toShort() == -1024); + CPPUNIT_ASSERT(intVector.toInt16() == -1024); intVector[0] = char(0x04); intVector[1] = char(0x00); - CPPUNIT_ASSERT(intVector.toShort() == 1024); + CPPUNIT_ASSERT(intVector.toInt16() == 1024); - CPPUNIT_ASSERT(ByteVector::fromLongLong(1).toLongLong() == 1); - CPPUNIT_ASSERT(ByteVector::fromLongLong(0).toLongLong() == 0); - CPPUNIT_ASSERT(ByteVector::fromLongLong(0xffffffffffffffffLL).toLongLong() == -1); - CPPUNIT_ASSERT(ByteVector::fromLongLong(0xfffffffffffffffeLL).toLongLong() == -2); - CPPUNIT_ASSERT(ByteVector::fromLongLong(1024).toLongLong() == 1024); + CPPUNIT_ASSERT(ByteVector::fromUInt64(1).toInt64() == 1); + CPPUNIT_ASSERT(ByteVector::fromUInt64(0).toInt64() == 0); + CPPUNIT_ASSERT(ByteVector::fromUInt64(0xffffffffffffffffLL).toInt64() == -1); + CPPUNIT_ASSERT(ByteVector::fromUInt64(0xfffffffffffffffeLL).toInt64() == -2); + CPPUNIT_ASSERT(ByteVector::fromUInt64(1024).toInt64() == 1024); ByteVector a1("foo"); a1.append("bar"); @@ -120,38 +120,38 @@ public: void testFind1() { - CPPUNIT_ASSERT_EQUAL(4, ByteVector("....SggO."). find("SggO")); - CPPUNIT_ASSERT_EQUAL(4, ByteVector("....SggO."). find("SggO", 0)); - CPPUNIT_ASSERT_EQUAL(4, ByteVector("....SggO."). find("SggO", 1)); - CPPUNIT_ASSERT_EQUAL(4, ByteVector("....SggO."). find("SggO", 2)); - CPPUNIT_ASSERT_EQUAL(4, ByteVector("....SggO."). find("SggO", 3)); - CPPUNIT_ASSERT_EQUAL(4, ByteVector("....SggO."). find("SggO", 4)); - CPPUNIT_ASSERT_EQUAL(-1, ByteVector("....SggO."). find("SggO", 5)); - CPPUNIT_ASSERT_EQUAL(-1, ByteVector("....SggO."). find("SggO", 6)); - CPPUNIT_ASSERT_EQUAL(-1, ByteVector("....SggO."). find("SggO", 7)); - CPPUNIT_ASSERT_EQUAL(-1, ByteVector("....SggO."). find("SggO", 8)); + CPPUNIT_ASSERT_EQUAL((size_t)4, ByteVector("....SggO."). find("SggO")); + CPPUNIT_ASSERT_EQUAL((size_t)4, ByteVector("....SggO."). find("SggO", 0)); + CPPUNIT_ASSERT_EQUAL((size_t)4, ByteVector("....SggO."). find("SggO", 1)); + CPPUNIT_ASSERT_EQUAL((size_t)4, ByteVector("....SggO."). find("SggO", 2)); + CPPUNIT_ASSERT_EQUAL((size_t)4, ByteVector("....SggO."). find("SggO", 3)); + CPPUNIT_ASSERT_EQUAL((size_t)4, ByteVector("....SggO."). find("SggO", 4)); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos, ByteVector("....SggO."). find("SggO", 5)); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos, ByteVector("....SggO."). find("SggO", 6)); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos, ByteVector("....SggO."). find("SggO", 7)); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos, ByteVector("....SggO."). find("SggO", 8)); } void testFind2() { - CPPUNIT_ASSERT_EQUAL(0, ByteVector("\x01", 1).find("\x01")); - CPPUNIT_ASSERT_EQUAL(0, ByteVector("\x01\x02", 2).find("\x01\x02")); - CPPUNIT_ASSERT_EQUAL(-1, ByteVector("\x01", 1).find("\x02")); - CPPUNIT_ASSERT_EQUAL(-1, ByteVector("\x01\x02", 2).find("\x01\x03")); + CPPUNIT_ASSERT_EQUAL((size_t)0, ByteVector("\x01", 1).find("\x01")); + CPPUNIT_ASSERT_EQUAL((size_t)0, ByteVector("\x01\x02", 2).find("\x01\x02")); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos, ByteVector("\x01", 1).find("\x02")); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos, ByteVector("\x01\x02", 2).find("\x01\x03")); } void testRfind1() { - CPPUNIT_ASSERT_EQUAL(1, ByteVector(".OggS....").rfind("OggS", 0)); - CPPUNIT_ASSERT_EQUAL(1, ByteVector(".OggS....").rfind("OggS", 1)); - CPPUNIT_ASSERT_EQUAL(1, ByteVector(".OggS....").rfind("OggS", 2)); - CPPUNIT_ASSERT_EQUAL(1, ByteVector(".OggS....").rfind("OggS", 3)); - CPPUNIT_ASSERT_EQUAL(1, ByteVector(".OggS....").rfind("OggS", 4)); - CPPUNIT_ASSERT_EQUAL(1, ByteVector(".OggS....").rfind("OggS", 5)); - CPPUNIT_ASSERT_EQUAL(1, ByteVector(".OggS....").rfind("OggS", 6)); - CPPUNIT_ASSERT_EQUAL(1, ByteVector(".OggS....").rfind("OggS", 7)); - CPPUNIT_ASSERT_EQUAL(1, ByteVector(".OggS....").rfind("OggS", 8)); - CPPUNIT_ASSERT_EQUAL(1, ByteVector(".OggS....").rfind("OggS")); + CPPUNIT_ASSERT_EQUAL((size_t)1, ByteVector(".OggS....").rfind("OggS", 0)); + CPPUNIT_ASSERT_EQUAL((size_t)1, ByteVector(".OggS....").rfind("OggS", 1)); + CPPUNIT_ASSERT_EQUAL((size_t)1, ByteVector(".OggS....").rfind("OggS", 2)); + CPPUNIT_ASSERT_EQUAL((size_t)1, ByteVector(".OggS....").rfind("OggS", 3)); + CPPUNIT_ASSERT_EQUAL((size_t)1, ByteVector(".OggS....").rfind("OggS", 4)); + CPPUNIT_ASSERT_EQUAL((size_t)1, ByteVector(".OggS....").rfind("OggS", 5)); + CPPUNIT_ASSERT_EQUAL((size_t)1, ByteVector(".OggS....").rfind("OggS", 6)); + CPPUNIT_ASSERT_EQUAL((size_t)1, ByteVector(".OggS....").rfind("OggS", 7)); + CPPUNIT_ASSERT_EQUAL((size_t)1, ByteVector(".OggS....").rfind("OggS", 8)); + CPPUNIT_ASSERT_EQUAL((size_t)1, ByteVector(".OggS....").rfind("OggS")); } void testRfind2() @@ -162,18 +162,18 @@ public: ByteVector r3("OggS******OggS"); ByteVector r4("OggS*OggS*OggS"); - CPPUNIT_ASSERT_EQUAL(-1, r0.find("OggS")); - CPPUNIT_ASSERT_EQUAL(-1, r0.rfind("OggS")); - CPPUNIT_ASSERT_EQUAL(0, r1.find("OggS")); - CPPUNIT_ASSERT_EQUAL(0, r1.rfind("OggS")); - CPPUNIT_ASSERT_EQUAL(10, r2.find("OggS")); - CPPUNIT_ASSERT_EQUAL(10, r2.rfind("OggS")); - CPPUNIT_ASSERT_EQUAL(0, r3.find("OggS")); - CPPUNIT_ASSERT_EQUAL(10, r3.rfind("OggS")); - CPPUNIT_ASSERT_EQUAL(10, r4.rfind("OggS")); - CPPUNIT_ASSERT_EQUAL(10, r4.rfind("OggS", 0)); - CPPUNIT_ASSERT_EQUAL(5, r4.rfind("OggS", 7)); - CPPUNIT_ASSERT_EQUAL(10, r4.rfind("OggS", 12)); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos, r0.find("OggS")); + CPPUNIT_ASSERT_EQUAL(ByteVector::npos, r0.rfind("OggS")); + CPPUNIT_ASSERT_EQUAL((size_t)0, r1.find("OggS")); + CPPUNIT_ASSERT_EQUAL((size_t)0, r1.rfind("OggS")); + CPPUNIT_ASSERT_EQUAL((size_t)10, r2.find("OggS")); + CPPUNIT_ASSERT_EQUAL((size_t)10, r2.rfind("OggS")); + CPPUNIT_ASSERT_EQUAL((size_t)0, r3.find("OggS")); + CPPUNIT_ASSERT_EQUAL((size_t)10, r3.rfind("OggS")); + CPPUNIT_ASSERT_EQUAL((size_t)10, r4.rfind("OggS")); + CPPUNIT_ASSERT_EQUAL((size_t)10, r4.rfind("OggS", 0)); + CPPUNIT_ASSERT_EQUAL((size_t)5, r4.rfind("OggS", 7)); + CPPUNIT_ASSERT_EQUAL((size_t)10, r4.rfind("OggS", 12)); } void testToHex() @@ -185,11 +185,11 @@ public: void testToUShort() { - CPPUNIT_ASSERT_EQUAL((unsigned short)0xFFFF, ByteVector("\xff\xff", 2).toUShort()); - CPPUNIT_ASSERT_EQUAL((unsigned short)0x0001, ByteVector("\x00\x01", 2).toUShort()); - CPPUNIT_ASSERT_EQUAL((unsigned short)0x0100, ByteVector("\x00\x01", 2).toUShort(false)); - CPPUNIT_ASSERT_EQUAL((unsigned short)0xFF01, ByteVector("\xFF\x01", 2).toUShort()); - CPPUNIT_ASSERT_EQUAL((unsigned short)0x01FF, ByteVector("\xFF\x01", 2).toUShort(false)); + CPPUNIT_ASSERT_EQUAL((unsigned short)0xFFFF, ByteVector("\xff\xff", 2).toUInt16()); + CPPUNIT_ASSERT_EQUAL((unsigned short)0x0001, ByteVector("\x00\x01", 2).toUInt16()); + CPPUNIT_ASSERT_EQUAL((unsigned short)0x0100, ByteVector("\x00\x01", 2).toUInt16(false)); + CPPUNIT_ASSERT_EQUAL((unsigned short)0xFF01, ByteVector("\xFF\x01", 2).toUInt16()); + CPPUNIT_ASSERT_EQUAL((unsigned short)0x01FF, ByteVector("\xFF\x01", 2).toUInt16(false)); } void testReplace() diff --git a/tests/test_bytevectorlist.cpp b/tests/test_bytevectorlist.cpp index 7e4a9fd7..a490daec 100644 --- a/tests/test_bytevectorlist.cpp +++ b/tests/test_bytevectorlist.cpp @@ -19,7 +19,7 @@ public: ByteVector v("a b"); ByteVectorList l = ByteVectorList::split(v, " "); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), l.size()); + CPPUNIT_ASSERT_EQUAL(size_t(2), l.size()); CPPUNIT_ASSERT_EQUAL(ByteVector("a"), l[0]); CPPUNIT_ASSERT_EQUAL(ByteVector("b"), l[1]); } @@ -29,7 +29,7 @@ public: ByteVector v("a"); ByteVectorList l = ByteVectorList::split(v, " "); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), l.size()); + CPPUNIT_ASSERT_EQUAL(size_t(1), l.size()); CPPUNIT_ASSERT_EQUAL(ByteVector("a"), l[0]); } diff --git a/tests/test_flac.cpp b/tests/test_flac.cpp index 7f40a382..d6224f96 100644 --- a/tests/test_flac.cpp +++ b/tests/test_flac.cpp @@ -58,7 +58,7 @@ public: FLAC::File *f = new FLAC::File(newname.c_str()); List lst = f->pictureList(); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), lst.size()); + CPPUNIT_ASSERT_EQUAL(size_t(1), lst.size()); FLAC::Picture *pic = lst.front(); CPPUNIT_ASSERT_EQUAL(FLAC::Picture::FrontCover, pic->type()); @@ -68,7 +68,7 @@ public: CPPUNIT_ASSERT_EQUAL(0, pic->numColors()); CPPUNIT_ASSERT_EQUAL(String("image/png"), pic->mimeType()); CPPUNIT_ASSERT_EQUAL(String("A pixel."), pic->description()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(150), pic->data().size()); + CPPUNIT_ASSERT_EQUAL(size_t(150), pic->data().size()); } void testAddPicture() @@ -78,7 +78,7 @@ public: FLAC::File *f = new FLAC::File(newname.c_str()); List lst = f->pictureList(); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), lst.size()); + CPPUNIT_ASSERT_EQUAL(size_t(1), lst.size()); FLAC::Picture *newpic = new FLAC::Picture(); newpic->setType(FLAC::Picture::BackCover); @@ -94,7 +94,7 @@ public: f = new FLAC::File(newname.c_str()); lst = f->pictureList(); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), lst.size()); + CPPUNIT_ASSERT_EQUAL(size_t(2), lst.size()); FLAC::Picture *pic = lst[0]; CPPUNIT_ASSERT_EQUAL(FLAC::Picture::FrontCover, pic->type()); @@ -104,7 +104,7 @@ public: CPPUNIT_ASSERT_EQUAL(0, pic->numColors()); CPPUNIT_ASSERT_EQUAL(String("image/png"), pic->mimeType()); CPPUNIT_ASSERT_EQUAL(String("A pixel."), pic->description()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(150), pic->data().size()); + CPPUNIT_ASSERT_EQUAL(size_t(150), pic->data().size()); pic = lst[1]; CPPUNIT_ASSERT_EQUAL(FLAC::Picture::BackCover, pic->type()); @@ -124,7 +124,7 @@ public: FLAC::File *f = new FLAC::File(newname.c_str()); List lst = f->pictureList(); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), lst.size()); + CPPUNIT_ASSERT_EQUAL(size_t(1), lst.size()); FLAC::Picture *newpic = new FLAC::Picture(); newpic->setType(FLAC::Picture::BackCover); @@ -141,7 +141,7 @@ public: f = new FLAC::File(newname.c_str()); lst = f->pictureList(); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), lst.size()); + CPPUNIT_ASSERT_EQUAL(size_t(1), lst.size()); FLAC::Picture *pic = lst[0]; CPPUNIT_ASSERT_EQUAL(FLAC::Picture::BackCover, pic->type()); @@ -161,14 +161,14 @@ public: FLAC::File *f = new FLAC::File(newname.c_str()); List lst = f->pictureList(); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), lst.size()); + CPPUNIT_ASSERT_EQUAL(size_t(1), lst.size()); f->removePictures(); f->save(); f = new FLAC::File(newname.c_str()); lst = f->pictureList(); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), lst.size()); + CPPUNIT_ASSERT_EQUAL(size_t(0), lst.size()); } void testRepeatedSave() @@ -206,7 +206,7 @@ public: f = new FLAC::File(newname.c_str()); c = f->xiphComment(true); Ogg::FieldListMap m = c->fieldListMap(); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), m["ARTIST"].size()); + CPPUNIT_ASSERT_EQUAL(size_t(2), m["ARTIST"].size()); CPPUNIT_ASSERT_EQUAL(String("artist 1"), m["ARTIST"][0]); CPPUNIT_ASSERT_EQUAL(String("artist 2"), m["ARTIST"][1]); } @@ -227,7 +227,7 @@ public: f = new FLAC::File(newname.c_str()); dict = f->properties(); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), dict["ARTIST"].size()); + CPPUNIT_ASSERT_EQUAL(size_t(2), dict["ARTIST"].size()); CPPUNIT_ASSERT_EQUAL(String("artøst 1"), dict["ARTIST"][0]); CPPUNIT_ASSERT_EQUAL(String("artöst 2"), dict["ARTIST"][1]); } @@ -236,11 +236,11 @@ public: { ScopedFileCopy copy("silence-44-s", ".flac"); PropertyMap map; - map["HÄÖ"] = String("bla"); + map["H\xc4\xd6"] = String("bla"); FLAC::File f(copy.fileName().c_str()); PropertyMap invalid = f.setProperties(map); - CPPUNIT_ASSERT_EQUAL(uint(1), invalid.size()); - CPPUNIT_ASSERT_EQUAL(uint(0), f.properties().size()); + CPPUNIT_ASSERT_EQUAL(size_t(1), invalid.size()); + CPPUNIT_ASSERT_EQUAL(size_t(0), f.properties().size()); } }; diff --git a/tests/test_flacpicture.cpp b/tests/test_flacpicture.cpp index 0ba9452f..b61d0caf 100644 --- a/tests/test_flacpicture.cpp +++ b/tests/test_flacpicture.cpp @@ -32,7 +32,7 @@ public: CPPUNIT_ASSERT_EQUAL(0, pic.numColors()); CPPUNIT_ASSERT_EQUAL(String("image/png"), pic.mimeType()); CPPUNIT_ASSERT_EQUAL(String("A pixel."), pic.description()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(150), pic.data().size()); + CPPUNIT_ASSERT_EQUAL(size_t(150), pic.data().size()); } void testPassThrough() diff --git a/tests/test_id3v2.cpp b/tests/test_id3v2.cpp index 48faf306..050dc035 100644 --- a/tests/test_id3v2.cpp +++ b/tests/test_id3v2.cpp @@ -96,7 +96,7 @@ public: f.setText(sl); f.header()->setVersion(3); ByteVector data = f.render(); - CPPUNIT_ASSERT_EQUAL((unsigned int)(4+4+2+1+6+2), data.size()); + CPPUNIT_ASSERT_EQUAL((size_t)(4+4+2+1+6+2), data.size()); ID3v2::TextIdentificationFrame f2(data); CPPUNIT_ASSERT_EQUAL(sl, f2.fieldList()); CPPUNIT_ASSERT_EQUAL(String::UTF16, f2.textEncoding()); @@ -109,7 +109,7 @@ public: sl.append("Foo"); sl.append("Bar"); f.setText(sl); - CPPUNIT_ASSERT_EQUAL((unsigned int)(4+4+2+1+6+2+6), f.render().size()); + CPPUNIT_ASSERT_EQUAL((size_t)(4+4+2+1+6+2+6), f.render().size()); } void testUTF16Delimiter() @@ -119,7 +119,7 @@ public: sl.append("Foo"); sl.append("Bar"); f.setText(sl); - CPPUNIT_ASSERT_EQUAL((unsigned int)(4+4+2+1+8+2+8), f.render().size()); + CPPUNIT_ASSERT_EQUAL((size_t)(4+4+2+1+8+2+8), f.render().size()); } void testBrokenFrame1() @@ -202,7 +202,7 @@ public: ID3v2::Tag tag; tag.addFrame(frame); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(1034), tag.render().size()); + CPPUNIT_ASSERT_EQUAL(size_t(1034), tag.render().size()); } // http://bugs.kde.org/show_bug.cgi?id=151078 @@ -456,7 +456,7 @@ public: "(22)Death Metal", 26); // Text ID3v2::TextIdentificationFrame *frame = static_cast(factory->createFrame(data, TagLib::uint(3))); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), frame->fieldList().size()); + CPPUNIT_ASSERT_EQUAL(size_t(1), frame->fieldList().size()); CPPUNIT_ASSERT_EQUAL(String("Death Metal"), frame->fieldList()[0]); ID3v2::Tag tag; @@ -475,7 +475,7 @@ public: "(4)Eurodisco", 23); // Text ID3v2::TextIdentificationFrame *frame = static_cast(factory->createFrame(data, TagLib::uint(3))); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), frame->fieldList().size()); + CPPUNIT_ASSERT_EQUAL(size_t(2), frame->fieldList().size()); CPPUNIT_ASSERT_EQUAL(String("4"), frame->fieldList()[0]); CPPUNIT_ASSERT_EQUAL(String("Eurodisco"), frame->fieldList()[1]); @@ -494,7 +494,7 @@ public: "14\0Eurodisco", 23); // Text ID3v2::TextIdentificationFrame *frame = static_cast(factory->createFrame(data, TagLib::uint(4))); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), frame->fieldList().size()); + CPPUNIT_ASSERT_EQUAL(size_t(2), frame->fieldList().size()); CPPUNIT_ASSERT_EQUAL(String("14"), frame->fieldList()[0]); CPPUNIT_ASSERT_EQUAL(String("Eurodisco"), frame->fieldList()[1]); @@ -549,15 +549,15 @@ public: MPEG::File bar(newname.c_str()); tf = static_cast(bar.ID3v2Tag()->frameList("TDOR").front()); CPPUNIT_ASSERT(tf); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), tf->fieldList().size()); + CPPUNIT_ASSERT_EQUAL(size_t(1), tf->fieldList().size()); CPPUNIT_ASSERT_EQUAL(String("2011"), tf->fieldList().front()); tf = static_cast(bar.ID3v2Tag()->frameList("TDRC").front()); CPPUNIT_ASSERT(tf); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), tf->fieldList().size()); + CPPUNIT_ASSERT_EQUAL(size_t(1), tf->fieldList().size()); CPPUNIT_ASSERT_EQUAL(String("2012"), tf->fieldList().front()); tf = dynamic_cast(bar.ID3v2Tag()->frameList("TIPL").front()); CPPUNIT_ASSERT(tf); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(8), tf->fieldList().size()); + CPPUNIT_ASSERT_EQUAL(size_t(8), tf->fieldList().size()); CPPUNIT_ASSERT_EQUAL(String("Guitar"), tf->fieldList()[0]); CPPUNIT_ASSERT_EQUAL(String("Artist 1"), tf->fieldList()[1]); CPPUNIT_ASSERT_EQUAL(String("Drums"), tf->fieldList()[2]); @@ -586,7 +586,7 @@ public: CPPUNIT_ASSERT_EQUAL(String("image/bmp"), frame->mimeType()); CPPUNIT_ASSERT_EQUAL(ID3v2::AttachedPictureFrame::Other, frame->type()); CPPUNIT_ASSERT_EQUAL(String(""), frame->description()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(86414), frame->picture().size()); + CPPUNIT_ASSERT_EQUAL(size_t(86414), frame->picture().size()); } void testW000() @@ -605,12 +605,12 @@ public: string newname = copy.fileName(); MPEG::File f(newname.c_str()); PropertyMap dict = f.ID3v2Tag(false)->properties(); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(6), dict.size()); + CPPUNIT_ASSERT_EQUAL(size_t(6), dict.size()); CPPUNIT_ASSERT(dict.contains("USERTEXTDESCRIPTION1")); CPPUNIT_ASSERT(dict.contains("QuodLibet::USERTEXTDESCRIPTION2")); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), dict["USERTEXTDESCRIPTION1"].size()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), dict["QuodLibet::USERTEXTDESCRIPTION2"].size()); + CPPUNIT_ASSERT_EQUAL(size_t(2), dict["USERTEXTDESCRIPTION1"].size()); + CPPUNIT_ASSERT_EQUAL(size_t(2), dict["QuodLibet::USERTEXTDESCRIPTION2"].size()); CPPUNIT_ASSERT_EQUAL(String("userTextData1"), dict["USERTEXTDESCRIPTION1"][0]); CPPUNIT_ASSERT_EQUAL(String("userTextData2"), dict["USERTEXTDESCRIPTION1"][1]); CPPUNIT_ASSERT_EQUAL(String("userTextData1"), dict["QuodLibet::USERTEXTDESCRIPTION2"][0]); @@ -623,7 +623,7 @@ public: CPPUNIT_ASSERT_EQUAL(String("http://a.user.url/with/empty/description"), dict["URL"].front()); CPPUNIT_ASSERT_EQUAL(String("A COMMENT"), dict["COMMENT"].front()); - CPPUNIT_ASSERT_EQUAL(1u, dict.unsupportedData().size()); + CPPUNIT_ASSERT_EQUAL((size_t)1u, dict.unsupportedData().size()); CPPUNIT_ASSERT_EQUAL(String("UFID/supermihi@web.de"), dict.unsupportedData().front()); } @@ -670,7 +670,7 @@ public: PropertyMap properties = tag.properties(); - CPPUNIT_ASSERT_EQUAL(3u, properties.unsupportedData().size()); + CPPUNIT_ASSERT_EQUAL((size_t)3u, properties.unsupportedData().size()); CPPUNIT_ASSERT(properties.unsupportedData().contains("TIPL")); CPPUNIT_ASSERT(properties.unsupportedData().contains("APIC")); CPPUNIT_ASSERT(properties.unsupportedData().contains("UFID/http://example.com")); @@ -703,7 +703,7 @@ public: MPEG::File f(newname.c_str()); ID3v2::Tag *t = f.ID3v2Tag(); ID3v2::Frame *frame = t->frameList("TCON")[0]; - CPPUNIT_ASSERT_EQUAL(1u, t->frameList("TCON").size()); + CPPUNIT_ASSERT_EQUAL((size_t)1u, t->frameList("TCON").size()); t->removeFrame(frame, true); f.save(MPEG::File::ID3v2); diff --git a/tests/test_mp4.cpp b/tests/test_mp4.cpp index be7ad2c3..9e14e63f 100644 --- a/tests/test_mp4.cpp +++ b/tests/test_mp4.cpp @@ -73,10 +73,10 @@ public: MP4::Atom *stco = a.find("moov")->findall("stco", true)[0]; f->seek(stco->offset + 12); ByteVector data = f->readBlock(stco->length - 12); - unsigned int count = data.mid(0, 4).toUInt(); + unsigned int count = data.mid(0, 4).toUInt32(); int pos = 4; while (count--) { - unsigned int offset = data.mid(pos, 4).toUInt(); + unsigned int offset = data.mid(pos, 4).toUInt32(); f->seek(offset); data1.append(f->readBlock(20)); pos += 4; @@ -92,10 +92,10 @@ public: MP4::Atom *stco = a.find("moov")->findall("stco", true)[0]; f->seek(stco->offset + 12); ByteVector data = f->readBlock(stco->length - 12); - unsigned int count = data.mid(0, 4).toUInt(); + unsigned int count = data.mid(0, 4).toUInt32(); int pos = 4, i = 0; while (count--) { - unsigned int offset = data.mid(pos, 4).toUInt(); + unsigned int offset = data.mid(pos, 4).toUInt32(); f->seek(offset); CPPUNIT_ASSERT_EQUAL(data1[i], f->readBlock(20)); pos += 4; @@ -179,11 +179,11 @@ public: MP4::File *f = new MP4::File(TEST_FILE_PATH_C("has-tags.m4a")); CPPUNIT_ASSERT(f->tag()->itemListMap().contains("covr")); MP4::CoverArtList l = f->tag()->itemListMap()["covr"].toCoverArtList(); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), l.size()); + CPPUNIT_ASSERT_EQUAL(size_t(2), l.size()); CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[0].format()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(79), l[0].data().size()); + CPPUNIT_ASSERT_EQUAL(size_t(79), l[0].data().size()); CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::JPEG, l[1].format()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(287), l[1].data().size()); + CPPUNIT_ASSERT_EQUAL(size_t(287), l[1].data().size()); delete f; } @@ -203,13 +203,13 @@ public: f = new MP4::File(filename.c_str()); CPPUNIT_ASSERT(f->tag()->itemListMap().contains("covr")); l = f->tag()->itemListMap()["covr"].toCoverArtList(); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), l.size()); + CPPUNIT_ASSERT_EQUAL(size_t(3), l.size()); CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[0].format()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(79), l[0].data().size()); + CPPUNIT_ASSERT_EQUAL(size_t(79), l[0].data().size()); CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::JPEG, l[1].format()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(287), l[1].data().size()); + CPPUNIT_ASSERT_EQUAL(size_t(287), l[1].data().size()); CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[2].format()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), l[2].data().size()); + CPPUNIT_ASSERT_EQUAL(size_t(3), l[2].data().size()); delete f; } @@ -218,11 +218,11 @@ public: MP4::File *f = new MP4::File(TEST_FILE_PATH_C("covr-junk.m4a")); CPPUNIT_ASSERT(f->tag()->itemListMap().contains("covr")); MP4::CoverArtList l = f->tag()->itemListMap()["covr"].toCoverArtList(); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), l.size()); + CPPUNIT_ASSERT_EQUAL(size_t(2), l.size()); CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::PNG, l[0].format()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(79), l[0].data().size()); + CPPUNIT_ASSERT_EQUAL(size_t(79), l[0].data().size()); CPPUNIT_ASSERT_EQUAL(MP4::CoverArt::JPEG, l[1].format()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(287), l[1].data().size()); + CPPUNIT_ASSERT_EQUAL(size_t(287), l[1].data().size()); delete f; } diff --git a/tests/test_ogg.cpp b/tests/test_ogg.cpp index 7e98ea72..8a494a14 100644 --- a/tests/test_ogg.cpp +++ b/tests/test_ogg.cpp @@ -61,7 +61,7 @@ public: Ogg::Vorbis::File *f = new Ogg::Vorbis::File(newname.c_str()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f->tag()->properties().size()); + CPPUNIT_ASSERT_EQUAL(size_t(0), f->tag()->properties().size()); PropertyMap newTags; StringList values("value 1"); @@ -70,8 +70,8 @@ public: f->tag()->setProperties(newTags); PropertyMap map = f->tag()->properties(); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), map.size()); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), map["ARTIST"].size()); + CPPUNIT_ASSERT_EQUAL(size_t(1), map.size()); + CPPUNIT_ASSERT_EQUAL(size_t(2), map["ARTIST"].size()); CPPUNIT_ASSERT_EQUAL(String("value 1"), map["ARTIST"][0]); delete f; @@ -85,7 +85,7 @@ public: Ogg::Vorbis::File *f = new Ogg::Vorbis::File(newname.c_str()); PropertyMap tags = f->tag()->properties(); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), tags["UNUSUALTAG"].size()); + CPPUNIT_ASSERT_EQUAL(size_t(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]); diff --git a/tests/test_propertymap.cpp b/tests/test_propertymap.cpp index d0b2fbb7..9b730a27 100644 --- a/tests/test_propertymap.cpp +++ b/tests/test_propertymap.cpp @@ -11,11 +11,11 @@ public: { TagLib::PropertyMap map1; CPPUNIT_ASSERT(map1.isEmpty()); - map1["ÄÖÜ"].append("test"); - CPPUNIT_ASSERT_EQUAL(map1.size(), 1u); + map1["\xc4\xd6\xdc"].append("test"); + CPPUNIT_ASSERT_EQUAL(map1.size(), (size_t)1u); TagLib::PropertyMap map2; - map2["ÄÖÜ"].append("test"); + map2["\xc4\xd6\xdc"].append("test"); CPPUNIT_ASSERT(map1 == map2); CPPUNIT_ASSERT(map1.contains(map2)); @@ -23,7 +23,7 @@ public: CPPUNIT_ASSERT(map1 != map2); CPPUNIT_ASSERT(map2.contains(map1)); - map2["ÄÖÜ"].append("test 2"); + map2["\xc4\xd6\xdc"].append("test 2"); CPPUNIT_ASSERT(!map2.contains(map1)); } diff --git a/tests/test_riff.cpp b/tests/test_riff.cpp index 8e120d06..eba926c5 100644 --- a/tests/test_riff.cpp +++ b/tests/test_riff.cpp @@ -92,7 +92,7 @@ public: CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f->chunkDataSize(2)); CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(2)); CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f->chunkPadding(2)); - CPPUNIT_ASSERT_EQUAL(long(4400), f->length()); + CPPUNIT_ASSERT_EQUAL(offset_t(4400), f->length()); CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f->riffSize()); f->setChunkData("TEST", "abcd"); CPPUNIT_ASSERT_EQUAL(TagLib::uint(4088), f->chunkOffset(2)); @@ -115,7 +115,7 @@ public: CPPUNIT_ASSERT_EQUAL(TagLib::uint(4), f->chunkDataSize(3)); CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(3)); CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f->chunkPadding(3)); - CPPUNIT_ASSERT_EQUAL(long(4412), f->length()); + CPPUNIT_ASSERT_EQUAL(offset_t(4412), f->length()); delete f; } @@ -129,7 +129,7 @@ public: CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f->chunkDataSize(2)); CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(2)); CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f->chunkPadding(2)); - CPPUNIT_ASSERT_EQUAL(long(4399), f->length()); + CPPUNIT_ASSERT_EQUAL(offset_t(4399), f->length()); CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f->riffSize()); f->setChunkData("TEST", "abcd"); CPPUNIT_ASSERT_EQUAL(TagLib::uint(4088), f->chunkOffset(2)); @@ -152,7 +152,7 @@ public: CPPUNIT_ASSERT_EQUAL(TagLib::uint(4), f->chunkDataSize(3)); CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(3)); CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f->chunkPadding(3)); - CPPUNIT_ASSERT_EQUAL(long(4412), f->length()); + CPPUNIT_ASSERT_EQUAL(offset_t(4412), f->length()); delete f; } @@ -166,7 +166,7 @@ public: CPPUNIT_ASSERT_EQUAL(TagLib::uint(311), f->chunkDataSize(2)); CPPUNIT_ASSERT_EQUAL(ByteVector("SSND"), f->chunkName(2)); CPPUNIT_ASSERT_EQUAL(TagLib::uint(0), f->chunkPadding(2)); - CPPUNIT_ASSERT_EQUAL(long(4399), f->length()); + CPPUNIT_ASSERT_EQUAL(offset_t(4399), f->length()); CPPUNIT_ASSERT_EQUAL(TagLib::uint(4399 - 8), f->riffSize()); f->setChunkData("TEST", "abc"); CPPUNIT_ASSERT_EQUAL(TagLib::uint(4088), f->chunkOffset(2)); @@ -189,7 +189,7 @@ public: CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), f->chunkDataSize(3)); CPPUNIT_ASSERT_EQUAL(ByteVector("TEST"), f->chunkName(3)); CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), f->chunkPadding(3)); - CPPUNIT_ASSERT_EQUAL(long(4412), f->length()); + CPPUNIT_ASSERT_EQUAL(offset_t(4412), f->length()); delete f; } diff --git a/tests/test_string.cpp b/tests/test_string.cpp index c67fa41e..de5efefd 100644 --- a/tests/test_string.cpp +++ b/tests/test_string.cpp @@ -156,15 +156,15 @@ public: void testRfind() { - CPPUNIT_ASSERT_EQUAL(-1, String("foo.bar").rfind(".", 0)); - CPPUNIT_ASSERT_EQUAL(-1, String("foo.bar").rfind(".", 1)); - CPPUNIT_ASSERT_EQUAL(-1, String("foo.bar").rfind(".", 2)); - CPPUNIT_ASSERT_EQUAL(3, String("foo.bar").rfind(".", 3)); - CPPUNIT_ASSERT_EQUAL(3, String("foo.bar").rfind(".", 4)); - CPPUNIT_ASSERT_EQUAL(3, String("foo.bar").rfind(".", 5)); - CPPUNIT_ASSERT_EQUAL(3, String("foo.bar").rfind(".", 6)); - CPPUNIT_ASSERT_EQUAL(3, String("foo.bar").rfind(".", 7)); - CPPUNIT_ASSERT_EQUAL(3, String("foo.bar").rfind(".")); + CPPUNIT_ASSERT_EQUAL(String::npos, String("foo.bar").rfind(".", 0)); + CPPUNIT_ASSERT_EQUAL(String::npos, String("foo.bar").rfind(".", 1)); + CPPUNIT_ASSERT_EQUAL(String::npos, String("foo.bar").rfind(".", 2)); + CPPUNIT_ASSERT_EQUAL((size_t)3, String("foo.bar").rfind(".", 3)); + CPPUNIT_ASSERT_EQUAL((size_t)3, String("foo.bar").rfind(".", 4)); + CPPUNIT_ASSERT_EQUAL((size_t)3, String("foo.bar").rfind(".", 5)); + CPPUNIT_ASSERT_EQUAL((size_t)3, String("foo.bar").rfind(".", 6)); + CPPUNIT_ASSERT_EQUAL((size_t)3, String("foo.bar").rfind(".", 7)); + CPPUNIT_ASSERT_EQUAL((size_t)3, String("foo.bar").rfind(".")); } void testToInt() diff --git a/tests/test_synchdata.cpp b/tests/test_synchdata.cpp index 2e3021ea..7b002fb4 100644 --- a/tests/test_synchdata.cpp +++ b/tests/test_synchdata.cpp @@ -90,7 +90,7 @@ public: { ByteVector a("\xff\x00\x00", 3); a = ID3v2::SynchData::decode(a); - CPPUNIT_ASSERT_EQUAL((unsigned int)2, a.size()); + CPPUNIT_ASSERT_EQUAL((size_t)2, a.size()); CPPUNIT_ASSERT_EQUAL(ByteVector("\xff\x00", 2), a); } @@ -98,7 +98,7 @@ public: { ByteVector a("\xff\x44", 2); a = ID3v2::SynchData::decode(a); - CPPUNIT_ASSERT_EQUAL((unsigned int)2, a.size()); + CPPUNIT_ASSERT_EQUAL((size_t)2, a.size()); CPPUNIT_ASSERT_EQUAL(ByteVector("\xff\x44", 2), a); } diff --git a/tests/test_xiphcomment.cpp b/tests/test_xiphcomment.cpp index 6526229b..897bbac0 100644 --- a/tests/test_xiphcomment.cpp +++ b/tests/test_xiphcomment.cpp @@ -70,7 +70,7 @@ public: Ogg::XiphComment cmt; PropertyMap unsuccessful = cmt.setProperties(map); - CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), unsuccessful.size()); + CPPUNIT_ASSERT_EQUAL(size_t(3), unsuccessful.size()); CPPUNIT_ASSERT(cmt.properties().isEmpty()); }