Inspection: Variable can be moved to init statement

This commit is contained in:
Urs Fleisch
2024-01-20 18:06:51 +01:00
parent 5d921c6325
commit dfe2aa5253
40 changed files with 149 additions and 220 deletions

View File

@ -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.");

View File

@ -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());

View File

@ -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());

View File

@ -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);

View File

@ -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) + ')';

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);
}
}