clang-tidy: Use auto where it improves the readability

run-clang-tidy -header-filter='.*' -checks='-*,modernize-use-auto' \
-config="{CheckOptions: [{key: modernize-use-auto.RemoveStars, value: '1'}]}" \
-fix

Manually fixed some wrong `const auto` replacements and verified
that all types are deduced correctly.
This commit is contained in:
Urs Fleisch
2023-07-16 06:13:34 +02:00
parent 63922f2676
commit c2c9e8989c
57 changed files with 289 additions and 299 deletions

View File

@ -95,7 +95,7 @@ ByteVector Ogg::File::packet(unsigned int i)
// Look for the first page in which the requested packet starts.
List<Page *>::ConstIterator it = d->pages.cbegin();
auto it = d->pages.cbegin();
while((*it)->containsPacket(i) == Page::DoesNotContainPacket)
++it;
@ -213,7 +213,7 @@ bool Ogg::File::readPages(unsigned int i)
// Read the next page and add it to the page list.
Page *nextPage = new Page(this, offset);
auto nextPage = new Page(this, offset);
if(!nextPage->header()->isValid()) {
delete nextPage;
return false;
@ -236,7 +236,7 @@ void Ogg::File::writePacket(unsigned int i, const ByteVector &packet)
// Look for the pages where the requested packet should belong to.
List<Page *>::ConstIterator it = d->pages.cbegin();
auto it = d->pages.cbegin();
while((*it)->containsPacket(i) == Page::DoesNotContainPacket)
++it;

View File

@ -90,7 +90,7 @@ unsigned int pageChecksum(const ByteVector &data)
};
unsigned int sum = 0;
for(ByteVector::ConstIterator it = data.begin(); it != data.end(); ++it)
for(auto it = data.begin(); it != data.end(); ++it)
sum = (sum << 8) ^ crcTable[((sum >> 24) & 0xff) ^ static_cast<unsigned char>(*it)];
return sum;
}
@ -213,7 +213,7 @@ ByteVectorList Ogg::Page::packets() const
const List<int> packetSizes = d->header.packetSizes();
List<int>::ConstIterator it = packetSizes.begin();
auto it = packetSizes.begin();
for(; it != packetSizes.end(); ++it)
l.append(d->file->readBlock(*it));
}
@ -243,7 +243,7 @@ ByteVector Ogg::Page::render() const
debug("Ogg::Page::render() -- this page is empty!");
}
else {
ByteVectorList::ConstIterator it = d->packets.cbegin();
auto it = d->packets.cbegin();
for(; it != d->packets.cend(); ++it)
data.append(*it);
}
@ -276,7 +276,7 @@ List<Ogg::Page *> Ogg::Page::paginate(const ByteVectorList &packets,
if(strategy != Repaginate) {
size_t tableSize = 0;
for(ByteVectorList::ConstIterator it = packets.begin(); it != packets.end(); ++it)
for(auto it = packets.begin(); it != packets.end(); ++it)
tableSize += it->size() / 255 + 1;
if(tableSize > 255)
@ -291,7 +291,7 @@ List<Ogg::Page *> Ogg::Page::paginate(const ByteVectorList &packets,
int pageIndex = firstPage;
for(ByteVectorList::ConstIterator it = packets.begin(); it != packets.end(); ++it) {
for(auto it = packets.begin(); it != packets.end(); ++it) {
const bool lastPacketInList = (it == --packets.end());
@ -356,7 +356,7 @@ Ogg::Page::Page(const ByteVectorList &packets,
ByteVector data;
List<int> packetSizes;
for(ByteVectorList::ConstIterator it = packets.begin(); it != packets.end(); ++it) {
for(auto it = packets.begin(); it != packets.end(); ++it) {
packetSizes.append((*it).size());
data.append(*it);
}

View File

@ -295,7 +295,7 @@ ByteVector Ogg::PageHeader::lacingValues() const
{
ByteVector data;
for(List<int>::ConstIterator it = d->packetSizes.cbegin(); it != d->packetSizes.cend(); ++it) {
for(auto it = d->packetSizes.cbegin(); it != d->packetSizes.cend(); ++it) {
// The size of a packet in an Ogg page is indicated by a series of "lacing
// values" where the sum of the values is the packet size in bytes. Each of

View File

@ -191,7 +191,7 @@ void Ogg::XiphComment::setTrack(unsigned int i)
bool Ogg::XiphComment::isEmpty() const
{
for(FieldConstIterator it = d->fieldListMap.cbegin(); it != d->fieldListMap.cend(); ++it) {
for(auto it = d->fieldListMap.cbegin(); it != d->fieldListMap.cend(); ++it) {
if(!(*it).second.isEmpty())
return false;
}
@ -203,7 +203,7 @@ unsigned int Ogg::XiphComment::fieldCount() const
{
unsigned int count = 0;
for(FieldConstIterator it = d->fieldListMap.cbegin(); it != d->fieldListMap.cend(); ++it)
for(auto it = d->fieldListMap.cbegin(); it != d->fieldListMap.cend(); ++it)
count += (*it).second.size();
count += d->pictureList.size();
@ -225,16 +225,16 @@ PropertyMap Ogg::XiphComment::setProperties(const PropertyMap &properties)
{
// check which keys are to be deleted
StringList toRemove;
for(FieldConstIterator it = d->fieldListMap.cbegin(); it != d->fieldListMap.cend(); ++it)
for(auto it = d->fieldListMap.cbegin(); it != d->fieldListMap.cend(); ++it)
if (!properties.contains(it->first))
toRemove.append(it->first);
for(StringList::ConstIterator it = toRemove.cbegin(); it != toRemove.cend(); ++it)
for(auto it = toRemove.cbegin(); it != toRemove.cend(); ++it)
removeFields(*it);
// now go through keys in \a properties and check that the values match those in the xiph comment
PropertyMap invalid;
PropertyMap::ConstIterator it = properties.begin();
auto it = properties.begin();
for(; it != properties.end(); ++it)
{
if(!checkKey(it->first))
@ -246,7 +246,7 @@ PropertyMap Ogg::XiphComment::setProperties(const PropertyMap &properties)
removeFields(it->first);
else {
// replace all strings in the list for the tag
StringList::ConstIterator valueIterator = sl.begin();
auto valueIterator = sl.begin();
addField(it->first, *valueIterator, true);
++valueIterator;
for(; valueIterator != sl.end(); ++valueIterator)
@ -301,7 +301,7 @@ void Ogg::XiphComment::removeFields(const String &key)
void Ogg::XiphComment::removeFields(const String &key, const String &value)
{
StringList &fields = d->fieldListMap[key.upper()];
for(StringList::Iterator it = fields.begin(); it != fields.end(); ) {
for(auto it = fields.begin(); it != fields.end(); ) {
if(*it == value)
it = fields.erase(it);
else
@ -321,7 +321,7 @@ bool Ogg::XiphComment::contains(const String &key) const
void Ogg::XiphComment::removePicture(FLAC::Picture *picture, bool del)
{
PictureIterator it = d->pictureList.find(picture);
auto it = d->pictureList.find(picture);
if(it != d->pictureList.end())
d->pictureList.erase(it);
@ -366,7 +366,7 @@ 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.
FieldListMap::ConstIterator it = d->fieldListMap.cbegin();
auto it = d->fieldListMap.cbegin();
for(; it != d->fieldListMap.cend(); ++it) {
// And now iterate over the values of the current list.
@ -374,7 +374,7 @@ ByteVector Ogg::XiphComment::render(bool addFramingBit) const
String fieldName = (*it).first;
const StringList values = (*it).second;
StringList::ConstIterator valuesIt = values.begin();
auto valuesIt = values.begin();
for(; valuesIt != values.end(); ++valuesIt) {
ByteVector fieldData = fieldName.data(String::UTF8);
fieldData.append('=');
@ -385,7 +385,7 @@ ByteVector Ogg::XiphComment::render(bool addFramingBit) const
}
}
for(PictureConstIterator it = d->pictureList.cbegin(); it != d->pictureList.cend(); ++it) {
for(auto it = d->pictureList.cbegin(); it != d->pictureList.cend(); ++it) {
ByteVector picture = (*it)->render().toBase64();
data.append(ByteVector::fromUInt(picture.size() + 23, false));
data.append("METADATA_BLOCK_PICTURE=");
@ -472,7 +472,7 @@ void Ogg::XiphComment::parse(const ByteVector &data)
// Decode FLAC Picture
FLAC::Picture * picture = new FLAC::Picture();
auto picture = new FLAC::Picture();
if(picture->parse(picturedata)) {
d->pictureList.append(picture);
}
@ -485,7 +485,7 @@ void Ogg::XiphComment::parse(const ByteVector &data)
// Assume it's some type of image file
FLAC::Picture * picture = new FLAC::Picture();
auto picture = new FLAC::Picture();
picture->setData(picturedata);
picture->setMimeType("image/");
picture->setType(FLAC::Picture::Other);