Use std algorithms (#1107)

Found with: readability-use-anyofallof

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev 2023-08-09 10:09:28 -07:00 committed by GitHub
parent f2d0e664e7
commit 574604765f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 20 additions and 82 deletions

View File

@ -65,13 +65,7 @@ namespace
return false;
}
const String upperKey = String(key).upper();
for(auto k : invalidKeys) {
if(upperKey == k)
return false;
}
return true;
return std::none_of(invalidKeys.begin(), invalidKeys.end(), [upperKey = String(key).upper()](auto k) { return upperKey == k; });
}
} // namespace

View File

@ -97,19 +97,12 @@ MP4::Atom::Atom(File *file)
if(name == c) {
if(name == "meta") {
offset_t posAfterMeta = file->tell();
ByteVector nextSize = file->readBlock(8).mid(4, 4);
static constexpr std::array metaChildrenNames {
"hdlr", "ilst", "mhdr", "ctry", "lang"
};
bool metaIsFullAtom = true;
for(auto child : metaChildrenNames) {
if(nextSize == child) {
// meta is not a full atom (i.e. not followed by version, flags). It
// is followed by the size and type of the first child atom.
metaIsFullAtom = false;
break;
}
}
// meta is not a full atom (i.e. not followed by version, flags). It
// is followed by the size and type of the first child atom.
auto metaIsFullAtom = std::none_of(metaChildrenNames.begin(), metaChildrenNames.end(), [nextSize = file->readBlock(8).mid(4, 4)](const auto &child) { return nextSize == child; });
// Only skip next four bytes, which contain version and flags, if meta
// is a full atom.
file->seek(posAfterMeta + (metaIsFullAtom ? 4 : 0));

View File

@ -36,16 +36,7 @@ namespace
{
bool checkValid(const MP4::AtomList &list)
{
for(auto it = list.begin(); it != list.end(); ++it) {
if((*it)->length == 0)
return false;
if(!checkValid((*it)->children))
return false;
}
return true;
return std::none_of(list.begin(), list.end(), [](const auto &a) { return a->length == 0 || !checkValid(a->children); });
}
} // namespace

View File

@ -294,14 +294,11 @@ PropertyMap TextIdentificationFrame::makeTIPLProperties() const
}
const StringList l = fieldList();
for(auto it = l.begin(); it != l.end(); ++it) {
bool found = false;
for(const auto &[o, t] : involvedPeople)
if(*it == o) {
map.insert(t, (++it)->split(","));
found = true;
break;
}
if(!found){
auto found = std::find_if(involvedPeople.begin(), involvedPeople.end(), [=](const auto &person) { return *it == person.first; });
if(found != involvedPeople.end()) {
map.insert(found->second, (++it)->split(","));
}
else {
// invalid involved role -> mark whole frame as unsupported in order to be consistent with writing
map.clear();
map.unsupportedData().append(frameID());

View File

@ -72,12 +72,7 @@ namespace
if(frameID.size() != 4)
return false;
for(auto it = frameID.begin(); it != frameID.end(); it++) {
if( (*it < 'A' || *it > 'Z') && (*it < '0' || *it > '9') ) {
return false;
}
}
return true;
return std::none_of(frameID.begin(), frameID.end(), [](auto c) { return (c < 'A' || c > 'Z') && (c < '0' || c > '9'); });
}
} // namespace

View File

@ -147,11 +147,9 @@ std::pair<Frame::Header *, bool> FrameFactory::prepareFrameHeader(
}
#endif
for(auto it = frameID.cbegin(); it != frameID.cend(); it++) {
if( (*it < 'A' || *it > 'Z') && (*it < '0' || *it > '9') ) {
delete header;
return {nullptr, false};
}
if(std::any_of(frameID.begin(), frameID.end(), [](auto c) { return (c < 'A' || c > 'Z') && (c < '0' || c > '9'); })) {
delete header;
return { nullptr, false };
}
if(version > 3 && (tagHeader->unsynchronisation() || header->unsynchronisation())) {

View File

@ -189,12 +189,7 @@ void Ogg::XiphComment::setTrack(unsigned int i)
bool Ogg::XiphComment::isEmpty() const
{
for(auto it = d->fieldListMap.cbegin(); it != d->fieldListMap.cend(); ++it) {
if(!(*it).second.isEmpty())
return false;
}
return true;
return std::all_of(d->fieldListMap.begin(), d->fieldListMap.end(), [](const auto &field) { return field.second.isEmpty(); });
}
unsigned int Ogg::XiphComment::fieldCount() const
@ -261,12 +256,7 @@ bool Ogg::XiphComment::checkKey(const String &key)
// A key may consist of ASCII 0x20 through 0x7D, 0x3D ('=') excluded.
for(String::ConstIterator it = key.begin(); it != key.end(); it++) {
if(*it < 0x20 || *it > 0x7D || *it == 0x3D)
return false;
}
return true;
return std::none_of(key.begin(), key.end(), [](auto c) { return c < 0x20 || c > 0x7D || c == 0x3D; });
}
String Ogg::XiphComment::vendorID() const

View File

@ -44,13 +44,7 @@ namespace TagLib
if(name.size() != 4)
return false;
for(auto it = name.begin(); it != name.end(); ++it) {
const int c = static_cast<unsigned char>(*it);
if(c < 32 || 127 < c)
return false;
}
return true;
return std::none_of(name.begin(), name.end(), [](unsigned char c) { return c < 32 || 127 < c; });
}
} // namespace

View File

@ -95,13 +95,7 @@ bool PropertyMap::contains(const String &key) const
bool PropertyMap::contains(const PropertyMap &other) const
{
for(auto it = other.begin(); it != other.end(); ++it) {
if(!SimplePropertyMap::contains(it->first))
return false;
if ((*this)[it->first] != it->second)
return false;
}
return true;
return std::all_of(other.begin(), other.end(), [this](const auto &o) { return contains(o.first) && (*this)[o.first] == o.second; });
}
PropertyMap &PropertyMap::erase(const String &key)

View File

@ -510,20 +510,12 @@ String String::stripWhiteSpace() const
bool String::isLatin1() const
{
for(ConstIterator it = begin(); it != end(); ++it) {
if(*it >= 256)
return false;
}
return true;
return std::none_of(this->begin(), this->end(), [](auto c) { return c >= 256; });
}
bool String::isAscii() const
{
for(ConstIterator it = begin(); it != end(); ++it) {
if(*it >= 128)
return false;
}
return true;
return std::none_of(this->begin(), this->end(), [](auto c) { return c >= 128; });
}
String String::number(int n) // static