From a3241065c55fd2a69e8793b89a5d0b1a957b3fd0 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Tue, 10 Oct 2023 21:14:50 +0100 Subject: Start migrating to range-based for loops. --- include/anope.h | 8 ++++---- include/modules/httpd.h | 18 ++++++++---------- include/modules/ldap.h | 4 ++-- include/modules/redis.h | 4 ++-- include/modules/sql.h | 20 +++++++++++--------- include/version.cpp | 4 ++-- 6 files changed, 29 insertions(+), 29 deletions(-) (limited to 'include') diff --git a/include/anope.h b/include/anope.h index 121ea716c..22094cf1d 100644 --- a/include/anope.h +++ b/include/anope.h @@ -254,8 +254,8 @@ namespace Anope inline string lower() const { Anope::string new_string = *this; - for (size_type i = 0; i < new_string.length(); ++i) - new_string[i] = Anope::tolower(new_string[i]); + for (auto &chr : new_string) + chr = Anope::tolower(chr); return new_string; } @@ -265,8 +265,8 @@ namespace Anope inline string upper() const { Anope::string new_string = *this; - for (size_type i = 0; i < new_string.length(); ++i) - new_string[i] = Anope::toupper(new_string[i]); + for (auto &chr : new_string) + chr = Anope::toupper(chr); return new_string; } diff --git a/include/modules/httpd.h b/include/modules/httpd.h index 544ba5ccd..207499d3b 100644 --- a/include/modules/httpd.h +++ b/include/modules/httpd.h @@ -35,14 +35,14 @@ struct HTTPReply headers = other.headers; cookies = other.cookies; - for (unsigned i = 0; i < other.out.size(); ++i) - out.push_back(new Data(other.out[i]->buf, other.out[i]->len)); + for (const auto &datum : other.out) + out.push_back(new Data(datum->buf, datum->len)); } ~HTTPReply() { - for (unsigned i = 0; i < out.size(); ++i) - delete out[i]; + for (const auto *datum : out) + delete datum; out.clear(); } @@ -196,10 +196,8 @@ namespace HTTPUtils { Anope::string encoded; - for (unsigned i = 0; i < url.length(); ++i) + for (const auto c : url) { - const char& c = url[i]; - if (isalnum(c) || c == '.' || c == '-' || c == '*' || c == '_') encoded += c; else if (c == ' ') @@ -215,9 +213,9 @@ namespace HTTPUtils { Anope::string dst; - for (unsigned i = 0; i < src.length(); ++i) + for (const auto c : src) { - switch (src[i]) + switch (c) { case '<': dst += "<"; @@ -232,7 +230,7 @@ namespace HTTPUtils dst += "&"; break; default: - dst += src[i]; + dst += c; } } diff --git a/include/modules/ldap.h b/include/modules/ldap.h index 8c448668e..34f73f65b 100644 --- a/include/modules/ldap.h +++ b/include/modules/ldap.h @@ -42,8 +42,8 @@ struct LDAPAttributes : public std::map keys() const { std::vector k; - for (const_iterator it = this->begin(), it_end = this->end(); it != it_end; ++it) - k.push_back(it->first); + for (const auto &[key, _] : *this) + k.push_back(key); return k; } diff --git a/include/modules/redis.h b/include/modules/redis.h index d953757f0..f30311f34 100644 --- a/include/modules/redis.h +++ b/include/modules/redis.h @@ -32,8 +32,8 @@ namespace Redis i = 0; bulk.clear(); multi_bulk_size = 0; - for (unsigned j = 0; j < multi_bulk.size(); ++j) - delete multi_bulk[j]; + for (const auto *reply : multi_bulk) + delete reply; multi_bulk.clear(); } diff --git a/include/modules/sql.h b/include/modules/sql.h index ff441302b..607f8bcd9 100644 --- a/include/modules/sql.h +++ b/include/modules/sql.h @@ -34,32 +34,34 @@ namespace SQL std::set KeySet() const override { std::set keys; - for (Map::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it) - keys.insert(it->first); + for (const auto &[key, _] : this->data) + keys.insert(key); return keys; } size_t Hash() const override { size_t hash = 0; - for (Map::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it) - if (!it->second->str().empty()) - hash ^= Anope::hash_cs()(it->second->str()); + for (const auto &[_, value] : this->data) + { + if (!value->str().empty()) + hash ^= Anope::hash_cs()(value->str()); + } return hash; } std::map GetData() const { std::map d; - for (Map::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it) - d[it->first] = it->second; + for (const auto &[key, value] : this->data) + d[key] = value; return d; } void Clear() { - for (Map::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it) - delete it->second; + for (const auto &[_, value] : this->data) + delete value; this->data.clear(); } diff --git a/include/version.cpp b/include/version.cpp index 164e07756..9cb16d78e 100644 --- a/include/version.cpp +++ b/include/version.cpp @@ -146,9 +146,9 @@ static bool write_version_h(const std::string &versionh, const std::map::const_iterator it = versions.begin(); it != versions.end(); ++it) + for (const auto &[key, value] : versions) { - fd << "#define " << it->first << " " << it->second << std::endl; + fd << "#define " << key << " " << value << std::endl; } fd.close(); -- cgit