Narrow the scope of iterators

Also make sure that it is visible at first glance that iterators are
not taken from temporaries.
This commit is contained in:
Urs Fleisch 2023-07-16 06:41:53 +02:00
parent c2c9e8989c
commit 77ab5e9689
17 changed files with 44 additions and 80 deletions

View File

@ -65,8 +65,8 @@ int main(int argc, char *argv[])
<< " bytes in tag"
<< endl;
auto it = id3v2tag->frameList().begin();
for(; it != id3v2tag->frameList().end(); it++) {
const auto &frames = id3v2tag->frameList();
for(auto it = frames.begin(); it != frames.end(); it++) {
cout << (*it)->frameID();
if(auto comment = dynamic_cast<ID3v2::CommentsFrame *>(*it))
@ -100,8 +100,8 @@ int main(int argc, char *argv[])
cout << endl << "APE" << endl;
if(ape) {
for(auto it = ape->itemListMap().begin();
it != ape->itemListMap().end(); ++it)
const auto &items = ape->itemListMap();
for(auto it = items.begin(); it != items.end(); ++it)
{
if((*it).second.type() != APE::Item::Binary)
cout << (*it).first << " - \"" << (*it).second.toString() << "\"" << endl;

View File

@ -217,8 +217,8 @@ namespace
PropertyMap APE::Tag::properties() const
{
PropertyMap properties;
auto it = itemListMap().begin();
for(; it != itemListMap().end(); ++it) {
const auto &items = itemListMap();
for(auto it = items.begin(); it != items.end(); ++it) {
String tagName = it->first.upper();
// if the item is Binary or Locator, or if the key is an invalid string,
// add to unsupportedData
@ -239,8 +239,7 @@ PropertyMap APE::Tag::properties() const
void APE::Tag::removeUnsupportedProperties(const StringList &properties)
{
auto it = properties.begin();
for(; it != properties.end(); ++it)
for(auto it = properties.begin(); it != properties.end(); ++it)
removeItem(*it);
}
@ -257,8 +256,8 @@ PropertyMap APE::Tag::setProperties(const PropertyMap &origProps)
// first check if tags need to be removed completely
StringList toRemove;
auto remIt = itemListMap().begin();
for(; remIt != itemListMap().end(); ++remIt) {
const auto &items = itemListMap();
for(auto remIt = items.begin(); remIt != items.end(); ++remIt) {
String key = remIt->first.upper();
// only remove if a) key is valid, b) type is text, c) key not contained in new properties
if(!key.isEmpty() && remIt->second.type() == APE::Item::Text && !properties.contains(key))
@ -269,9 +268,8 @@ PropertyMap APE::Tag::setProperties(const PropertyMap &origProps)
removeItem(*removeIt);
// now sync in the "forward direction"
auto it = properties.cbegin();
PropertyMap invalid;
for(; it != properties.cend(); ++it) {
for(auto it = properties.begin(); it != properties.cend(); ++it) {
const String &tagName = it->first;
if(!checkKey(tagName))
invalid.insert(it->first, it->second);

View File

@ -287,12 +287,10 @@ PropertyMap ASF::Tag::properties() const
props["COMMENT"] = d->comment;
}
auto it = d->attributeListMap.cbegin();
for(; it != d->attributeListMap.cend(); ++it) {
for(auto it = d->attributeListMap.cbegin(); it != d->attributeListMap.cend(); ++it) {
const String key = translateKey(it->first);
if(!key.isEmpty()) {
auto it2 = it->second.begin();
for(; it2 != it->second.end(); ++it2) {
for(auto it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
if(key == "TRACKNUMBER") {
if(it2->type() == ASF::Attribute::DWordType)
props.insert(key, String::number(it2->toUInt()));
@ -313,8 +311,7 @@ PropertyMap ASF::Tag::properties() const
void ASF::Tag::removeUnsupportedProperties(const StringList &props)
{
auto it = props.begin();
for(; it != props.end(); ++it)
for(auto it = props.begin(); it != props.end(); ++it)
d->attributeListMap.erase(*it);
}
@ -355,8 +352,7 @@ PropertyMap ASF::Tag::setProperties(const PropertyMap &props)
if(reverseKeyMap.contains(it->first)) {
String name = reverseKeyMap[it->first];
removeItem(name);
auto it2 = it->second.begin();
for(; it2 != it->second.end(); ++it2) {
for(auto it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
addAttribute(name, *it2);
}
}

View File

@ -74,8 +74,7 @@ namespace
if(::strlen(fileName) == 0)
return nullptr;
#endif
auto it = fileTypeResolvers.cbegin();
for(; it != fileTypeResolvers.cend(); ++it) {
for(auto it = fileTypeResolvers.cbegin(); it != fileTypeResolvers.cend(); ++it) {
File *file = (*it)->createFile(fileName, readAudioProperties, audioPropertiesStyle);
if(file)
return file;
@ -87,10 +86,8 @@ namespace
File *detectByResolvers(IOStream* stream, bool readAudioProperties,
AudioProperties::ReadStyle audioPropertiesStyle)
{
for(auto it = fileTypeResolvers.cbegin();
it != fileTypeResolvers.cend(); ++it) {
if(auto streamResolver =
dynamic_cast<const FileRef::StreamTypeResolver*>(*it)) {
for(auto it = fileTypeResolvers.cbegin(); it != fileTypeResolvers.cend(); ++it) {
if(auto streamResolver = dynamic_cast<const FileRef::StreamTypeResolver*>(*it)) {
if(File *file = streamResolver->createFileFromStream(
stream, readAudioProperties, audioPropertiesStyle))
return file;

View File

@ -85,8 +85,7 @@ ChapterFrame::ChapterFrame(const ByteVector &elementID,
d->startOffset = startOffset;
d->endOffset = endOffset;
for(auto it = embeddedFrames.begin();
it != embeddedFrames.end(); ++it)
for(auto it = embeddedFrames.begin(); it != embeddedFrames.end(); ++it)
addEmbeddedFrame(*it);
}
@ -205,8 +204,7 @@ String ChapterFrame::toString() const
if(!d->embeddedFrameList.isEmpty()) {
StringList frameIDs;
for(auto it = d->embeddedFrameList.cbegin();
it != d->embeddedFrameList.cend(); ++it)
for(auto it = d->embeddedFrameList.cbegin(); it != d->embeddedFrameList.cend(); ++it)
frameIDs.append((*it)->frameID());
s += ", sub-frames: [ " + frameIDs.toString(", ") + " ]";
}

View File

@ -127,9 +127,7 @@ CommentsFrame *CommentsFrame::findByDescription(const ID3v2::Tag *tag, const Str
{
const ID3v2::FrameList comments = tag->frameList("COMM");
for(auto it = comments.begin();
it != comments.end();
++it)
for(auto it = comments.begin(); it != comments.end(); ++it)
{
auto frame = dynamic_cast<CommentsFrame *>(*it);
if(frame && frame->description() == d)

View File

@ -121,9 +121,7 @@ ByteVector EventTimingCodesFrame::renderFields() const
ByteVector v;
v.append(static_cast<char>(d->timestampFormat));
for(auto it = d->synchedEvents.cbegin();
it != d->synchedEvents.cend();
++it) {
for(auto it = d->synchedEvents.cbegin(); it != d->synchedEvents.cend(); ++it) {
const SynchedEvent &entry = *it;
v.append(static_cast<char>(entry.type));
v.append(ByteVector::fromUInt(entry.time));

View File

@ -78,8 +78,7 @@ List<RelativeVolumeFrame::ChannelType> RelativeVolumeFrame::channels() const
{
List<ChannelType> l;
auto it = d->channels.cbegin();
for(; it != d->channels.cend(); ++it)
for(auto it = d->channels.cbegin(); it != d->channels.cend(); ++it)
l.append((*it).first);
return l;
@ -162,9 +161,7 @@ ByteVector RelativeVolumeFrame::renderFields() const
data.append(d->identification.data(String::Latin1));
data.append(textDelimiter(String::Latin1));
auto it = d->channels.cbegin();
for(; it != d->channels.cend(); ++it) {
for(auto it = d->channels.cbegin(); it != d->channels.cend(); ++it) {
ChannelType type = (*it).first;
const ChannelData &channel = (*it).second;

View File

@ -218,9 +218,7 @@ ByteVector SynchronizedLyricsFrame::renderFields() const
v.append(static_cast<char>(d->type));
v.append(d->description.data(encoding));
v.append(textDelimiter(encoding));
for(auto it = d->synchedText.cbegin();
it != d->synchedText.cend();
++it) {
for(auto it = d->synchedText.cbegin(); it != d->synchedText.cend(); ++it) {
const SynchedText &entry = *it;
v.append(entry.text.data(encoding));
v.append(textDelimiter(encoding));

View File

@ -230,8 +230,7 @@ String TableOfContentsFrame::toString() const
if(!d->embeddedFrameList.isEmpty()) {
StringList frameIDs;
for(auto it = d->embeddedFrameList.cbegin();
it != d->embeddedFrameList.cend(); ++it)
for(auto it = d->embeddedFrameList.cbegin(); it != d->embeddedFrameList.cend(); ++it)
frameIDs.append((*it)->frameID());
s += ", sub-frames: [ " + frameIDs.toString(", ") + " ]";
}
@ -269,9 +268,7 @@ TableOfContentsFrame *TableOfContentsFrame::findTopLevel(const ID3v2::Tag *tag)
{
const ID3v2::FrameList tablesOfContents = tag->frameList("CTOC");
for(auto it = tablesOfContents.begin();
it != tablesOfContents.end();
++it)
for(auto it = tablesOfContents.begin(); it != tablesOfContents.end(); ++it)
{
auto frame = dynamic_cast<TableOfContentsFrame *>(*it);
if(frame && frame->isTopLevel())

View File

@ -105,9 +105,7 @@ UniqueFileIdentifierFrame *UniqueFileIdentifierFrame::findByOwner(const ID3v2::T
{
const ID3v2::FrameList comments = tag->frameList("UFID");
for(auto it = comments.begin();
it != comments.end();
++it)
for(auto it = comments.begin(); it != comments.end(); ++it)
{
auto frame = dynamic_cast<UniqueFileIdentifierFrame *>(*it);
if(frame && frame->owner() == o)

View File

@ -386,7 +386,8 @@ void ID3v2::Tag::removeFrames(const ByteVector &id)
PropertyMap ID3v2::Tag::properties() const
{
PropertyMap properties;
for(auto it = frameList().begin(); it != frameList().end(); ++it) {
const auto &frames = frameList();
for(auto it = frames.begin(); it != frames.end(); ++it) {
PropertyMap props = (*it)->asProperties();
properties.merge(props);
}
@ -442,7 +443,8 @@ PropertyMap ID3v2::Tag::setProperties(const PropertyMap &origProps)
PropertyMap tiplProperties;
PropertyMap tmclProperties;
Frame::splitProperties(origProps, properties, tiplProperties, tmclProperties);
for(auto it = frameListMap().begin(); it != frameListMap().end(); ++it){
const auto &frames = frameListMap();
for(auto it = frames.begin(); it != frames.end(); ++it){
for(auto lit = it->second.begin(); lit != it->second.end(); ++lit){
PropertyMap frameProperties = (*lit)->asProperties();
if(it->first == "TIPL") {
@ -531,8 +533,7 @@ void ID3v2::Tag::downgradeFrames(FrameList *frames, FrameList *newFrames) const
String content = frameTDOR->toString();
if(content.size() >= 4) {
auto frameTORY =
new ID3v2::TextIdentificationFrame("TORY", String::Latin1);
auto frameTORY = new ID3v2::TextIdentificationFrame("TORY", String::Latin1);
frameTORY->setText(content.substr(0, 4));
frames->append(frameTORY);
newFrames->append(frameTORY);
@ -542,20 +543,17 @@ void ID3v2::Tag::downgradeFrames(FrameList *frames, FrameList *newFrames) const
if(frameTDRC) {
String content = frameTDRC->toString();
if(content.size() >= 4) {
auto frameTYER =
new ID3v2::TextIdentificationFrame("TYER", String::Latin1);
auto frameTYER = new ID3v2::TextIdentificationFrame("TYER", String::Latin1);
frameTYER->setText(content.substr(0, 4));
frames->append(frameTYER);
newFrames->append(frameTYER);
if(content.size() >= 10 && content[4] == '-' && content[7] == '-') {
auto frameTDAT =
new ID3v2::TextIdentificationFrame("TDAT", String::Latin1);
auto frameTDAT = new ID3v2::TextIdentificationFrame("TDAT", String::Latin1);
frameTDAT->setText(content.substr(8, 2) + content.substr(5, 2));
frames->append(frameTDAT);
newFrames->append(frameTDAT);
if(content.size() >= 16 && content[10] == 'T' && content[13] == ':') {
auto frameTIME =
new ID3v2::TextIdentificationFrame("TIME", String::Latin1);
auto frameTIME = new ID3v2::TextIdentificationFrame("TIME", String::Latin1);
frameTIME->setText(content.substr(11, 2) + content.substr(14, 2));
frames->append(frameTIME);
newFrames->append(frameTIME);
@ -565,8 +563,7 @@ void ID3v2::Tag::downgradeFrames(FrameList *frames, FrameList *newFrames) const
}
if(frameTIPL || frameTMCL) {
auto frameIPLS =
new ID3v2::TextIdentificationFrame("IPLS", String::Latin1);
auto frameIPLS = new ID3v2::TextIdentificationFrame("IPLS", String::Latin1);
StringList people;

View File

@ -213,8 +213,7 @@ ByteVectorList Ogg::Page::packets() const
const List<int> packetSizes = d->header.packetSizes();
auto it = packetSizes.begin();
for(; it != packetSizes.end(); ++it)
for(auto it = packetSizes.begin(); it != packetSizes.end(); ++it)
l.append(d->file->readBlock(*it));
}
else
@ -243,8 +242,7 @@ ByteVector Ogg::Page::render() const
debug("Ogg::Page::render() -- this page is empty!");
}
else {
auto it = d->packets.cbegin();
for(; it != d->packets.cend(); ++it)
for(auto it = d->packets.cbegin(); it != d->packets.cend(); ++it)
data.append(*it);
}

View File

@ -234,8 +234,7 @@ PropertyMap Ogg::XiphComment::setProperties(const PropertyMap &properties)
// now go through keys in \a properties and check that the values match those in the xiph comment
PropertyMap invalid;
auto it = properties.begin();
for(; it != properties.end(); ++it)
for(auto it = properties.begin(); it != properties.end(); ++it)
{
if(!checkKey(it->first))
invalid.insert(it->first, it->second);
@ -366,16 +365,14 @@ ByteVector Ogg::XiphComment::render(bool addFramingBit) const
// std::pair<String, StringList> where the first String is the field name and
// the StringList is the values associated with that field.
auto it = d->fieldListMap.cbegin();
for(; it != d->fieldListMap.cend(); ++it) {
for(auto it = d->fieldListMap.cbegin(); it != d->fieldListMap.cend(); ++it) {
// And now iterate over the values of the current list.
String fieldName = (*it).first;
const StringList values = (*it).second;
auto valuesIt = values.begin();
for(; valuesIt != values.end(); ++valuesIt) {
for(auto valuesIt = values.begin(); valuesIt != values.end(); ++valuesIt) {
ByteVector fieldData = fieldName.data(String::UTF8);
fieldData.append('=');
fieldData.append((*valuesIt).data(String::UTF8));

View File

@ -201,8 +201,7 @@ ByteVector RIFF::Info::Tag::render() const
{
ByteVector data("INFO");
auto it = d->fieldListMap.cbegin();
for(; it != d->fieldListMap.cend(); ++it) {
for(auto it = d->fieldListMap.cbegin(); it != d->fieldListMap.cend(); ++it) {
ByteVector text = stringHandler->render(it->second);
if(text.isEmpty())
continue;

View File

@ -74,8 +74,7 @@ public:
}
void clear() {
if(autoDelete) {
auto it = list.begin();
for(; it != list.end(); ++it)
for(auto it = list.begin(); it != list.end(); ++it)
delete *it;
}
list.clear();

View File

@ -72,8 +72,7 @@ StringList::StringList(const String &s)
StringList::StringList(const ByteVectorList &bl, String::Type t)
{
auto i = bl.begin();
for(;i != bl.end(); i++) {
for(auto i = bl.begin(); i != bl.end(); i++) {
append(String(*i, t));
}
}