Inspection: Code redundancies

This commit is contained in:
Urs Fleisch 2024-01-20 23:30:40 +01:00
parent 580b0b0c82
commit 7bcfb96098
51 changed files with 154 additions and 164 deletions

View File

@ -75,7 +75,7 @@ bool APE::File::isSupported(IOStream *stream)
// An APE file has an ID "MAC " somewhere. An ID3v2 tag may precede.
const ByteVector buffer = Utils::readHeader(stream, bufferSize(), true);
return (buffer.find("MAC ") >= 0);
return buffer.find("MAC ") >= 0;
}
////////////////////////////////////////////////////////////////////////////////
@ -178,7 +178,7 @@ bool APE::File::save()
insert(data, d->APELocation, d->APESize);
if(d->ID3v1Location >= 0)
d->ID3v1Location += (static_cast<long>(data.size()) - d->APESize);
d->ID3v1Location += static_cast<long>(data.size()) - d->APESize;
d->APESize = data.size();
}
@ -224,12 +224,12 @@ void APE::File::strip(int tags)
bool APE::File::hasAPETag() const
{
return (d->APELocation >= 0);
return d->APELocation >= 0;
}
bool APE::File::hasID3v1Tag() const
{
return (d->ID3v1Location >= 0);
return d->ID3v1Location >= 0;
}
////////////////////////////////////////////////////////////////////////////////
@ -283,7 +283,7 @@ void APE::File::read(bool readProperties)
if(d->ID3v2Location >= 0) {
seek(d->ID3v2Location + d->ID3v2Size);
streamLength -= (d->ID3v2Location + d->ID3v2Size);
streamLength -= d->ID3v2Location + d->ID3v2Size;
}
else {
seek(0);

View File

@ -241,7 +241,7 @@ void APE::Item::parse(const ByteVector &data)
ByteVector APE::Item::render() const
{
ByteVector data;
unsigned int flags = ((d->readOnly) ? 1 : 0) | (d->type << 1);
unsigned int flags = (d->readOnly ? 1 : 0) | (d->type << 1);
ByteVector val;
if(isEmpty())

View File

@ -154,7 +154,7 @@ void APE::Properties::analyzeCurrent(File *file)
}
if(const unsigned int descriptorBytes = descriptor.toUInt(0, false);
(descriptorBytes - 52) > 0)
descriptorBytes - 52 > 0)
file->seek(descriptorBytes - 52, File::Current);
// Read the header

View File

@ -154,7 +154,7 @@ unsigned int ASF::Attribute::toUInt() const
unsigned long long ASF::Attribute::toULongLong() const
{
return static_cast<unsigned long long>(d->numericValue);
return d->numericValue;
}
ASF::Picture ASF::Attribute::toPicture() const
@ -199,10 +199,10 @@ String ASF::Attribute::parse(ASF::File &file, int kind)
case BoolType:
if(kind == 0) {
d->numericValue = (readDWORD(&file) != 0);
d->numericValue = readDWORD(&file) != 0;
}
else {
d->numericValue = (readWORD(&file) != 0);
d->numericValue = readWORD(&file) != 0;
}
break;

View File

@ -472,7 +472,7 @@ bool ASF::File::isSupported(IOStream *stream)
// An ASF file has to start with the designated GUID.
const ByteVector id = Utils::readHeader(stream, 16, false);
return (id == headerGuid);
return id == headerGuid;
}
////////////////////////////////////////////////////////////////////////////////
@ -564,8 +564,8 @@ bool ASF::File::save()
bool inMetadataObject = false;
for(const auto &attribute : attributes) {
const bool largeValue = (attribute.dataSize() > 65535);
const bool guid = (attribute.type() == Attribute::GuidType);
const bool largeValue = attribute.dataSize() > 65535;
const bool guid = attribute.type() == Attribute::GuidType;
if(!inExtendedContentDescriptionObject && !guid && !largeValue && attribute.language() == 0 && attribute.stream() == 0) {
d->extendedContentDescriptionObject->attributeData.append(attribute.render(name));
@ -681,6 +681,5 @@ void ASF::File::read()
if(!filePropertiesObject || !streamPropertiesObject) {
debug("ASF::File::read(): Missing mandatory header objects.");
setValid(false);
return;
}
}

View File

@ -130,7 +130,7 @@ bool DSDIFF::File::isSupported(IOStream *stream)
{
// A DSDIFF file has to start with "FRM8????????DSD ".
const ByteVector id = Utils::readHeader(stream, 16, false);
return (id.startsWith("FRM8") && id.containsAt("DSD ", 12));
return id.startsWith("FRM8") && id.containsAt("DSD ", 12);
}
////////////////////////////////////////////////////////////////////////////////
@ -429,7 +429,7 @@ void DSDIFF::File::removeChildChunk(unsigned int i, unsigned int childChunkNum)
// Update the internal offsets
// For child chunks
if((i + 1) < childChunks.size()) {
if(i + 1 < childChunks.size()) {
childChunks[i + 1].offset = childChunks[i].offset;
for(unsigned int c = i + 2; c < childChunks.size(); ++c)
childChunks[c].offset = childChunks[c - 1].offset + 12
@ -555,13 +555,13 @@ void DSDIFF::File::setChildChunkData(const ByteVector &name,
// Now add the chunk to the file
unsigned long long nextRootChunkIdx = length();
if((d->childChunkIndex[childChunkNum] + 1) < static_cast<int>(d->chunks.size()))
if(d->childChunkIndex[childChunkNum] + 1 < static_cast<int>(d->chunks.size()))
nextRootChunkIdx = d->chunks[d->childChunkIndex[childChunkNum] + 1].offset - 12;
writeChunk(name, data, offset,
static_cast<unsigned long>(
nextRootChunkIdx > offset ? nextRootChunkIdx - offset : 0),
(offset & 1) ? 1 : 0);
offset & 1 ? 1 : 0);
// For root chunks
@ -571,7 +571,7 @@ void DSDIFF::File::setChildChunkData(const ByteVector &name,
chunk.name = name;
chunk.size = data.size();
chunk.offset = offset + 12;
chunk.padding = (data.size() & 0x01) ? 1 : 0;
chunk.padding = data.size() & 0x01 ? 1 : 0;
childChunks.push_back(chunk);
}
@ -645,7 +645,7 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
chunk.padding = 0;
if(offset_t uPosNotPadded = tell(); (uPosNotPadded & 0x01) != 0) {
if(ByteVector iByte = readBlock(1);
(iByte.size() != 1) || (iByte[0] != 0))
iByte.size() != 1 || iByte[0] != 0)
// Not well formed, re-seek
seek(uPosNotPadded, Beginning);
else
@ -705,7 +705,7 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
// Check padding
if(offset_t uPosNotPadded = tell(); (uPosNotPadded & 0x01) != 0) {
if(ByteVector iByte = readBlock(1);
(iByte.size() != 1) || (iByte[0] != 0))
iByte.size() != 1 || iByte[0] != 0)
// Not well formed, re-seek
seek(uPosNotPadded, Beginning);
}
@ -745,7 +745,7 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
chunk.padding = 0;
if(offset_t uPosNotPadded = tell(); (uPosNotPadded & 0x01) != 0) {
if(ByteVector iByte = readBlock(1);
(iByte.size() != 1) || (iByte[0] != 0))
iByte.size() != 1 || iByte[0] != 0)
// Not well formed, re-seek
seek(uPosNotPadded, Beginning);
else
@ -793,7 +793,7 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
if(offset_t uPosNotPadded = tell(); (uPosNotPadded & 0x01) != 0) {
if(ByteVector iByte = readBlock(1);
(iByte.size() != 1) || (iByte[0] != 0))
iByte.size() != 1 || iByte[0] != 0)
// Not well formed, re-seek
seek(uPosNotPadded, Beginning);
else
@ -894,7 +894,7 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
int bitrate = 0;
if(lengthDSDSamplesTimeChannels > 0)
bitrate = static_cast<int>(
(audioDataSizeinBytes * 8 * sampleRate) / lengthDSDSamplesTimeChannels / 1000);
audioDataSizeinBytes * 8 * sampleRate / lengthDSDSamplesTimeChannels / 1000);
d->properties = std::make_unique<Properties>(sampleRate, channels,
lengthDSDSamplesTimeChannels, bitrate, propertiesStyle);

View File

@ -44,10 +44,10 @@ public:
// public members
////////////////////////////////////////////////////////////////////////////////
DSDIFF::Properties::Properties(const unsigned int sampleRate,
const unsigned short channels,
const unsigned long long samplesCount,
const int bitrate,
DSDIFF::Properties::Properties(unsigned int sampleRate,
unsigned short channels,
unsigned long long samplesCount,
int bitrate,
ReadStyle style) :
AudioProperties(style),
d(std::make_unique<PropertiesPrivate>())
@ -58,7 +58,7 @@ DSDIFF::Properties::Properties(const unsigned int sampleRate,
d->sampleRate = sampleRate;
d->bitrate = bitrate;
d->length = d->sampleRate > 0
? static_cast<int>((d->sampleCount * 1000.0) / d->sampleRate + 0.5)
? static_cast<int>(d->sampleCount * 1000.0 / d->sampleRate + 0.5)
: 0;
}

View File

@ -48,8 +48,8 @@ namespace TagLib {
* Create an instance of DSDIFF::Properties with the data read from the
* ByteVector \a data.
*/
Properties(const unsigned int sampleRate, const unsigned short channels,
const unsigned long long samplesCount, const int bitrate,
Properties(unsigned int sampleRate, unsigned short channels,
unsigned long long samplesCount, int bitrate,
ReadStyle style);
/*!

View File

@ -127,7 +127,7 @@ void DSF::Properties::read(const ByteVector &data)
d->blockSizePerChannel = data.toUInt(32U,false);
d->bitrate = static_cast<unsigned int>(
(d->samplingFrequency * d->bitsPerSample * d->channelNum) / 1000.0 + 0.5);
d->samplingFrequency * d->bitsPerSample * d->channelNum / 1000.0 + 0.5);
d->length = d->samplingFrequency > 0
? static_cast<unsigned int>(d->sampleCount * 1000.0 / d->samplingFrequency + 0.5)
: 0;

View File

@ -456,12 +456,12 @@ void FileRef::swap(FileRef &ref) noexcept
bool FileRef::operator==(const FileRef &ref) const
{
return (ref.d->file == d->file);
return ref.d->file == d->file;
}
bool FileRef::operator!=(const FileRef &ref) const
{
return (ref.d->file != d->file);
return ref.d->file != d->file;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -86,7 +86,7 @@ bool FLAC::File::isSupported(IOStream *stream)
// A FLAC file has an ID "fLaC" somewhere. An ID3v2 tag may precede.
const ByteVector buffer = Utils::readHeader(stream, bufferSize(), true);
return (buffer.find("fLaC") >= 0);
return buffer.find("fLaC") >= 0;
}
////////////////////////////////////////////////////////////////////////////////
@ -301,10 +301,10 @@ bool FLAC::File::save()
insert(data, d->flacStart, originalLength);
d->streamStart += (static_cast<long>(data.size()) - originalLength);
d->streamStart += static_cast<long>(data.size()) - originalLength;
if(d->ID3v1Location >= 0)
d->ID3v1Location += (static_cast<long>(data.size()) - originalLength);
d->ID3v1Location += static_cast<long>(data.size()) - originalLength;
// Update ID3 tags
@ -318,11 +318,11 @@ bool FLAC::File::save()
data = ID3v2Tag()->render();
insert(data, d->ID3v2Location, d->ID3v2OriginalSize);
d->flacStart += (static_cast<long>(data.size()) - d->ID3v2OriginalSize);
d->streamStart += (static_cast<long>(data.size()) - d->ID3v2OriginalSize);
d->flacStart += static_cast<long>(data.size()) - d->ID3v2OriginalSize;
d->streamStart += static_cast<long>(data.size()) - d->ID3v2OriginalSize;
if(d->ID3v1Location >= 0)
d->ID3v1Location += (static_cast<long>(data.size()) - d->ID3v2OriginalSize);
d->ID3v1Location += static_cast<long>(data.size()) - d->ID3v2OriginalSize;
d->ID3v2OriginalSize = data.size();
}
@ -447,12 +447,12 @@ bool FLAC::File::hasXiphComment() const
bool FLAC::File::hasID3v1Tag() const
{
return (d->ID3v1Location >= 0);
return d->ID3v1Location >= 0;
}
bool FLAC::File::hasID3v2Tag() const
{
return (d->ID3v2Location >= 0);
return d->ID3v2Location >= 0;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -128,7 +128,7 @@ PropertyMap Mod::Tag::properties() const
PropertyMap properties;
properties["TITLE"] = d->title;
properties["COMMENT"] = d->comment;
if(!(d->trackerName.isEmpty()))
if(!d->trackerName.isEmpty())
properties["TRACKERNAME"] = d->trackerName;
return properties;
}

View File

@ -271,28 +271,25 @@ namespace
}
} // namespace
bool MP4::Atoms::checkRootLevelAtoms()
{
bool MP4::Atoms::checkRootLevelAtoms() {
bool moovValid = false;
for(auto it = d->atoms.begin(); it != d->atoms.end(); ++it) {
bool invalid = (*it)->length() == 0 || !checkValid((*it)->children());
if(!moovValid && !invalid && (*it)->name() == "moov") {
bool invalid = (*it)->length() == 0 || !checkValid((*it)->children());
if(!moovValid && !invalid && (*it)->name() == "moov") {
moovValid = true;
}
if(invalid) {
}
if(invalid) {
if(moovValid && (*it)->name() != "moof") {
// Only the root level atoms "moov" and (if present) "moof" are
// modified. If they are valid, ignore following invalid root level
// atoms as trailing garbage.
while(it != d->atoms.end()) {
// Only the root level atoms "moov" and (if present) "moof" are
// modified. If they are valid, ignore following invalid root level
// atoms as trailing garbage.
while(it != d->atoms.end()) {
delete *it;
it = d->atoms.erase(it);
}
return true;
}
else {
return false;
}
return true;
}
return false;
}
}

View File

@ -174,5 +174,5 @@ MP4::File::strip(int tags)
bool
MP4::File::hasMP4Tag() const
{
return (d->atoms->find("moov", "udta", "meta", "ilst") != nullptr);
return d->atoms->find("moov", "udta", "meta", "ilst") != nullptr;
}

View File

@ -95,9 +95,8 @@ ByteVector ItemFactory::renderItem(
if(itemName.startsWith("----")) {
return renderFreeForm(itemName, item);
}
else {
const ByteVector name = itemName.data(String::Latin1);
switch(handlerTypeForName(name)) {
const ByteVector name = itemName.data(String::Latin1);
switch(handlerTypeForName(name)) {
case ItemHandlerType::Unknown:
debug("MP4: Unknown item name \"" + name + "\"");
break;
@ -127,7 +126,6 @@ ByteVector ItemFactory::renderItem(
return renderText(name, item, TypeImplicit);
case ItemHandlerType::Text:
return renderText(name, item);
}
}
return ByteVector();
}
@ -573,15 +571,13 @@ std::pair<String, Item> ItemFactory::parseFreeForm(
item.setAtomDataType(type);
return {name, item};
}
else {
ByteVectorList value;
for(auto it = itBegin; it != data.end(); ++it) {
value.append(it->data);
}
Item item(value);
item.setAtomDataType(type);
return {name, item};
ByteVectorList value;
for(auto it = itBegin; it != data.end(); ++it) {
value.append(it->data);
}
Item item(value);
item.setAtomDataType(type);
return {name, item};
}
return {atom->name(), Item()};
}

View File

@ -228,7 +228,7 @@ MP4::Properties::read(File *file, const Atoms *atoms)
}
else {
d->bitrate = static_cast<int>(
(calculateMdatLength(atoms->atoms()) * 8) / d->length);
calculateMdatLength(atoms->atoms()) * 8 / d->length);
}
}
}
@ -245,7 +245,7 @@ MP4::Properties::read(File *file, const Atoms *atoms)
// There are files which do not contain a nominal bitrate, e.g. those
// generated by refalac64.exe. Calculate the bitrate from the audio
// data size (mdat atoms) and the duration.
d->bitrate = static_cast<int>((calculateMdatLength(atoms->atoms()) * 8) / d->length);
d->bitrate = static_cast<int>(calculateMdatLength(atoms->atoms()) * 8 / d->length);
}
}
}

View File

@ -68,7 +68,7 @@ bool MPC::File::isSupported(IOStream *stream)
// have keys to do a quick check. An ID3v2 tag may precede.
const ByteVector id = Utils::readHeader(stream, 4, true);
return (id == "MPCK" || id.startsWith("MP+"));
return id == "MPCK" || id.startsWith("MP+");
}
////////////////////////////////////////////////////////////////////////////////
@ -186,7 +186,7 @@ bool MPC::File::save()
insert(data, d->APELocation, d->APESize);
if(d->ID3v1Location >= 0)
d->ID3v1Location += (static_cast<long>(data.size()) - d->APESize);
d->ID3v1Location += static_cast<long>(data.size()) - d->APESize;
d->APESize = data.size();
}
@ -236,12 +236,12 @@ void MPC::File::strip(int tags)
bool MPC::File::hasID3v1Tag() const
{
return (d->ID3v1Location >= 0);
return d->ID3v1Location >= 0;
}
bool MPC::File::hasAPETag() const
{
return (d->APELocation >= 0);
return d->APELocation >= 0;
}
////////////////////////////////////////////////////////////////////////////////
@ -295,7 +295,7 @@ void MPC::File::read(bool readProperties)
if(d->ID3v2Location >= 0) {
seek(d->ID3v2Location + d->ID3v2Size);
streamLength -= (d->ID3v2Location + d->ID3v2Size);
streamLength -= d->ID3v2Location + d->ID3v2Size;
}
else {
seek(0);

View File

@ -162,7 +162,7 @@ namespace
do {
tmp = data[pos++];
size = (size << 7) | (tmp & 0x7F);
} while((tmp & 0x80) && (pos < data.size()));
} while((tmp & 0x80) && pos < data.size());
return size;
}

View File

@ -287,7 +287,7 @@ ByteVector TextIdentificationFrame::renderFields() const
if(it != d->fieldList.cbegin())
v.append(textDelimiter(encoding));
v.append((*it).data(encoding));
v.append(it->data(encoding));
}
return v;

View File

@ -553,7 +553,7 @@ Frame *FrameFactory::createFrameForProperty(const String &key, const StringList
auto frame = new TextIdentificationFrame(frameID, String::UTF8);
frame->setText(values);
return frame;
} if((frameID[0] == 'W') && (values.size() == 1)){ // URL frame (not WXXX); support only one value
} if(frameID[0] == 'W' && values.size() == 1){ // URL frame (not WXXX); support only one value
auto frame = new UrlLinkFrame(frameID);
frame->setUrl(values.front());
return frame;

View File

@ -300,7 +300,7 @@ bool ID3v2::Tag::isEmpty() const
Header *ID3v2::Tag::header() const
{
return &(d->header);
return &d->header;
}
ExtendedHeader *ID3v2::Tag::extendedHeader() const

View File

@ -238,10 +238,10 @@ bool MPEG::File::save(int tags, StripTags strip, ID3v2::Version version, Duplica
insert(data, d->ID3v2Location, d->ID3v2OriginalSize);
if(d->APELocation >= 0)
d->APELocation += (static_cast<long>(data.size()) - d->ID3v2OriginalSize);
d->APELocation += static_cast<long>(data.size()) - d->ID3v2OriginalSize;
if(d->ID3v1Location >= 0)
d->ID3v1Location += (static_cast<long>(data.size()) - d->ID3v2OriginalSize);
d->ID3v1Location += static_cast<long>(data.size()) - d->ID3v2OriginalSize;
d->ID3v2OriginalSize = data.size();
}
@ -294,7 +294,7 @@ bool MPEG::File::save(int tags, StripTags strip, ID3v2::Version version, Duplica
insert(data, d->APELocation, d->APEOriginalSize);
if(d->ID3v1Location >= 0)
d->ID3v1Location += (static_cast<long>(data.size()) - d->APEOriginalSize);
d->ID3v1Location += static_cast<long>(data.size()) - d->APEOriginalSize;
d->APEOriginalSize = data.size();
}
@ -445,17 +445,17 @@ offset_t MPEG::File::lastFrameOffset()
bool MPEG::File::hasID3v1Tag() const
{
return (d->ID3v1Location >= 0);
return d->ID3v1Location >= 0;
}
bool MPEG::File::hasID3v2Tag() const
{
return (d->ID3v2Location >= 0);
return d->ID3v2Location >= 0;
}
bool MPEG::File::hasAPETag() const
{
return (d->APELocation >= 0);
return d->APELocation >= 0;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -210,7 +210,7 @@ void MPEG::Header::parse(File *file, offset_t offset, bool checkLength)
}
}
d->protectionEnabled = (static_cast<unsigned char>(data[1] & 0x01) == 0);
d->protectionEnabled = static_cast<unsigned char>(data[1] & 0x01) == 0;
if(isADTS()) {
static constexpr std::array sampleRates {
@ -262,8 +262,8 @@ void MPEG::Header::parse(File *file, offset_t offset, bool checkLength)
},
};
const int versionIndex = (d->version == Version1) ? 0 : 1;
const int layerIndex = (d->layer > 0) ? d->layer - 1 : 0;
const int versionIndex = d->version == Version1 ? 0 : 1;
const int layerIndex = d->layer > 0 ? d->layer - 1 : 0;
// The bitrate index is encoded as the first 4 bits of the 3rd byte,
// i.e. 1111xxxx
@ -300,9 +300,9 @@ void MPEG::Header::parse(File *file, offset_t offset, bool checkLength)
// TODO: Add mode extension for completeness
d->isOriginal = ((static_cast<unsigned char>(data[3]) & 0x04) != 0);
d->isCopyrighted = ((static_cast<unsigned char>(data[3]) & 0x08) != 0);
d->isPadded = ((static_cast<unsigned char>(data[2]) & 0x02) != 0);
d->isOriginal = (static_cast<unsigned char>(data[3]) & 0x04) != 0;
d->isCopyrighted = (static_cast<unsigned char>(data[3]) & 0x08) != 0;
d->isPadded = (static_cast<unsigned char>(data[2]) & 0x02) != 0;
// Samples per frame

View File

@ -210,7 +210,7 @@ void MPEG::Properties::read(File *file, ReadStyle readStyle)
}
}
bitRate = firstHeader.samplesPerFrame() != 0
? static_cast<int>((bytesPerFrame * 8 * firstHeader.sampleRate())
? static_cast<int>(bytesPerFrame * 8 * firstHeader.sampleRate()
/ 1000 / firstHeader.samplesPerFrame())
: 0;
}

View File

@ -54,7 +54,7 @@ MPEG::XingHeader::~XingHeader() = default;
bool MPEG::XingHeader::isValid() const
{
return (d->type != Invalid && d->frames > 0 && d->size > 0);
return d->type != Invalid && d->frames > 0 && d->size > 0;
}
unsigned int MPEG::XingHeader::totalFrames() const

View File

@ -57,7 +57,7 @@ bool Ogg::FLAC::File::isSupported(IOStream *stream)
// An Ogg FLAC file has IDs "OggS" and "fLaC" somewhere.
const ByteVector buffer = Utils::readHeader(stream, bufferSize(), false);
return (buffer.find("OggS") >= 0 && buffer.find("fLaC") >= 0);
return buffer.find("OggS") >= 0 && buffer.find("fLaC") >= 0;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -293,16 +293,16 @@ List<Ogg::Page *> Ogg::Page::paginate(const ByteVectorList &packets,
for(auto it = packets.begin(); it != packets.end(); ++it) {
const bool lastPacketInList = (it == --packets.end());
const bool lastPacketInList = it == --packets.end();
// mark very first packet?
bool continued = (firstPacketContinued && it == packets.begin());
bool continued = firstPacketContinued && it == packets.begin();
unsigned int pos = 0;
while(pos < it->size()) {
const bool lastSplit = (pos + SplitSize >= it->size());
const bool lastSplit = pos + SplitSize >= it->size();
ByteVectorList packetList;
packetList.append(it->mid(pos, SplitSize));

View File

@ -286,7 +286,7 @@ ByteVector Ogg::PageHeader::lacingValues() const
// these values is a byte. A value of less than 255 (0xff) indicates the end
// of the packet.
data.resize(data.size() + (*it / 255), '\xff');
data.resize(data.size() + *it / 255, '\xff');
if(it != std::prev(d->packetSizes.cend()) || d->lastPacketCompleted)
data.append(static_cast<unsigned char>(*it % 255));

View File

@ -52,7 +52,7 @@ bool Ogg::Opus::File::isSupported(IOStream *stream)
// An Opus file has IDs "OggS" and "OpusHead" somewhere.
const ByteVector buffer = Utils::readHeader(stream, bufferSize(), false);
return (buffer.find("OggS") >= 0 && buffer.find("OpusHead") >= 0);
return buffer.find("OggS") >= 0 && buffer.find("OpusHead") >= 0;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -138,7 +138,7 @@ void Opus::Properties::read(File *file)
const long long end = last->absoluteGranularPosition();
if(start >= 0 && end >= 0) {
if(const long long frameCount = (end - start - preSkip); 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"

View File

@ -52,7 +52,7 @@ bool Ogg::Speex::File::isSupported(IOStream *stream)
// A Speex file has IDs "OggS" and "Speex " somewhere.
const ByteVector buffer = Utils::readHeader(stream, bufferSize(), false);
return (buffer.find("OggS") >= 0 && buffer.find("Speex ") >= 0);
return buffer.find("OggS") >= 0 && buffer.find("Speex ") >= 0;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -55,7 +55,7 @@ bool Vorbis::File::isSupported(IOStream *stream)
// An Ogg Vorbis file has IDs "OggS" and "\x01vorbis" somewhere.
const ByteVector buffer = Utils::readHeader(stream, bufferSize(), false);
return (buffer.find("OggS") >= 0 && buffer.find("\x01vorbis") >= 0);
return buffer.find("OggS") >= 0 && buffer.find("\x01vorbis") >= 0;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -58,7 +58,7 @@ bool RIFF::AIFF::File::isSupported(IOStream *stream)
// An AIFF file has to start with "FORM????AIFF" or "FORM????AIFC".
const ByteVector id = Utils::readHeader(stream, 12, false);
return (id.startsWith("FORM") && (id.containsAt("AIFF", 8) || id.containsAt("AIFC", 8)));
return id.startsWith("FORM") && (id.containsAt("AIFF", 8) || id.containsAt("AIFC", 8));
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -90,7 +90,7 @@ unsigned int RIFF::AIFF::Properties::sampleFrames() const
bool RIFF::AIFF::Properties::isAiffC() const
{
return (!d->compressionType.isEmpty());
return !d->compressionType.isEmpty();
}
ByteVector RIFF::AIFF::Properties::compressionType() const

View File

@ -281,7 +281,7 @@ void RIFF::File::removeChunk(const ByteVector &name)
void RIFF::File::read()
{
const bool bigEndian = (d->endianness == BigEndian);
const bool bigEndian = d->endianness == BigEndian;
offset_t offset = tell();

View File

@ -66,7 +66,7 @@ bool RIFF::WAV::File::isSupported(IOStream *stream)
// A WAV file has to start with "RIFF????WAVE".
const ByteVector id = Utils::readHeader(stream, 12, false);
return (id.startsWith("RIFF") && id.containsAt("WAVE", 8));
return id.startsWith("RIFF") && id.containsAt("WAVE", 8);
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -42,27 +42,27 @@ Tag::~Tag() = default;
bool Tag::isEmpty() const
{
return (title().isEmpty() &&
artist().isEmpty() &&
album().isEmpty() &&
comment().isEmpty() &&
genre().isEmpty() &&
year() == 0 &&
track() == 0);
return title().isEmpty() &&
artist().isEmpty() &&
album().isEmpty() &&
comment().isEmpty() &&
genre().isEmpty() &&
year() == 0 &&
track() == 0;
}
PropertyMap Tag::properties() const
{
PropertyMap map;
if(!(title().isEmpty()))
if(!title().isEmpty())
map["TITLE"].append(title());
if(!(artist().isEmpty()))
if(!artist().isEmpty())
map["ARTIST"].append(artist());
if(!(album().isEmpty()))
if(!album().isEmpty())
map["ALBUM"].append(album());
if(!(comment().isEmpty()))
if(!comment().isEmpty())
map["COMMENT"].append(comment());
if(!(genre().isEmpty()))
if(!genre().isEmpty())
map["GENRE"].append(genre());
if(year() != 0)
map["DATE"].append(String::number(year()));

View File

@ -45,7 +45,7 @@ offset_t Utils::findID3v1(File *file)
const offset_t p = file->tell() + 3;
if(const TagLib::ByteVector data = file->readBlock(8);
data.containsAt(ID3v1::Tag::fileIdentifier(), 3) && (data != APE::Tag::fileIdentifier()))
data.containsAt(ID3v1::Tag::fileIdentifier(), 3) && data != APE::Tag::fileIdentifier())
return p;
} else {
file->seek(-128, File::End);

View File

@ -129,8 +129,8 @@ T toNumber(const ByteVector &v, size_t offset, size_t length, bool mostSignifica
template <class T>
T toNumber(const ByteVector &v, size_t offset, bool mostSignificantByteFirst)
{
const bool isBigEndian = (Utils::systemByteOrder() == Utils::BigEndian);
const bool swap = (mostSignificantByteFirst != isBigEndian);
const bool isBigEndian = Utils::systemByteOrder() == Utils::BigEndian;
const bool swap = mostSignificantByteFirst != isBigEndian;
if(offset + sizeof(T) > v.size())
return toNumber<T>(v, offset, v.size() - offset, mostSignificantByteFirst);
@ -147,7 +147,7 @@ T toNumber(const ByteVector &v, size_t offset, bool mostSignificantByteFirst)
template <class T>
ByteVector fromNumber(T value, bool mostSignificantByteFirst)
{
const bool isBigEndian = (Utils::systemByteOrder() == Utils::BigEndian);
const bool isBigEndian = Utils::systemByteOrder() == Utils::BigEndian;
if(mostSignificantByteFirst != isBigEndian)
value = Utils::byteSwap(value);
@ -381,12 +381,12 @@ ByteVector &ByteVector::setData(const char *data)
char *ByteVector::data()
{
detach();
return !isEmpty() ? (&(*d->data)[d->offset]) : nullptr;
return !isEmpty() ? &(*d->data)[d->offset] : nullptr;
}
const char *ByteVector::data() const
{
return !isEmpty() ? (&(*d->data)[d->offset]) : nullptr;
return !isEmpty() ? &(*d->data)[d->offset] : nullptr;
}
ByteVector ByteVector::mid(unsigned int index, unsigned int length) const
@ -399,7 +399,7 @@ ByteVector ByteVector::mid(unsigned int index, unsigned int length) const
char ByteVector::at(unsigned int index) const
{
return (index < size()) ? (*d->data)[d->offset + index] : 0;
return index < size() ? (*d->data)[d->offset + index] : 0;
}
int ByteVector::find(const ByteVector &pattern, unsigned int offset, int byteAlign) const
@ -439,7 +439,7 @@ bool ByteVector::containsAt(const ByteVector &pattern, unsigned int offset, unsi
if(offset + compareLength > size() || patternOffset >= pattern.size() || patternLength == 0)
return false;
return (::memcmp(data() + offset, pattern.data() + patternOffset, compareLength) == 0);
return ::memcmp(data() + offset, pattern.data() + patternOffset, compareLength) == 0;
}
bool ByteVector::startsWith(const ByteVector &pattern) const
@ -653,7 +653,7 @@ ByteVector::ConstReverseIterator ByteVector::rend() const
bool ByteVector::isEmpty() const
{
return (d->length == 0);
return d->length == 0;
}
unsigned int ByteVector::toUInt(bool mostSignificantByteFirst) const
@ -757,7 +757,7 @@ bool ByteVector::operator==(const ByteVector &v) const
if(size() != v.size())
return false;
return (::memcmp(data(), v.data(), size()) == 0);
return ::memcmp(data(), v.data(), size()) == 0;
}
bool ByteVector::operator!=(const ByteVector &v) const
@ -770,7 +770,7 @@ bool ByteVector::operator==(const char *s) const
if(size() != ::strlen(s))
return false;
return (::memcmp(data(), s, size()) == 0);
return ::memcmp(data(), s, size()) == 0;
}
bool ByteVector::operator!=(const char *s) const
@ -788,7 +788,7 @@ bool ByteVector::operator<(const ByteVector &v) const
bool ByteVector::operator>(const ByteVector &v) const
{
return (v < *this);
return v < *this;
}
ByteVector ByteVector::operator+(const ByteVector &v) const
@ -833,7 +833,7 @@ ByteVector ByteVector::toHex() const
for(unsigned int i = 0; i < size(); i++) {
unsigned char c = data()[i];
*p++ = hexTable[(c >> 4) & 0x0F];
*p++ = hexTable[(c ) & 0x0F];
*p++ = hexTable[ c & 0x0F];
}
return encoded;

View File

@ -132,8 +132,6 @@ namespace TagLib {
ByteVector *data();
protected:
private:
class ByteVectorStreamPrivate;
TAGLIB_MSVC_SUPPRESS_WARNING_NEEDS_TO_HAVE_DLL_INTERFACE

View File

@ -176,7 +176,7 @@ offset_t File::find(const ByteVector &pattern, offset_t fromOffset, const ByteVe
// (1) previous partial match
if(previousPartialMatch >= 0 && static_cast<int>(bufferSize()) > previousPartialMatch) {
if(const int patternOffset = (bufferSize() - previousPartialMatch);
if(const int patternOffset = bufferSize() - previousPartialMatch;
buffer.containsAt(pattern, 0, patternOffset)) {
seek(originalPosition);
return bufferOffset - bufferSize() + previousPartialMatch;
@ -184,7 +184,7 @@ offset_t File::find(const ByteVector &pattern, offset_t fromOffset, const ByteVe
}
if(!before.isEmpty() && beforePreviousPartialMatch >= 0 && static_cast<int>(bufferSize()) > beforePreviousPartialMatch) {
if(const int beforeOffset = (bufferSize() - beforePreviousPartialMatch);
if(const int beforeOffset = bufferSize() - beforePreviousPartialMatch;
buffer.containsAt(before, 0, beforeOffset)) {
seek(originalPosition);
return -1;

View File

@ -357,7 +357,7 @@ bool FileStream::readOnly() const
bool FileStream::isOpen() const
{
return (d->file != InvalidFileHandle);
return d->file != InvalidFileHandle;
}
void FileStream::seek(offset_t offset, Position p)

View File

@ -142,12 +142,12 @@ bool PropertyMap::operator==(const PropertyMap &other) const
{
for(const auto &[property, val] : other) {
if(auto thisFind = find(property);
thisFind == end() || (thisFind->second != val))
thisFind == end() || thisFind->second != val)
return false;
}
for(const auto &[property, val] : *this) {
if(auto otherFind = other.find(property);
otherFind == other.end() || (otherFind->second != val))
otherFind == other.end() || otherFind->second != val)
return false;
}
return d->unsupported == other.d->unsupported;

View File

@ -117,7 +117,7 @@ namespace
length--;
}
else {
swap = (t != wcharByteOrder());
swap = t != wcharByteOrder();
}
data.resize(length);
@ -483,8 +483,8 @@ int String::toInt(bool *ok) const
// Has wcstol() consumed the entire string and not overflowed?
if(ok) {
*ok = (errno == 0 && endPtr > beginPtr && *endPtr == L'\0');
*ok = (*ok && value > INT_MIN && value < INT_MAX);
*ok = errno == 0 && endPtr > beginPtr && *endPtr == L'\0';
*ok = *ok && value > INT_MIN && value < INT_MAX;
}
return static_cast<int>(value);
@ -535,7 +535,7 @@ const wchar_t &String::operator[](int i) const
bool String::operator==(const String &s) const
{
return (d == s.d || d->data == s.d->data);
return d == s.d || d->data == s.d->data;
}
bool String::operator!=(const String &s) const
@ -561,7 +561,7 @@ bool String::operator!=(const char *s) const
bool String::operator==(const wchar_t *s) const
{
return (d->data == s);
return d->data == s;
}
bool String::operator!=(const wchar_t *s) const
@ -663,7 +663,7 @@ void String::swap(String &s) noexcept
bool String::operator<(const String &s) const
{
return (d->data < s.d->data);
return d->data < s.d->data;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -375,7 +375,7 @@ TagLib::Map<TagLib::String, TagLib::Variant> Variant::toMap(bool *ok) const
bool Variant::operator==(const Variant &v) const
{
return (d == v.d || d->data == v.d->data);
return d == v.d || d->data == v.d->data;
}
bool Variant::operator!=(const Variant &v) const

View File

@ -63,7 +63,7 @@ ByteVector zlib::decompress([[maybe_unused]] const ByteVector &data)
ByteVector inData = data;
stream.avail_in = static_cast<uInt>(inData.size());
stream.avail_in = inData.size();
stream.next_in = reinterpret_cast<Bytef *>(inData.data());
ByteVector outData;

View File

@ -71,7 +71,7 @@ bool TrueAudio::File::isSupported(IOStream *stream)
// A TrueAudio file has to start with "TTA". An ID3v2 tag may precede.
const ByteVector id = Utils::readHeader(stream, 3, true);
return (id == "TTA");
return id == "TTA";
}
////////////////////////////////////////////////////////////////////////////////
@ -168,7 +168,7 @@ bool TrueAudio::File::save()
insert(data, d->ID3v2Location, d->ID3v2OriginalSize);
if(d->ID3v1Location >= 0)
d->ID3v1Location += (static_cast<long>(data.size()) - d->ID3v2OriginalSize);
d->ID3v1Location += static_cast<long>(data.size()) - d->ID3v2OriginalSize;
d->ID3v2OriginalSize = data.size();
}
@ -241,12 +241,12 @@ void TrueAudio::File::strip(int tags)
bool TrueAudio::File::hasID3v1Tag() const
{
return (d->ID3v1Location >= 0);
return d->ID3v1Location >= 0;
}
bool TrueAudio::File::hasID3v2Tag() const
{
return (d->ID3v2Location >= 0);
return d->ID3v2Location >= 0;
}
////////////////////////////////////////////////////////////////////////////////
@ -287,7 +287,7 @@ void TrueAudio::File::read(bool readProperties)
if(d->ID3v2Location >= 0) {
seek(d->ID3v2Location + d->ID3v2OriginalSize);
streamLength -= (d->ID3v2Location + d->ID3v2OriginalSize);
streamLength -= d->ID3v2Location + d->ID3v2OriginalSize;
}
else {
seek(0);

View File

@ -66,7 +66,7 @@ bool WavPack::File::isSupported(IOStream *stream)
// A WavPack file has to start with "wvpk".
const ByteVector id = Utils::readHeader(stream, 4, false);
return (id == "wvpk");
return id == "wvpk";
}
////////////////////////////////////////////////////////////////////////////////
@ -169,7 +169,7 @@ bool WavPack::File::save()
insert(data, d->APELocation, d->APESize);
if(d->ID3v1Location >= 0)
d->ID3v1Location += (static_cast<long>(data.size()) - d->APESize);
d->ID3v1Location += static_cast<long>(data.size()) - d->APESize;
d->APESize = data.size();
}
@ -215,12 +215,12 @@ void WavPack::File::strip(int tags)
bool WavPack::File::hasID3v1Tag() const
{
return (d->ID3v1Location >= 0);
return d->ID3v1Location >= 0;
}
bool WavPack::File::hasAPETag() const
{
return (d->APELocation >= 0);
return d->APELocation >= 0;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -37,7 +37,7 @@
int main(int argc, char* argv[])
{
std::string testPath = (argc > 1) ? std::string(argv[1]) : "";
std::string testPath = argc > 1 ? std::string(argv[1]) : "";
// Create the event manager and test controller
CppUnit::TestResult controller;

View File

@ -63,7 +63,7 @@ public:
Map<String, int> m2 = m1;
auto it = m2.find("bob");
(*it).second = 99;
it->second = 99;
CPPUNIT_ASSERT_EQUAL(9, m1["bob"]);
CPPUNIT_ASSERT_EQUAL(99, m2["bob"]);
}

View File

@ -183,10 +183,10 @@ public:
Vorbis::File f(newname.c_str());
List<FLAC::Picture *> lst = f.tag()->pictureList();
CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(1), lst.size());
CPPUNIT_ASSERT_EQUAL(static_cast<int>(5), lst[0]->width());
CPPUNIT_ASSERT_EQUAL(static_cast<int>(6), lst[0]->height());
CPPUNIT_ASSERT_EQUAL(static_cast<int>(16), lst[0]->colorDepth());
CPPUNIT_ASSERT_EQUAL(static_cast<int>(7), lst[0]->numColors());
CPPUNIT_ASSERT_EQUAL(5, lst[0]->width());
CPPUNIT_ASSERT_EQUAL(6, lst[0]->height());
CPPUNIT_ASSERT_EQUAL(16, lst[0]->colorDepth());
CPPUNIT_ASSERT_EQUAL(7, lst[0]->numColors());
CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), lst[0]->mimeType());
CPPUNIT_ASSERT_EQUAL(String("new image"), lst[0]->description());
CPPUNIT_ASSERT_EQUAL(ByteVector("JPEG data"), lst[0]->data());