diff --git a/taglib/ape/apeproperties.cpp b/taglib/ape/apeproperties.cpp index 73ca0f52..61dda605 100644 --- a/taglib/ape/apeproperties.cpp +++ b/taglib/ape/apeproperties.cpp @@ -153,9 +153,8 @@ void APE::Properties::analyzeCurrent(File *file) return; } - const unsigned int descriptorBytes = descriptor.toUInt(0, false); - - if((descriptorBytes - 52) > 0) + if(const unsigned int descriptorBytes = descriptor.toUInt(0, false); + (descriptorBytes - 52) > 0) file->seek(descriptorBytes - 52, File::Current); // Read the header diff --git a/taglib/ape/apetag.cpp b/taglib/ape/apetag.cpp index 6f7b16f2..4d75c7aa 100644 --- a/taglib/ape/apetag.cpp +++ b/taglib/ape/apetag.cpp @@ -203,10 +203,10 @@ PropertyMap APE::Tag::properties() const { PropertyMap properties; for(const auto &[tag, item] : std::as_const(itemListMap())) { - String tagName = tag.upper(); // if the item is Binary or Locator, or if the key is an invalid string, // add to unsupportedData - if(item.type() != Item::Text || tagName.isEmpty()) { + if(String tagName = tag.upper(); + item.type() != Item::Text || tagName.isEmpty()) { properties.addUnsupportedData(tag); } else { @@ -241,9 +241,9 @@ PropertyMap APE::Tag::setProperties(const PropertyMap &origProps) // first check if tags need to be removed completely StringList toRemove; for(const auto &[k, t] : std::as_const(itemListMap())) { - String key = k.upper(); // only remove if a) key is valid, b) type is text, c) key not contained in new properties - if(!key.isEmpty() && t.type() == APE::Item::Text && !props.contains(key)) + if(String key = k.upper(); + !key.isEmpty() && t.type() == APE::Item::Text && !props.contains(key)) toRemove.append(k); } @@ -281,13 +281,12 @@ StringList APE::Tag::complexPropertyKeys() const List APE::Tag::complexProperties(const String &key) const { List props; - const String uppercaseKey = key.upper(); - if(uppercaseKey == "PICTURE") { + if(const String uppercaseKey = key.upper(); uppercaseKey == "PICTURE") { const StringList itemNames = StringList(FRONT_COVER).append(BACK_COVER); for(const auto &itemName: itemNames) { if(d->itemListMap.contains(itemName)) { - Item picture = d->itemListMap.value(itemName); - if(picture.type() == Item::Binary) { + if(Item picture = d->itemListMap.value(itemName); + picture.type() == Item::Binary) { ByteVector data = picture.binaryData(); // Do not search for a description if the first byte could start JPG or PNG // data. @@ -316,8 +315,7 @@ List APE::Tag::complexProperties(const String &key) const bool APE::Tag::setComplexProperties(const String &key, const List &value) { - const String uppercaseKey = key.upper(); - if(uppercaseKey == "PICTURE") { + if(const String uppercaseKey = key.upper(); uppercaseKey == "PICTURE") { removeItem(FRONT_COVER); removeItem(BACK_COVER); diff --git a/taglib/asf/asftag.cpp b/taglib/asf/asftag.cpp index f6ec38e1..9fe73f04 100644 --- a/taglib/asf/asftag.cpp +++ b/taglib/asf/asftag.cpp @@ -313,8 +313,7 @@ PropertyMap ASF::Tag::properties() const } for(const auto &[k, attributes] : std::as_const(d->attributeListMap)) { - const String key = translateKey(k); - if(!key.isEmpty()) { + if(const String key = translateKey(k); !key.isEmpty()) { for(const auto &attr : attributes) { if(key == "TRACKNUMBER") { if(attr.type() == ASF::Attribute::DWordType) @@ -411,8 +410,7 @@ StringList ASF::Tag::complexPropertyKeys() const List ASF::Tag::complexProperties(const String &key) const { List props; - const String uppercaseKey = key.upper(); - if(uppercaseKey == "PICTURE") { + if(const String uppercaseKey = key.upper(); uppercaseKey == "PICTURE") { const AttributeList pictures = d->attributeListMap.value("WM/Picture"); for(const Attribute &attr : pictures) { ASF::Picture picture = attr.toPicture(); @@ -430,8 +428,7 @@ List ASF::Tag::complexProperties(const String &key) const bool ASF::Tag::setComplexProperties(const String &key, const List &value) { - const String uppercaseKey = key.upper(); - if(uppercaseKey == "PICTURE") { + if(const String uppercaseKey = key.upper(); uppercaseKey == "PICTURE") { removeItem("WM/Picture"); for(const auto &property : value) { diff --git a/taglib/dsdiff/dsdifffile.cpp b/taglib/dsdiff/dsdifffile.cpp index 21f4d40a..7353fbe1 100644 --- a/taglib/dsdiff/dsdifffile.cpp +++ b/taglib/dsdiff/dsdifffile.cpp @@ -226,9 +226,7 @@ bool DSDIFF::File::save(int tags, StripTags strip, ID3v2::Version version) // First: save ID3V2 chunk - const ID3v2::Tag *id3v2Tag = ID3v2Tag(); - - if((tags & ID3v2) && id3v2Tag) { + if(const ID3v2::Tag *id3v2Tag = ID3v2Tag(); (tags & ID3v2) && id3v2Tag) { if(d->isID3InPropChunk) { if(!id3v2Tag->isEmpty()) { setChildChunkData(d->id3v2TagChunkID, id3v2Tag->render(version), PROPChunk); @@ -255,9 +253,7 @@ bool DSDIFF::File::save(int tags, StripTags strip, ID3v2::Version version) // Second: save the DIIN chunk - const DSDIFF::DIIN::Tag *diinTag = DIINTag(); - - if((tags & DIIN) && diinTag) { + if(const DSDIFF::DIIN::Tag *diinTag = DIINTag(); (tags & DIIN) && diinTag) { if(!diinTag->title().isEmpty()) { ByteVector diinTitle; diinTitle.append(ByteVector::fromUInt(diinTag->title().size(), d->endianness == BigEndian)); @@ -527,8 +523,8 @@ void DSDIFF::File::setChildChunkData(const ByteVector &name, int i = d->childChunkIndex[DIINChunk]; if(i < 0) { setRootChunkData("DIIN", ByteVector()); - const int lastChunkIndex = static_cast(d->chunks.size()) - 1; - if(lastChunkIndex >= 0 && d->chunks[lastChunkIndex].name == "DIIN") { + if(const int lastChunkIndex = static_cast(d->chunks.size()) - 1; + lastChunkIndex >= 0 && d->chunks[lastChunkIndex].name == "DIIN") { i = lastChunkIndex; d->childChunkIndex[DIINChunk] = lastChunkIndex; d->hasDiin = true; @@ -589,8 +585,8 @@ void DSDIFF::File::updateRootChunksStructure(unsigned int startingChunk) // Update child chunks structure as well if(d->childChunkIndex[PROPChunk] >= static_cast(startingChunk)) { - ChunkList &childChunksToUpdate = d->childChunks[PROPChunk]; - if(!childChunksToUpdate.empty()) { + if(ChunkList &childChunksToUpdate = d->childChunks[PROPChunk]; + !childChunksToUpdate.empty()) { childChunksToUpdate[0].offset = d->chunks[d->childChunkIndex[PROPChunk]].offset + 12; for(unsigned int i = 1; i < childChunksToUpdate.size(); i++) childChunksToUpdate[i].offset = childChunksToUpdate[i - 1].offset + 12 @@ -599,8 +595,8 @@ void DSDIFF::File::updateRootChunksStructure(unsigned int startingChunk) } if(d->childChunkIndex[DIINChunk] >= static_cast(startingChunk)) { - ChunkList &childChunksToUpdate = d->childChunks[DIINChunk]; - if(!childChunksToUpdate.empty()) { + if(ChunkList &childChunksToUpdate = d->childChunks[DIINChunk]; + !childChunksToUpdate.empty()) { childChunksToUpdate[0].offset = d->chunks[d->childChunkIndex[DIINChunk]].offset + 12; for(unsigned int i = 1; i < childChunksToUpdate.size(); i++) childChunksToUpdate[i].offset = childChunksToUpdate[i - 1].offset + 12 @@ -647,10 +643,9 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty // Check padding chunk.padding = 0; - offset_t uPosNotPadded = tell(); - if((uPosNotPadded & 0x01) != 0) { - ByteVector iByte = readBlock(1); - if((iByte.size() != 1) || (iByte[0] != 0)) + if(offset_t uPosNotPadded = tell(); (uPosNotPadded & 0x01) != 0) { + if(ByteVector iByte = readBlock(1); + (iByte.size() != 1) || (iByte[0] != 0)) // Not well formed, re-seek seek(uPosNotPadded, Beginning); else @@ -708,10 +703,9 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty seek(dstChunkSize, Current); // Check padding - offset_t uPosNotPadded = tell(); - if((uPosNotPadded & 0x01) != 0) { - ByteVector iByte = readBlock(1); - if((iByte.size() != 1) || (iByte[0] != 0)) + if(offset_t uPosNotPadded = tell(); (uPosNotPadded & 0x01) != 0) { + if(ByteVector iByte = readBlock(1); + (iByte.size() != 1) || (iByte[0] != 0)) // Not well formed, re-seek seek(uPosNotPadded, Beginning); } @@ -749,10 +743,9 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty // Check padding chunk.padding = 0; - offset_t uPosNotPadded = tell(); - if((uPosNotPadded & 0x01) != 0) { - ByteVector iByte = readBlock(1); - if((iByte.size() != 1) || (iByte[0] != 0)) + if(offset_t uPosNotPadded = tell(); (uPosNotPadded & 0x01) != 0) { + if(ByteVector iByte = readBlock(1); + (iByte.size() != 1) || (iByte[0] != 0)) // Not well formed, re-seek seek(uPosNotPadded, Beginning); else @@ -797,11 +790,10 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty // Check padding chunk.padding = 0; - offset_t uPosNotPadded = tell(); - if((uPosNotPadded & 0x01) != 0) { - ByteVector iByte = readBlock(1); - if((iByte.size() != 1) || (iByte[0] != 0)) + if(offset_t uPosNotPadded = tell(); (uPosNotPadded & 0x01) != 0) { + if(ByteVector iByte = readBlock(1); + (iByte.size() != 1) || (iByte[0] != 0)) // Not well formed, re-seek seek(uPosNotPadded, Beginning); else @@ -867,16 +859,16 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty for(unsigned int i = 0; i < d->childChunks[DIINChunk].size(); i++) { if(d->childChunks[DIINChunk][i].name == "DITI") { seek(d->childChunks[DIINChunk][i].offset); - unsigned int titleStrLength = readBlock(4).toUInt(0, 4, bigEndian); - if(titleStrLength <= d->childChunks[DIINChunk][i].size) { + if(unsigned int titleStrLength = readBlock(4).toUInt(0, 4, bigEndian); + titleStrLength <= d->childChunks[DIINChunk][i].size) { ByteVector titleStr = readBlock(titleStrLength); d->tag.access(DIINIndex, false)->setTitle(titleStr); } } else if(d->childChunks[DIINChunk][i].name == "DIAR") { seek(d->childChunks[DIINChunk][i].offset); - unsigned int artistStrLength = readBlock(4).toUInt(0, 4, bigEndian); - if(artistStrLength <= d->childChunks[DIINChunk][i].size) { + if(unsigned int artistStrLength = readBlock(4).toUInt(0, 4, bigEndian); + artistStrLength <= d->childChunks[DIINChunk][i].size) { ByteVector artistStr = readBlock(artistStrLength); d->tag.access(DIINIndex, false)->setArtist(artistStr); } diff --git a/taglib/fileref.cpp b/taglib/fileref.cpp index a5bab9af..1b8b197c 100644 --- a/taglib/fileref.cpp +++ b/taglib/fileref.cpp @@ -119,8 +119,7 @@ namespace #endif String ext; - const int pos = s.rfind("."); - if(pos != -1) + if(const int pos = s.rfind("."); pos != -1) ext = s.substr(pos + 1).upper(); // If this list is updated, the method defaultFileExtensions() should also be diff --git a/taglib/flac/flacfile.cpp b/taglib/flac/flacfile.cpp index 3812e4a2..c94713e4 100644 --- a/taglib/flac/flacfile.cpp +++ b/taglib/flac/flacfile.cpp @@ -171,8 +171,7 @@ StringList FLAC::File::complexPropertyKeys() const List FLAC::File::complexProperties(const String &key) const { - const String uppercaseKey = key.upper(); - if(uppercaseKey == "PICTURE") { + if(const String uppercaseKey = key.upper(); uppercaseKey == "PICTURE") { List props; for(const auto &block : std::as_const(d->blocks)) { if(auto picture = dynamic_cast(block)) { @@ -196,8 +195,7 @@ List FLAC::File::complexProperties(const String &key) const bool FLAC::File::setComplexProperties(const String &key, const List &value) { - const String uppercaseKey = key.upper(); - if(uppercaseKey == "PICTURE") { + if(const String uppercaseKey = key.upper(); uppercaseKey == "PICTURE") { removePictures(); for(const auto &property : value) { diff --git a/taglib/mp4/mp4atom.cpp b/taglib/mp4/mp4atom.cpp index 7ee6cd48..85165b24 100644 --- a/taglib/mp4/mp4atom.cpp +++ b/taglib/mp4/mp4atom.cpp @@ -73,8 +73,8 @@ MP4::Atom::Atom(File *file) } else if(d->length == 1) { // The atom has a 64-bit length. - const long long longLength = file->readBlock(8).toLongLong(); - if(longLength <= LONG_MAX) { + if(const long long longLength = file->readBlock(8).toLongLong(); + longLength <= LONG_MAX) { // The actual length fits in long. That's always the case if long is 64-bit. d->length = static_cast(longLength); } @@ -95,8 +95,7 @@ MP4::Atom::Atom(File *file) d->name = header.mid(4, 4); for(int i = 0; i < 4; ++i) { - const char ch = d->name.at(i); - if((ch < ' ' || ch > '~') && ch != '\251') { + if(const char ch = d->name.at(i); (ch < ' ' || ch > '~') && ch != '\251') { debug("MP4: Invalid atom type"); d->length = 0; file->seek(0, File::End); diff --git a/taglib/mp4/mp4itemfactory.cpp b/taglib/mp4/mp4itemfactory.cpp index da92d63f..0eb3d6df 100644 --- a/taglib/mp4/mp4itemfactory.cpp +++ b/taglib/mp4/mp4itemfactory.cpp @@ -189,8 +189,7 @@ std::pair ItemFactory::itemFromProperty( std::pair ItemFactory::itemToProperty( const ByteVector &itemName, const Item &item) const { - const String key = propertyKeyForName(itemName); - if(!key.isEmpty()) { + if(const String key = propertyKeyForName(itemName); !key.isEmpty()) { auto handlerType = itemName.startsWith("----") ? ItemHandlerType::FreeForm : handlerTypeForName(itemName); @@ -458,8 +457,7 @@ std::pair ItemFactory::parseInt( std::pair ItemFactory::parseTextOrInt( const MP4::Atom *atom, const ByteVector &bytes) { - AtomDataList data = parseData2(atom, bytes); - if(!data.isEmpty()) { + if(AtomDataList data = parseData2(atom, bytes); !data.isEmpty()) { AtomData val = data[0]; return { atom->name(), @@ -503,8 +501,7 @@ std::pair ItemFactory::parseByte( std::pair ItemFactory::parseGnre( const MP4::Atom *atom, const ByteVector &bytes) { - ByteVectorList data = parseData(atom, bytes); - if(!data.isEmpty()) { + if(ByteVectorList data = parseData(atom, bytes); !data.isEmpty()) { int idx = static_cast(data[0].toShort()); if(idx > 0) { return { @@ -519,8 +516,7 @@ std::pair ItemFactory::parseGnre( std::pair ItemFactory::parseIntPair( const MP4::Atom *atom, const ByteVector &bytes) { - ByteVectorList data = parseData(atom, bytes); - if(!data.isEmpty()) { + if(ByteVectorList data = parseData(atom, bytes); !data.isEmpty()) { const int a = data[0].toShort(2U); const int b = data[0].toShort(4U); return {atom->name(), Item(a, b)}; @@ -531,8 +527,7 @@ std::pair ItemFactory::parseIntPair( std::pair ItemFactory::parseBool( const MP4::Atom *atom, const ByteVector &bytes) { - ByteVectorList data = parseData(atom, bytes); - if(!data.isEmpty()) { + if(ByteVectorList data = parseData(atom, bytes); !data.isEmpty()) { bool value = !data[0].isEmpty() && data[0][0] != '\0'; return {atom->name(), Item(value)}; } @@ -542,8 +537,8 @@ std::pair ItemFactory::parseBool( std::pair ItemFactory::parseText( const MP4::Atom *atom, const ByteVector &bytes, int expectedFlags) { - const ByteVectorList data = parseData(atom, bytes, expectedFlags); - if(!data.isEmpty()) { + if(const ByteVectorList data = parseData(atom, bytes, expectedFlags); + !data.isEmpty()) { StringList value; for(const auto &byte : data) { value.append(String(byte, String::UTF8)); @@ -556,8 +551,8 @@ std::pair ItemFactory::parseText( std::pair ItemFactory::parseFreeForm( const MP4::Atom *atom, const ByteVector &bytes) { - const AtomDataList data = parseData2(atom, bytes, -1, true); - if(data.size() > 2) { + if(const AtomDataList data = parseData2(atom, bytes, -1, true); + data.size() > 2) { auto itBegin = data.begin(); String name = "----:"; diff --git a/taglib/mp4/mp4properties.cpp b/taglib/mp4/mp4properties.cpp index b591fb92..850797e7 100644 --- a/taglib/mp4/mp4properties.cpp +++ b/taglib/mp4/mp4properties.cpp @@ -222,8 +222,8 @@ MP4::Properties::read(File *file, const Atoms *atoms) pos += 3; } pos += 10; - const unsigned int bitrateValue = data.toUInt(pos); - if(bitrateValue != 0 || d->length <= 0) { + if(const unsigned int bitrateValue = data.toUInt(pos); + bitrateValue != 0 || d->length <= 0) { d->bitrate = static_cast((bitrateValue + 500) / 1000.0 + 0.5); } else { diff --git a/taglib/mp4/mp4tag.cpp b/taglib/mp4/mp4tag.cpp index 42905574..c4277d23 100644 --- a/taglib/mp4/mp4tag.cpp +++ b/taglib/mp4/mp4tag.cpp @@ -74,8 +74,8 @@ MP4::Tag::Tag(TagLib::File *file, MP4::Atoms *atoms, for(const auto &atom : ilst->children()) { file->seek(atom->offset() + 8); ByteVector data = d->file->readBlock(atom->length() - 8); - const auto &[name, itm] = d->factory->parseItem(atom, data); - if (itm.isValid()) { + if(const auto &[name, itm] = d->factory->parseItem(atom, data); + itm.isValid()) { addItem(name, itm); } } @@ -214,8 +214,8 @@ MP4::Tag::updateOffsets(offset_t delta, offset_t offset) } d->file->seek(atom->offset() + 9); ByteVector data = d->file->readBlock(atom->length() - 9); - const unsigned int flags = data.toUInt(0, 3, true); - if(flags & 1) { + if(const unsigned int flags = data.toUInt(0, 3, true); + flags & 1) { long long o = data.toLongLong(7U); if(o > offset) { o += delta; @@ -268,8 +268,7 @@ MP4::Tag::saveExisting(ByteVector data, const AtomList &path) // check if there is an atom before 'ilst', and possibly use it as padding if(index != meta->children().cbegin()) { auto prevIndex = std::prev(index); - const MP4::Atom *prev = *prevIndex; - if(prev->name() == "free") { + if(const MP4::Atom *prev = *prevIndex; prev->name() == "free") { offset = prev->offset(); length += prev->length(); } @@ -277,8 +276,7 @@ MP4::Tag::saveExisting(ByteVector data, const AtomList &path) // check if there is an atom after 'ilst', and possibly use it as padding auto nextIndex = std::next(index); if(nextIndex != meta->children().cend()) { - const MP4::Atom *next = *nextIndex; - if(next->name() == "free") { + if(const MP4::Atom *next = *nextIndex; next->name() == "free") { length += next->length(); } } @@ -303,8 +301,7 @@ MP4::Tag::saveExisting(ByteVector data, const AtomList &path) } else { // Strip meta if data is empty, only the case when called from strip(). - MP4::Atom *udta = *std::prev(it); - if(udta->removeChild(meta)) { + if(MP4::Atom *udta = *std::prev(it); udta->removeChild(meta)) { offset = meta->offset(); delta = - meta->length(); d->file->removeBlock(meta->offset(), meta->length()); @@ -470,8 +467,8 @@ PropertyMap MP4::Tag::properties() const { PropertyMap props; for(const auto &[k, t] : std::as_const(d->items)) { - auto [key, val] = d->factory->itemToProperty(k.data(String::Latin1), t); - if(!key.isEmpty()) { + if(auto [key, val] = d->factory->itemToProperty(k.data(String::Latin1), t); + !key.isEmpty()) { props[key] = val; } else { @@ -498,8 +495,8 @@ PropertyMap MP4::Tag::setProperties(const PropertyMap &props) PropertyMap ignoredProps; for(const auto &[prop, val] : props) { - auto [name, itm] = d->factory->itemFromProperty(prop, val); - if(itm.isValid()) { + if(auto [name, itm] = d->factory->itemFromProperty(prop, val); + itm.isValid()) { d->items[name] = itm; } else { @@ -522,8 +519,7 @@ StringList MP4::Tag::complexPropertyKeys() const List MP4::Tag::complexProperties(const String &key) const { List props; - const String uppercaseKey = key.upper(); - if(uppercaseKey == "PICTURE") { + if(const String uppercaseKey = key.upper(); uppercaseKey == "PICTURE") { const CoverArtList pictures = d->items.value("covr").toCoverArtList(); for(const CoverArt &picture : pictures) { String mimeType = "image/"; @@ -555,8 +551,7 @@ List MP4::Tag::complexProperties(const String &key) const bool MP4::Tag::setComplexProperties(const String &key, const List &value) { - const String uppercaseKey = key.upper(); - if(uppercaseKey == "PICTURE") { + if(const String uppercaseKey = key.upper(); uppercaseKey == "PICTURE") { CoverArtList pictures; for(const auto &property : value) { auto mimeType = property.value("mimeType").value(); diff --git a/taglib/mpc/mpcproperties.cpp b/taglib/mpc/mpcproperties.cpp index 90959759..5bbf6423 100644 --- a/taglib/mpc/mpcproperties.cpp +++ b/taglib/mpc/mpcproperties.cpp @@ -225,8 +225,8 @@ void MPC::Properties::readSV8(File *file, offset_t streamLength) d->sampleRate = sftable[(flags >> 13) & 0x07]; d->channels = ((flags >> 4) & 0x0F) + 1; - const auto frameCount = d->sampleFrames - begSilence; - if(frameCount > 0 && d->sampleRate > 0) { + if(const auto frameCount = d->sampleFrames - begSilence; + frameCount > 0 && d->sampleRate > 0) { const double length = frameCount * 1000.0 / d->sampleRate; d->length = static_cast(length + 0.5); d->bitrate = static_cast(streamLength * 8.0 / length + 0.5); @@ -243,8 +243,7 @@ void MPC::Properties::readSV8(File *file, offset_t streamLength) readRG = true; - const int replayGainVersion = data[0]; - if(replayGainVersion == 1) { + if(const int replayGainVersion = data[0]; replayGainVersion == 1) { d->trackGain = data.toShort(1, true); d->trackPeak = data.toShort(3, true); d->albumGain = data.toShort(5, true); diff --git a/taglib/mpeg/id3v1/id3v1tag.cpp b/taglib/mpeg/id3v1/id3v1tag.cpp index 7cc107a2..8f55a16e 100644 --- a/taglib/mpeg/id3v1/id3v1tag.cpp +++ b/taglib/mpeg/id3v1/id3v1tag.cpp @@ -216,10 +216,9 @@ void ID3v1::Tag::read() if(d->file && d->file->isValid()) { d->file->seek(d->tagOffset); // read the tag -- always 128 bytes - const ByteVector data = d->file->readBlock(128); - // some initial sanity checking - if(data.size() == 128 && data.startsWith("TAG")) + if(const ByteVector data = d->file->readBlock(128); + data.size() == 128 && data.startsWith("TAG")) parse(data); else debug("ID3v1 tag is not valid or could not be read at the specified offset."); diff --git a/taglib/mpeg/id3v2/frames/commentsframe.cpp b/taglib/mpeg/id3v2/frames/commentsframe.cpp index 326c0f15..2a464fcc 100644 --- a/taglib/mpeg/id3v2/frames/commentsframe.cpp +++ b/taglib/mpeg/id3v2/frames/commentsframe.cpp @@ -148,9 +148,8 @@ void CommentsFrame::parseFields(const ByteVector &data) int byteAlign = d->textEncoding == String::Latin1 || d->textEncoding == String::UTF8 ? 1 : 2; - ByteVectorList l = ByteVectorList::split(data.mid(4), textDelimiter(d->textEncoding), byteAlign, 2); - - if(l.size() == 2) { + if(ByteVectorList l = ByteVectorList::split(data.mid(4), textDelimiter(d->textEncoding), byteAlign, 2); + l.size() == 2) { if(d->textEncoding == String::Latin1) { d->description = Tag::latin1StringHandler()->parse(l.front()); d->text = Tag::latin1StringHandler()->parse(l.back()); diff --git a/taglib/mpeg/id3v2/frames/unsynchronizedlyricsframe.cpp b/taglib/mpeg/id3v2/frames/unsynchronizedlyricsframe.cpp index ec7d425b..04460967 100644 --- a/taglib/mpeg/id3v2/frames/unsynchronizedlyricsframe.cpp +++ b/taglib/mpeg/id3v2/frames/unsynchronizedlyricsframe.cpp @@ -150,10 +150,9 @@ void UnsynchronizedLyricsFrame::parseFields(const ByteVector &data) int byteAlign = d->textEncoding == String::Latin1 || d->textEncoding == String::UTF8 ? 1 : 2; - ByteVectorList l = - ByteVectorList::split(data.mid(4), textDelimiter(d->textEncoding), byteAlign, 2); - - if(l.size() == 2) { + if(ByteVectorList l = + ByteVectorList::split(data.mid(4), textDelimiter(d->textEncoding), byteAlign, 2); + l.size() == 2) { if(d->textEncoding == String::Latin1) { d->description = Tag::latin1StringHandler()->parse(l.front()); d->text = Tag::latin1StringHandler()->parse(l.back()); diff --git a/taglib/mpeg/id3v2/id3v2framefactory.cpp b/taglib/mpeg/id3v2/id3v2framefactory.cpp index 785a42a8..d96ccc0f 100644 --- a/taglib/mpeg/id3v2/id3v2framefactory.cpp +++ b/taglib/mpeg/id3v2/id3v2framefactory.cpp @@ -547,8 +547,7 @@ bool FrameFactory::updateFrame(Frame::Header *header) const Frame *FrameFactory::createFrameForProperty(const String &key, const StringList &values) const { // check if the key is contained in the key<=>frameID mapping - ByteVector frameID = Frame::keyToFrameID(key); - if(!frameID.isEmpty()) { + if(ByteVector frameID = Frame::keyToFrameID(key); !frameID.isEmpty()) { // Apple proprietary WFED (Podcast URL), MVNM (Movement Name), MVIN (Movement Number), GRP1 (Grouping) are in fact text frames. if(frameID[0] == 'T' || frameID == "WFED" || frameID == "MVNM" || frameID == "MVIN" || frameID == "GRP1"){ // text frame auto frame = new TextIdentificationFrame(frameID, String::UTF8); diff --git a/taglib/mpeg/id3v2/id3v2tag.cpp b/taglib/mpeg/id3v2/id3v2tag.cpp index 0bb4f5c4..cb6ec1c2 100644 --- a/taglib/mpeg/id3v2/id3v2tag.cpp +++ b/taglib/mpeg/id3v2/id3v2tag.cpp @@ -231,9 +231,7 @@ void ID3v2::Tag::setComment(const String &s) return; } - const FrameList &comments = d->frameListMap["COMM"]; - - if(!comments.isEmpty()) { + if(const FrameList &comments = d->frameListMap["COMM"]; !comments.isEmpty()) { for(const auto &commFrame : comments) { auto frame = dynamic_cast(commFrame); if(frame && frame->description().isEmpty()) { @@ -464,8 +462,7 @@ StringList ID3v2::Tag::complexPropertyKeys() const List ID3v2::Tag::complexProperties(const String &key) const { List props; - const String uppercaseKey = key.upper(); - if(uppercaseKey == "PICTURE") { + if(const String uppercaseKey = key.upper(); uppercaseKey == "PICTURE") { const FrameList pictures = d->frameListMap.value("APIC"); for(const Frame *frame : pictures) { if(auto picture = dynamic_cast(frame)) { @@ -497,8 +494,7 @@ List ID3v2::Tag::complexProperties(const String &key) const bool ID3v2::Tag::setComplexProperties(const String &key, const List &value) { - const String uppercaseKey = key.upper(); - if(uppercaseKey == "PICTURE") { + if(const String uppercaseKey = key.upper(); uppercaseKey == "PICTURE") { removeFrames("APIC"); for(const auto &property : value) { @@ -590,8 +586,7 @@ void ID3v2::Tag::downgradeFrames(FrameList *frames, FrameList *newFrames) const } if(frameTDRC) { - String content = frameTDRC->toString(); - if(content.size() >= 4) { + if(String content = frameTDRC->toString(); content.size() >= 4) { auto frameTYER = new ID3v2::TextIdentificationFrame("TYER", String::Latin1); frameTYER->setText(content.substr(0, 4)); frames->append(frameTYER); @@ -647,8 +642,8 @@ void ID3v2::Tag::downgradeFrames(FrameList *frames, FrameList *newFrames) const // genre number exists can be finally added as a refinement. for(const auto &genre : genres) { bool ok = false; - int number = genre.toInt(&ok); - if((ok && number >= 0 && number <= 255) || genre == "RX" || genre == "CR") + if(int number = genre.toInt(&ok); + (ok && number >= 0 && number <= 255) || genre == "RX" || genre == "CR") combined += '(' + genre + ')'; else if(hasMultipleGenres && (number = ID3v1::genreIndex(genre)) != 255) combined += '(' + String::number(number) + ')'; diff --git a/taglib/mpeg/mpegfile.cpp b/taglib/mpeg/mpegfile.cpp index ed238695..e0b957e9 100644 --- a/taglib/mpeg/mpegfile.cpp +++ b/taglib/mpeg/mpegfile.cpp @@ -107,8 +107,7 @@ bool MPEG::File::isSupported(IOStream *stream) for(unsigned int i = 0; i < buffer.size() - 1; ++i) { if(isFrameSync(buffer, i)) { - const Header header(&file, headerOffset + i, true); - if(header.isValid()) { + if(const Header header(&file, headerOffset + i, true); header.isValid()) { stream->seek(originalPosition); return true; } @@ -387,8 +386,7 @@ offset_t MPEG::File::nextFrameOffset(offset_t position) frameSyncBytes[0] = frameSyncBytes[1]; frameSyncBytes[1] = buffer[i]; if(isFrameSync(frameSyncBytes)) { - const Header header(this, position + i - 1, true); - if(header.isValid()) + if(const Header header(this, position + i - 1, true); header.isValid()) return position + i - 1; } } @@ -412,8 +410,7 @@ offset_t MPEG::File::previousFrameOffset(offset_t position) frameSyncBytes[1] = frameSyncBytes[0]; frameSyncBytes[0] = buffer[i]; if(isFrameSync(frameSyncBytes)) { - const Header header(this, position + i, true); - if(header.isValid()) + if(const Header header(this, position + i, true); header.isValid()) return position + i + header.frameLength(); } } @@ -518,8 +515,7 @@ offset_t MPEG::File::findID3v2(Properties::ReadStyle readStyle) if(readStyle == Properties::Fast) return -1; - const Header firstHeader(this, 0, true); - if(firstHeader.isValid()) + if(const Header firstHeader(this, 0, true); firstHeader.isValid()) return -1; // Look for an ID3v2 tag until reaching the first valid MPEG frame. @@ -538,8 +534,7 @@ offset_t MPEG::File::findID3v2(Properties::ReadStyle readStyle) frameSyncBytes[0] = frameSyncBytes[1]; frameSyncBytes[1] = buffer[i]; if(isFrameSync(frameSyncBytes)) { - const Header header(this, position + i - 1, true); - if(header.isValid()) + if(const Header header(this, position + i - 1, true); header.isValid()) return -1; } diff --git a/taglib/mpeg/mpegheader.cpp b/taglib/mpeg/mpegheader.cpp index 84d85e78..2439e690 100644 --- a/taglib/mpeg/mpegheader.cpp +++ b/taglib/mpeg/mpegheader.cpp @@ -181,9 +181,8 @@ void MPEG::Header::parse(File *file, offset_t offset, bool checkLength) // Set the MPEG layer - const int layerBits = (static_cast(data[1]) >> 1) & 0x03; - - if(layerBits == 1) + if(const int layerBits = (static_cast(data[1]) >> 1) & 0x03; + layerBits == 1) d->layer = 3; else if(layerBits == 2) d->layer = 2; @@ -234,9 +233,8 @@ void MPEG::Header::parse(File *file, offset_t offset, bool checkLength) d->isCopyrighted = (static_cast(data[3]) & 0x04) != 0; // Calculate the frame length - const ByteVector frameLengthData = file->readBlock(2); - - if(frameLengthData.size() >= 2) { + if(const ByteVector frameLengthData = file->readBlock(2); + frameLengthData.size() >= 2) { d->frameLength = (static_cast(data[3]) & 0x3) << 11 | (static_cast(frameLengthData[0]) << 3) | (static_cast(frameLengthData[1]) >> 5); @@ -352,9 +350,9 @@ void MPEG::Header::parse(File *file, offset_t offset, bool checkLength) constexpr unsigned int HeaderMask = 0xfffe0c00; const unsigned int header = data.toUInt(0, true) & HeaderMask; - const unsigned int nextHeader = nextData.toUInt(0, true) & HeaderMask; - if(header != nextHeader) + if(const unsigned int nextHeader = nextData.toUInt(0, true) & HeaderMask; + header != nextHeader) return; } diff --git a/taglib/mpeg/mpegproperties.cpp b/taglib/mpeg/mpegproperties.cpp index 647234d3..434beffd 100644 --- a/taglib/mpeg/mpegproperties.cpp +++ b/taglib/mpeg/mpegproperties.cpp @@ -229,15 +229,15 @@ void MPEG::Properties::read(File *file, ReadStyle readStyle) // Look for the last MPEG audio frame to calculate the stream length. - const offset_t lastFrameOffset = file->lastFrameOffset(); - if(lastFrameOffset < 0) { + if(const offset_t lastFrameOffset = file->lastFrameOffset(); + lastFrameOffset < 0) { debug("MPEG::Properties::read() -- Could not find an MPEG frame in the stream."); } else { const Header lastHeader(file, lastFrameOffset, false); - const offset_t streamLength = lastFrameOffset - firstFrameOffset + lastHeader.frameLength(); - if (streamLength > 0) + if(const offset_t streamLength = lastFrameOffset - firstFrameOffset + lastHeader.frameLength(); + streamLength > 0) d->length = static_cast(streamLength * 8.0 / d->bitrate + 0.5); } } diff --git a/taglib/ogg/oggfile.cpp b/taglib/ogg/oggfile.cpp index fa947de8..29f1803a 100644 --- a/taglib/ogg/oggfile.cpp +++ b/taglib/ogg/oggfile.cpp @@ -269,10 +269,9 @@ void Ogg::File::writePacket(unsigned int i, const ByteVector &packet) // Renumber the following pages if the pages have been split or merged. - const int numberOfNewPages - = pages.back()->pageSequenceNumber() - lastPage->pageSequenceNumber(); - - if(numberOfNewPages != 0) { + if(const int numberOfNewPages + = pages.back()->pageSequenceNumber() - lastPage->pageSequenceNumber(); + numberOfNewPages != 0) { offset_t pageOffset = originalOffset + data.size(); while(true) { diff --git a/taglib/ogg/opus/opusproperties.cpp b/taglib/ogg/opus/opusproperties.cpp index ce1ecff8..e695b488 100644 --- a/taglib/ogg/opus/opusproperties.cpp +++ b/taglib/ogg/opus/opusproperties.cpp @@ -138,9 +138,7 @@ void Opus::Properties::read(File *file) const long long end = last->absoluteGranularPosition(); if(start >= 0 && end >= 0) { - const long long frameCount = (end - start - preSkip); - - if(frameCount > 0) { + if(const long long frameCount = (end - start - preSkip); frameCount > 0) { const double length = frameCount * 1000.0 / 48000.0; offset_t fileLengthWithoutOverhead = file->length(); // Ignore the two mandatory header packets, see "3. Packet Organization" diff --git a/taglib/ogg/speex/speexproperties.cpp b/taglib/ogg/speex/speexproperties.cpp index 1843fcf8..f1b84e53 100644 --- a/taglib/ogg/speex/speexproperties.cpp +++ b/taglib/ogg/speex/speexproperties.cpp @@ -154,9 +154,7 @@ void Speex::Properties::read(File *file) const long long end = last->absoluteGranularPosition(); if(start >= 0 && end >= 0 && d->sampleRate > 0) { - const long long frameCount = end - start; - - if(frameCount > 0) { + if(const long long frameCount = end - start; frameCount > 0) { const double length = frameCount * 1000.0 / d->sampleRate; offset_t fileLengthWithoutOverhead = file->length(); // Ignore the two header packets, see "Ogg file format" in diff --git a/taglib/ogg/vorbis/vorbisproperties.cpp b/taglib/ogg/vorbis/vorbisproperties.cpp index 4ba6f84d..10af261e 100644 --- a/taglib/ogg/vorbis/vorbisproperties.cpp +++ b/taglib/ogg/vorbis/vorbisproperties.cpp @@ -157,9 +157,7 @@ void Vorbis::Properties::read(File *file) const long long end = last->absoluteGranularPosition(); if(start >= 0 && end >= 0 && d->sampleRate > 0) { - const long long frameCount = end - start; - - if(frameCount > 0) { + if(const long long frameCount = end - start; frameCount > 0) { const double length = frameCount * 1000.0 / d->sampleRate; offset_t fileLengthWithoutOverhead = file->length(); // Ignore the three initial header packets, see "1.3.1. Decode Setup" in diff --git a/taglib/ogg/xiphcomment.cpp b/taglib/ogg/xiphcomment.cpp index 6b1109ad..9903c51c 100644 --- a/taglib/ogg/xiphcomment.cpp +++ b/taglib/ogg/xiphcomment.cpp @@ -247,8 +247,7 @@ StringList Ogg::XiphComment::complexPropertyKeys() const List Ogg::XiphComment::complexProperties(const String &key) const { List props; - const String uppercaseKey = key.upper(); - if(uppercaseKey == "PICTURE") { + if(const String uppercaseKey = key.upper(); uppercaseKey == "PICTURE") { for(const FLAC::Picture *picture : std::as_const(d->pictureList)) { VariantMap property; property.insert("data", picture->data()); @@ -268,8 +267,7 @@ List Ogg::XiphComment::complexProperties(const String &key) const bool Ogg::XiphComment::setComplexProperties(const String &key, const List &value) { - const String uppercaseKey = key.upper(); - if(uppercaseKey == "PICTURE") { + if(const String uppercaseKey = key.upper(); uppercaseKey == "PICTURE") { removeAllPictures(); for(const auto &property : value) { @@ -495,8 +493,7 @@ void Ogg::XiphComment::parse(const ByteVector &data) // Decode FLAC Picture - auto picture = new FLAC::Picture(); - if(picture->parse(picturedata)) { + if(auto picture = new FLAC::Picture(); picture->parse(picturedata)) { d->pictureList.append(picture); } else { diff --git a/taglib/riff/aiff/aifffile.cpp b/taglib/riff/aiff/aifffile.cpp index 18d74b62..e3a42230 100644 --- a/taglib/riff/aiff/aifffile.cpp +++ b/taglib/riff/aiff/aifffile.cpp @@ -153,8 +153,7 @@ bool RIFF::AIFF::File::hasID3v2Tag() const void RIFF::AIFF::File::read(bool readProperties) { for(unsigned int i = 0; i < chunkCount(); ++i) { - const ByteVector name = chunkName(i); - if(name == "ID3 " || name == "id3 ") { + if(const ByteVector name = chunkName(i); name == "ID3 " || name == "id3 ") { if(!d->tag) { d->tag = std::make_unique(this, chunkOffset(i), d->ID3v2FrameFactory); diff --git a/taglib/riff/aiff/aiffproperties.cpp b/taglib/riff/aiff/aiffproperties.cpp index b35f5b25..dbc4875d 100644 --- a/taglib/riff/aiff/aiffproperties.cpp +++ b/taglib/riff/aiff/aiffproperties.cpp @@ -112,8 +112,7 @@ void RIFF::AIFF::Properties::read(File *file) ByteVector data; unsigned int streamLength = 0; for(unsigned int i = 0; i < file->chunkCount(); i++) { - const ByteVector name = file->chunkName(i); - if(name == "COMM") { + if(const ByteVector name = file->chunkName(i); name == "COMM") { if(data.isEmpty()) data = file->chunkData(i); else diff --git a/taglib/riff/rifffile.cpp b/taglib/riff/rifffile.cpp index 9e08c19c..67d307ee 100644 --- a/taglib/riff/rifffile.cpp +++ b/taglib/riff/rifffile.cpp @@ -322,13 +322,12 @@ void RIFF::File::read() if(offset & 1) { seek(offset); - const ByteVector iByte = readBlock(1); - if(iByte.size() == 1) { + if(const ByteVector iByte = readBlock(1); iByte.size() == 1) { bool skipPadding = iByte[0] == '\0'; if(!skipPadding) { // Padding byte is not zero, check if it is good to ignore it - const ByteVector fourCcAfterPadding = readBlock(4); - if(isValidChunkName(fourCcAfterPadding)) { + if(const ByteVector fourCcAfterPadding = readBlock(4); + isValidChunkName(fourCcAfterPadding)) { // Use the padding, it is followed by a valid chunk name. skipPadding = true; } diff --git a/taglib/riff/wav/infotag.cpp b/taglib/riff/wav/infotag.cpp index ac9fed8b..4a8630bd 100644 --- a/taglib/riff/wav/infotag.cpp +++ b/taglib/riff/wav/infotag.cpp @@ -200,8 +200,7 @@ PropertyMap RIFF::Info::Tag::properties() const { PropertyMap props; for(const auto &[id, val] : std::as_const(d->fieldListMap)) { - String key = propertyKeyForId.value(id); - if(!key.isEmpty()) { + if(String key = propertyKeyForId.value(id); !key.isEmpty()) { props[key].append(val); } else { @@ -235,8 +234,8 @@ PropertyMap RIFF::Info::Tag::setProperties(const PropertyMap &props) PropertyMap ignoredProps; for(const auto &[key, val] : props) { - ByteVector id = idForPropertyKey.value(key); - if(!id.isEmpty() && !val.isEmpty()) { + if(ByteVector id = idForPropertyKey.value(key); + !id.isEmpty() && !val.isEmpty()) { d->fieldListMap[id] = val.front(); } else { @@ -319,8 +318,7 @@ void RIFF::Info::Tag::parse(const ByteVector &data) if(size > data.size() - p - 8) break; - const ByteVector id = data.mid(p, 4); - if(isValidChunkName(id)) { + if(const ByteVector id = data.mid(p, 4); isValidChunkName(id)) { const String text = stringHandler->parse(data.mid(p + 8, size)); d->fieldListMap[id] = text; } diff --git a/taglib/riff/wav/wavfile.cpp b/taglib/riff/wav/wavfile.cpp index 0714285d..d4c93947 100644 --- a/taglib/riff/wav/wavfile.cpp +++ b/taglib/riff/wav/wavfile.cpp @@ -198,8 +198,7 @@ bool RIFF::WAV::File::hasInfoTag() const void RIFF::WAV::File::read(bool readProperties) { for(unsigned int i = 0; i < chunkCount(); ++i) { - const ByteVector name = chunkName(i); - if(name == "ID3 " || name == "id3 ") { + if(const ByteVector name = chunkName(i); name == "ID3 " || name == "id3 ") { if(!d->tag[ID3v2Index]) { d->tag.set(ID3v2Index, new ID3v2::Tag(this, chunkOffset(i), d->ID3v2FrameFactory)); @@ -210,8 +209,7 @@ void RIFF::WAV::File::read(bool readProperties) } } else if(name == "LIST") { - const ByteVector data = chunkData(i); - if(data.startsWith("INFO")) { + if(const ByteVector data = chunkData(i); data.startsWith("INFO")) { if(!d->tag[InfoIndex]) { d->tag.set(InfoIndex, new RIFF::Info::Tag(data)); d->hasInfo = true; diff --git a/taglib/riff/wav/wavproperties.cpp b/taglib/riff/wav/wavproperties.cpp index 82f9c9e0..07faa912 100644 --- a/taglib/riff/wav/wavproperties.cpp +++ b/taglib/riff/wav/wavproperties.cpp @@ -112,8 +112,7 @@ void RIFF::WAV::Properties::read(File *file) unsigned int totalSamples = 0; for(unsigned int i = 0; i < file->chunkCount(); ++i) { - const ByteVector name = file->chunkName(i); - if(name == "fmt ") { + if(const ByteVector name = file->chunkName(i); name == "fmt ") { if(data.isEmpty()) data = file->chunkData(i); else @@ -172,8 +171,7 @@ void RIFF::WAV::Properties::read(File *file) d->bitrate = static_cast(streamLength * 8.0 / length + 0.5); } else { - const unsigned int byteRate = data.toUInt(8, false); - if(byteRate > 0) { + if(const unsigned int byteRate = data.toUInt(8, false); byteRate > 0) { d->length = static_cast(streamLength * 1000.0 / byteRate + 0.5); d->bitrate = static_cast(byteRate * 8.0 / 1000.0 + 0.5); } diff --git a/taglib/tagunion.cpp b/taglib/tagunion.cpp index 22a0215c..fdd5b882 100644 --- a/taglib/tagunion.cpp +++ b/taglib/tagunion.cpp @@ -125,8 +125,7 @@ StringList TagUnion::complexPropertyKeys() const { for(const auto &t : d->tags) { if(t) { - const StringList keys = t->complexPropertyKeys(); - if(!keys.isEmpty()) { + if(const StringList keys = t->complexPropertyKeys(); !keys.isEmpty()) { return keys; } } @@ -138,8 +137,8 @@ List TagUnion::complexProperties(const String &key) const { for(const auto &t : d->tags) { if(t) { - const List props = t->complexProperties(key); - if(!props.isEmpty()) { + if(const List props = t->complexProperties(key); + !props.isEmpty()) { return props; } } diff --git a/taglib/tagutils.cpp b/taglib/tagutils.cpp index 5fd9e7f0..93efed4d 100644 --- a/taglib/tagutils.cpp +++ b/taglib/tagutils.cpp @@ -43,9 +43,9 @@ offset_t Utils::findID3v1(File *file) if (file->length() >= 131) { file->seek(-131, File::End); const offset_t p = file->tell() + 3; - const TagLib::ByteVector data = file->readBlock(8); - if(data.containsAt(ID3v1::Tag::fileIdentifier(), 3) && (data != APE::Tag::fileIdentifier())) + if(const TagLib::ByteVector data = file->readBlock(8); + data.containsAt(ID3v1::Tag::fileIdentifier(), 3) && (data != APE::Tag::fileIdentifier())) return p; } else { file->seek(-128, File::End); @@ -100,8 +100,8 @@ ByteVector TagLib::Utils::readHeader(IOStream *stream, unsigned int length, if(skipID3v2) { stream->seek(0); - const ByteVector data = stream->readBlock(ID3v2::Header::size()); - if(data.startsWith(ID3v2::Header::fileIdentifier())) + if(const ByteVector data = stream->readBlock(ID3v2::Header::size()); + data.startsWith(ID3v2::Header::fileIdentifier())) bufferOffset = ID3v2::Header(data).completeTagSize(); } diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index 14fbc7c7..5ce4bd86 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -48,8 +48,7 @@ int findChar( const TIterator dataBegin, const TIterator dataEnd, char c, unsigned int offset, int byteAlign) { - const size_t dataSize = dataEnd - dataBegin; - if(offset + 1 > dataSize) + if(const size_t dataSize = dataEnd - dataBegin; offset + 1 > dataSize) return -1; // n % 0 is invalid @@ -782,8 +781,8 @@ bool ByteVector::operator!=(const char *s) const bool ByteVector::operator<(const ByteVector &v) const { - const int result = ::memcmp(data(), v.data(), std::min(size(), v.size())); - if(result != 0) + if(const int result = ::memcmp(data(), v.data(), std::min(size(), v.size())); + result != 0) return result < 0; return size() < v.size(); } diff --git a/taglib/toolkit/tfile.cpp b/taglib/toolkit/tfile.cpp index 340c9216..3d0b72b9 100644 --- a/taglib/toolkit/tfile.cpp +++ b/taglib/toolkit/tfile.cpp @@ -178,16 +178,16 @@ offset_t File::find(const ByteVector &pattern, offset_t fromOffset, const ByteVe // (1) previous partial match if(previousPartialMatch >= 0 && static_cast(bufferSize()) > previousPartialMatch) { - const int patternOffset = (bufferSize() - previousPartialMatch); - if(buffer.containsAt(pattern, 0, patternOffset)) { + if(const int patternOffset = (bufferSize() - previousPartialMatch); + buffer.containsAt(pattern, 0, patternOffset)) { seek(originalPosition); return bufferOffset - bufferSize() + previousPartialMatch; } } if(!before.isEmpty() && beforePreviousPartialMatch >= 0 && static_cast(bufferSize()) > beforePreviousPartialMatch) { - const int beforeOffset = (bufferSize() - beforePreviousPartialMatch); - if(buffer.containsAt(before, 0, beforeOffset)) { + if(const int beforeOffset = (bufferSize() - beforePreviousPartialMatch); + buffer.containsAt(before, 0, beforeOffset)) { seek(originalPosition); return -1; } @@ -277,8 +277,7 @@ offset_t File::rfind(const ByteVector &pattern, offset_t fromOffset, const ByteV // (2) pattern contained in current buffer - const long location = buffer.rfind(pattern); - if(location >= 0) { + if(const long location = buffer.rfind(pattern); location >= 0) { seek(originalPosition); return bufferOffset + location; } diff --git a/taglib/toolkit/tfilestream.cpp b/taglib/toolkit/tfilestream.cpp index 3898576c..4563d3a9 100644 --- a/taglib/toolkit/tfilestream.cpp +++ b/taglib/toolkit/tfilestream.cpp @@ -203,8 +203,8 @@ ByteVector FileStream::readBlock(size_t length) return ByteVector(); if(length > bufferSize()) { - const auto streamLength = static_cast(FileStream::length()); - if(length > streamLength) { + if(const auto streamLength = static_cast(FileStream::length()); + length > streamLength) { length = streamLength; } } @@ -491,8 +491,7 @@ void FileStream::truncate(offset_t length) #else fflush(d->file); - const int error = ftruncate(fileno(d->file), length); - if(error != 0) + if(const int error = ftruncate(fileno(d->file), length); error != 0) debug("FileStream::truncate() -- Couldn't truncate the file."); #endif diff --git a/taglib/toolkit/tpropertymap.cpp b/taglib/toolkit/tpropertymap.cpp index 61807742..777b5704 100644 --- a/taglib/toolkit/tpropertymap.cpp +++ b/taglib/toolkit/tpropertymap.cpp @@ -141,13 +141,13 @@ StringList &PropertyMap::operator[](const String &key) bool PropertyMap::operator==(const PropertyMap &other) const { for(const auto &[property, val] : other) { - auto thisFind = find(property); - if(thisFind == end() || (thisFind->second != val)) + if(auto thisFind = find(property); + thisFind == end() || (thisFind->second != val)) return false; } for(const auto &[property, val] : *this) { - auto otherFind = other.find(property); - if(otherFind == other.end() || (otherFind->second != val)) + if(auto otherFind = other.find(property); + otherFind == other.end() || (otherFind->second != val)) return false; } return d->unsupported == other.d->unsupported; diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index b965f1d5..50470c7b 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -105,8 +105,7 @@ namespace return; } - const unsigned short bom = nextUTF16(&s); - if(bom == 0xfeff) + if(const unsigned short bom = nextUTF16(&s); bom == 0xfeff) swap = false; // Same as CPU endian. No need to swap bytes. else if(bom == 0xfffe) swap = true; // Not same as CPU endian. Need to swap bytes. diff --git a/taglib/toolkit/tzlib.cpp b/taglib/toolkit/tzlib.cpp index 82e161f5..4ddb8a63 100644 --- a/taglib/toolkit/tzlib.cpp +++ b/taglib/toolkit/tzlib.cpp @@ -77,9 +77,8 @@ ByteVector zlib::decompress([[maybe_unused]] const ByteVector &data) stream.avail_out = static_cast(chunkSize); stream.next_out = reinterpret_cast(outData.data() + offset); - const int result = inflate(&stream, Z_NO_FLUSH); - - if(result == Z_STREAM_ERROR || + if(const int result = inflate(&stream, Z_NO_FLUSH); + result == Z_STREAM_ERROR || result == Z_NEED_DICT || result == Z_DATA_ERROR || result == Z_MEM_ERROR) diff --git a/taglib/wavpack/wavpackproperties.cpp b/taglib/wavpack/wavpackproperties.cpp index d8960cb8..ba3313c3 100644 --- a/taglib/wavpack/wavpackproperties.cpp +++ b/taglib/wavpack/wavpackproperties.cpp @@ -191,8 +191,8 @@ namespace // if we got DSD block, return the specified rate shift amount if(id == ID_DSD_BLOCK && (metaId & ID_UNIQUE) == ID_DSD_BLOCK && metaBc > 0) { - const auto rateShift = static_cast(block[index]); - if(rateShift <= 31) + if(const auto rateShift = static_cast(block[index]); + rateShift <= 31) return rateShift; } diff --git a/taglib/xm/xmfile.cpp b/taglib/xm/xmfile.cpp index 5600bb2d..c4e0388d 100644 --- a/taglib/xm/xmfile.cpp +++ b/taglib/xm/xmfile.cpp @@ -468,8 +468,7 @@ bool XM::File::save() for(unsigned short j = 0; j < sampleCount; ++ j) { if(sampleHeaderSize > 4U) { seek(pos); - unsigned long sampleLength = 0; - if(!readU32L(sampleLength)) + if(unsigned long sampleLength = 0; !readU32L(sampleLength)) return false; if(sampleHeaderSize > 18U) {