mirror of
https://github.com/taglib/taglib.git
synced 2025-05-27 21:20:26 -04:00
Inspection: Variable can be moved to init statement
This commit is contained in:
parent
5d921c6325
commit
dfe2aa5253
@ -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
|
||||
|
@ -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<VariantMap> APE::Tag::complexProperties(const String &key) const
|
||||
{
|
||||
List<VariantMap> 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<VariantMap> APE::Tag::complexProperties(const String &key) const
|
||||
|
||||
bool APE::Tag::setComplexProperties(const String &key, const List<VariantMap> &value)
|
||||
{
|
||||
const String uppercaseKey = key.upper();
|
||||
if(uppercaseKey == "PICTURE") {
|
||||
if(const String uppercaseKey = key.upper(); uppercaseKey == "PICTURE") {
|
||||
removeItem(FRONT_COVER);
|
||||
removeItem(BACK_COVER);
|
||||
|
||||
|
@ -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<VariantMap> ASF::Tag::complexProperties(const String &key) const
|
||||
{
|
||||
List<VariantMap> 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<VariantMap> ASF::Tag::complexProperties(const String &key) const
|
||||
|
||||
bool ASF::Tag::setComplexProperties(const String &key, const List<VariantMap> &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) {
|
||||
|
@ -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<int>(d->chunks.size()) - 1;
|
||||
if(lastChunkIndex >= 0 && d->chunks[lastChunkIndex].name == "DIIN") {
|
||||
if(const int lastChunkIndex = static_cast<int>(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<int>(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<int>(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<DSDIFF::DIIN::Tag>(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<DSDIFF::DIIN::Tag>(DIINIndex, false)->setArtist(artistStr);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -171,8 +171,7 @@ StringList FLAC::File::complexPropertyKeys() const
|
||||
|
||||
List<VariantMap> FLAC::File::complexProperties(const String &key) const
|
||||
{
|
||||
const String uppercaseKey = key.upper();
|
||||
if(uppercaseKey == "PICTURE") {
|
||||
if(const String uppercaseKey = key.upper(); uppercaseKey == "PICTURE") {
|
||||
List<VariantMap> props;
|
||||
for(const auto &block : std::as_const(d->blocks)) {
|
||||
if(auto picture = dynamic_cast<Picture *>(block)) {
|
||||
@ -196,8 +195,7 @@ List<VariantMap> FLAC::File::complexProperties(const String &key) const
|
||||
|
||||
bool FLAC::File::setComplexProperties(const String &key, const List<VariantMap> &value)
|
||||
{
|
||||
const String uppercaseKey = key.upper();
|
||||
if(uppercaseKey == "PICTURE") {
|
||||
if(const String uppercaseKey = key.upper(); uppercaseKey == "PICTURE") {
|
||||
removePictures();
|
||||
|
||||
for(const auto &property : value) {
|
||||
|
@ -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<long>(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);
|
||||
|
@ -189,8 +189,7 @@ std::pair<ByteVector, Item> ItemFactory::itemFromProperty(
|
||||
std::pair<String, StringList> 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<String, Item> ItemFactory::parseInt(
|
||||
std::pair<String, Item> 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<String, Item> ItemFactory::parseByte(
|
||||
std::pair<String, Item> 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<int>(data[0].toShort());
|
||||
if(idx > 0) {
|
||||
return {
|
||||
@ -519,8 +516,7 @@ std::pair<String, Item> ItemFactory::parseGnre(
|
||||
std::pair<String, Item> 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<String, Item> ItemFactory::parseIntPair(
|
||||
std::pair<String, Item> 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<String, Item> ItemFactory::parseBool(
|
||||
std::pair<String, Item> 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<String, Item> ItemFactory::parseText(
|
||||
std::pair<String, Item> 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 = "----:";
|
||||
|
@ -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<int>((bitrateValue + 500) / 1000.0 + 0.5);
|
||||
}
|
||||
else {
|
||||
|
@ -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<VariantMap> MP4::Tag::complexProperties(const String &key) const
|
||||
{
|
||||
List<VariantMap> 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<VariantMap> MP4::Tag::complexProperties(const String &key) const
|
||||
|
||||
bool MP4::Tag::setComplexProperties(const String &key, const List<VariantMap> &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<String>();
|
||||
|
@ -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<int>(length + 0.5);
|
||||
d->bitrate = static_cast<int>(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);
|
||||
|
@ -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.");
|
||||
|
@ -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());
|
||||
|
@ -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());
|
||||
|
@ -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);
|
||||
|
@ -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<CommentsFrame *>(commFrame);
|
||||
if(frame && frame->description().isEmpty()) {
|
||||
@ -464,8 +462,7 @@ StringList ID3v2::Tag::complexPropertyKeys() const
|
||||
List<VariantMap> ID3v2::Tag::complexProperties(const String &key) const
|
||||
{
|
||||
List<VariantMap> 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<const AttachedPictureFrame *>(frame)) {
|
||||
@ -497,8 +494,7 @@ List<VariantMap> ID3v2::Tag::complexProperties(const String &key) const
|
||||
|
||||
bool ID3v2::Tag::setComplexProperties(const String &key, const List<VariantMap> &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) + ')';
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -181,9 +181,8 @@ void MPEG::Header::parse(File *file, offset_t offset, bool checkLength)
|
||||
|
||||
// Set the MPEG layer
|
||||
|
||||
const int layerBits = (static_cast<unsigned char>(data[1]) >> 1) & 0x03;
|
||||
|
||||
if(layerBits == 1)
|
||||
if(const int layerBits = (static_cast<unsigned char>(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<unsigned char>(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<unsigned char>(data[3]) & 0x3) << 11 |
|
||||
(static_cast<unsigned char>(frameLengthData[0]) << 3) |
|
||||
(static_cast<unsigned char>(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;
|
||||
}
|
||||
|
||||
|
@ -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<int>(streamLength * 8.0 / d->bitrate + 0.5);
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -247,8 +247,7 @@ StringList Ogg::XiphComment::complexPropertyKeys() const
|
||||
List<VariantMap> Ogg::XiphComment::complexProperties(const String &key) const
|
||||
{
|
||||
List<VariantMap> 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<VariantMap> Ogg::XiphComment::complexProperties(const String &key) const
|
||||
|
||||
bool Ogg::XiphComment::setComplexProperties(const String &key, const List<VariantMap> &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 {
|
||||
|
@ -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<ID3v2::Tag>(this, chunkOffset(i),
|
||||
d->ID3v2FrameFactory);
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<int>(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<int>(streamLength * 1000.0 / byteRate + 0.5);
|
||||
d->bitrate = static_cast<int>(byteRate * 8.0 / 1000.0 + 0.5);
|
||||
}
|
||||
|
@ -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<VariantMap> TagUnion::complexProperties(const String &key) const
|
||||
{
|
||||
for(const auto &t : d->tags) {
|
||||
if(t) {
|
||||
const List<VariantMap> props = t->complexProperties(key);
|
||||
if(!props.isEmpty()) {
|
||||
if(const List<VariantMap> props = t->complexProperties(key);
|
||||
!props.isEmpty()) {
|
||||
return props;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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<int>(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<int>(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;
|
||||
}
|
||||
|
@ -203,8 +203,8 @@ ByteVector FileStream::readBlock(size_t length)
|
||||
return ByteVector();
|
||||
|
||||
if(length > bufferSize()) {
|
||||
const auto streamLength = static_cast<size_t>(FileStream::length());
|
||||
if(length > streamLength) {
|
||||
if(const auto streamLength = static_cast<size_t>(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
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -77,9 +77,8 @@ ByteVector zlib::decompress([[maybe_unused]] const ByteVector &data)
|
||||
stream.avail_out = static_cast<uInt>(chunkSize);
|
||||
stream.next_out = reinterpret_cast<Bytef *>(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)
|
||||
|
@ -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<unsigned char>(block[index]);
|
||||
if(rateShift <= 31)
|
||||
if(const auto rateShift = static_cast<unsigned char>(block[index]);
|
||||
rateShift <= 31)
|
||||
return rateShift;
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user