diff options
146 files changed, 1155 insertions, 1457 deletions
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<Anope::string, std::vector<Anope::string const std::vector<Anope::string> keys() const { std::vector<Anope::string> 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<Anope::string> KeySet() const override { std::set<Anope::string> 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<Anope::string, std::iostream *> GetData() const { std::map<Anope::string, std::iostream *> 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<std::str return false; fd << "#pragma once" << std::endl; - for (std::map<std::string, std::string>::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(); diff --git a/modules/commands/bs_badwords.cpp b/modules/commands/bs_badwords.cpp index 5f14a2eb6..72e8c60f3 100644 --- a/modules/commands/bs_badwords.cpp +++ b/modules/commands/bs_badwords.cpp @@ -251,8 +251,8 @@ class CommandBSBadwords : public Command source.Reply(_("Bad words list for %s:"), ci->name.c_str()); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("End of bad words list.")); } diff --git a/modules/commands/bs_botlist.cpp b/modules/commands/bs_botlist.cpp index d47a98f4d..b124aa2ce 100644 --- a/modules/commands/bs_botlist.cpp +++ b/modules/commands/bs_botlist.cpp @@ -26,10 +26,8 @@ class CommandBSBotList : public Command list.AddColumn(_("Nick")).AddColumn(_("Mask")); - for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) + for (const auto &[_, bi] : *BotListByNick) { - BotInfo *bi = it->second; - if (source.HasPriv("botserv/administration") || !bi->oper_only) { ++count; @@ -50,8 +48,8 @@ class CommandBSBotList : public Command { source.Reply(_("Bot list:")); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("%d bots available."), count); } diff --git a/modules/commands/bs_info.cpp b/modules/commands/bs_info.cpp index d75390dfc..d9b3afe1d 100644 --- a/modules/commands/bs_info.cpp +++ b/modules/commands/bs_info.cpp @@ -17,10 +17,8 @@ class CommandBSInfo : public Command void send_bot_channels(std::vector<Anope::string> &buffers, const BotInfo *bi) { Anope::string buf; - for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it) + for (const auto &[_, ci] : *RegisteredChannelList) { - const ChannelInfo *ci = it->second; - if (ci->bi == bi) { buf += " " + ci->name + " "; @@ -63,15 +61,15 @@ class CommandBSInfo : public Command std::vector<Anope::string> replies; info.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); if (source.HasPriv("botserv/administration")) { std::vector<Anope::string> buf; this->send_bot_channels(buf, bi); - for (unsigned i = 0; i < buf.size(); ++i) - source.Reply(buf[i]); + for (const auto &line : buf) + source.Reply(line); } } @@ -94,8 +92,8 @@ class CommandBSInfo : public Command std::vector<Anope::string> replies; info.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } else source.Reply(_("\002%s\002 is not a valid bot or registered channel."), query.c_str()); diff --git a/modules/commands/bs_kick.cpp b/modules/commands/bs_kick.cpp index f3a3ef7cd..051400d16 100644 --- a/modules/commands/bs_kick.cpp +++ b/modules/commands/bs_kick.cpp @@ -20,8 +20,8 @@ struct KickerDataImpl : KickerData KickerDataImpl(Extensible *obj) { amsgs = badwords = bolds = caps = colors = flood = italics = repeat = reverses = underlines = false; - for (int16_t i = 0; i < TTB_SIZE; ++i) - ttb[i] = 0; + for (auto &ttbtype : ttb) + ttbtype = 0; capsmin = capspercent = 0; floodlines = floodsecs = 0; repeattimes = 0; @@ -69,8 +69,8 @@ struct KickerDataImpl : KickerData data.SetType("repeattimes", Serialize::Data::DT_INT); data["repeattimes"] << kd->repeattimes; data.SetType("dontkickops", Serialize::Data::DT_INT); data["dontkickops"] << kd->dontkickops; data.SetType("dontkickvoices", Serialize::Data::DT_INT); data["dontkickvoices"] << kd->dontkickvoices; - for (int16_t i = 0; i < TTB_SIZE; ++i) - data["ttb"] << kd->ttb[i] << " "; + for (auto ttbtype : kd->ttb) + data["ttb"] << ttbtype << " "; } void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) override @@ -136,11 +136,8 @@ class CommandBSKick : public Command source.Reply(_("Configures bot kickers. \037option\037 can be one of:")); Anope::string this_name = source.command; - for (CommandInfo::map::const_iterator it = source.service->commands.begin(), it_end = source.service->commands.end(); it != it_end; ++it) + for (const auto &[c_name, info] : source.service->commands) { - const Anope::string &c_name = it->first; - const CommandInfo &info = it->second; - if (c_name.find_ci(this_name + " ") == 0) { ServiceReference<Command> command("Command", info.name); @@ -928,8 +925,8 @@ struct BanData Data() { last_use = 0; - for (int i = 0; i < TTB_SIZE; ++i) - this->ttb[i] = 0; + for (auto &ttbtype : this->ttb) + ttbtype = 0; } }; @@ -997,10 +994,8 @@ class BanDataPurger : public Timer { Log(LOG_DEBUG) << "bs_main: Running bandata purger"; - for (channel_map::iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it) + for (auto &[_, c] : ChannelList) { - Channel *c = it->second; - BanData *bd = c->GetExt<BanData>("bandata"); if (bd != NULL) { @@ -1049,7 +1044,7 @@ class BSKick : public Module UserData *ud = userdata.Require(uc); return ud; - } + } void check_ban(ChannelInfo *ci, User *u, KickerData *kd, int ttbtype) { @@ -1308,11 +1303,11 @@ class BSKick : public Module { int i = 0, l = 0; - for (unsigned j = 0, end = realbuf.length(); j < end; ++j) + for (auto chr : realbuf) { - if (isupper(realbuf[j])) + if (isupper(chr)) ++i; - else if (islower(realbuf[j])) + else if (islower(chr)) ++l; } diff --git a/modules/commands/bs_set.cpp b/modules/commands/bs_set.cpp index 8f9e8a894..0670b537f 100644 --- a/modules/commands/bs_set.cpp +++ b/modules/commands/bs_set.cpp @@ -35,10 +35,8 @@ class CommandBSSet : public Command bool hide_privileged_commands = Config->GetBlock("options")->Get<bool>("hideprivilegedcommands"), hide_registered_commands = Config->GetBlock("options")->Get<bool>("hideregisteredcommands"); Anope::string this_name = source.command; - for (CommandInfo::map::const_iterator it = source.service->commands.begin(), it_end = source.service->commands.end(); it != it_end; ++it) + for (const auto &[c_name, info] : source.service->commands) { - const Anope::string &c_name = it->first; - const CommandInfo &info = it->second; if (c_name.find_ci(this_name + " ") == 0) { if (info.hide) @@ -54,7 +52,7 @@ class CommandBSSet : public Command if (hide_privileged_commands && !info.permission.empty() && !source.HasCommand(info.permission)) continue; - source.command = it->first; + source.command = c_name; command->OnServHelp(source); } } diff --git a/modules/commands/cs_access.cpp b/modules/commands/cs_access.cpp index 52dbdef20..f1d132963 100644 --- a/modules/commands/cs_access.cpp +++ b/modules/commands/cs_access.cpp @@ -16,8 +16,8 @@ static std::map<Anope::string, int16_t, ci::less> defaultLevels; static inline void reset_levels(ChannelInfo *ci) { ci->ClearLevels(); - for (std::map<Anope::string, int16_t, ci::less>::iterator it = defaultLevels.begin(), it_end = defaultLevels.end(); it != it_end; ++it) - ci->SetLevel(it->first, it->second); + for (auto &[priv, level] : defaultLevels) + ci->SetLevel(priv, level); } class AccessChanAccess : public ChanAccess @@ -369,12 +369,14 @@ class CommandCSAccess : public Command Anope::string timebuf; if (ci->c) - for (Channel::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end; ++cit) + { + for (const auto &[_, cuc] : ci->c->users) { ChannelInfo *p; - if (access->Matches(cit->second->user, cit->second->user->Account(), p)) + if (access->Matches(cuc->user, cuc->user->Account(), p)) timebuf = "Now"; } + } if (timebuf.empty()) { if (access->last_seen == 0) @@ -407,12 +409,14 @@ class CommandCSAccess : public Command Anope::string timebuf; if (ci->c) - for (Channel::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end; ++cit) + { + for (auto &[_, cuc] : ci->c->users) { ChannelInfo *p; - if (access->Matches(cit->second->user, cit->second->user->Account(), p)) + if (access->Matches(cuc->user, cuc->user->Account(), p)) timebuf = "Now"; } + } if (timebuf.empty()) { if (access->last_seen == 0) @@ -441,8 +445,8 @@ class CommandCSAccess : public Command source.Reply(_("Access list for %s:"), ci->name.c_str()); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("End of access list")); } @@ -701,9 +705,8 @@ class CommandCSLevels : public Command const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges(); - for (unsigned i = 0; i < privs.size(); ++i) + for (const auto &p : privs) { - const Privilege &p = privs[i]; int16_t j = ci->GetLevel(p.name); ListFormatter::ListEntry entry; @@ -722,8 +725,8 @@ class CommandCSLevels : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } void DoReset(CommandSource &source, ChannelInfo *ci) @@ -801,10 +804,8 @@ class CommandCSLevels : public Command ListFormatter list(source.GetAccount()); list.AddColumn(_("Name")).AddColumn(_("Description")); - const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges(); - for (unsigned i = 0; i < privs.size(); ++i) + for (const auto &p : PrivilegeManager::GetPrivileges()) { - const Privilege &p = privs[i]; ListFormatter::ListEntry entry; entry["Name"] = p.name; entry["Description"] = Language::Translate(source.nc, p.desc.c_str()); @@ -814,8 +815,8 @@ class CommandCSLevels : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } else { diff --git a/modules/commands/cs_akick.cpp b/modules/commands/cs_akick.cpp index 04ee17da3..78215dacd 100644 --- a/modules/commands/cs_akick.cpp +++ b/modules/commands/cs_akick.cpp @@ -96,10 +96,9 @@ class CommandCSAKick : public Command /* Check excepts BEFORE we get this far */ if (ci->c) { - std::vector<Anope::string> modes = ci->c->GetModeList("EXCEPT"); - for (unsigned int i = 0; i < modes.size(); ++i) + for (const auto &mode : ci->c->GetModeList("EXCEPT")) { - if (Anope::Match(modes[i], mask)) + if (Anope::Match(mode, mask)) { source.Reply(CHAN_EXCEPTED, mask.c_str(), ci->name.c_str()); return; @@ -129,10 +128,8 @@ class CommandCSAKick : public Command { /* Match against all currently online users with equal or * higher access. - Viper */ - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (const auto &[_, u2] : UserListByNick) { - User *u2 = it->second; - AccessGroup nc_access = ci->AccessFor(nc), u_access = source.AccessFor(ci); Entry entry_mask("", mask); @@ -145,9 +142,9 @@ class CommandCSAKick : public Command /* Match against the lastusermask of all nickalias's with equal * or higher access. - Viper */ - for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it) + for (const auto &[_, na2] : *NickAliasList) { - na = it->second; + na = na2; AccessGroup nc_access = ci->AccessFor(na->nc), u_access = source.AccessFor(ci); if (na->nc && (na->nc == ci->GetFounder() || nc_access >= u_access)) @@ -373,8 +370,8 @@ class CommandCSAKick : public Command source.Reply(_("Autokick list for %s:"), ci->name.c_str()); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("End of autokick list")); } diff --git a/modules/commands/cs_clone.cpp b/modules/commands/cs_clone.cpp index 84c7d91cb..c287f6a0b 100644 --- a/modules/commands/cs_clone.cpp +++ b/modules/commands/cs_clone.cpp @@ -99,11 +99,9 @@ class CommandCSClone : public Command void CopyLevels(CommandSource &source, ChannelInfo *ci, ChannelInfo *target_ci) { - const Anope::map<int16_t> &cilevels = ci->GetLevelEntries(); - - for (Anope::map<int16_t>::const_iterator it = cilevels.begin(); it != cilevels.end(); ++it) + for (const auto &[priv, level] : ci->GetLevelEntries()) { - target_ci->SetLevel(it->first, it->second); + target_ci->SetLevel(priv, level); } source.Reply(_("All level entries from \002%s\002 have been cloned into \002%s\002."), ci->name.c_str(), target_ci->name.c_str()); @@ -199,8 +197,8 @@ public: const Anope::string settings[] = { "NOAUTOOP", "CS_KEEP_MODES", "PEACE", "PERSIST", "RESTRICTED", "CS_SECURE", "SECUREFOUNDER", "SECUREOPS", "SIGNKICK", "SIGNKICK_LEVEL", "CS_NO_EXPIRE" }; - for (unsigned int i = 0; i < sizeof(settings) / sizeof(Anope::string); ++i) - CopySetting(ci, target_ci, settings[i]); + for (const auto &setting : settings) + CopySetting(ci, target_ci, setting); CopyAccess(source, ci, target_ci); CopyAkick(source, ci, target_ci); diff --git a/modules/commands/cs_enforce.cpp b/modules/commands/cs_enforce.cpp index 801191293..eca2d0651 100644 --- a/modules/commands/cs_enforce.cpp +++ b/modules/commands/cs_enforce.cpp @@ -29,10 +29,8 @@ class CommandCSEnforce : public Command bool hadsecureops = ci->HasExt("SECUREOPS"); ci->Extend<bool>("SECUREOPS"); - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + for (const auto &[_, uc] : ci->c->users) { - ChanUserContainer *uc = it->second; - ci->c->SetCorrectModes(uc->user, false); } @@ -48,9 +46,9 @@ class CommandCSEnforce : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce restricted"; std::vector<User *> users; - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + + for (const auto &[_, uc] : ci->c->users) { - ChanUserContainer *uc = it->second; User *user = uc->user; if (user->IsProtected()) @@ -60,10 +58,8 @@ class CommandCSEnforce : public Command users.push_back(user); } - for (unsigned i = 0; i < users.size(); ++i) + for (auto *user : users) { - User *user = users[i]; - Anope::string mask = ci->GetIdealBan(user); Anope::string reason = Language::Translate(user, _("RESTRICTED enforced by ")) + source.GetNick(); ci->c->SetMode(NULL, "BAN", mask); @@ -79,9 +75,8 @@ class CommandCSEnforce : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce registered only"; std::vector<User *> users; - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + for (const auto &[_, uc] : ci->c->users) { - ChanUserContainer *uc = it->second; User *user = uc->user; if (user->IsProtected()) @@ -91,10 +86,8 @@ class CommandCSEnforce : public Command users.push_back(user); } - for (unsigned i = 0; i < users.size(); ++i) + for (auto *user : users) { - User *user = users[i]; - Anope::string mask = ci->GetIdealBan(user); Anope::string reason = Language::Translate(user, _("REGONLY enforced by ")) + source.GetNick(); if (!ci->c->HasMode("REGISTEREDONLY")) @@ -111,9 +104,8 @@ class CommandCSEnforce : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce SSL only"; std::vector<User *> users; - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + for (auto &[_, uc] : ci->c->users) { - ChanUserContainer *uc = it->second; User *user = uc->user; if (user->IsProtected()) @@ -123,10 +115,8 @@ class CommandCSEnforce : public Command users.push_back(user); } - for (unsigned i = 0; i < users.size(); ++i) + for (auto *user : users) { - User *user = users[i]; - Anope::string mask = ci->GetIdealBan(user); Anope::string reason = Language::Translate(user, _("SSLONLY enforced by ")) + source.GetNick(); if (!ci->c->HasMode("SSL")) @@ -143,9 +133,8 @@ class CommandCSEnforce : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enforce bans"; std::vector<User *> users; - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + for (const auto &[_, uc] : ci->c->users) { - ChanUserContainer *uc = it->second; User *user = uc->user; if (user->IsProtected()) @@ -155,10 +144,8 @@ class CommandCSEnforce : public Command users.push_back(user); } - for (unsigned i = 0; i < users.size(); ++i) + for (auto *user : users) { - User *user = users[i]; - Anope::string reason = Language::Translate(user, _("BANS enforced by ")) + source.GetNick(); ci->c->Kick(NULL, user, "%s", reason.c_str()); } @@ -210,10 +197,8 @@ class CommandCSEnforce : public Command users.push_back(user); } - for (unsigned i = 0; i < users.size(); ++i) + for (auto *user : users) { - User *user = users[i]; - Anope::string reason = Language::Translate(user, _("LIMIT enforced by ")) + source.GetNick(); ci->c->Kick(NULL, user, "%s", reason.c_str()); } diff --git a/modules/commands/cs_entrymsg.cpp b/modules/commands/cs_entrymsg.cpp index 84b33423d..0b6fdcbfe 100644 --- a/modules/commands/cs_entrymsg.cpp +++ b/modules/commands/cs_entrymsg.cpp @@ -128,8 +128,8 @@ class CommandEntryMessage : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("End of entry message list.")); } @@ -280,8 +280,8 @@ class CSEntryMessage : public Module EntryMessageList *messages = c->ci->GetExt<EntryMessageList>("entrymsg"); if (messages != NULL) - for (unsigned i = 0; i < (*messages)->size(); ++i) - u->SendMessage(c->ci->WhoSends(), "[%s] %s", c->ci->name.c_str(), (*messages)->at(i)->message.c_str()); + for (const auto &message : *(*messages)) + u->SendMessage(c->ci->WhoSends(), "[%s] %s", c->ci->name.c_str(), message->message.c_str()); } } }; diff --git a/modules/commands/cs_flags.cpp b/modules/commands/cs_flags.cpp index 6edb736fc..54a99d7b6 100644 --- a/modules/commands/cs_flags.cpp +++ b/modules/commands/cs_flags.cpp @@ -48,9 +48,9 @@ class FlagsChanAccess : public ChanAccess std::set<char> buffer; - for (std::map<Anope::string, char>::iterator it = defaultFlags.begin(), it_end = defaultFlags.end(); it != it_end; ++it) - if (access->HasPriv(it->first)) - buffer.insert(it->second); + for (auto &[priv, flag] : defaultFlags) + if (access->HasPriv(priv)) + buffer.insert(flag); if (buffer.empty()) return "(none)"; @@ -189,14 +189,14 @@ class CommandCSFlags : public Command add = false; break; case '*': - for (std::map<Anope::string, char>::iterator it = defaultFlags.begin(), it_end = defaultFlags.end(); it != it_end; ++it) + for (const auto &[priv, flag] : defaultFlags) { - bool has = current_flags.count(it->second); + bool has = current_flags.count(flag); // If we are adding a flag they already have or removing one they don't have, don't bother if (add == has) continue; - if (!u_access.HasPriv(it->first) && !u_access.founder) + if (!u_access.HasPriv(priv) && !u_access.founder) { if (source.HasPriv("chanserv/access/modify")) override = true; @@ -205,9 +205,9 @@ class CommandCSFlags : public Command } if (add) - current_flags.insert(it->second); + current_flags.insert(flag); else - current_flags.erase(it->second); + current_flags.erase(flag); } break; default: @@ -218,11 +218,11 @@ class CommandCSFlags : public Command i = flags.length(); } - for (std::map<Anope::string, char>::iterator it = defaultFlags.begin(), it_end = defaultFlags.end(); it != it_end; ++it) + for (const auto &[priv, flag] : defaultFlags) { - if (f != it->second) + if (f != flag) continue; - else if (!u_access.HasPriv(it->first) && !u_access.founder) + else if (!u_access.HasPriv(priv) && !u_access.founder) { if (source.HasPriv("chanserv/access/modify")) override = true; @@ -341,8 +341,8 @@ class CommandCSFlags : public Command list.Process(replies); source.Reply(_("Flags list for %s"), ci->name.c_str()); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); if (count == ci->GetAccessCount()) source.Reply(_("End of access list.")); else @@ -454,15 +454,15 @@ class CommandCSFlags : public Command typedef std::multimap<char, Anope::string, ci::less> reverse_map; reverse_map reverse; - for (std::map<Anope::string, char>::iterator it = defaultFlags.begin(), it_end = defaultFlags.end(); it != it_end; ++it) - reverse.emplace(it->second, it->first); + for (auto &[priv, flag] : defaultFlags) + reverse.emplace(flag, priv); - for (reverse_map::iterator it = reverse.begin(), it_end = reverse.end(); it != it_end; ++it) + for (auto &[flag, priv] : reverse) { - Privilege *p = PrivilegeManager::FindPrivilege(it->second); + Privilege *p = PrivilegeManager::FindPrivilege(priv); if (p == NULL) continue; - source.Reply(" %c - %s", it->first, Language::Translate(source.nc, p->desc.c_str())); + source.Reply(" %c - %s", flag, Language::Translate(source.nc, p->desc.c_str())); } return true; diff --git a/modules/commands/cs_info.cpp b/modules/commands/cs_info.cpp index 42dab2e45..d47f9f8c1 100644 --- a/modules/commands/cs_info.cpp +++ b/modules/commands/cs_info.cpp @@ -65,8 +65,8 @@ class CommandCSInfo : public Command std::vector<Anope::string> replies; info.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/commands/cs_list.cpp b/modules/commands/cs_list.cpp index e90ab9395..8323b6adb 100644 --- a/modules/commands/cs_list.cpp +++ b/modules/commands/cs_list.cpp @@ -75,13 +75,11 @@ class CommandCSList : public Command list.AddColumn(_("Name")).AddColumn(_("Description")); Anope::map<ChannelInfo *> ordered_map; - for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it) - ordered_map[it->first] = it->second; + for (const auto &[cname, ci] : *RegisteredChannelList) + ordered_map[cname] = ci; - for (Anope::map<ChannelInfo *>::const_iterator it = ordered_map.begin(), it_end = ordered_map.end(); it != it_end; ++it) + for (const auto &[_, ci] : ordered_map) { - const ChannelInfo *ci = it->second; - if (!is_servadmin) { if (ci->HasExt("CS_PRIVATE") || ci->HasExt("CS_SUSPENDED")) @@ -124,8 +122,8 @@ class CommandCSList : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("End of list - %d/%d matches shown."), nchans > listmax ? listmax : nchans, nchans); } diff --git a/modules/commands/cs_log.cpp b/modules/commands/cs_log.cpp index 51f3ab8fe..2a6f2d0ec 100644 --- a/modules/commands/cs_log.cpp +++ b/modules/commands/cs_log.cpp @@ -144,8 +144,8 @@ public: std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } } else if (params.size() > 2) @@ -199,12 +199,14 @@ public: return; } - for (unsigned i = 0; i < extra.length(); ++i) - if (ModeManager::GetStatusChar(extra[i]) == 0) + for (auto chr : extra) + { + if (ModeManager::GetStatusChar(chr) == 0) { - source.Reply(_("%c is an unknown status mode."), extra[i]); + source.Reply(_("%c is an unknown status mode."), chr); return; } + } bool override = !source.AccessFor(ci).HasPriv("SET"); @@ -326,10 +328,8 @@ class CSLog : public Module return; LogSettings *ls = logsettings.Require(ci); - for (unsigned i = 0; i < defaults.size(); ++i) + for (auto &d : defaults) { - LogDefault &d = defaults[i]; - LogSetting *log = new LogSettingImpl(); log->chan = ci->name; @@ -360,11 +360,10 @@ class CSLog : public Module LogSettings *ls = logsettings.Get(l->ci); if (ls) - for (unsigned i = 0; i < (*ls)->size(); ++i) + { + for (auto *log : *(*ls)) { - const LogSetting *log = (*ls)->at(i); - - /* wrong command */ + /* wrong command */ if (log->service_name != l->c->name) continue; @@ -393,6 +392,7 @@ class CSLog : public Module else if (log->method.equals_ci("NOTICE") && l->ci->c) IRCD->SendNotice(l->ci->WhoSends(), log->extra + l->ci->c->name, "%s", buffer.c_str()); } + } } }; diff --git a/modules/commands/cs_mode.cpp b/modules/commands/cs_mode.cpp index fcd6222d4..69e2247ba 100644 --- a/modules/commands/cs_mode.cpp +++ b/modules/commands/cs_mode.cpp @@ -46,9 +46,8 @@ struct ModeLocksImpl : ModeLocks { ModeList modelist; mlocks->swap(modelist); - for (ModeList::iterator it = modelist.begin(); it != modelist.end(); ++it) + for (auto *ml : modelist) { - ModeLock *ml = *it; delete ml; } } @@ -58,10 +57,8 @@ struct ModeLocksImpl : ModeLocks if (!mode) return false; - for (ModeList::const_iterator it = this->mlocks->begin(); it != this->mlocks->end(); ++it) + for (auto *ml : *this->mlocks) { - const ModeLock *ml = *it; - if (ml->name == mode->name && ml->set == status && ml->param == param) return true; } @@ -104,10 +101,8 @@ struct ModeLocksImpl : ModeLocks if (!mode) return false; - for (ModeList::iterator it = this->mlocks->begin(); it != this->mlocks->end(); ++it) + for (auto *m : *this->mlocks) { - ModeLock *m = *it; - if (m->name == mode->name) { // For list or status modes, we must check the parameter @@ -139,8 +134,8 @@ struct ModeLocksImpl : ModeLocks { ModeList ml; this->mlocks->swap(ml); - for (unsigned i = 0; i < ml.size(); ++i) - delete ml[i]; + for (const auto *lock : ml) + delete lock; } const ModeList &GetMLock() const override @@ -151,10 +146,9 @@ struct ModeLocksImpl : ModeLocks std::list<ModeLock *> GetModeLockList(const Anope::string &name) override { std::list<ModeLock *> mlist; - for (ModeList::const_iterator it = this->mlocks->begin(); it != this->mlocks->end(); ++it) + for (auto *m : *this->mlocks) { - ModeLock *m = *it; - if (m->name == name) + if (m->name == name) mlist.push_back(m); } return mlist; @@ -162,10 +156,8 @@ struct ModeLocksImpl : ModeLocks const ModeLock *GetMLock(const Anope::string &mname, const Anope::string ¶m = "") override { - for (ModeList::const_iterator it = this->mlocks->begin(); it != this->mlocks->end(); ++it) + for (auto *m : *this->mlocks) { - ModeLock *m = *it; - if (m->name == mname && m->param == param) return m; } @@ -177,9 +169,8 @@ struct ModeLocksImpl : ModeLocks { Anope::string pos = "+", neg = "-", params; - for (ModeList::const_iterator it = this->mlocks->begin(); it != this->mlocks->end(); ++it) + for (auto *ml : *this->mlocks) { - const ModeLock *ml = *it; ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name); if (!cm || cm->type == MODE_LIST || cm->type == MODE_STATUS) @@ -281,9 +272,8 @@ class CommandCSMode : public Command if (subcommand.equals_ci("SET")) { const ModeLocks::ModeList mlocks = modelocks->GetMLock(); - for (ModeLocks::ModeList::const_iterator it = mlocks.begin(); it != mlocks.end(); ++it) + for (auto *ml : mlocks) { - const ModeLock *ml = *it; ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name); if (cm && cm->CanSet(source.GetUser())) modelocks->RemoveMLock(cm, ml->set, ml->param); @@ -299,9 +289,9 @@ class CommandCSMode : public Command int adding = 1; bool needreply = true; - for (size_t i = 0; i < modes.length(); ++i) + for (auto mode : modes) { - switch (modes[i]) + switch (mode) { case '+': adding = 1; @@ -311,15 +301,15 @@ class CommandCSMode : public Command break; default: needreply = false; - ChannelMode *cm = ModeManager::FindChannelModeByChar(modes[i]); + ChannelMode *cm = ModeManager::FindChannelModeByChar(mode); if (!cm) { - source.Reply(_("Unknown mode character %c ignored."), modes[i]); + source.Reply(_("Unknown mode character %c ignored."), mode); break; } else if (u && !cm->CanSet(u)) { - source.Reply(_("You may not (un)lock mode %c."), modes[i]); + source.Reply(_("You may not (un)lock mode %c."), mode); break; } @@ -391,9 +381,9 @@ class CommandCSMode : public Command int adding = 1; bool needreply = true; - for (size_t i = 0; i < modes.length(); ++i) + for (auto mode : modes) { - switch (modes[i]) + switch (mode) { case '+': adding = 1; @@ -403,15 +393,15 @@ class CommandCSMode : public Command break; default: needreply = false; - ChannelMode *cm = ModeManager::FindChannelModeByChar(modes[i]); + ChannelMode *cm = ModeManager::FindChannelModeByChar(mode); if (!cm) { - source.Reply(_("Unknown mode character %c ignored."), modes[i]); + source.Reply(_("Unknown mode character %c ignored."), mode); break; } else if (u && !cm->CanSet(u)) { - source.Reply(_("You may not (un)lock mode %c."), modes[i]); + source.Reply(_("You may not (un)lock mode %c."), mode); break; } @@ -448,9 +438,8 @@ class CommandCSMode : public Command ListFormatter list(source.GetAccount()); list.AddColumn(_("Mode")).AddColumn(_("Param")).AddColumn(_("Creator")).AddColumn(_("Created")); - for (ModeLocks::ModeList::const_iterator it = mlocks.begin(), it_end = mlocks.end(); it != it_end; ++it) + for (auto *ml : mlocks) { - const ModeLock *ml = *it; ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name); if (!cm) continue; @@ -468,8 +457,8 @@ class CommandCSMode : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } } else @@ -489,9 +478,9 @@ class CommandCSMode : public Command bool override = !source.AccessFor(ci).HasPriv("MODE") && source.HasPriv("chanserv/administration"); int adding = -1; - for (size_t i = 0; i < modes.length(); ++i) + for (auto mode : modes) { - switch (modes[i]) + switch (mode) { case '+': adding = 1; @@ -521,7 +510,7 @@ class CommandCSMode : public Command default: if (adding == -1) break; - ChannelMode *cm = ModeManager::FindChannelModeByChar(modes[i]); + ChannelMode *cm = ModeManager::FindChannelModeByChar(mode); if (!cm || (u && !cm->CanSet(u) && !can_override)) continue; switch (cm->type) @@ -665,10 +654,11 @@ class CommandCSMode : public Command } else { - std::vector<Anope::string> v = ci->c->GetModeList(cm->name); - for (unsigned j = 0; j < v.size(); ++j) - if (Anope::Match(v[j], param)) - ci->c->RemoveMode(NULL, cm, v[j]); + for (const auto &mode : ci->c->GetModeList(cm->name)) + { + if (Anope::Match(mode, param)) + ci->c->RemoveMode(NULL, cm, mode); + } } } } // switch @@ -963,10 +953,10 @@ class CSMode : public Module ModeLocks *locks = modelocks.Get(c->ci); if (locks) - for (ModeLocks::ModeList::const_iterator it = locks->GetMLock().begin(), it_end = locks->GetMLock().end(); it != it_end; ++it) + { + for (auto *ml : locks->GetMLock()) { - const ModeLock *ml = *it; - ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name); + ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name); if (!cm) continue; @@ -1003,6 +993,7 @@ class CSMode : public Module c->RemoveMode(NULL, cm, ml->param, false); } } + } } void OnChanRegistered(ChannelInfo *ci) override @@ -1013,21 +1004,21 @@ class CSMode : public Module if (sep.GetToken(mlock)) { bool add = true; - for (unsigned i = 0; i < mlock.length(); ++i) + for (auto mode : mlock) { - if (mlock[i] == '+') + if (mode == '+') { add = true; continue; } - if (mlock[i] == '-') + if (mode == '-') { add = false; continue; } - ChannelMode *cm = ModeManager::FindChannelModeByChar(mlock[i]); + ChannelMode *cm = ModeManager::FindChannelModeByChar(mode); if (!cm) continue; diff --git a/modules/commands/cs_seen.cpp b/modules/commands/cs_seen.cpp index 0151a5a36..6bdb85bbf 100644 --- a/modules/commands/cs_seen.cpp +++ b/modules/commands/cs_seen.cpp @@ -125,14 +125,14 @@ class CommandOSSeen : public Command { size_t mem_counter; mem_counter = sizeof(database_map); - for (database_map::iterator it = database.begin(), it_end = database.end(); it != it_end; ++it) + for (auto &[nick, si] : database) { mem_counter += (5 * sizeof(Anope::string)) + sizeof(TypeInfo) + sizeof(time_t); - mem_counter += it->first.capacity(); - mem_counter += it->second->vhost.capacity(); - mem_counter += it->second->nick2.capacity(); - mem_counter += it->second->channel.capacity(); - mem_counter += it->second->message.capacity(); + mem_counter += nick.capacity(); + mem_counter += si->vhost.capacity(); + mem_counter += si->nick2.capacity(); + mem_counter += si->channel.capacity(); + mem_counter += si->message.capacity(); } source.Reply(_("%lu nicks are stored in the database, using %.2Lf kB of memory."), database.size(), static_cast<long double>(mem_counter) / 1024); } @@ -222,9 +222,8 @@ class CommandSeen : public Command return; } - for (Channel::ChanUserList::const_iterator it = source.c->users.begin(), it_end = source.c->users.end(); it != it_end; ++it) + for (const auto &[_, uc] : source.c->users) { - ChanUserContainer *uc = it->second; User *u = uc->user; if (u->Account() == na->nc) @@ -236,10 +235,8 @@ class CommandSeen : public Command AccessGroup ag = source.c->ci->AccessFor(na->nc); time_t last = 0; - for (unsigned int i = 0; i < ag.paths.size(); ++i) + for (const auto &p : ag.paths) { - ChanAccess::Path &p = ag.paths[i]; - if (p.empty()) continue; diff --git a/modules/commands/cs_set.cpp b/modules/commands/cs_set.cpp index 116db161e..0456f56b8 100644 --- a/modules/commands/cs_set.cpp +++ b/modules/commands/cs_set.cpp @@ -37,10 +37,8 @@ class CommandCSSet : public Command Anope::string this_name = source.command; bool hide_privileged_commands = Config->GetBlock("options")->Get<bool>("hideprivilegedcommands"), hide_registered_commands = Config->GetBlock("options")->Get<bool>("hideregisteredcommands"); - for (CommandInfo::map::const_iterator it = source.service->commands.begin(), it_end = source.service->commands.end(); it != it_end; ++it) + for (const auto &[c_name, info] : source.service->commands) { - const Anope::string &c_name = it->first; - const CommandInfo &info = it->second; if (c_name.find_ci(this_name + " ") == 0) { if (info.hide) @@ -56,7 +54,7 @@ class CommandCSSet : public Command else if (hide_privileged_commands && !info.permission.empty() && !source.HasCommand(info.permission)) continue; - source.command = it->first; + source.command = c_name; c->OnServHelp(source); } } @@ -1112,13 +1110,13 @@ class CSSet : public Module const ChannelInfo *ci = anope_dynamic_static_cast<const ChannelInfo *>(s); Anope::string modes; - for (Channel::ModeList::const_iterator it = ci->last_modes.begin(); it != ci->last_modes.end(); ++it) + for (const auto &[last_mode, last_value] : ci->last_modes) { if (!modes.empty()) modes += " "; - modes += it->first; - if (!it->second.empty()) - modes += "," + it->second; + modes += last_mode; + if (!last_value.empty()) + modes += "," + last_value; } data["last_modes"] << modes; } @@ -1199,8 +1197,8 @@ class CSSet : public Module if (c->ci && keep_modes.HasExt(c->ci)) { Channel::ModeList ml = c->ci->last_modes; - for (Channel::ModeList::iterator it = ml.begin(); it != ml.end(); ++it) - c->SetMode(c->ci->WhoSends(), it->first, it->second); + for (const auto &[last_mode, last_value] : c->ci->last_modes) + c->SetMode(c->ci->WhoSends(), last_mode, last_value); } } diff --git a/modules/commands/cs_set_misc.cpp b/modules/commands/cs_set_misc.cpp index 477595ad8..86233c97a 100644 --- a/modules/commands/cs_set_misc.cpp +++ b/modules/commands/cs_set_misc.cpp @@ -178,8 +178,8 @@ class CSSetMisc : public Module ~CSSetMisc() override { - for (Anope::map<ExtensibleItem<CSMiscData> *>::iterator it = items.begin(); it != items.end(); ++it) - delete it->second; + for (const auto &[_, item] : items) + delete item; } void OnReload(Configuration::Conf *conf) override @@ -205,9 +205,8 @@ class CSSetMisc : public Module void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool) override { - for (Anope::map<ExtensibleItem<CSMiscData> *>::iterator it = items.begin(); it != items.end(); ++it) + for (const auto &[_, e] : items) { - ExtensibleItem<CSMiscData> *e = it->second; MiscData *data = e->Get(ci); if (data != NULL) diff --git a/modules/commands/cs_status.cpp b/modules/commands/cs_status.cpp index dae9dd9d1..9d5f856f8 100644 --- a/modules/commands/cs_status.cpp +++ b/modules/commands/cs_status.cpp @@ -57,11 +57,9 @@ public: { source.Reply(_("Access for \002%s\002 on \002%s\002:"), nick.c_str(), ci->name.c_str()); - for (unsigned i = 0; i < ag.paths.size(); ++i) + for (const auto &p : ag.paths) { - ChanAccess::Path &p = ag.paths[i]; - - if (p.empty()) + if (p.empty()) continue; if (p.size() == 1) diff --git a/modules/commands/cs_suspend.cpp b/modules/commands/cs_suspend.cpp index 55fd83d27..ca8dfce56 100644 --- a/modules/commands/cs_suspend.cpp +++ b/modules/commands/cs_suspend.cpp @@ -109,16 +109,15 @@ class CommandCSSuspend : public Command { std::vector<User *> users; - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + for (const auto &[_, uc] : ci->c->users) { - ChanUserContainer *uc = it->second; User *user = uc->user; if (!user->HasMode("OPER") && user->server != Me) users.push_back(user); } - for (unsigned i = 0; i < users.size(); ++i) - ci->c->Kick(NULL, users[i], "%s", !reason.empty() ? reason.c_str() : Language::Translate(users[i], _("This channel has been suspended."))); + for (auto *user : users) + ci->c->Kick(NULL, user, "%s", !reason.empty() ? reason.c_str() : Language::Translate(user, _("This channel has been suspended."))); } Log(LOG_ADMIN, source, this, ci) << "(" << (!reason.empty() ? reason : "No reason") << "), expires on " << (expiry_secs ? Anope::strftime(Anope::CurTime + expiry_secs) : "never"); diff --git a/modules/commands/cs_sync.cpp b/modules/commands/cs_sync.cpp index 60bc0a205..2610f521c 100644 --- a/modules/commands/cs_sync.cpp +++ b/modules/commands/cs_sync.cpp @@ -35,8 +35,8 @@ class CommandCSSync : public Command bool override = !source.AccessFor(ci).HasPriv("ACCESS_CHANGE") && source.HasPriv("chanserv/administration"); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci); - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) - ci->c->SetCorrectModes(it->second->user, true); + for (const auto &[_, uc] : ci->c->users) + ci->c->SetCorrectModes(uc->user, true); source.Reply(_("All user modes on \002%s\002 have been synced."), ci->name.c_str()); } diff --git a/modules/commands/cs_unban.cpp b/modules/commands/cs_unban.cpp index de5ad1782..fec777cc0 100644 --- a/modules/commands/cs_unban.cpp +++ b/modules/commands/cs_unban.cpp @@ -38,17 +38,15 @@ class CommandCSUnban : public Command source.GetAccount()->GetChannelReferences(queue); unsigned count = 0; - for (unsigned i = 0; i < queue.size(); ++i) + for (auto *ci : queue) { - ChannelInfo *ci = queue[i]; - if (!ci->c || !source.AccessFor(ci).HasPriv("UNBAN")) continue; FOREACH_MOD(OnChannelUnban, (source.GetUser(), ci)); - for (unsigned j = 0; j < modes.size(); ++j) - if (ci->c->Unban(source.GetUser(), modes[j]->name, true)) + for (const auto *mode : modes) + if (ci->c->Unban(source.GetUser(), mode->name, true)) ++count; } @@ -92,8 +90,8 @@ class CommandCSUnban : public Command FOREACH_MOD(OnChannelUnban, (u2, ci)); - for (unsigned i = 0; i < modes.size(); ++i) - ci->c->Unban(u2, modes[i]->name, source.GetUser() == u2); + for (const auto *mode : modes) + ci->c->Unban(u2, mode->name, source.GetUser() == u2); if (u2 == source.GetUser()) source.Reply(_("You have been unbanned from \002%s\002."), ci->c->name.c_str()); else diff --git a/modules/commands/cs_updown.cpp b/modules/commands/cs_updown.cpp index 040e5917c..59bd19660 100644 --- a/modules/commands/cs_updown.cpp +++ b/modules/commands/cs_updown.cpp @@ -24,9 +24,8 @@ class CommandCSUp : public Command bool given = false; AccessGroup u_access = c->ci->AccessFor(u); - for (unsigned i = 0; i < ModeManager::GetStatusChannelModesByRank().size(); ++i) + for (auto *cm : ModeManager::GetStatusChannelModesByRank()) { - ChannelModeStatus *cm = ModeManager::GetStatusChannelModesByRank()[i]; bool has_priv = u_access.HasPriv("AUTO" + cm->name) || u_access.HasPriv(cm->name); if (has_priv) diff --git a/modules/commands/cs_xop.cpp b/modules/commands/cs_xop.cpp index 1d5cfb7d9..5bd9de696 100644 --- a/modules/commands/cs_xop.cpp +++ b/modules/commands/cs_xop.cpp @@ -58,25 +58,28 @@ class XOPChanAccess : public ChanAccess { std::map<Anope::string, int> count; - for (std::map<Anope::string, std::vector<Anope::string> >::const_iterator it = permissions.begin(), it_end = permissions.end(); it != it_end; ++it) + for (const auto &[name, perms] : permissions) { - int &c = count[it->first]; - const std::vector<Anope::string> &perms = it->second; - for (unsigned i = 0; i < perms.size(); ++i) - if (access->HasPriv(perms[i])) + int &c = count[name]; + for (const auto &perm : perms) + { + if (access->HasPriv(perm)) ++c; + } } - Anope::string max; - int maxn = 0; - for (std::map<Anope::string, int>::iterator it = count.begin(), it_end = count.end(); it != it_end; ++it) - if (it->second > maxn) + Anope::string maxname; + int maxpriv = 0; + for (const auto &[name, priv] : count) + { + if (priv > maxpriv) { - maxn = it->second; - max = it->first; + maxname = name; + maxpriv = priv; } + } - return max; + return maxname; } } }; @@ -436,8 +439,8 @@ class CommandCSXOP : public Command list.Process(replies); source.Reply(_("%s list for %s"), source.command.c_str(), ci->name.c_str()); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } } @@ -528,9 +531,9 @@ class CommandCSXOP : public Command " "), cmd.c_str(), cmd.c_str()); Anope::string buf; - for (unsigned i = 0; i < permissions[cmd].size(); ++i) + for (const auto &permission : permissions[cmd]) { - buf += ", " + permissions[cmd][i]; + buf += ", " + permission; if (buf.length() > 75) { source.Reply(" %s\n", buf.substr(2).c_str()); diff --git a/modules/commands/help.cpp b/modules/commands/help.cpp index 31b27e0ea..071161fcd 100644 --- a/modules/commands/help.cpp +++ b/modules/commands/help.cpp @@ -17,9 +17,8 @@ class CommandHelp : public Command static CommandGroup *FindGroup(const Anope::string &name) { - for (unsigned i = 0; i < Config->CommandGroups.size(); ++i) + for (auto &gr : Config->CommandGroups) { - CommandGroup &gr = Config->CommandGroups[i]; if (gr.name == name) return &gr; } @@ -56,18 +55,15 @@ class CommandHelp : public Command if (all) source.Reply(_("All available commands for \002%s\002:"), source.service->nick.c_str()); - for (CommandInfo::map::const_iterator it = map.begin(), it_end = map.end(); it != it_end; ++it) + for (const auto &[c_name, info] : map) { - const Anope::string &c_name = it->first; - const CommandInfo &info = it->second; - if (info.hide) continue; // Smaller command exists Anope::string cmd; spacesepstream(c_name).GetToken(cmd, 0); - if (cmd != it->first && map.count(cmd)) + if (cmd != c_name && map.count(cmd)) continue; ServiceReference<Command> c("Command", info.name); @@ -95,18 +91,14 @@ class CommandHelp : public Command } - for (GroupInfo::iterator it = groups.begin(), it_end = groups.end(); it != it_end; ++it) + for (auto &[gr, cmds] : groups) { - CommandGroup *gr = it->first; - source.Reply(" "); source.Reply("%s", gr->description.c_str()); Anope::string buf; - for (std::list<Anope::string>::iterator it2 = it->second.begin(), it2_end = it->second.end(); it2 != it2_end; ++it2) + for (const auto &c_name : cmds) { - const Anope::string &c_name = *it2; - buf += ", " + c_name; if (buf.length() > help_wrap_len) diff --git a/modules/commands/hs_del.cpp b/modules/commands/hs_del.cpp index fd6e93bbb..9d4514907 100644 --- a/modules/commands/hs_del.cpp +++ b/modules/commands/hs_del.cpp @@ -74,9 +74,9 @@ class CommandHSDelAll : public Command { FOREACH_MOD(OnDeleteVhost, (na)); const NickCore *nc = na->nc; - for (unsigned i = 0; i < nc->aliases->size(); ++i) + for (auto *alias : *nc->aliases) { - na = nc->aliases->at(i); + na = alias; na->RemoveVhost(); } Log(LOG_ADMIN, source, this) << "for all nicks in group " << nc->display; diff --git a/modules/commands/hs_group.cpp b/modules/commands/hs_group.cpp index 33b204ad1..03e1dc333 100644 --- a/modules/commands/hs_group.cpp +++ b/modules/commands/hs_group.cpp @@ -25,9 +25,8 @@ class CommandHSGroup : public Command return; setting = true; - for (unsigned i = 0; i < na->nc->aliases->size(); ++i) + for (auto *nick : *na->nc->aliases) { - NickAlias *nick = na->nc->aliases->at(i); if (nick) { nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator()); diff --git a/modules/commands/hs_list.cpp b/modules/commands/hs_list.cpp index c2aa67a83..00f2915d1 100644 --- a/modules/commands/hs_list.cpp +++ b/modules/commands/hs_list.cpp @@ -57,10 +57,8 @@ class CommandHSList : public Command ListFormatter list(source.GetAccount()); list.AddColumn(_("Number")).AddColumn(_("Nick")).AddColumn(_("Vhost")).AddColumn(_("Creator")).AddColumn(_("Created")); - for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it) + for (const auto &[_, na] : *NickAliasList) { - const NickAlias *na = it->second; - if (!na->HasVhost()) continue; @@ -125,8 +123,8 @@ class CommandHSList : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/commands/hs_request.cpp b/modules/commands/hs_request.cpp index a1b504d27..c626deca2 100644 --- a/modules/commands/hs_request.cpp +++ b/modules/commands/hs_request.cpp @@ -132,12 +132,14 @@ class CommandHSRequest : public Command source.Reply(HOST_NO_VIDENT); return; } - for (Anope::string::iterator s = user.begin(), s_end = user.end(); s != s_end; ++s) - if (!isvalidchar(*s)) + for (const auto &chr : user) + { + if (!isvalidchar(chr)) { source.Reply(HOST_SET_IDENT_ERROR); return; } + } } if (host.length() > Config->GetBlock("networkinfo")->Get<unsigned>("hostlen")) @@ -304,9 +306,8 @@ class CommandHSWaiting : public Command list.AddColumn(_("Number")).AddColumn(_("Nick")).AddColumn(_("Vhost")).AddColumn(_("Created")); - for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it) + for (const auto &[nick, na] : *NickAliasList) { - const NickAlias *na = it->second; HostRequest *hr = na->GetExt<HostRequest>("hostrequest"); if (!hr) continue; @@ -317,7 +318,7 @@ class CommandHSWaiting : public Command ListFormatter::ListEntry entry; entry["Number"] = stringify(display_counter); - entry["Nick"] = it->first; + entry["Nick"] = nick; if (!hr->ident.empty()) entry["Vhost"] = hr->ident + "@" + hr->host; else @@ -331,8 +332,8 @@ class CommandHSWaiting : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("Displayed \002%d\002 records (\002%d\002 total)."), display_counter, counter); } @@ -369,18 +370,15 @@ class HSRequest : public Module static void req_send_memos(Module *me, CommandSource &source, const Anope::string &vIdent, const Anope::string &vHost) { Anope::string host; - std::list<std::pair<Anope::string, Anope::string> >::iterator it, it_end; - if (!vIdent.empty()) host = vIdent + "@" + vHost; else host = vHost; if (Config->GetModule(me)->Get<bool>("memooper") && memoserv) - for (unsigned i = 0; i < Oper::opers.size(); ++i) + { + for (auto *o : Oper::opers) { - Oper *o = Oper::opers[i]; - const NickAlias *na = NickAlias::Find(o->name); if (!na) continue; @@ -389,6 +387,7 @@ static void req_send_memos(Module *me, CommandSource &source, const Anope::strin memoserv->Send(source.service->nick, na->nick, message, true); } + } } MODULE_INIT(HSRequest) diff --git a/modules/commands/hs_set.cpp b/modules/commands/hs_set.cpp index 4487723f9..926dc3bfe 100644 --- a/modules/commands/hs_set.cpp +++ b/modules/commands/hs_set.cpp @@ -111,9 +111,8 @@ class CommandHSSetAll : public Command if (!na || !na->HasVhost()) return; - for (unsigned i = 0; i < na->nc->aliases->size(); ++i) + for (auto *nick : *na->nc->aliases) { - NickAlias *nick = na->nc->aliases->at(i); if (nick) nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator()); } diff --git a/modules/commands/ms_ignore.cpp b/modules/commands/ms_ignore.cpp index 452b1e977..ca6e1ae86 100644 --- a/modules/commands/ms_ignore.cpp +++ b/modules/commands/ms_ignore.cpp @@ -84,10 +84,10 @@ class CommandMSIgnore : public Command { ListFormatter list(source.GetAccount()); list.AddColumn(_("Mask")); - for (unsigned i = 0; i < mi->ignores.size(); ++i) + for (const auto &ignore : mi->ignores) { ListFormatter::ListEntry entry; - entry["Mask"] = mi->ignores[i]; + entry["Mask"] = ignore; list.AddEntry(entry); } @@ -96,8 +96,8 @@ class CommandMSIgnore : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } } else diff --git a/modules/commands/ms_list.cpp b/modules/commands/ms_list.cpp index 35a199e2a..728fe1a71 100644 --- a/modules/commands/ms_list.cpp +++ b/modules/commands/ms_list.cpp @@ -129,8 +129,8 @@ class CommandMSList : public Command list.Process(replies); source.Reply(_("Memos for %s:"), ci ? ci->name.c_str() : source.GetNick().c_str()); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } return; } diff --git a/modules/commands/ms_sendall.cpp b/modules/commands/ms_sendall.cpp index eeb8e94e4..904e5e161 100644 --- a/modules/commands/ms_sendall.cpp +++ b/modules/commands/ms_sendall.cpp @@ -34,10 +34,8 @@ class CommandMSSendAll : public Command Log(LOG_ADMIN, source, this) << "to send " << text; - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + for (const auto &[_, nc] : *NickCoreList) { - const NickCore *nc = it->second; - if (nc != source.nc) memoserv->Send(source.GetNick(), nc->display, text); } diff --git a/modules/commands/ms_staff.cpp b/modules/commands/ms_staff.cpp index e85566ca4..2b0efae6d 100644 --- a/modules/commands/ms_staff.cpp +++ b/modules/commands/ms_staff.cpp @@ -32,10 +32,8 @@ class CommandMSStaff : public Command const Anope::string &text = params[0]; - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + for (const auto &[_, nc] : *NickCoreList) { - const NickCore *nc = it->second; - if (source.nc != nc && nc->IsServicesOper()) memoserv->Send(source.GetNick(), nc->display, text, true); } diff --git a/modules/commands/ns_ajoin.cpp b/modules/commands/ns_ajoin.cpp index 1bee6faf8..a783708a9 100644 --- a/modules/commands/ns_ajoin.cpp +++ b/modules/commands/ns_ajoin.cpp @@ -82,8 +82,8 @@ struct AJoinEntry : Serializable AJoinList::~AJoinList() { - for (unsigned i = 0; i < (*this)->size(); ++i) - delete (*this)->at(i); + for (const auto *ajoin : *(*this)) + delete ajoin; } class CommandNSAJoin : public Command @@ -113,8 +113,8 @@ class CommandNSAJoin : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } } @@ -327,9 +327,8 @@ class NSAJoin : public Module /* Set +r now, so we can ajoin users into +R channels */ ModeManager::ProcessModes(); - for (unsigned i = 0; i < (*channels)->size(); ++i) + for (auto *entry : *(*channels)) { - AJoinEntry *entry = (*channels)->at(i); Channel *c = Channel::Find(entry->channel); ChannelInfo *ci; diff --git a/modules/commands/ns_alist.cpp b/modules/commands/ns_alist.cpp index e9b69809c..e0f160aa2 100644 --- a/modules/commands/ns_alist.cpp +++ b/modules/commands/ns_alist.cpp @@ -51,9 +51,8 @@ class CommandNSAList : public Command nc->GetChannelReferences(queue); std::sort(queue.begin(), queue.end(), ChannelSort); - for (unsigned i = 0; i < queue.size(); ++i) + for (auto *ci : queue) { - ChannelInfo *ci = queue[i]; ListFormatter::ListEntry entry; if (ci->GetFounder() == nc) @@ -86,10 +85,8 @@ class CommandNSAList : public Command entry["Number"] = stringify(chan_count); entry["Channel"] = (ci->HasExt("CS_NO_EXPIRE") ? "!" : "") + ci->name; - for (unsigned j = 0; j < access.paths.size(); ++j) + for (auto &p : access.paths) { - ChanAccess::Path &p = access.paths[j]; - // not interested in indirect access if (p.size() != 1) continue; @@ -113,8 +110,8 @@ class CommandNSAList : public Command { source.Reply(_("Channels that \002%s\002 has access on:"), nc->display.c_str()); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("End of list - %d channels shown."), chan_count); } diff --git a/modules/commands/ns_cert.cpp b/modules/commands/ns_cert.cpp index e21d1e6f3..4e42d9fb5 100644 --- a/modules/commands/ns_cert.cpp +++ b/modules/commands/ns_cert.cpp @@ -108,8 +108,8 @@ struct NSCertListImpl : NSCertList void ClearCert() override { FOREACH_MOD(OnNickClearCert, (this->nc)); - for (unsigned i = 0; i < certs.size(); ++i) - certmap.erase(certs[i]); + for (const auto &cert : certs) + certmap.erase(cert); this->certs.clear(); } @@ -148,8 +148,8 @@ struct NSCertListImpl : NSCertList Anope::string buf; data["cert"] >> buf; spacesepstream sep(buf); - for (unsigned i = 0; i < c->certs.size(); ++i) - certmap.erase(c->certs[i]); + for (const auto &cert : c->certs) + certmap.erase(cert); c->certs.clear(); while (sep.GetToken(buf)) { diff --git a/modules/commands/ns_getemail.cpp b/modules/commands/ns_getemail.cpp index 765b50b93..de418cd0c 100644 --- a/modules/commands/ns_getemail.cpp +++ b/modules/commands/ns_getemail.cpp @@ -31,10 +31,8 @@ class CommandNSGetEMail : public Command Log(LOG_ADMIN, source, this) << "on " << email; - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + for (const auto &[_, nc] : *NickCoreList) { - const NickCore *nc = it->second; - if (!nc->email.empty() && Anope::Match(nc->email, email)) { ++j; diff --git a/modules/commands/ns_group.cpp b/modules/commands/ns_group.cpp index 43ccc9388..af9b71584 100644 --- a/modules/commands/ns_group.cpp +++ b/modules/commands/ns_group.cpp @@ -128,16 +128,16 @@ class CommandNSGroup : public Command } if (Config->GetModule("nickserv")->Get<bool>("restrictopernicks")) - for (unsigned i = 0; i < Oper::opers.size(); ++i) + { + for (auto *o : Oper::opers) { - Oper *o = Oper::opers[i]; - if (user != NULL && !user->HasMode("OPER") && user->nick.find_ci(o->name) != Anope::string::npos) { source.Reply(NICK_CANNOT_BE_REGISTERED, user->nick.c_str()); return; } } + } NickAlias *target, *na = NickAlias::Find(source.GetNick()); const Anope::string &guestnick = Config->GetModule("nickserv")->Get<const Anope::string>("guestnickprefix", "Guest"); @@ -327,10 +327,8 @@ class CommandNSGList : public Command list.AddColumn(_("Nick")).AddColumn(_("Expires")); time_t nickserv_expire = Config->GetModule("nickserv")->Get<time_t>("expire", "90d"), unconfirmed_expire = Config->GetModule("ns_register")->Get<time_t>("unconfirmedexpire", "1d"); - for (unsigned i = 0; i < nc->aliases->size(); ++i) + for (auto *na2 : *nc->aliases) { - const NickAlias *na2 = nc->aliases->at(i); - Anope::string expires; if (na2->HasExt("NS_NO_EXPIRE")) expires = NO_EXPIRE; @@ -351,8 +349,8 @@ class CommandNSGList : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("%d nickname(s) in the group."), nc->aliases->size()); } diff --git a/modules/commands/ns_info.cpp b/modules/commands/ns_info.cpp index 6b1f391e5..abe423acb 100644 --- a/modules/commands/ns_info.cpp +++ b/modules/commands/ns_info.cpp @@ -114,8 +114,8 @@ class CommandNSInfo : public Command std::vector<Anope::string> replies; info.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } } diff --git a/modules/commands/ns_list.cpp b/modules/commands/ns_list.cpp index 4ee7743b5..3c690984e 100644 --- a/modules/commands/ns_list.cpp +++ b/modules/commands/ns_list.cpp @@ -75,13 +75,11 @@ class CommandNSList : public Command list.AddColumn(_("Nick")).AddColumn(_("Last usermask")); Anope::map<NickAlias *> ordered_map; - for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it) - ordered_map[it->first] = it->second; + for (const auto &[nick, na] : *NickAliasList) + ordered_map[nick] = na; - for (Anope::map<NickAlias *>::const_iterator it = ordered_map.begin(), it_end = ordered_map.end(); it != it_end; ++it) + for (const auto &[_, na] : ordered_map) { - const NickAlias *na = it->second; - /* Don't show private nicks to non-services admins. */ if (na->nc->HasExt("NS_PRIVATE") && !is_servadmin && na->nc != mync) continue; @@ -125,8 +123,8 @@ class CommandNSList : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("End of list - %d/%d matches shown."), nnicks > listmax ? listmax : nnicks, nnicks); return; diff --git a/modules/commands/ns_recover.cpp b/modules/commands/ns_recover.cpp index 776080afb..f8ca00329 100644 --- a/modules/commands/ns_recover.cpp +++ b/modules/commands/ns_recover.cpp @@ -69,8 +69,8 @@ class NSRecoverRequest : public IdentifyRequest if (!u->chans.empty()) { NSRecoverInfo *ei = source.GetUser()->Extend<NSRecoverInfo>("recover"); - for (User::ChanUserList::iterator it = u->chans.begin(), it_end = u->chans.end(); it != it_end; ++it) - (*ei)[it->first->name] = it->second->status; + for (auto &[chan, cuc] : u->chans) + (*ei)[chan->name] = cuc->status; } } @@ -283,8 +283,8 @@ class NSRecover : public Module NSRecoverInfo::iterator it = ei->find(c->name); if (it != ei->end()) { - for (size_t i = 0; i < it->second.Modes().length(); ++i) - c->SetMode(c->WhoSends(), ModeManager::FindChannelModeByChar(it->second.Modes()[i]), u->GetUID()); + for (auto mode : it->second.Modes()) + c->SetMode(c->WhoSends(), ModeManager::FindChannelModeByChar(mode), u->GetUID()); ei->erase(it); if (ei->empty()) diff --git a/modules/commands/ns_register.cpp b/modules/commands/ns_register.cpp index ab113b934..6fd47ad38 100644 --- a/modules/commands/ns_register.cpp +++ b/modules/commands/ns_register.cpp @@ -180,10 +180,8 @@ class CommandNSRegister : public Command if (Config->GetModule("nickserv")->Get<bool>("restrictopernicks")) { - for (unsigned i = 0; i < Oper::opers.size(); ++i) + for (auto *o : Oper::opers) { - Oper *o = Oper::opers[i]; - if (!source.IsOper() && u_nick.find_ci(o->name) != Anope::string::npos) { source.Reply(NICK_CANNOT_BE_REGISTERED, u_nick.c_str()); diff --git a/modules/commands/ns_set.cpp b/modules/commands/ns_set.cpp index 9c4101540..b18bb9cff 100644 --- a/modules/commands/ns_set.cpp +++ b/modules/commands/ns_set.cpp @@ -35,11 +35,8 @@ class CommandNSSet : public Command Anope::string this_name = source.command; bool hide_privileged_commands = Config->GetBlock("options")->Get<bool>("hideprivilegedcommands"), hide_registered_commands = Config->GetBlock("options")->Get<bool>("hideregisteredcommands"); - for (CommandInfo::map::const_iterator it = source.service->commands.begin(), it_end = source.service->commands.end(); it != it_end; ++it) + for (const auto &[c_name, info] : source.service->commands) { - const Anope::string &c_name = it->first; - const CommandInfo &info = it->second; - if (c_name.find_ci(this_name + " ") == 0) { if (info.hide) @@ -88,11 +85,8 @@ class CommandNSSASet : public Command source.Reply(_("Sets various nickname options. \037option\037 can be one of:")); Anope::string this_name = source.command; - for (CommandInfo::map::const_iterator it = source.service->commands.begin(), it_end = source.service->commands.end(); it != it_end; ++it) + for (const auto &[c_name, info] : source.service->commands) { - const Anope::string &c_name = it->first; - const CommandInfo &info = it->second; - if (c_name.find_ci(this_name + " ") == 0) { ServiceReference<Command> command("Command", info.name); @@ -858,12 +852,12 @@ class CommandNSSetLanguage : public Command "supported languages:")); source.Reply(" en_US (English)"); - for (unsigned j = 0; j < Language::Languages.size(); ++j) + for (const auto &language : Language::Languages) { - const Anope::string &langname = Language::Translate(Language::Languages[j].c_str(), _("English")); + const Anope::string &langname = Language::Translate(language.c_str(), _("English")); if (langname == "English") continue; - source.Reply(" %s (%s)", Language::Languages[j].c_str(), langname.c_str()); + source.Reply(" %s (%s)", language.c_str(), langname.c_str()); } return true; @@ -893,12 +887,12 @@ class CommandNSSASetLanguage : public CommandNSSetLanguage "\037language\037 should be chosen from the following list of\n" "supported languages:")); source.Reply(" en (English)"); - for (unsigned j = 0; j < Language::Languages.size(); ++j) + for (const auto &language : Language::Languages) { - const Anope::string &langname = Language::Translate(Language::Languages[j].c_str(), _("English")); + const Anope::string &langname = Language::Translate(language.c_str(), _("English")); if (langname == "English") continue; - source.Reply(" %s (%s)", Language::Languages[j].c_str(), langname.c_str()); + source.Reply(" %s (%s)", language.c_str(), langname.c_str()); } return true; } @@ -1205,13 +1199,13 @@ class NSSet : public Module const NickCore *nc = anope_dynamic_static_cast<const NickCore *>(s); Anope::string modes; - for (User::ModeList::const_iterator it = nc->last_modes.begin(); it != nc->last_modes.end(); ++it) + for (const auto &[last_mode, last_value] : nc->last_modes) { if (!modes.empty()) modes += " "; - modes += it->first; - if (!it->second.empty()) - modes += "," + it->second; + modes += last_mode; + if (!last_value.empty()) + modes += "," + last_value; } data["last_modes"] << modes; } @@ -1342,13 +1336,12 @@ class NSSet : public Module { if (keep_modes.HasExt(u->Account())) { - User::ModeList modes = u->Account()->last_modes; - for (User::ModeList::iterator it = modes.begin(); it != modes.end(); ++it) + for (const auto &[last_mode, last_value] : u->Account()->last_modes) { - UserMode *um = ModeManager::FindUserModeByName(it->first); + UserMode *um = ModeManager::FindUserModeByName(last_mode); /* if the null user can set the mode, then it's probably safe */ if (um && um->CanSet(NULL)) - u->SetMode(NULL, it->first, it->second); + u->SetMode(NULL, last_mode, last_value); } } } diff --git a/modules/commands/ns_set_misc.cpp b/modules/commands/ns_set_misc.cpp index db7a1e8ef..be2804f04 100644 --- a/modules/commands/ns_set_misc.cpp +++ b/modules/commands/ns_set_misc.cpp @@ -191,8 +191,8 @@ class NSSetMisc : public Module ~NSSetMisc() override { - for (Anope::map<ExtensibleItem<NSMiscData> *>::iterator it = items.begin(); it != items.end(); ++it) - delete it->second; + for (const auto &[_, data] : items) + delete data; } void OnReload(Configuration::Conf *conf) override @@ -220,9 +220,8 @@ class NSSetMisc : public Module void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool) override { - for (Anope::map<ExtensibleItem<NSMiscData> *>::iterator it = items.begin(); it != items.end(); ++it) + for (const auto &[_, e] : items) { - ExtensibleItem<NSMiscData> *e = it->second; NSMiscData *data = e->Get(na->nc); if (data != NULL) diff --git a/modules/commands/ns_suspend.cpp b/modules/commands/ns_suspend.cpp index d9f26fe9c..28ca99b68 100644 --- a/modules/commands/ns_suspend.cpp +++ b/modules/commands/ns_suspend.cpp @@ -116,10 +116,8 @@ class CommandNSSuspend : public Command si->when = Anope::CurTime; si->expires = expiry_secs ? expiry_secs + Anope::CurTime : 0; - for (unsigned i = 0; i < nc->aliases->size(); ++i) + for (auto *na2 : *nc->aliases) { - NickAlias *na2 = nc->aliases->at(i); - if (na2 && *na2->nc == *na->nc) { na2->last_quit = reason; diff --git a/modules/commands/os_akill.cpp b/modules/commands/os_akill.cpp index 56203e4c1..31f96b507 100644 --- a/modules/commands/os_akill.cpp +++ b/modules/commands/os_akill.cpp @@ -172,8 +172,8 @@ class CommandOSAKill : public Command x->id = XLineManager::GenerateUID(); unsigned int affected = 0; - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - if (akills->Check(it->second, x)) + for (const auto &[_, user] : UserListByNick) + if (akills->Check(user, x)) ++affected; float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0; @@ -325,8 +325,8 @@ class CommandOSAKill : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("End of AKILL list.")); } diff --git a/modules/commands/os_chankill.cpp b/modules/commands/os_chankill.cpp index 5f2563bcf..a22eae178 100644 --- a/modules/commands/os_chankill.cpp +++ b/modules/commands/os_chankill.cpp @@ -69,10 +69,8 @@ class CommandOSChanKill : public Command if ((c = Channel::Find(channel))) { - for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) + for (const auto &[_, uc] : c->users) { - ChanUserContainer *uc = it->second; - if (uc->user->server == Me || uc->user->HasMode("OPER")) continue; diff --git a/modules/commands/os_config.cpp b/modules/commands/os_config.cpp index f94491a5c..3f211d695 100644 --- a/modules/commands/os_config.cpp +++ b/modules/commands/os_config.cpp @@ -62,11 +62,11 @@ class CommandOSConfig : public Command ListFormatter lflist(source.GetAccount()); lflist.AddColumn(_("Name")).AddColumn(_("Value")); - for (Configuration::Block::item_map::const_iterator it = items.begin(), it_end = items.end(); it != it_end; ++it) + for (const auto &[name, value] : items) { ListFormatter::ListEntry entry; - entry["Name"] = it->first; - entry["Value"] = it->second; + entry["Name"] = name; + entry["Value"] = value; lflist.AddEntry(entry); } @@ -75,8 +75,8 @@ class CommandOSConfig : public Command source.Reply(_("%s settings:"), block->GetName().c_str()); - for (unsigned j = 0; j < replies.size(); ++j) - source.Reply(replies[j]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(" "); } @@ -95,10 +95,10 @@ class CommandOSConfig : public Command ListFormatter::ListEntry entry; entry["Module Name"] = block->Get<Anope::string>("name"); - for (Configuration::Block::item_map::const_iterator it = items.begin(), it_end = items.end(); it != it_end; ++it) + for (const auto &[name, value] : items) { - entry["Name"] = it->first; - entry["Value"] = it->second; + entry["Name"] = name; + entry["Value"] = value; lflist.AddEntry(entry); } } @@ -108,8 +108,8 @@ class CommandOSConfig : public Command source.Reply(_("Module settings:")); - for (unsigned j = 0; j < replies.size(); ++j) - source.Reply(replies[j]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("End of configuration.")); } diff --git a/modules/commands/os_defcon.cpp b/modules/commands/os_defcon.cpp index 7721d7815..8a93a7f7b 100644 --- a/modules/commands/os_defcon.cpp +++ b/modules/commands/os_defcon.cpp @@ -253,7 +253,6 @@ class OSDefcon : public Module void ParseModeString() { int add = -1; /* 1 if adding, 0 if deleting, -1 if neither */ - unsigned char mode; ChannelMode *cm; ChannelModeParam *cmp; Anope::string modes, param; @@ -265,10 +264,8 @@ class OSDefcon : public Module ss.GetToken(modes); /* Loop while there are modes to set */ - for (unsigned i = 0, end = modes.length(); i < end; ++i) + for (auto mode : modes) { - mode = modes[i]; - switch (mode) { case '+': @@ -559,8 +556,8 @@ static void runDefCon() { Log(OperServ, "operserv/defcon") << "DEFCON: setting " << DConfig.chanmodes << " on all channels"; DefConModesSet = true; - for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it) - it->second->SetModes(OperServ, false, "%s", DConfig.chanmodes.c_str()); + for (const auto &[_, chan] : ChannelList) + chan->SetModes(OperServ, false, "%s", DConfig.chanmodes.c_str()); } } } @@ -575,8 +572,8 @@ static void runDefCon() if (!newmodes.empty()) { Log(OperServ, "operserv/defcon") << "DEFCON: setting " << newmodes << " on all channels"; - for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it) - it->second->SetModes(OperServ, true, "%s", newmodes.c_str()); + for (const auto &[_, chan] : ChannelList) + chan->SetModes(OperServ, true, "%s", newmodes.c_str()); } } } @@ -588,14 +585,14 @@ static Anope::string defconReverseModes(const Anope::string &modes) if (modes.empty()) return ""; Anope::string newmodes; - for (unsigned i = 0, end = modes.length(); i < end; ++i) + for (auto mode : modes) { - if (modes[i] == '+') + if (mode == '+') newmodes += '-'; - else if (modes[i] == '-') + else if (mode == '-') newmodes += '+'; else - newmodes += modes[i]; + newmodes += mode; } return newmodes; } diff --git a/modules/commands/os_dns.cpp b/modules/commands/os_dns.cpp index bcc1eaef0..c297ec062 100644 --- a/modules/commands/os_dns.cpp +++ b/modules/commands/os_dns.cpp @@ -40,8 +40,8 @@ struct DNSZone : Serializable { data["name"] << name; unsigned count = 0; - for (std::set<Anope::string, ci::less>::iterator it = servers.begin(), it_end = servers.end(); it != it_end; ++it) - data["server" + stringify(count++)] << *it; + for (const auto &server : servers) + data["server" + stringify(count++)] << server; } static Serializable* Unserialize(Serializable *obj, Serialize::Data &data) @@ -74,13 +74,14 @@ struct DNSZone : Serializable static DNSZone *Find(const Anope::string &name) { - for (unsigned i = 0; i < zones->size(); ++i) - if (zones->at(i)->name.equals_ci(name)) + for (auto *zone : *zones) + { + if (zone->name.equals_ci(name)) { - DNSZone *z = zones->at(i); - z->QueueUpdate(); - return z; + zone->QueueUpdate(); + return zone; } + } return NULL; } }; @@ -134,8 +135,8 @@ class DNSServer : public Serializable if (dnsmanager) { dnsmanager->UpdateSerial(); - for (std::set<Anope::string, ci::less>::iterator it = zones.begin(), it_end = zones.end(); it != it_end; ++it) - dnsmanager->Notify(*it); + for (const auto &zone : zones) + dnsmanager->Notify(zone); } } @@ -147,8 +148,8 @@ class DNSServer : public Serializable data["limit"] << limit; data["pooled"] << pooled; unsigned count = 0; - for (std::set<Anope::string, ci::less>::iterator it = zones.begin(), it_end = zones.end(); it != it_end; ++it) - data["zone" + stringify(count++)] << *it; + for (const auto &zone : zones) + data["zone" + stringify(count++)] << zone; } static Serializable* Unserialize(Serializable *obj, Serialize::Data &data) @@ -193,10 +194,9 @@ class DNSServer : public Serializable static DNSServer *Find(const Anope::string &s) { - for (unsigned i = 0; i < dns_servers->size(); ++i) - if (dns_servers->at(i)->GetName().equals_ci(s)) + for (auto *serv : *dns_servers) + if (serv->GetName().equals_ci(s)) { - DNSServer *serv = dns_servers->at(i); serv->QueueUpdate(); return serv; } @@ -216,9 +216,8 @@ class CommandOSDNS : public Command ListFormatter lf(source.GetAccount()); lf.AddColumn(_("Server")).AddColumn(_("IP")).AddColumn(_("Limit")).AddColumn(_("State")); - for (unsigned i = 0; i < dns_servers->size(); ++i) + for (auto *s : *dns_servers) { - DNSServer *s = dns_servers->at(i); Server *srv = Server::Find(s->GetName(), true); ListFormatter::ListEntry entry; @@ -226,8 +225,8 @@ class CommandOSDNS : public Command entry["Limit"] = s->GetLimit() ? stringify(s->GetLimit()) : Language::Translate(source.GetAccount(), _("None")); Anope::string ip_str; - for (unsigned j = 0; j < s->GetIPs().size(); ++j) - ip_str += s->GetIPs()[j] + " "; + for (const auto &ip : s->GetIPs()) + ip_str += ip + " "; ip_str.trim(); if (ip_str.empty()) ip_str = "None"; @@ -254,16 +253,14 @@ class CommandOSDNS : public Command ListFormatter lf2(source.GetAccount()); lf2.AddColumn(_("Zone")).AddColumn(_("Servers")); - for (unsigned i = 0; i < zones->size(); ++i) + for (auto *z : *zones) { - const DNSZone *z = zones->at(i); - ListFormatter::ListEntry entry; entry["Zone"] = z->name; Anope::string server_str; - for (std::set<Anope::string, ci::less>::iterator it = z->servers.begin(), it_end = z->servers.end(); it != it_end; ++it) - server_str += *it + " "; + for (const auto &server : z->servers) + server_str += server + " "; server_str.trim(); if (server_str.empty()) @@ -277,8 +274,8 @@ class CommandOSDNS : public Command lf2.Process(replies); } - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } void AddZone(CommandSource &source, const std::vector<Anope::string> ¶ms) @@ -316,9 +313,9 @@ class CommandOSDNS : public Command Log(LOG_ADMIN, source, this) << "to delete zone " << z->name; - for (std::set<Anope::string, ci::less>::iterator it = z->servers.begin(), it_end = z->servers.end(); it != it_end; ++it) + for (const auto &server : z->servers) { - DNSServer *s = DNSServer::Find(*it); + DNSServer *s = DNSServer::Find(server); if (s) s->zones.erase(z->name); } @@ -466,9 +463,9 @@ class CommandOSDNS : public Command return; } - for (std::set<Anope::string, ci::less>::iterator it = s->zones.begin(), it_end = s->zones.end(); it != it_end; ++it) + for (const auto &zone : s->zones) { - DNSZone *z = DNSZone::Find(*it); + DNSZone *z = DNSZone::Find(zone); if (z) z->servers.erase(s->GetName()); } @@ -494,12 +491,14 @@ class CommandOSDNS : public Command return; } - for (unsigned i = 0; i < s->GetIPs().size(); ++i) - if (params[2].equals_ci(s->GetIPs()[i])) + for (const auto &ip : s->GetIPs()) + { + if (params[2].equals_ci(ip)) { - source.Reply(_("IP %s already exists for %s."), s->GetIPs()[i].c_str(), s->GetName().c_str()); + source.Reply(_("IP %s already exists for %s."), ip.c_str(), s->GetName().c_str()); return; } + } sockaddrs addr(params[2]); if (!addr.valid()) @@ -518,8 +517,8 @@ class CommandOSDNS : public Command if (s->Active() && dnsmanager) { dnsmanager->UpdateSerial(); - for (std::set<Anope::string, ci::less>::iterator it = s->zones.begin(), it_end = s->zones.end(); it != it_end; ++it) - dnsmanager->Notify(*it); + for (const auto &zone : s->zones) + dnsmanager->Notify(zone); } } @@ -552,8 +551,8 @@ class CommandOSDNS : public Command if (s->Active() && dnsmanager) { dnsmanager->UpdateSerial(); - for (std::set<Anope::string, ci::less>::iterator it = s->zones.begin(), it_end = s->zones.end(); it != it_end; ++it) - dnsmanager->Notify(*it); + for (const auto &zone : s->zones) + dnsmanager->Notify(zone); } return; @@ -735,9 +734,8 @@ class ModuleDNS : public Module ModuleDNS(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), zone_type("DNSZone", DNSZone::Unserialize), dns_type("DNSServer", DNSServer::Unserialize), commandosdns(this) { - for (unsigned j = 0; j < dns_servers->size(); ++j) + for (auto *s : *dns_servers) { - DNSServer *s = dns_servers->at(j); if (s->Pooled() && Server::Find(s->GetName(), true)) s->SetActive(true); } @@ -862,21 +860,21 @@ class ModuleDNS : public Module size_t answer_size = packet->answers.size(); if (zone) { - for (std::set<Anope::string, ci::less>::iterator it = zone->servers.begin(), it_end = zone->servers.end(); it != it_end; ++it) + for (const auto &server : zone->servers) { - DNSServer *s = DNSServer::Find(*it); + DNSServer *s = DNSServer::Find(server); if (!s || !s->Active()) continue; - for (unsigned j = 0; j < s->GetIPs().size(); ++j) + for (const auto &ip : s->GetIPs()) { - DNS::QueryType q_type = s->GetIPs()[j].find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A; + DNS::QueryType q_type = ip.find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A; if (q.type == DNS::QUERY_AXFR || q.type == DNS::QUERY_ANY || q_type == q.type) { DNS::ResourceRecord rr(q.name, q_type); rr.ttl = this->ttl; - rr.rdata = s->GetIPs()[j]; + rr.rdata = ip; packet->answers.push_back(rr); } } @@ -886,21 +884,20 @@ class ModuleDNS : public Module if (packet->answers.size() == answer_size) { /* Default zone */ - for (unsigned i = 0; i < dns_servers->size(); ++i) + for (auto *s : *dns_servers) { - DNSServer *s = dns_servers->at(i); if (!s->Active()) continue; - for (unsigned j = 0; j < s->GetIPs().size(); ++j) + for (const auto &ip : s->GetIPs()) { - DNS::QueryType q_type = s->GetIPs()[j].find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A; + DNS::QueryType q_type = ip.find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A; if (q.type == DNS::QUERY_AXFR || q.type == DNS::QUERY_ANY || q_type == q.type) { DNS::ResourceRecord rr(q.name, q_type); rr.ttl = this->ttl; - rr.rdata = s->GetIPs()[j]; + rr.rdata = ip; packet->answers.push_back(rr); } } @@ -916,19 +913,17 @@ class ModuleDNS : public Module } /* Something messed up, just return them all and hope one is available */ - for (unsigned i = 0; i < dns_servers->size(); ++i) + for (auto *s : *dns_servers) { - DNSServer *s = dns_servers->at(i); - - for (unsigned j = 0; j < s->GetIPs().size(); ++j) + for (const auto &ip : s->GetIPs()) { - DNS::QueryType q_type = s->GetIPs()[j].find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A; + DNS::QueryType q_type = ip.find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A; if (q.type == DNS::QUERY_AXFR || q.type == DNS::QUERY_ANY || q_type == q.type) { DNS::ResourceRecord rr(q.name, q_type); rr.ttl = this->ttl; - rr.rdata = s->GetIPs()[j]; + rr.rdata = ip; packet->answers.push_back(rr); } } diff --git a/modules/commands/os_forbid.cpp b/modules/commands/os_forbid.cpp index 7c907a9f7..c17a719b7 100644 --- a/modules/commands/os_forbid.cpp +++ b/modules/commands/os_forbid.cpp @@ -70,9 +70,8 @@ class MyForbidService : public ForbidService ~MyForbidService() override { - std::vector<ForbidData *> f = GetForbids(); - for (unsigned i = 0; i < f.size(); ++i) - delete f[i]; + for (const auto *forbid : GetForbids()) + delete forbid; } void AddForbid(ForbidData *d) override @@ -245,8 +244,8 @@ class CommandOSForbid : public Command { int na_matches = 0; - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - module->OnUserNickChange(it->second, ""); + for (const auto &[_, user] : UserListByNick) + module->OnUserNickChange(user, ""); for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end;) { @@ -358,31 +357,29 @@ class CommandOSForbid : public Command list.AddColumn(_("Mask")).AddColumn(_("Type")).AddColumn(_("Creator")).AddColumn(_("Expires")).AddColumn(_("Reason")); unsigned shown = 0; - for (unsigned i = 0; i < forbids.size(); ++i) + for (auto *forbid : forbids) { - ForbidData *d = forbids[i]; - - if (ftype != FT_SIZE && ftype != d->type) + if (ftype != FT_SIZE && ftype != forbid->type) continue; Anope::string stype; - if (d->type == FT_NICK) + if (forbid->type == FT_NICK) stype = "NICK"; - else if (d->type == FT_CHAN) + else if (forbid->type == FT_CHAN) stype = "CHAN"; - else if (d->type == FT_EMAIL) + else if (forbid->type == FT_EMAIL) stype = "EMAIL"; - else if (d->type == FT_REGISTER) + else if (forbid->type == FT_REGISTER) stype = "REGISTER"; else continue; ListFormatter::ListEntry entry; - entry["Mask"] = d->mask; + entry["Mask"] = forbid->mask; entry["Type"] = stype; - entry["Creator"] = d->creator; - entry["Expires"] = d->expires ? Anope::strftime(d->expires, NULL, true).c_str() : Language::Translate(source.GetAccount(), _("Never")); - entry["Reason"] = d->reason; + entry["Creator"] = forbid->creator; + entry["Expires"] = forbid->expires ? Anope::strftime(forbid->expires, NULL, true).c_str() : Language::Translate(source.GetAccount(), _("Never")); + entry["Reason"] = forbid->reason; list.AddEntry(entry); ++shown; } @@ -398,8 +395,8 @@ class CommandOSForbid : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); if (shown >= forbids.size()) source.Reply(_("End of forbid list.")); diff --git a/modules/commands/os_ignore.cpp b/modules/commands/os_ignore.cpp index 685e49d36..f779840fb 100644 --- a/modules/commands/os_ignore.cpp +++ b/modules/commands/os_ignore.cpp @@ -282,8 +282,8 @@ class CommandOSIgnore : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } } diff --git a/modules/commands/os_info.cpp b/modules/commands/os_info.cpp index 95d48ba16..8015f835d 100644 --- a/modules/commands/os_info.cpp +++ b/modules/commands/os_info.cpp @@ -148,10 +148,8 @@ class CommandOSInfo : public Command return; } - for (unsigned i = 0; i < (*oi)->size(); ++i) + for (auto *o : *(*oi)) { - OperInfo *o = (*oi)->at(i); - if (o->info.equals_ci(info)) { source.Reply(_("The oper info already exists on \002%s\002."), target.c_str()); @@ -262,9 +260,8 @@ class OSInfo : public Module if (!oi) return; - for (unsigned i = 0; i < (*oi)->size(); ++i) + for (auto *o : *(*oi)) { - OperInfo *o = (*oi)->at(i); info[_("Oper Info")] = Anope::printf(_("(by %s on %s) %s"), o->adder.c_str(), Anope::strftime(o->created, source.GetAccount(), true).c_str(), o->info.c_str()); } } diff --git a/modules/commands/os_list.cpp b/modules/commands/os_list.cpp index d2b94c089..163044210 100644 --- a/modules/commands/os_list.cpp +++ b/modules/commands/os_list.cpp @@ -46,14 +46,16 @@ class CommandOSChanList : public Command { source.Reply(_("\002%s\002 channel list:"), u2->nick.c_str()); - for (User::ChanUserList::iterator uit = u2->chans.begin(), uit_end = u2->chans.end(); uit != uit_end; ++uit) + for (const auto &[_, cc]: u2->chans) { - ChanUserContainer *cc = uit->second; - if (!modes.empty()) - for (std::set<Anope::string>::iterator it = modes.begin(), it_end = modes.end(); it != it_end; ++it) - if (!cc->chan->HasMode(*it)) + { + for (const auto &mode : modes) + { + if (!cc->chan->HasMode(mode)) continue; + } + } ListFormatter::ListEntry entry; entry["Name"] = cc->chan->name; @@ -69,16 +71,18 @@ class CommandOSChanList : public Command { source.Reply(_("Channel list:")); - for (channel_map::const_iterator cit = ChannelList.begin(), cit_end = ChannelList.end(); cit != cit_end; ++cit) + for (const auto &[_, c] : ChannelList) { - Channel *c = cit->second; - if (!pattern.empty() && !Anope::Match(c->name, pattern, false, true)) continue; if (!modes.empty()) - for (std::set<Anope::string>::iterator it = modes.begin(), it_end = modes.end(); it != it_end; ++it) - if (!c->HasMode(*it)) + { + for (const auto &mode : modes) + { + if (!c->HasMode(mode)) continue; + } + } ListFormatter::ListEntry entry; entry["Name"] = c->name; @@ -94,8 +98,8 @@ class CommandOSChanList : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("End of channel list. \002%u\002 channels shown."), count); } @@ -156,14 +160,16 @@ class CommandOSUserList : public Command { source.Reply(_("\002%s\002 users list:"), pattern.c_str()); - for (Channel::ChanUserList::iterator cuit = c->users.begin(), cuit_end = c->users.end(); cuit != cuit_end; ++cuit) + for (const auto &[_, uc] : c->users) { - ChanUserContainer *uc = cuit->second; - if (!modes.empty()) - for (std::set<Anope::string>::iterator it = modes.begin(), it_end = modes.end(); it != it_end; ++it) - if (!uc->user->HasMode(*it)) + { + for (const auto &mode : modes) + { + if (!uc->user->HasMode(mode)) continue; + } + } ListFormatter::ListEntry entry; entry["Name"] = uc->user->nick; @@ -178,8 +184,8 @@ class CommandOSUserList : public Command { /* Historically this has been ordered, so... */ Anope::map<User *> ordered_map; - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - ordered_map[it->first] = it->second; + for (const auto &[nick, user] : UserListByNick) + ordered_map[nick] = user; source.Reply(_("Users list:")); @@ -197,10 +203,10 @@ class CommandOSUserList : public Command }; bool match = false; - for (unsigned int i = 0; i < sizeof(masks) / sizeof(*masks); ++i) + for (const auto &mask : masks) { /* Check mask with realname included, too */ - if (Anope::Match(masks[i], pattern, false, true) || Anope::Match(masks[i] + "#" + u2->realname, pattern, false, true)) + if (Anope::Match(mask, pattern, false, true) || Anope::Match(mask + "#" + u2->realname, pattern, false, true)) { match = true; break; @@ -211,9 +217,13 @@ class CommandOSUserList : public Command continue; if (!modes.empty()) - for (std::set<Anope::string>::iterator mit = modes.begin(), mit_end = modes.end(); mit != mit_end; ++mit) - if (!u2->HasMode(*mit)) + { + for (const auto &mode : modes) + { + if (!u2->HasMode(mode)) continue; + } + } } ListFormatter::ListEntry entry; @@ -229,8 +239,8 @@ class CommandOSUserList : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("End of users list. \002%u\002 users shown."), count); return; diff --git a/modules/commands/os_logsearch.cpp b/modules/commands/os_logsearch.cpp index eed329c04..ecea323c5 100644 --- a/modules/commands/os_logsearch.cpp +++ b/modules/commands/os_logsearch.cpp @@ -147,8 +147,8 @@ class CommandOSLogSearch : public Command source.Reply(_("Matches for \002%s\002:"), search_string.c_str()); unsigned int count = 0; - for (std::vector<Anope::string>::iterator it = matches.begin(), it_end = matches.end(); it != it_end; ++it) - source.Reply("#%d: %s", ++count, it->c_str()); + for (const auto &match : matches) + source.Reply("#%d: %s", ++count, match.c_str()); source.Reply(_("Showed %d/%d matches for \002%s\002."), matches.size(), found, search_string.c_str()); } diff --git a/modules/commands/os_mode.cpp b/modules/commands/os_mode.cpp index 541aa8fbc..096f50118 100644 --- a/modules/commands/os_mode.cpp +++ b/modules/commands/os_mode.cpp @@ -35,9 +35,8 @@ class CommandOSMode : public Command { bool all = params.size() > 2 && params[2].equals_ci("ALL"); - const Channel::ModeList chmodes = c->GetModes(); - for (Channel::ModeList::const_iterator it = chmodes.begin(), it_end = chmodes.end(); it != it_end && c; ++it) - c->RemoveMode(c->WhoSends(), it->first, it->second, false); + for (const auto &[mode, value] : c->GetModes()) + c->RemoveMode(c->WhoSends(), mode, value, false); if (!c) { @@ -47,10 +46,8 @@ class CommandOSMode : public Command if (all) { - for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) + for (const auto &[_, uc] : c->users) { - ChanUserContainer *uc = it->second; - if (uc->user->HasMode("OPER")) continue; diff --git a/modules/commands/os_modinfo.cpp b/modules/commands/os_modinfo.cpp index 1dfa519ae..5d6de2e6c 100644 --- a/modules/commands/os_modinfo.cpp +++ b/modules/commands/os_modinfo.cpp @@ -34,22 +34,18 @@ class CommandOSModInfo : public Command source.Reply(_(" Loaded at: %p"), m->handle); std::vector<Anope::string> servicekeys = Service::GetServiceKeys("Command"); - for (unsigned i = 0; i < servicekeys.size(); ++i) + for (const auto &servicekey : servicekeys) { - ServiceReference<Command> c("Command", servicekeys[i]); + ServiceReference<Command> c("Command", servicekey); if (!c || c->owner != m) continue; source.Reply(_(" Providing service: \002%s\002"), c->name.c_str()); - for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) + for (const auto &[_, bi] : *BotListByNick) { - const BotInfo *bi = it->second; - - for (CommandInfo::map::const_iterator cit = bi->commands.begin(), cit_end = bi->commands.end(); cit != cit_end; ++cit) + for (const auto &[c_name, info] : bi->commands) { - const Anope::string &c_name = cit->first; - const CommandInfo &info = cit->second; if (info.name != c->name) continue; source.Reply(_(" Command \002%s\002 on \002%s\002 is linked to \002%s\002"), c_name.c_str(), bi->nick.c_str(), c->name.c_str()); @@ -116,10 +112,8 @@ class CommandOSModList : public Command source.Reply(_("Current module list:")); int count = 0; - for (std::list<Module *>::iterator it = ModuleManager::Modules.begin(), it_end = ModuleManager::Modules.end(); it != it_end; ++it) + for (auto *m : ModuleManager::Modules) { - Module *m = *it; - bool show = false; Anope::string mtype; diff --git a/modules/commands/os_news.cpp b/modules/commands/os_news.cpp index 373774570..68c9f2629 100644 --- a/modules/commands/os_news.cpp +++ b/modules/commands/os_news.cpp @@ -101,9 +101,11 @@ class MyNewsService : public NewsService ~MyNewsService() override { - for (unsigned i = 0; i < 3; ++i) - for (unsigned j = 0; j < newsItems[i].size(); ++j) - delete newsItems[i][j]; + for (const auto &newstype : newsItems) + { + for (const auto *newsitem : newstype) + delete newsitem; + } } NewsItem *CreateNewsItem() override @@ -134,9 +136,9 @@ class MyNewsService : public NewsService #define lenof(a) (sizeof(a) / sizeof(*(a))) static const char **findmsgs(NewsType type) { - for (unsigned i = 0; i < lenof(msgarray); ++i) - if (msgarray[i].type == type) - return msgarray[i].msgs; + for (auto &msg : msgarray) + if (msg.type == type) + return msg.msgs; return NULL; } @@ -170,8 +172,8 @@ class NewsBase : public Command std::vector<Anope::string> replies; lflist.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); source.Reply(_("End of news list.")); } diff --git a/modules/commands/os_noop.cpp b/modules/commands/os_noop.cpp index bfcb28a5d..23cf83142 100644 --- a/modules/commands/os_noop.cpp +++ b/modules/commands/os_noop.cpp @@ -42,10 +42,8 @@ class CommandOSNOOP : public Command Anope::string reason = "NOOP command used by " + source.GetNick(); /* Kill all the IRCops of the server */ - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (const auto &[_, u2] : UserListByNick) { - User *u2 = it->second; - if (u2->server == s && u2->HasMode("OPER")) u2->Kill(*source.service, reason); } diff --git a/modules/commands/os_oper.cpp b/modules/commands/os_oper.cpp index 0d17b0cd6..67612ea74 100644 --- a/modules/commands/os_oper.cpp +++ b/modules/commands/os_oper.cpp @@ -50,15 +50,17 @@ class CommandOSOper : public Command { bool HasPrivs(CommandSource &source, OperType *ot) const { - std::list<Anope::string> commands = ot->GetCommands(), privs = ot->GetPrivs(); - - for (std::list<Anope::string>::iterator it = commands.begin(); it != commands.end(); ++it) - if (!source.HasCommand(*it)) + for (const auto &command : ot->GetCommands()) + { + if (!source.HasCommand(command)) return false; + } - for (std::list<Anope::string>::iterator it = privs.begin(); it != privs.end(); ++it) - if (!source.HasPriv(*it)) + for (const auto &priv : ot->GetPrivs()) + { + if (!source.HasPriv(priv)) return false; + } return true; } @@ -151,20 +153,17 @@ class CommandOSOper : public Command else if (subcommand.equals_ci("LIST")) { source.Reply(_("Name Type")); - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + for (const auto &[_, nc] : *NickCoreList) { - const NickCore *nc = it->second; - if (!nc->o) continue; source.Reply(_("%-8s %s"), nc->o->name.c_str(), nc->o->ot->GetName().c_str()); if (std::find(Config->Opers.begin(), Config->Opers.end(), nc->o) != Config->Opers.end()) source.Reply(_(" This oper is configured in the configuration file.")); - for (std::list<User *>::const_iterator uit = nc->users.begin(); uit != nc->users.end(); ++uit) + for (auto *u : nc->users) { - User *u = *uit; - source.Reply(_(" %s is online using this oper block."), u->nick.c_str()); + source.Reply(_(" %s is online using this oper block."), u->nick.c_str()); } } } @@ -173,9 +172,8 @@ class CommandOSOper : public Command if (params.size() < 2) { source.Reply(_("Available opertypes:")); - for (unsigned i = 0; i < Config->MyOperTypes.size(); ++i) + for (auto *ot : Config->MyOperTypes) { - OperType *ot = Config->MyOperTypes[i]; source.Reply("%s", ot->GetName().c_str()); } return; @@ -196,9 +194,9 @@ class CommandOSOper : public Command source.Reply(_("Available commands for \002%s\002:"), ot->GetName().c_str()); Anope::string buf; std::list<Anope::string> cmds = ot->GetCommands(); - for (std::list<Anope::string>::const_iterator it = cmds.begin(), it_end = cmds.end(); it != it_end; ++it) + for (const auto &cmd : cmds) { - buf += *it + " "; + buf += cmd + " "; if (buf.length() > 400) { source.Reply("%s", buf.c_str()); @@ -218,9 +216,9 @@ class CommandOSOper : public Command source.Reply(_("Available privileges for \002%s\002:"), ot->GetName().c_str()); Anope::string buf; std::list<Anope::string> privs = ot->GetPrivs(); - for (std::list<Anope::string>::const_iterator it = privs.begin(), it_end = privs.end(); it != it_end; ++it) + for (const auto &priv : privs) { - buf += *it + " "; + buf += priv + " "; if (buf.length() > 400) { source.Reply("%s", buf.c_str()); @@ -267,10 +265,8 @@ class OSOper : public Module ~OSOper() override { - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + for (const auto &[_, nc] : *NickCoreList) { - NickCore *nc = it->second; - if (nc->o && dynamic_cast<MyOper *>(nc->o)) { delete nc->o; diff --git a/modules/commands/os_session.cpp b/modules/commands/os_session.cpp index 517b22279..07e1e551f 100644 --- a/modules/commands/os_session.cpp +++ b/modules/commands/os_session.cpp @@ -61,9 +61,8 @@ class MySessionService : public SessionService Exception *FindException(User *u) override { - for (std::vector<Exception *>::const_iterator it = this->Exceptions->begin(), it_end = this->Exceptions->end(); it != it_end; ++it) + for (auto *e : *this->Exceptions) { - Exception *e = *it; if (Anope::Match(u->host, e->mask) || Anope::Match(u->ip.addr(), e->mask)) return e; @@ -75,9 +74,8 @@ class MySessionService : public SessionService Exception *FindException(const Anope::string &host) override { - for (std::vector<Exception *>::const_iterator it = this->Exceptions->begin(), it_end = this->Exceptions->end(); it != it_end; ++it) + for (auto *e : *this->Exceptions) { - Exception *e = *it; if (Anope::Match(host, e->mask)) return e; @@ -191,10 +189,8 @@ class CommandOSSession : public Command ListFormatter list(source.GetAccount()); list.AddColumn(_("Session")).AddColumn(_("Host")); - for (SessionService::SessionMap::iterator it = session_service->GetSessions().begin(), it_end = session_service->GetSessions().end(); it != it_end; ++it) + for (const auto &[_, session] : session_service->GetSessions()) { - Session *session = it->second; - if (session->count >= mincount) { ListFormatter::ListEntry entry; @@ -210,8 +206,8 @@ class CommandOSSession : public Command list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } return; @@ -347,9 +343,8 @@ class CommandOSException : public Command return; } - for (std::vector<Exception *>::iterator it = session_service->GetExceptions().begin(), it_end = session_service->GetExceptions().end(); it != it_end; ++it) + for (auto *e : session_service->GetExceptions()) { - Exception *e = *it; if (e->mask.equals_ci(mask)) { if (e->limit != limit) @@ -495,8 +490,8 @@ class CommandOSException : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } } diff --git a/modules/commands/os_stats.cpp b/modules/commands/os_stats.cpp index 302addceb..2fe23ddaf 100644 --- a/modules/commands/os_stats.cpp +++ b/modules/commands/os_stats.cpp @@ -50,8 +50,10 @@ static int stats_count_servers(Server *s) int count = 1; if (!s->GetLinks().empty()) - for (unsigned i = 0, j = s->GetLinks().size(); i < j; ++i) - count += stats_count_servers(s->GetLinks()[i]); + { + for (auto *link : s->GetLinks()) + count += stats_count_servers(link); + } return count; } @@ -145,8 +147,8 @@ class CommandOSStats : public Command void DoStatsUplink(CommandSource &source) { Anope::string buf; - for (std::set<Anope::string>::iterator it = Servers::Capab.begin(); it != Servers::Capab.end(); ++it) - buf += " " + *it; + for (const auto &capab : Servers::Capab) + buf += " " + capab; if (!buf.empty()) buf.erase(buf.begin()); diff --git a/modules/commands/os_sxline.cpp b/modules/commands/os_sxline.cpp index b280297a8..f08b64933 100644 --- a/modules/commands/os_sxline.cpp +++ b/modules/commands/os_sxline.cpp @@ -182,8 +182,8 @@ class CommandOSSXLineBase : public Command std::vector<Anope::string> replies; list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + for (const auto &reply : replies) + source.Reply(reply); } } @@ -371,8 +371,8 @@ class CommandOSSNLine : public CommandOSSXLineBase x->id = XLineManager::GenerateUID(); unsigned int affected = 0; - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - if (this->xlm()->Check(it->second, x)) + for (const auto &[_, user] : UserListByNick) + if (this->xlm()->Check(user, x)) ++affected; float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0; @@ -401,10 +401,8 @@ class CommandOSSNLine : public CommandOSSXLineBase { Anope::string rreason = "G-Lined: " + reason; - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (const auto &[_, user] : UserListByNick) { - User *user = it->second; - if (!user->HasMode("OPER") && user->server != Me && this->xlm()->Check(user, x)) user->Kill(Me, rreason); } @@ -579,8 +577,8 @@ class CommandOSSQLine : public CommandOSSXLineBase x->id = XLineManager::GenerateUID(); unsigned int affected = 0; - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - if (this->xlm()->Check(it->second, x)) + for (const auto &[_, user] : UserListByNick) + if (this->xlm()->Check(user, x)) ++affected; float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0; @@ -611,33 +609,28 @@ class CommandOSSQLine : public CommandOSSXLineBase if (mask[0] == '#') { - for (channel_map::const_iterator cit = ChannelList.begin(), cit_end = ChannelList.end(); cit != cit_end; ++cit) + for (const auto &[_, c] : ChannelList) { - Channel *c = cit->second; - if (!Anope::Match(c->name, mask, false, true)) continue; std::vector<User *> users; - for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) + for (const auto &[_, uc] : c->users) { - ChanUserContainer *uc = it->second; User *user = uc->user; if (!user->HasMode("OPER") && user->server != Me) users.push_back(user); } - for (unsigned i = 0; i < users.size(); ++i) - c->Kick(NULL, users[i], "%s", reason.c_str()); + for (auto *user : users) + c->Kick(NULL, user, "%s", reason.c_str()); } } else { - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (const auto &[_, user] : UserListByNick) { - User *user = it->second; - if (!user->HasMode("OPER") && user->server != Me && this->xlm()->Check(user, x)) user->Kill(Me, rreason); } diff --git a/modules/cs_statusupdate.cpp b/modules/cs_statusupdate.cpp index 3ae3890db..c871489fc 100644 --- a/modules/cs_statusupdate.cpp +++ b/modules/cs_statusupdate.cpp @@ -19,46 +19,48 @@ class StatusUpdate : public Module void OnAccessAdd(ChannelInfo *ci, CommandSource &, ChanAccess *access) override { if (ci->c) - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + { + for (const auto &[_, uc] : ci->c->users) { - User *user = it->second->user; + User *user = uc->user; ChannelInfo *next; if (user->server != Me && access->Matches(user, user->Account(), next)) { AccessGroup ag = ci->AccessFor(user); - for (unsigned i = 0; i < ModeManager::GetStatusChannelModesByRank().size(); ++i) + for (auto *cms : ModeManager::GetStatusChannelModesByRank()) { - ChannelModeStatus *cms = ModeManager::GetStatusChannelModesByRank()[i]; if (!ag.HasPriv("AUTO" + cms->name)) ci->c->RemoveMode(NULL, cms, user->GetUID()); } ci->c->SetCorrectModes(user, true); } } + } } void OnAccessDel(ChannelInfo *ci, CommandSource &, ChanAccess *access) override { if (ci->c) - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + { + for (const auto &[_, uc] : ci->c->users) { - User *user = it->second->user; + User *user = uc->user; ChannelInfo *next; if (user->server != Me && access->Matches(user, user->Account(), next)) { AccessGroup ag = ci->AccessFor(user); - for (unsigned i = 0; i < ModeManager::GetStatusChannelModesByRank().size(); ++i) + for (auto *cms : ModeManager::GetStatusChannelModesByRank()) { - ChannelModeStatus *cms = ModeManager::GetStatusChannelModesByRank()[i]; - if (!ag.HasPriv("AUTO" + cms->name)) + if (!ag.HasPriv("AUTO" + cms->name)) ci->c->RemoveMode(NULL, cms, user->GetUID()); } } } + } } }; diff --git a/modules/database/db_flatfile.cpp b/modules/database/db_flatfile.cpp index e4ad7329a..7841a57cf 100644 --- a/modules/database/db_flatfile.cpp +++ b/modules/database/db_flatfile.cpp @@ -77,17 +77,17 @@ class LoadData : public Serialize::Data std::set<Anope::string> KeySet() const override { std::set<Anope::string> keys; - for (std::map<Anope::string, Anope::string>::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 (std::map<Anope::string, Anope::string>::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it) - if (!it->second.empty()) - hash ^= Anope::hash_cs()(it->second); + for (const auto &[_, value] : this->data) + if (!value.empty()) + hash ^= Anope::hash_cs()(value); return hash; } @@ -117,51 +117,49 @@ class DBFlatFile : public Module, public Pipe { last_day = tm->tm_mday; - const std::vector<Anope::string> &type_order = Serialize::Type::GetTypeOrder(); - std::set<Anope::string> dbs; dbs.insert(Config->GetModule(this)->Get<const Anope::string>("database", "anope.db")); - for (unsigned i = 0; i < type_order.size(); ++i) + for (const auto &type_order : Serialize::Type::GetTypeOrder()) { - Serialize::Type *stype = Serialize::Type::Find(type_order[i]); + Serialize::Type *stype = Serialize::Type::Find(type_order); if (stype && stype->GetOwner()) dbs.insert("module_" + stype->GetOwner()->name + ".db"); } - for (std::set<Anope::string>::const_iterator it = dbs.begin(), it_end = dbs.end(); it != it_end; ++it) + for (const auto &db : dbs) { - const Anope::string &oldname = Anope::DataDir + "/" + *it; - Anope::string newname = Anope::DataDir + "/backups/" + *it + "-" + stringify(tm->tm_year + 1900) + Anope::printf("-%02i-", tm->tm_mon + 1) + Anope::printf("%02i", tm->tm_mday); + const Anope::string &oldname = Anope::DataDir + "/" + db; + Anope::string newname = Anope::DataDir + "/backups/" + db + "-" + stringify(tm->tm_year + 1900) + Anope::printf("-%02i-", tm->tm_mon + 1) + Anope::printf("%02i", tm->tm_mday); /* Backup already exists or no database to backup */ if (Anope::IsFile(newname) || !Anope::IsFile(oldname)) continue; - Log(LOG_DEBUG) << "db_flatfile: Attempting to rename " << *it << " to " << newname; + Log(LOG_DEBUG) << "db_flatfile: Attempting to rename " << db << " to " << newname; if (rename(oldname.c_str(), newname.c_str())) { Anope::string err = Anope::LastError(); - Log(this) << "Unable to back up database " << *it << " (" << err << ")!"; + Log(this) << "Unable to back up database " << db << " (" << err << ")!"; if (!Config->GetModule(this)->Get<bool>("nobackupokay")) { Anope::Quitting = true; - Anope::QuitReason = "Unable to back up database " + *it + " (" + err + ")"; + Anope::QuitReason = "Unable to back up database " + db + " (" + err + ")"; } continue; } - backups[*it].push_back(newname); + backups[db].push_back(newname); unsigned keepbackups = Config->GetModule(this)->Get<unsigned>("keepbackups"); - if (keepbackups > 0 && backups[*it].size() > keepbackups) + if (keepbackups > 0 && backups[db].size() > keepbackups) { - unlink(backups[*it].front().c_str()); - backups[*it].pop_front(); + unlink(backups[db].front().c_str()); + backups[db].pop_front(); } } } @@ -217,7 +215,6 @@ class DBFlatFile : public Module, public Pipe EventReturn OnLoadDatabase() override { - const std::vector<Anope::string> &type_order = Serialize::Type::GetTypeOrder(); std::set<Anope::string> tried_dbs; const Anope::string &db_name = Anope::DataDir + "/" + Config->GetModule(this)->Get<const Anope::string>("database", "anope.db"); @@ -238,18 +235,16 @@ class DBFlatFile : public Module, public Pipe LoadData ld; ld.fs = &fd; - for (unsigned i = 0; i < type_order.size(); ++i) + for (const auto &type_order : Serialize::Type::GetTypeOrder()) { - Serialize::Type *stype = Serialize::Type::Find(type_order[i]); + Serialize::Type *stype = Serialize::Type::Find(type_order); if (!stype || stype->GetOwner()) continue; - std::vector<std::streampos> &pos = positions[stype->GetName()]; - - for (unsigned j = 0; j < pos.size(); ++j) + for (const auto &position : positions[stype->GetName()]) { fd.clear(); - fd.seekg(pos[j]); + fd.seekg(position); Serializable *obj = stype->Unserialize(NULL, ld); if (obj != NULL) @@ -295,10 +290,8 @@ class DBFlatFile : public Module, public Pipe std::map<Module *, std::fstream *> databases; /* First open the databases of all of the registered types. This way, if we have a type with 0 objects, that database will be properly cleared */ - for (std::map<Anope::string, Serialize::Type *>::const_iterator it = Serialize::Type::GetTypes().begin(), it_end = Serialize::Type::GetTypes().end(); it != it_end; ++it) + for (const auto &[_, s_type] : Serialize::Type::GetTypes()) { - Serialize::Type *s_type = it->second; - if (databases[s_type->GetOwner()]) continue; @@ -316,9 +309,8 @@ class DBFlatFile : public Module, public Pipe SaveData data; const std::list<Serializable *> &items = Serializable::GetItems(); - for (std::list<Serializable *>::const_iterator it = items.begin(), it_end = items.end(); it != it_end; ++it) + for (auto *base : items) { - Serializable *base = *it; Serialize::Type *s_type = base->GetSerializableType(); data.fs = databases[s_type->GetOwner()]; @@ -332,10 +324,9 @@ class DBFlatFile : public Module, public Pipe *data.fs << "\nEND\n"; } - for (std::map<Module *, std::fstream *>::iterator it = databases.begin(), it_end = databases.end(); it != it_end; ++it) + for (auto &[mod, f] : databases) { - std::fstream *f = it->second; - const Anope::string &db_name = Anope::DataDir + "/" + (it->first ? (it->first->name + ".db") : Config->GetModule(this)->Get<const Anope::string>("database", "anope.db")); + const Anope::string &db_name = Anope::DataDir + "/" + (mod ? (mod->name + ".db") : Config->GetModule(this)->Get<const Anope::string>("database", "anope.db")); if (!f->is_open() || !f->good()) { diff --git a/modules/database/db_old.cpp b/modules/database/db_old.cpp index 710815068..f8663b395 100644 --- a/modules/database/db_old.cpp +++ b/modules/database/db_old.cpp @@ -146,20 +146,22 @@ enum static void process_mlock(ChannelInfo *ci, uint32_t lock, bool status, uint32_t *limit, Anope::string *key) { ModeLocks *ml = ci->Require<ModeLocks>("modelocks"); - for (unsigned i = 0; i < (sizeof(mlock_infos) / sizeof(mlock_info)); ++i) - if (lock & mlock_infos[i].m) + for (auto &mlock_info : mlock_infos) + { + if (lock & mlock_info.m) { - ChannelMode *cm = ModeManager::FindChannelModeByChar(mlock_infos[i].c); + ChannelMode *cm = ModeManager::FindChannelModeByChar(mlock_info.c); if (cm && ml) { - if (limit && mlock_infos[i].c == 'l') + if (limit && mlock_info.c == 'l') ml->SetMLock(cm, status, stringify(*limit)); - else if (key && mlock_infos[i].c == 'k') + else if (key && mlock_info.c == 'k') ml->SetMLock(cm, status, *key); else ml->SetMLock(cm, status); } } + } } static const char Base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; @@ -449,8 +451,8 @@ static void LoadNicks() const Anope::string settings[] = { "killprotect", "kill_quick", "ns_secure", "ns_private", "hide_email", "hide_mask", "hide_quit", "memo_signon", "memo_receive", "autoop", "msg", "ns_keepmodes" }; - for (unsigned j = 0; j < sizeof(settings) / sizeof(Anope::string); ++j) - nc->Shrink<bool>(settings[j].upper()); + for (const auto &setting : settings) + nc->Shrink<bool>(setting.upper()); char pwbuf[32]; READ(read_buffer(pwbuf, f)); @@ -752,8 +754,8 @@ static void LoadChannels() const Anope::string settings[] = { "keeptopic", "peace", "cs_private", "restricted", "cs_secure", "secureops", "securefounder", "signkick", "signkick_level", "topiclock", "persist", "noautoop", "cs_keepmodes" }; - for (unsigned j = 0; j < sizeof(settings) / sizeof(Anope::string); ++j) - ci->Shrink<bool>(settings[j].upper()); + for (const auto &setting : settings) + ci->Shrink<bool>(setting.upper()); READ(read_string(buffer, f)); ci->SetFounder(NickCore::Find(buffer)); @@ -1104,9 +1106,8 @@ static void LoadOper() XLineManager *akill, *sqline, *snline, *szline; akill = sqline = snline = szline = NULL; - for (std::list<XLineManager *>::iterator it = XLineManager::XLineManagers.begin(), it_end = XLineManager::XLineManagers.end(); it != it_end; ++it) + for (auto *xl : XLineManager::XLineManagers) { - XLineManager *xl = *it; if (xl->Type() == 'G') akill = xl; else if (xl->Type() == 'Q') @@ -1328,9 +1329,8 @@ class DBOld : public Module void OnUplinkSync(Server *s) override { - for (registered_channel_map::iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it) + for (auto &[_, ci] : *RegisteredChannelList) { - ChannelInfo *ci = it->second; uint32_t *limit = mlock_limit.Get(ci); Anope::string *key = mlock_key.Get(ci); diff --git a/modules/database/db_redis.cpp b/modules/database/db_redis.cpp index 974e9ea3f..4c90d179d 100644 --- a/modules/database/db_redis.cpp +++ b/modules/database/db_redis.cpp @@ -21,8 +21,8 @@ class Data : public Serialize::Data ~Data() override { - for (std::map<Anope::string, std::stringstream *>::iterator it = data.begin(), it_end = data.end(); it != it_end; ++it) - delete it->second; + for (auto &[_, stream] : data) + delete stream; } std::iostream& operator[](const Anope::string &key) override @@ -36,17 +36,17 @@ class Data : public Serialize::Data std::set<Anope::string> KeySet() const override { std::set<Anope::string> keys; - for (std::map<Anope::string, std::stringstream *>::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 (std::map<Anope::string, std::stringstream *>::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; } }; @@ -161,11 +161,9 @@ class DatabaseRedis : public Module, public Pipe void OnNotify() override { - for (std::set<Serializable *>::iterator it = this->updated_items.begin(), it_end = this->updated_items.end(); it != it_end; ++it) + for (auto *obj : this->updated_items) { - Serializable *s = *it; - - this->InsertObject(s); + this->InsertObject(obj); } this->updated_items.clear(); @@ -185,10 +183,9 @@ class DatabaseRedis : public Module, public Pipe return EVENT_CONTINUE; } - const std::vector<Anope::string> type_order = Serialize::Type::GetTypeOrder(); - for (unsigned i = 0; i < type_order.size(); ++i) + for (const auto &type_order : Serialize::Type::GetTypeOrder()) { - Serialize::Type *sb = Serialize::Type::Find(type_order[i]); + Serialize::Type *sb = Serialize::Type::Find(type_order); this->OnSerializeTypeCreate(sb); } @@ -266,10 +263,8 @@ void TypeLoader::OnResult(const Reply &r) return; } - for (unsigned i = 0; i < r.multi_bulk.size(); ++i) + for (auto *reply : r.multi_bulk) { - const Reply *reply = r.multi_bulk[i]; - if (reply->type != Reply::BULK) continue; @@ -440,12 +435,8 @@ void Updater::OnResult(const Reply &r) args.emplace_back("HMSET"); args.push_back("hash:" + this->type + ":" + stringify(obj->id)); - typedef std::map<Anope::string, std::stringstream *> items; - for (items::iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it) + for (const auto &[key, value] : data.data) { - const Anope::string &key = it->first; - std::stringstream *value = it->second; - args.push_back(key); args.emplace_back(value->str()); @@ -549,12 +540,8 @@ void SubscriptionListener::OnResult(const Reply &r) /* Transaction start */ me->redis->StartTransaction(); - typedef std::map<Anope::string, std::stringstream *> items; - for (items::iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it) + for (const auto &[k, value] : data.data) { - const Anope::string &k = it->first; - std::stringstream *value = it->second; - std::vector<Anope::string> args; args.emplace_back("SREM"); args.push_back("value:" + type + ":" + k + ":" + value->str()); @@ -602,12 +589,8 @@ void ModifiedObject::OnResult(const Reply &r) obj->Serialize(data); - typedef std::map<Anope::string, std::stringstream *> items; - for (items::iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it) + for (auto &[key, value] : data.data) { - const Anope::string &key = it->first; - std::stringstream *value = it->second; - std::vector<Anope::string> args; args.emplace_back("SREM"); args.push_back("value:" + st->GetName() + ":" + key + ":" + value->str()); @@ -635,12 +618,8 @@ void ModifiedObject::OnResult(const Reply &r) obj->UpdateCache(data); /* Insert new object values */ - typedef std::map<Anope::string, std::stringstream *> items; - for (items::iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it) + for (const auto &[key, value] : data.data) { - const Anope::string &key = it->first; - std::stringstream *value = it->second; - std::vector<Anope::string> args; args.emplace_back("SADD"); args.push_back("value:" + st->GetName() + ":" + key + ":" + value->str()); diff --git a/modules/database/db_sql.cpp b/modules/database/db_sql.cpp index 6494914c4..0f89de06d 100644 --- a/modules/database/db_sql.cpp +++ b/modules/database/db_sql.cpp @@ -100,10 +100,8 @@ class DBSQL : public Module, public Pipe void OnNotify() override { - for (std::set<Serializable *>::iterator it = this->updated_items.begin(), it_end = this->updated_items.end(); it != it_end; ++it) + for (auto *obj : this->updated_items) { - Serializable *obj = *it; - if (this->sql) { Data data; @@ -127,15 +125,15 @@ class DBSQL : public Module, public Pipe if (this->imported) { - for (unsigned i = 0; i < create.size(); ++i) - this->RunBackground(create[i]); + for (const auto &query : create) + this->RunBackground(query); this->RunBackground(insert, new ResultSQLSQLInterface(this, obj)); } else { - for (unsigned i = 0; i < create.size(); ++i) - this->sql->RunQuery(create[i]); + for (const auto &query : create) + this->sql->RunQuery(query); /* We are importing objects from another database module, so don't do asynchronous * queries in case the core has to shut down, it will cut short the import @@ -180,10 +178,9 @@ class DBSQL : public Module, public Pipe this->loading_databases = true; - const std::vector<Anope::string> type_order = Serialize::Type::GetTypeOrder(); - for (unsigned i = 0; i < type_order.size(); ++i) + for (const auto &type_order : Serialize::Type::GetTypeOrder()) { - Serialize::Type *sb = Serialize::Type::Find(type_order[i]); + Serialize::Type *sb = Serialize::Type::Find(type_order); this->OnSerializeTypeCreate(sb); } @@ -235,9 +232,8 @@ class DBSQL : public Module, public Pipe { Data data; - const std::map<Anope::string, Anope::string> &row = res.Row(j); - for (std::map<Anope::string, Anope::string>::const_iterator rit = row.begin(), rit_end = row.end(); rit != rit_end; ++rit) - data[rit->first] << rit->second; + for (const auto &[key, value] : res.Row(j)) + data[key] << value; Serializable *obj = sb->Unserialize(NULL, data); try diff --git a/modules/database/db_sql_live.cpp b/modules/database/db_sql_live.cpp index 73bcb6ba8..825628127 100644 --- a/modules/database/db_sql_live.cpp +++ b/modules/database/db_sql_live.cpp @@ -88,10 +88,8 @@ class DBMySQL : public Module, public Pipe if (!this->CheckInit()) return; - for (std::set<Serializable *>::iterator it = this->updated_items.begin(), it_end = this->updated_items.end(); it != it_end; ++it) + for (auto *obj : this->updated_items) { - Serializable *obj = *it; - if (obj && this->SQL) { Data data; @@ -107,8 +105,8 @@ class DBMySQL : public Module, public Pipe continue; std::vector<Query> create = this->SQL->CreateTable(this->prefix + s_type->GetName(), data); - for (unsigned i = 0; i < create.size(); ++i) - this->RunQueryResult(create[i]); + for (const auto &query : create) + this->RunQueryResult(query); Result res = this->RunQueryResult(this->SQL->BuildInsert(this->prefix + s_type->GetName(), obj->id, data)); if (res.GetID() && obj->id != res.GetID()) @@ -207,8 +205,8 @@ class DBMySQL : public Module, public Pipe { Data data; - for (std::map<Anope::string, Anope::string>::const_iterator it = row.begin(), it_end = row.end(); it != it_end; ++it) - data[it->first] << it->second; + for (const auto &[key, value] : row) + data[key] << value; Serializable *s = NULL; std::map<uint64_t, Serializable *>::iterator it = obj->objects.find(id); diff --git a/modules/encryption/enc_bcrypt.cpp b/modules/encryption/enc_bcrypt.cpp index 7eec04ad2..94c6fc164 100644 --- a/modules/encryption/enc_bcrypt.cpp +++ b/modules/encryption/enc_bcrypt.cpp @@ -20,8 +20,8 @@ class EBCRYPT : public Module Anope::string Salt() { char entropy[16]; - for (unsigned int i = 0; i < sizeof(entropy); i++) - entropy[i] = static_cast<char>(rand() % 0xFF); + for (auto &chr : entropy) + chr = static_cast<char>(rand() % 0xFF); char salt[32]; if (!_crypt_gensalt_blowfish_rn("$2a$", rounds, entropy, sizeof(entropy), salt, sizeof(salt))) diff --git a/modules/encryption/enc_sha256.cpp b/modules/encryption/enc_sha256.cpp index 878598248..d5cebcb74 100644 --- a/modules/encryption/enc_sha256.cpp +++ b/modules/encryption/enc_sha256.cpp @@ -245,8 +245,8 @@ class ESHA256 : public Module /* initializes the IV with a new random value */ void NewRandomIV() { - for (int i = 0; i < 8; ++i) - iv[i] = static_cast<uint32_t>(rand()); + for (auto &ivsegment : iv) + ivsegment = static_cast<uint32_t>(rand()); } /* returns the IV as base64-encrypted string */ diff --git a/modules/extra/m_ldap.cpp b/modules/extra/m_ldap.cpp index aa34162d0..a92385c7d 100644 --- a/modules/extra/m_ldap.cpp +++ b/modules/extra/m_ldap.cpp @@ -315,10 +315,8 @@ class LDAPService : public LDAPProvider, public Thread, public Condition this->Lock(); - for (unsigned int i = 0; i < this->queries.size(); ++i) + for (auto *req : this->queries) { - LDAPRequest *req = this->queries[i]; - /* queries have no results yet */ req->result = new LDAPResult(); req->result->type = req->type; @@ -330,10 +328,8 @@ class LDAPService : public LDAPProvider, public Thread, public Condition } this->queries.clear(); - for (unsigned int i = 0; i < this->results.size(); ++i) + for (const auto *req : this->queries) { - LDAPRequest *req = this->results[i]; - /* even though this may have already finished successfully we return that it didn't */ req->result->error = "LDAP Interface is going away"; if (req->inter) @@ -454,9 +450,8 @@ class LDAPService : public LDAPProvider, public Thread, public Condition return; } - for (unsigned int i = 0; i < q.size(); ++i) + for (auto *req : q) { - LDAPRequest *req = q[i]; int ret = req->run(); if (ret == LDAP_SERVER_DOWN || ret == LDAP_TIMEOUT) @@ -633,9 +628,8 @@ class ModuleLDAP : public Module, public Pipe results.swap(s->results); s->Unlock(); - for (unsigned int i = 0; i < results.size(); ++i) + for (const auto *req : results) { - LDAPRequest *req = results[i]; LDAPInterface *li = req->inter; LDAPResult *r = req->result; diff --git a/modules/extra/m_ldap_oper.cpp b/modules/extra/m_ldap_oper.cpp index 5da45e642..0a3c2c71a 100644 --- a/modules/extra/m_ldap_oper.cpp +++ b/modules/extra/m_ldap_oper.cpp @@ -100,8 +100,8 @@ class LDAPOper : public Module this->filter = config->Get<const Anope::string>("filter"); opertype_attribute = config->Get<const Anope::string>("opertype_attribute"); - for (std::set<Oper *>::iterator it = my_opers.begin(), it_end = my_opers.end(); it != it_end; ++it) - delete *it; + for (const auto *oper : my_opers) + delete oper; my_opers.clear(); } diff --git a/modules/extra/m_mysql.cpp b/modules/extra/m_mysql.cpp index 83fc3b73e..0ec7f8989 100644 --- a/modules/extra/m_mysql.cpp +++ b/modules/extra/m_mysql.cpp @@ -284,10 +284,8 @@ class ModuleSQL : public Module, public Pipe this->FinishedRequests.clear(); this->DThread->Unlock(); - for (std::deque<QueryResult>::const_iterator it = finishedRequests.begin(), it_end = finishedRequests.end(); it != it_end; ++it) + for (const auto &qr : finishedRequests) { - const QueryResult &qr = *it; - if (!qr.sqlinterface) throw SQL::Exception("NULL qr.sqlinterface in MySQLPipe::OnNotify() ?"); @@ -389,12 +387,12 @@ std::vector<Query> MySQLService::CreateTable(const Anope::string &table, const D { Anope::string query_text = "CREATE TABLE `" + table + "` (`id` int(10) unsigned NOT NULL AUTO_INCREMENT," " `timestamp` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"; - for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it) + for (const auto &[column, _] : data.data) { - known_cols.insert(it->first); + known_cols.insert(column); - query_text += ", `" + it->first + "` "; - if (data.GetType(it->first) == Serialize::Data::DT_INT) + query_text += ", `" + column + "` "; + if (data.GetType(column) == Serialize::Data::DT_INT) query_text += "int(11)"; else query_text += "text"; @@ -403,21 +401,23 @@ std::vector<Query> MySQLService::CreateTable(const Anope::string &table, const D queries.push_back(query_text); } else - for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it) + { + for (const auto &[column, _] : data.data) { - if (known_cols.count(it->first) > 0) + if (known_cols.count(column) > 0) continue; - known_cols.insert(it->first); + known_cols.insert(column); - Anope::string query_text = "ALTER TABLE `" + table + "` ADD `" + it->first + "` "; - if (data.GetType(it->first) == Serialize::Data::DT_INT) + Anope::string query_text = "ALTER TABLE `" + table + "` ADD `" + column + "` "; + if (data.GetType(column) == Serialize::Data::DT_INT) query_text += "int(11)"; else query_text += "text"; queries.push_back(query_text); } + } return queries; } @@ -425,27 +425,29 @@ std::vector<Query> MySQLService::CreateTable(const Anope::string &table, const D Query MySQLService::BuildInsert(const Anope::string &table, unsigned int id, Data &data) { /* Empty columns not present in the data set */ - const std::set<Anope::string> &known_cols = this->active_schema[table]; - for (std::set<Anope::string>::iterator it = known_cols.begin(), it_end = known_cols.end(); it != it_end; ++it) - if (*it != "id" && *it != "timestamp" && data.data.count(*it) == 0) - data[*it] << ""; + for (const auto &known_col : this->active_schema[table]) + { + if (known_col != "id" && known_col != "timestamp" && data.data.count(known_col) == 0) + data[known_col] << ""; + } Anope::string query_text = "INSERT INTO `" + table + "` (`id`"; - for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it) - query_text += ",`" + it->first + "`"; + + for (const auto &[field, _] : data.data) + query_text += ",`" + field + "`"; query_text += ") VALUES (" + stringify(id); - for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it) - query_text += ",@" + it->first + "@"; + for (const auto &[field, _] : data.data) + query_text += ",@" + field + "@"; query_text += ") ON DUPLICATE KEY UPDATE "; - for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it) - query_text += "`" + it->first + "`=VALUES(`" + it->first + "`),"; + for (const auto &[field, _] : data.data) + query_text += "`" + field + "`=VALUES(`" + field + "`),"; query_text.erase(query_text.end() - 1); Query query(query_text); - for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it) + for (auto &[field, value] : data.data) { Anope::string buf; - *it->second >> buf; + *value >> buf; bool escape = true; if (buf.empty()) @@ -454,7 +456,7 @@ Query MySQLService::BuildInsert(const Anope::string &table, unsigned int id, Dat escape = false; } - query.SetValue(it->first, buf, escape); + query.SetValue(field, buf, escape); } return query; @@ -509,8 +511,8 @@ Anope::string MySQLService::BuildQuery(const Query &q) { Anope::string real_query = q.query; - for (std::map<Anope::string, QueryData>::const_iterator it = q.parameters.begin(), it_end = q.parameters.end(); it != it_end; ++it) - real_query = real_query.replace_all_cs("@" + it->first + "@", (it->second.escape ? ("'" + this->Escape(it->second.data) + "'") : it->second.data)); + for (const auto &[name, value] : q.parameters) + real_query = real_query.replace_all_cs("@" + name + "@", (value.escape ? ("'" + this->Escape(value.data) + "'") : value.data)); return real_query; } diff --git a/modules/extra/m_regex_pcre.cpp b/modules/extra/m_regex_pcre.cpp index 888fc6b48..8fd18bebe 100644 --- a/modules/extra/m_regex_pcre.cpp +++ b/modules/extra/m_regex_pcre.cpp @@ -61,15 +61,10 @@ class ModuleRegexPCRE : public Module ~ModuleRegexPCRE() { - for (std::list<XLineManager *>::iterator it = XLineManager::XLineManagers.begin(); it != XLineManager::XLineManagers.end(); ++it) + for (auto *xlm : XLineManager::XLineManagers) { - XLineManager *xlm = *it; - const std::vector<XLine *> &xlines = xlm->GetList(); - - for (unsigned int i = 0; i < xlines.size(); ++i) + for (auto *x : xlm->GetList()) { - XLine *x = xlines[i]; - if (x->regex && dynamic_cast<PCRERegex *>(x->regex)) { delete x->regex; diff --git a/modules/extra/m_regex_pcre2.cpp b/modules/extra/m_regex_pcre2.cpp index f741ff2ba..2d2be3916 100644 --- a/modules/extra/m_regex_pcre2.cpp +++ b/modules/extra/m_regex_pcre2.cpp @@ -71,15 +71,10 @@ class ModuleRegexPCRE : public Module ~ModuleRegexPCRE() { - for (std::list<XLineManager *>::iterator it = XLineManager::XLineManagers.begin(); it != XLineManager::XLineManagers.end(); ++it) + for (auto *xlm : XLineManager::XLineManagers) { - XLineManager *xlm = *it; - const std::vector<XLine *> &xlines = xlm->GetList(); - - for (unsigned int i = 0; i < xlines.size(); ++i) + for (auto *x : xlm->GetList()) { - XLine *x = xlines[i]; - if (x->regex && dynamic_cast<PCRERegex *>(x->regex)) { delete x->regex; diff --git a/modules/extra/m_regex_posix.cpp b/modules/extra/m_regex_posix.cpp index 67e1c9cd1..add8ab084 100644 --- a/modules/extra/m_regex_posix.cpp +++ b/modules/extra/m_regex_posix.cpp @@ -62,15 +62,10 @@ class ModuleRegexPOSIX : public Module ~ModuleRegexPOSIX() { - for (std::list<XLineManager *>::iterator it = XLineManager::XLineManagers.begin(); it != XLineManager::XLineManagers.end(); ++it) + for (auto *xlm : XLineManager::XLineManagers) { - XLineManager *xlm = *it; - const std::vector<XLine *> &xlines = xlm->GetList(); - - for (unsigned int i = 0; i < xlines.size(); ++i) + for (auto *x : xlm->GetList()) { - XLine *x = xlines[i]; - if (x->regex && dynamic_cast<POSIXRegex *>(x->regex)) { delete x->regex; diff --git a/modules/extra/m_regex_tre.cpp b/modules/extra/m_regex_tre.cpp index 89b0e4ce0..4ff111b6a 100644 --- a/modules/extra/m_regex_tre.cpp +++ b/modules/extra/m_regex_tre.cpp @@ -63,15 +63,10 @@ class ModuleRegexTRE : public Module ~ModuleRegexTRE() { - for (std::list<XLineManager *>::iterator it = XLineManager::XLineManagers.begin(); it != XLineManager::XLineManagers.end(); ++it) + for (auto *xlm : XLineManager::XLineManagers) { - XLineManager *xlm = *it; - const std::vector<XLine *> &xlines = xlm->GetList(); - - for (unsigned int i = 0; i < xlines.size(); ++i) + for (auto *x : xlm->GetList()) { - XLine *x = xlines[i]; - if (x->regex && dynamic_cast<TRERegex *>(x->regex)) { delete x->regex; diff --git a/modules/extra/m_sql_log.cpp b/modules/extra/m_sql_log.cpp index cd1d702c8..e64b0ebd4 100644 --- a/modules/extra/m_sql_log.cpp +++ b/modules/extra/m_sql_log.cpp @@ -30,9 +30,8 @@ class SQLLog : public Module Anope::string ref_name; ServiceReference<SQL::Provider> SQL; - for (unsigned i = 0; i < li->targets.size(); ++i) + for (const auto &target : li->targets) { - const Anope::string &target = li->targets[i]; size_t sz = target.find("sql_log:"); if (!sz) { diff --git a/modules/extra/m_sql_oper.cpp b/modules/extra/m_sql_oper.cpp index 423dde49f..4be312459 100644 --- a/modules/extra/m_sql_oper.cpp +++ b/modules/extra/m_sql_oper.cpp @@ -137,10 +137,8 @@ class ModuleSQLOper : public Module ~ModuleSQLOper() { - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + for (const auto &[_, nc] : *NickCoreList) { - NickCore *nc = it->second; - if (nc->o && dynamic_cast<SQLOper *>(nc->o)) { delete nc->o; diff --git a/modules/extra/m_sqlite.cpp b/modules/extra/m_sqlite.cpp index 8702220e8..28c9d6ed5 100644 --- a/modules/extra/m_sqlite.cpp +++ b/modules/extra/m_sqlite.cpp @@ -226,12 +226,12 @@ std::vector<Query> SQLiteService::CreateTable(const Anope::string &table, const { Anope::string query_text = "CREATE TABLE `" + table + "` (`id` INTEGER PRIMARY KEY, `timestamp` timestamp DEFAULT CURRENT_TIMESTAMP"; - for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it) + for (const auto &[column, _] : data.data) { - known_cols.insert(it->first); + known_cols.insert(column); - query_text += ", `" + it->first + "` "; - if (data.GetType(it->first) == Serialize::Data::DT_INT) + query_text += ", `" + column + "` "; + if (data.GetType(column) == Serialize::Data::DT_INT) query_text += "int(11)"; else query_text += "text"; @@ -251,21 +251,23 @@ std::vector<Query> SQLiteService::CreateTable(const Anope::string &table, const queries.push_back(query_text); } else - for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it) + { + for (const auto &[column, _] : data.data) { - if (known_cols.count(it->first) > 0) + if (known_cols.count(column) > 0) continue; - known_cols.insert(it->first); + known_cols.insert(column); - Anope::string query_text = "ALTER TABLE `" + table + "` ADD `" + it->first + "` "; - if (data.GetType(it->first) == Serialize::Data::DT_INT) + Anope::string query_text = "ALTER TABLE `" + table + "` ADD `" + column + "` "; + if (data.GetType(column) == Serialize::Data::DT_INT) query_text += "int(11)"; else query_text += "text"; queries.push_back(query_text); } + } return queries; } @@ -273,31 +275,32 @@ std::vector<Query> SQLiteService::CreateTable(const Anope::string &table, const Query SQLiteService::BuildInsert(const Anope::string &table, unsigned int id, Data &data) { /* Empty columns not present in the data set */ - const std::set<Anope::string> &known_cols = this->active_schema[table]; - for (std::set<Anope::string>::iterator it = known_cols.begin(), it_end = known_cols.end(); it != it_end; ++it) - if (*it != "id" && *it != "timestamp" && data.data.count(*it) == 0) - data[*it] << ""; + for (const auto &known_col : this->active_schema[table]) + { + if (known_col != "id" && known_col != "timestamp" && data.data.count(known_col) == 0) + data[known_col] << ""; + } Anope::string query_text = "REPLACE INTO `" + table + "` ("; if (id > 0) query_text += "`id`,"; - for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it) - query_text += "`" + it->first + "`,"; + for (const auto &[field, _] : data.data) + query_text += "`" + field + "`,"; query_text.erase(query_text.length() - 1); query_text += ") VALUES ("; if (id > 0) query_text += stringify(id) + ","; - for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it) - query_text += "@" + it->first + "@,"; + for (const auto &[field, _] : data.data) + query_text += "@" + field + "@,"; query_text.erase(query_text.length() - 1); query_text += ")"; Query query(query_text); - for (Data::Map::const_iterator it = data.data.begin(), it_end = data.data.end(); it != it_end; ++it) + for (auto &[field, value] : data.data) { Anope::string buf; - *it->second >> buf; - query.SetValue(it->first, buf); + *value >> buf; + query.SetValue(field, buf); } return query; @@ -320,8 +323,8 @@ Anope::string SQLiteService::BuildQuery(const Query &q) { Anope::string real_query = q.query; - for (std::map<Anope::string, QueryData>::const_iterator it = q.parameters.begin(), it_end = q.parameters.end(); it != it_end; ++it) - real_query = real_query.replace_all_cs("@" + it->first + "@", (it->second.escape ? ("'" + this->Escape(it->second.data) + "'") : it->second.data)); + for (const auto &[name, value] : q.parameters) + real_query = real_query.replace_all_cs("@" + name + "@", (value.escape ? ("'" + this->Escape(value.data) + "'") : value.data)); return real_query; } diff --git a/modules/extra/stats/irc2sql/irc2sql.cpp b/modules/extra/stats/irc2sql/irc2sql.cpp index faa639d00..730255656 100644 --- a/modules/extra/stats/irc2sql/irc2sql.cpp +++ b/modules/extra/stats/irc2sql/irc2sql.cpp @@ -47,19 +47,18 @@ void IRC2SQL::OnReload(Configuration::Conf *conf) this->OnNewServer(it->second); } - for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it) + for (const auto &[_, c] : ChannelList) { - this->OnChannelCreate(it->second); + this->OnChannelCreate(c); } - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (const auto &[_, u] : UserListByNick) { - User *u = it->second; bool exempt = false; this->OnUserConnect(u, exempt); - for (User::ChanUserList::const_iterator cit = u->chans.begin(), cit_end = u->chans.end(); cit != cit_end; ++cit) + for (const auto &[_, uc] : u->chans) { - this->OnJoinChannel(u, cit->second->chan); + this->OnJoinChannel(u, uc->chan); } } } diff --git a/modules/m_dns.cpp b/modules/m_dns.cpp index 6df332da0..525e8637d 100644 --- a/modules/m_dns.cpp +++ b/modules/m_dns.cpp @@ -286,10 +286,8 @@ class Packet : public Query output[pos++] = this->additional.size() >> 8; output[pos++] = this->additional.size() & 0xFF; - for (unsigned i = 0; i < this->questions.size(); ++i) + for (auto &q : this->questions) { - Question &q = this->questions[i]; - if (q.type == QUERY_PTR) { sockaddrs ip(q.name); @@ -324,11 +322,10 @@ class Packet : public Query } std::vector<ResourceRecord> types[] = { this->answers, this->authorities, this->additional }; - for (int i = 0; i < 3; ++i) - for (unsigned j = 0; j < types[i].size(); ++j) + for (auto &type : types) + { + for (const auto &rr : type) { - ResourceRecord &rr = types[i][j]; - this->PackName(output, output_size, pos, rr.name); if (pos + 8 >= output_size) @@ -443,6 +440,7 @@ class Packet : public Query break; } } + } return pos; } @@ -562,8 +560,8 @@ class UDPSocket : public ReplySocket ~UDPSocket() override { - for (unsigned i = 0; i < packets.size(); ++i) - delete packets[i]; + for (const auto *packet : packets) + delete packet; } void Reply(Packet *p) override @@ -799,10 +797,8 @@ class MyManager : public Manager, public Timer packet->authorities.clear(); packet->additional.clear(); - for (unsigned i = 0; i < recv_packet.questions.size(); ++i) + for (auto &q : recv_packet.questions) { - const Question& q = recv_packet.questions[i]; - if (q.type == QUERY_AXFR || q.type == QUERY_SOA) { ResourceRecord rr(q.name, QUERY_SOA); @@ -825,10 +821,8 @@ class MyManager : public Manager, public Timer FOREACH_MOD(OnDnsRequest, (recv_packet, packet)); - for (unsigned i = 0; i < recv_packet.questions.size(); ++i) + for (auto &q : recv_packet.questions) { - const Question& q = recv_packet.questions[i]; - if (q.type == QUERY_AXFR) { ResourceRecord rr(q.name, QUERY_SOA); @@ -927,11 +921,8 @@ class MyManager : public Manager, public Timer void Notify(const Anope::string &zone) override { /* notify slaves of the update */ - for (unsigned i = 0; i < notify.size(); ++i) + for (const auto &[ip, port] : notify) { - const Anope::string &ip = notify[i].first; - short port = notify[i].second; - sockaddrs addr; addr.pton(ip.find(':') != Anope::string::npos ? AF_INET6 : AF_INET, ip, port); if (!addr.valid()) diff --git a/modules/m_dnsbl.cpp b/modules/m_dnsbl.cpp index ca17dc287..59cd1f3fc 100644 --- a/modules/m_dnsbl.cpp +++ b/modules/m_dnsbl.cpp @@ -30,11 +30,11 @@ struct Blacklist Anope::string reason; std::vector<Reply> replies; - Reply *Find(int code) + const Reply *Find(int code) { - for (unsigned int i = 0; i < replies.size(); ++i) - if (replies[i].code == code) - return &replies[i]; + for (const auto &reply : replies) + if (reply.code == code) + return &reply; return NULL; } }; @@ -62,7 +62,7 @@ class DNSBLResolver : public Request sresult.pton(AF_INET, ans_record.rdata); int result = sresult.sa4.sin_addr.s_addr >> 24; - Blacklist::Reply *reply = blacklist.Find(result); + const Blacklist::Reply *reply = blacklist.Find(result); if (!blacklist.replies.empty() && !reply) return; @@ -173,10 +173,8 @@ class ModuleDNSBL : public Module Anope::string reverse = user->ip.reverse(); - for (unsigned i = 0; i < this->blacklists.size(); ++i) + for (const auto &b : this->blacklists) { - const Blacklist &b = this->blacklists[i]; - Anope::string dnsbl_host = reverse + "." + b.name; DNSBLResolver *res = NULL; try diff --git a/modules/m_httpd.cpp b/modules/m_httpd.cpp index d80da48f4..5edd891ab 100644 --- a/modules/m_httpd.cpp +++ b/modules/m_httpd.cpp @@ -69,10 +69,8 @@ class MyHTTPClient : public HTTPClient if (std::find(this->provider->ext_ips.begin(), this->provider->ext_ips.end(), this->ip) != this->provider->ext_ips.end()) { - for (unsigned i = 0; i < this->provider->ext_headers.size(); ++i) + for (auto &token : this->provider->ext_headers) { - const Anope::string &token = this->provider->ext_headers[i]; - if (this->message.headers.count(token)) { this->ip = this->message.headers[token]; @@ -255,30 +253,27 @@ class MyHTTPClient : public HTTPClient this->WriteClient("Content-Type: " + msg->content_type); this->WriteClient("Content-Length: " + stringify(msg->length)); - for (unsigned i = 0; i < msg->cookies.size(); ++i) + for (const auto &cookie : msg->cookies) { Anope::string buf = "Set-Cookie:"; - for (HTTPReply::cookie::iterator it = msg->cookies[i].begin(), it_end = msg->cookies[i].end(); it != it_end; ++it) - buf += " " + it->first + "=" + it->second + ";"; + for (const auto &[name, value] : cookie) + buf += " " + name + "=" + value + ";"; buf.erase(buf.length() - 1); this->WriteClient(buf); } - typedef std::map<Anope::string, Anope::string> map; - for (map::iterator it = msg->headers.begin(), it_end = msg->headers.end(); it != it_end; ++it) - this->WriteClient(it->first + ": " + it->second); + for (auto &[name, value] : msg->headers) + this->WriteClient(name + ": " + value); this->WriteClient("Connection: Close"); this->WriteClient(""); - for (unsigned i = 0; i < msg->out.size(); ++i) + for (auto *d : msg->out) { - HTTPReply::Data* d = msg->out[i]; - - this->Write(d->buf, d->len); + this->Write(d->buf, d->len); delete d; } @@ -455,10 +450,8 @@ class HTTPD : public Module void OnModuleLoad(User *u, Module *m) override { - for (std::map<Anope::string, MyHTTPProvider *>::iterator it = this->providers.begin(), it_end = this->providers.end(); it != it_end; ++it) + for (auto &[_, p] : this->providers) { - MyHTTPProvider *p = it->second; - if (p->IsSSL() && sslref) try { diff --git a/modules/m_proxyscan.cpp b/modules/m_proxyscan.cpp index 052512f98..50a0b021c 100644 --- a/modules/m_proxyscan.cpp +++ b/modules/m_proxyscan.cpp @@ -350,20 +350,20 @@ class ModuleProxyScan : public Module { ProxyCheck &p = this->proxyscans[i - 1]; - for (std::set<Anope::string, ci::less>::iterator it = p.types.begin(), it_end = p.types.end(); it != it_end; ++it) + for (const auto &type : p.types) { - for (unsigned k = 0; k < p.ports.size(); ++k) + for (const auto port : p.ports) { try { ProxyConnect *con = NULL; - if (it->equals_ci("HTTP")) - con = new HTTPProxyConnect(p, p.ports[k]); - else if (it->equals_ci("SOCKS5")) - con = new SOCKS5ProxyConnect(p, p.ports[k]); + if (type.equals_ci("HTTP")) + con = new HTTPProxyConnect(p, port); + else if (type.equals_ci("SOCKS5")) + con = new SOCKS5ProxyConnect(p, port); else continue; - con->Connect(user->ip.addr(), p.ports[k]); + con->Connect(user->ip.addr(), port); } catch (const SocketException &ex) { diff --git a/modules/m_redis.cpp b/modules/m_redis.cpp index 064f406e1..4148ff65a 100644 --- a/modules/m_redis.cpp +++ b/modules/m_redis.cpp @@ -40,14 +40,12 @@ class Transaction : public Interface ~Transaction() override { - for (unsigned i = 0; i < interfaces.size(); ++i) + for (auto *iface : interfaces) { - Interface *inter = interfaces[i]; - - if (!inter) + if (!iface) continue; - inter->OnError("Interface going away"); + iface->OnError("Interface going away"); } } @@ -59,10 +57,8 @@ class Transaction : public Interface Log(LOG_DEBUG_2) << "redis: transaction complete with " << r.multi_bulk.size() << " results"; - for (unsigned i = 0; i < r.multi_bulk.size(); ++i) + for (auto *result : r.multi_bulk) { - const Reply *reply = r.multi_bulk[i]; - if (interfaces.empty()) break; @@ -70,7 +66,7 @@ class Transaction : public Interface interfaces.pop_front(); if (inter) - inter->OnResult(*reply); + inter->OnResult(*result); } } }; @@ -130,15 +126,13 @@ class MyRedisService : public Provider Pack(buffer, stringify(args.size()).c_str()); Pack(buffer, "\r\n"); - for (unsigned j = 0; j < args.size(); ++j) + for (const auto &[key, value] : args) { - const std::pair<const char *, size_t> &pair = args[j]; - Pack(buffer, "$"); - Pack(buffer, stringify(pair.second).c_str()); + Pack(buffer, stringify(value).c_str()); Pack(buffer, "\r\n"); - Pack(buffer, pair.first, pair.second); + Pack(buffer, key, value); Pack(buffer, "\r\n"); } @@ -164,8 +158,8 @@ class MyRedisService : public Provider void SendCommand(RedisSocket *s, Interface *i, const std::vector<Anope::string> &cmds) { std::vector<std::pair<const char *, size_t> > args; - for (unsigned j = 0; j < cmds.size(); ++j) - args.emplace_back(cmds[j].c_str(), cmds[j].length()); + for (const auto &cmd : cmds) + args.emplace_back(cmd.c_str(), cmd.length()); this->Send(s, i, args); } @@ -190,8 +184,8 @@ class MyRedisService : public Provider void SendCommand(Interface *i, const std::vector<Anope::string> &cmds) override { std::vector<std::pair<const char *, size_t> > args; - for (unsigned j = 0; j < cmds.size(); ++j) - args.emplace_back(cmds[j].c_str(), cmds[j].length()); + for (const auto &cmd : cmds) + args.emplace_back(cmd.c_str(), cmd.length()); this->Send(i, args); } @@ -266,14 +260,12 @@ RedisSocket::~RedisSocket() provider->sub = NULL; } - for (unsigned i = 0; i < interfaces.size(); ++i) + for (auto *iface : interfaces) { - Interface *inter = interfaces[i]; - - if (!inter) + if (!iface) continue; - inter->OnError("Interface going away"); + iface->OnError("Interface going away"); } } @@ -402,9 +394,9 @@ size_t RedisSocket::ParseReply(Reply &r, const char *buffer, size_t l) else if (r.multi_bulk_size >= 0 && r.multi_bulk.size() == static_cast<unsigned>(r.multi_bulk_size)) { /* This multi bulk is already complete, so check the sub bulks */ - for (unsigned i = 0; i < r.multi_bulk.size(); ++i) - if (r.multi_bulk[i]->type == Reply::MULTI_BULK) - ParseReply(*r.multi_bulk[i], buffer + used, l - used); + for (auto &bulk : r.multi_bulk) + if (bulk->type == Reply::MULTI_BULK) + ParseReply(*bulk, buffer + used, l - used); break; } @@ -535,12 +527,11 @@ class ModuleRedis : public Module ~ModuleRedis() override { - for (std::map<Anope::string, MyRedisService *>::iterator it = services.begin(); it != services.end(); ++it) + for (auto &[_, p] : services) { - MyRedisService *p = it->second; - delete p->sock; p->sock = NULL; + delete p->sub; p->sub = NULL; @@ -579,10 +570,8 @@ class ModuleRedis : public Module void OnModuleUnload(User *, Module *m) override { - for (std::map<Anope::string, MyRedisService *>::iterator it = services.begin(); it != services.end(); ++it) + for (auto &[_, p] : services) { - MyRedisService *p = it->second; - if (p->sock) for (unsigned i = p->sock->interfaces.size(); i > 0; --i) { diff --git a/modules/m_rewrite.cpp b/modules/m_rewrite.cpp index 7783f27c1..b5218756c 100644 --- a/modules/m_rewrite.cpp +++ b/modules/m_rewrite.cpp @@ -74,10 +74,8 @@ struct Rewrite static Rewrite *Find(const Anope::string &client, const Anope::string &cmd) { - for (unsigned i = 0; i < rewrites.size(); ++i) + for (auto &r : rewrites) { - Rewrite &r = rewrites[i]; - if ((client.empty() || r.client.equals_ci(client)) && (r.source_message.equals_ci(cmd) || r.source_message.find_ci(cmd + " ") == 0)) return &r; } @@ -87,10 +85,8 @@ struct Rewrite static Rewrite *Match(const Anope::string &client, const std::vector<Anope::string> ¶ms) { - for (unsigned i = 0; i < rewrites.size(); ++i) + for (auto &r : rewrites) { - Rewrite &r = rewrites[i]; - if ((client.empty() || r.client.equals_ci(client)) && r.Matches(params)) return &r; } diff --git a/modules/m_sasl.cpp b/modules/m_sasl.cpp index dbad95926..d14118e3c 100644 --- a/modules/m_sasl.cpp +++ b/modules/m_sasl.cpp @@ -133,8 +133,8 @@ class SASLService : public SASL::Service, public Timer ~SASLService() override { - for (std::map<Anope::string, Session *>::iterator it = sessions.begin(); it != sessions.end(); it++) - delete it->second; + for (const auto &[_, session] : sessions) + delete session; } void ProcessMessage(const SASL::Message &m) override @@ -275,8 +275,8 @@ class SASLService : public SASL::Service, public Timer { std::vector<Anope::string> mechs = Service::GetServiceKeys("SASL::Mechanism"); Anope::string buf; - for (unsigned j = 0; j < mechs.size(); ++j) - buf += "," + mechs[j]; + for (const auto &mech : mechs) + buf += "," + mech; this->SendMessage(session, "M", buf.empty() ? "" : buf.substr(1)); } diff --git a/modules/m_xmlrpc.cpp b/modules/m_xmlrpc.cpp index 1855cda2e..2ced4bca9 100644 --- a/modules/m_xmlrpc.cpp +++ b/modules/m_xmlrpc.cpp @@ -164,10 +164,8 @@ class MyXMLRPCServiceInterface : public XMLRPCServiceInterface, public HTTPPage request.data.push_back(data); } - for (unsigned i = 0; i < this->events.size(); ++i) + for (auto *e : this->events) { - XMLRPCEvent *e = this->events[i]; - if (!e->Run(this, client, request)) return false; else if (!request.get_replies().empty()) @@ -188,8 +186,8 @@ class MyXMLRPCServiceInterface : public XMLRPCServiceInterface, public HTTPPage request.reply("id", request.id); Anope::string r = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n<methodResponse>\n<params>\n<param>\n<value>\n<struct>\n"; - for (std::map<Anope::string, Anope::string>::const_iterator it = request.get_replies().begin(); it != request.get_replies().end(); ++it) - r += "<member>\n<name>" + it->first + "</name>\n<value>\n<string>" + this->Sanitize(it->second) + "</string>\n</value>\n</member>\n"; + for (const auto &[name, value] : request.get_replies()) + r += "<member>\n<name>" + name + "</name>\n<value>\n<string>" + this->Sanitize(value) + "</string>\n</value>\n</member>\n"; r += "</struct>\n</value>\n</param>\n</params>\n</methodResponse>"; request.r.Write(r); diff --git a/modules/m_xmlrpc_main.cpp b/modules/m_xmlrpc_main.cpp index a01e4969c..cdc12ed7f 100644 --- a/modules/m_xmlrpc_main.cpp +++ b/modules/m_xmlrpc_main.cpp @@ -142,8 +142,8 @@ class MyXMLRPCEvent : public XMLRPCEvent request.reply("uplinkname", Me->GetLinks().front()->GetName()); { Anope::string buf; - for (std::set<Anope::string>::iterator it = Servers::Capab.begin(); it != Servers::Capab.end(); ++it) - buf += " " + *it; + for (const auto &capab : Servers::Capab) + buf += " " + capab; if (!buf.empty()) buf.erase(buf.begin()); request.reply("uplinkcapab", buf); @@ -166,21 +166,18 @@ class MyXMLRPCEvent : public XMLRPCEvent { request.reply("bancount", stringify(c->HasMode("BAN"))); int count = 0; - std::vector<Anope::string> v = c->GetModeList("BAN"); - for (unsigned int i = 0; i < v.size(); ++i) - request.reply("ban" + stringify(++count), iface->Sanitize(v[i])); + for (auto &ban : c->GetModeList("BAN")) + request.reply("ban" + stringify(++count), iface->Sanitize(ban)); request.reply("exceptcount", stringify(c->HasMode("EXCEPT"))); count = 0; - v = c->GetModeList("EXCEPT"); - for (unsigned int i = 0; i < v.size(); ++i) - request.reply("except" + stringify(++count), iface->Sanitize(v[i])); + for (auto &except : c->GetModeList("EXCEPT")) + request.reply("except" + stringify(++count), iface->Sanitize(except)); request.reply("invitecount", stringify(c->HasMode("INVITEOVERRIDE"))); count = 0; - v = c->GetModeList("INVITEOVERRIDE"); - for (unsigned int i = 0; i < v.size(); ++i) - request.reply("invite" + stringify(++count), iface->Sanitize(v[i])); + for (auto &invite : c->GetModeList("INVITEOVERRIDE")) + request.reply("invite" + stringify(++count), iface->Sanitize(invite)); Anope::string users; for (Channel::ChanUserList::const_iterator it = c->users.begin(); it != c->users.end(); ++it) @@ -249,18 +246,13 @@ class MyXMLRPCEvent : public XMLRPCEvent void DoOperType(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) { - for (unsigned i = 0; i < Config->MyOperTypes.size(); ++i) + for (auto *ot : Config->MyOperTypes) { - OperType *ot = Config->MyOperTypes[i]; Anope::string perms; - - std::list<Anope::string> privs = ot->GetPrivs(); - for (std::list<Anope::string>::const_iterator it2 = privs.begin(), it2_end = privs.end(); it2 != it2_end; ++it2) - perms += " " + *it2; - - std::list<Anope::string> commands = ot->GetCommands(); - for (std::list<Anope::string>::const_iterator it2 = commands.begin(), it2_end = commands.end(); it2 != it2_end; ++it2) - perms += " " + *it2; + for (const auto &priv : ot->GetPrivs()) + perms += " " + priv; + for (const auto &command : ot->GetCommands()) + perms += " " + command; request.reply(ot->GetName(), perms); } } diff --git a/modules/ns_maxemail.cpp b/modules/ns_maxemail.cpp index dd71ffb5c..28aebbf55 100644 --- a/modules/ns_maxemail.cpp +++ b/modules/ns_maxemail.cpp @@ -62,10 +62,8 @@ class NSMaxEmail : public Module Anope::string cleanemail = clean ? CleanMail(email) : email; - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + for (const auto &[_, nc] : *NickCoreList) { - const NickCore *nc = it->second; - Anope::string cleannc = clean ? CleanMail(nc->email) : nc->email; if (unc != nc && cleanemail.equals_ci(cleannc)) diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp index dec19e029..608d3d869 100644 --- a/modules/protocol/bahamut.cpp +++ b/modules/protocol/bahamut.cpp @@ -176,8 +176,8 @@ class BahamutIRCdProto : public IRCDProto uc->status.Clear(); BotInfo *setter = BotInfo::Find(user->GetUID()); - for (size_t i = 0; i < cs.Modes().length(); ++i) - c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false); + for (auto mode : cs.Modes()) + c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), user->GetUID(), false); if (uc != NULL) uc->status = cs; @@ -191,9 +191,9 @@ class BahamutIRCdProto : public IRCDProto if (!u) { /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */ - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - if (x->manager->Check(it->second, x)) - this->SendAkill(it->second, x); + for (const auto &[_, user] : UserListByNick) + if (x->manager->Check(user, x)) + this->SendAkill(user, x); return; } diff --git a/modules/protocol/hybrid.cpp b/modules/protocol/hybrid.cpp index 9ca7aed33..c554cc19d 100644 --- a/modules/protocol/hybrid.cpp +++ b/modules/protocol/hybrid.cpp @@ -122,8 +122,8 @@ class HybridProto : public IRCDProto uc->status.Clear(); BotInfo *setter = BotInfo::Find(u->GetUID()); - for (size_t i = 0; i < cs.Modes().length(); ++i) - c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), u->GetUID(), false); + for (auto mode : cs.Modes()) + c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), u->GetUID(), false); if (uc) uc->status = cs; @@ -140,9 +140,9 @@ class HybridProto : public IRCDProto * No user (this akill was just added), and contains nick and/or realname. * Find users that match and ban them. */ - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - if (x->manager->Check(it->second, x)) - this->SendAkill(it->second, x); + for (const auto &[_, user] : UserListByNick) + if (x->manager->Check(user, x)) + this->SendAkill(user, x); return; } @@ -305,10 +305,8 @@ class HybridProto : public IRCDProto if (a == '-' || a == '_' || a == '.') return false; - for (i = 0; i < ident.length(); ++i) + for (const auto c : ident) { - const char &c = ident[i]; - /* A tilde can only be used as the first character of a user name. */ if (c == '~' && i == 0) continue; diff --git a/modules/protocol/inspircd.cpp b/modules/protocol/inspircd.cpp index 0e5b94f19..e91e54b57 100644 --- a/modules/protocol/inspircd.cpp +++ b/modules/protocol/inspircd.cpp @@ -101,8 +101,8 @@ class InspIRCdProto : public IRCDProto void SendSASLMechanisms(std::vector<Anope::string> &mechanisms) override { Anope::string mechlist; - for (unsigned i = 0; i < mechanisms.size(); ++i) - mechlist += "," + mechanisms[i]; + for (const auto &mechanism : mechanisms) + mechlist += "," + mechanism; UplinkSocket::Message(Me) << "METADATA * saslmechlist :" << (mechanisms.empty() ? "" : mechlist.substr(1)); } @@ -235,9 +235,9 @@ class InspIRCdProto : public IRCDProto if (!u) { /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */ - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - if (x->manager->Check(it->second, x)) - this->SendAkill(it->second, x); + for (const auto &[_, user] : UserListByNick) + if (x->manager->Check(user, x)) + this->SendAkill(user, x); return; } @@ -331,8 +331,8 @@ class InspIRCdProto : public IRCDProto uc->status.Clear(); BotInfo *setter = BotInfo::Find(user->GetUID()); - for (size_t i = 0; i < cs.Modes().length(); ++i) - c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false); + for (auto mode : cs.Modes()) + c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), user->GetUID(), false); if (uc != NULL) uc->status = cs; @@ -498,10 +498,8 @@ class InspIRCdProto : public IRCDProto if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen")) return false; - for (unsigned i = 0; i < ident.length(); ++i) + for (auto c : ident) { - const char &c = ident[i]; - if (c >= 'A' && c <= '}') continue; @@ -1639,8 +1637,8 @@ struct IRCDMessageIJoin : IRCDMessage if (params.size() >= 4) { chants = params[2].is_pos_number_only() ? convertTo<unsigned>(params[2]) : 0; - for (unsigned i = 0; i < params[3].length(); ++i) - user.first.AddMode(params[3][i]); + for (auto mode : params[3]) + user.first.AddMode(mode); } std::list<Message::Join::SJoinUser> users; diff --git a/modules/protocol/ngircd.cpp b/modules/protocol/ngircd.cpp index 6e09ebe25..7b2fc908e 100644 --- a/modules/protocol/ngircd.cpp +++ b/modules/protocol/ngircd.cpp @@ -100,8 +100,8 @@ class ngIRCdProto : public IRCDProto uc->status.Clear(); BotInfo *setter = BotInfo::Find(user->GetUID()); - for (size_t i = 0; i < cs.Modes().length(); ++i) - c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false); + for (auto mode : cs.Modes()) + c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), user->GetUID(), false); if (uc != NULL) uc->status = cs; @@ -157,13 +157,13 @@ struct IRCDMessage005 : IRCDMessage { size_t pos; Anope::string parameter, data; - for (unsigned i = 0, end = params.size(); i < end; ++i) + for (const auto ¶m : params) { - pos = params[i].find('='); + pos = param.find('='); if (pos != Anope::string::npos) { - parameter = params[i].substr(0, pos); - data = params[i].substr(pos+1, params[i].length()); + parameter = param.substr(0, pos); + data = param.substr(pos+1, param.length()); if (parameter == "MODES") { unsigned maxmodes = convertTo<unsigned>(data); diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp index c93f5e39a..679915b9d 100644 --- a/modules/protocol/plexus.cpp +++ b/modules/protocol/plexus.cpp @@ -69,8 +69,8 @@ class PlexusProto : public IRCDProto uc->status.Clear(); BotInfo *setter = BotInfo::Find(user->GetUID()); - for (size_t i = 0; i < cs.Modes().length(); ++i) - c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false); + for (auto mode : cs.Modes()) + c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), user->GetUID(), false); if (uc != NULL) uc->status = cs; diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp index 490284407..1324fa057 100644 --- a/modules/protocol/ratbox.cpp +++ b/modules/protocol/ratbox.cpp @@ -24,9 +24,9 @@ class RatboxProto : public IRCDProto if (bi && bi->introduced) return bi; - for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) - if (it->second->introduced) - return it->second; + for (const auto &[_, bi] : *BotListByNick) + if (bi->introduced) + return bi; return NULL; } diff --git a/modules/protocol/solanum.cpp b/modules/protocol/solanum.cpp index e83f231dd..1ba740d04 100644 --- a/modules/protocol/solanum.cpp +++ b/modules/protocol/solanum.cpp @@ -69,11 +69,8 @@ class SolanumProto : public IRCDProto void SendSASLMechanisms(std::vector<Anope::string> &mechanisms) override { Anope::string mechlist; - - for (unsigned i = 0; i < mechanisms.size(); ++i) - { - mechlist += "," + mechanisms[i]; - } + for (const auto &mechanism : mechanisms) + mechlist += "," + mechanism; UplinkSocket::Message(Me) << "ENCAP * MECHLIST :" << (mechanisms.empty() ? "" : mechlist.substr(1)); } diff --git a/modules/protocol/unrealircd.cpp b/modules/protocol/unrealircd.cpp index 6f4b75541..0195f8861 100644 --- a/modules/protocol/unrealircd.cpp +++ b/modules/protocol/unrealircd.cpp @@ -93,9 +93,9 @@ class UnrealIRCdProto : public IRCDProto if (!u) { /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */ - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - if (x->manager->Check(it->second, x)) - this->SendAkill(it->second, x); + for (const auto &[_, user] : UserListByNick) + if (x->manager->Check(user, x)) + this->SendAkill(user, x); return; } @@ -174,8 +174,8 @@ class UnrealIRCdProto : public IRCDProto uc->status.Clear(); BotInfo *setter = BotInfo::Find(user->GetUID()); - for (size_t i = 0; i < cs.Modes().length(); ++i) - c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false); + for (auto mode : cs.Modes()) + c->SetMode(setter, ModeManager::FindChannelModeByChar(mode), user->GetUID(), false); if (uc != NULL) uc->status = cs; @@ -237,8 +237,8 @@ class UnrealIRCdProto : public IRCDProto void SendSASLMechanisms(std::vector<Anope::string> &mechanisms) override { Anope::string mechlist; - for (unsigned i = 0; i < mechanisms.size(); ++i) - mechlist += "," + mechanisms[i]; + for (const auto &mechanism : mechanisms) + mechlist += "," + mechanism; UplinkSocket::Message() << "MD client " << Me->GetName() << " saslmechlist :" << (mechanisms.empty() ? "" : mechlist.substr(1)); } @@ -421,10 +421,8 @@ class UnrealIRCdProto : public IRCDProto if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen")) return false; - for (unsigned i = 0; i < ident.length(); ++i) + for (auto c : ident) { - const char &c = ident[i]; - if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-') continue; @@ -750,16 +748,14 @@ struct IRCDMessageCapab : Message::Capab void Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) override { - for (unsigned i = 0; i < params.size(); ++i) + for (const auto &capab : params) { - Anope::string capab = params[i]; - if (capab.find("USERMODES=") != Anope::string::npos) { Anope::string modebuf(capab.begin() + 10, capab.end()); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) + for (auto mode : modebuf) { - switch (modebuf[t]) + switch (mode) { case 'B': ModeManager::AddUserMode(new UserMode("BOT", 'B')); @@ -825,7 +821,7 @@ struct IRCDMessageCapab : Message::Capab ModeManager::AddUserMode(new UserMode("SSLPRIV", 'Z')); continue; default: - ModeManager::AddUserMode(new UserMode("", modebuf[t])); + ModeManager::AddUserMode(new UserMode("", mode)); } } } @@ -836,9 +832,9 @@ struct IRCDMessageCapab : Message::Capab Anope::string modebuf; sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) + for (auto mode : modebuf) { - switch (modebuf[t]) + switch (mode) { case 'b': ModeManager::AddChannelMode(new ChannelModeList("BAN", 'b')); @@ -862,14 +858,14 @@ struct IRCDMessageCapab : Message::Capab ModeManager::AddChannelMode(new ChannelModeList("INVITEOVERRIDE", 'I')); continue; default: - ModeManager::AddChannelMode(new ChannelModeList("", modebuf[t])); + ModeManager::AddChannelMode(new ChannelModeList("", mode)); } } sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) + for (auto mode : modebuf) { - switch (modebuf[t]) + switch (mode) { case 'k': ModeManager::AddChannelMode(new ChannelModeKey('k')); @@ -881,14 +877,14 @@ struct IRCDMessageCapab : Message::Capab ModeManager::AddChannelMode(new ChannelModeParam("REDIRECT", 'L')); continue; default: - ModeManager::AddChannelMode(new ChannelModeParam("", modebuf[t])); + ModeManager::AddChannelMode(new ChannelModeParam("", mode)); } } sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) + for (auto mode : modebuf) { - switch (modebuf[t]) + switch (mode) { case 'l': ModeManager::AddChannelMode(new ChannelModeParam("LIMIT", 'l', true)); @@ -897,14 +893,14 @@ struct IRCDMessageCapab : Message::Capab ModeManager::AddChannelMode(new ChannelModeHistory('H')); continue; default: - ModeManager::AddChannelMode(new ChannelModeParam("", modebuf[t], true)); + ModeManager::AddChannelMode(new ChannelModeParam("", mode, true)); } } sep.GetToken(modebuf); - for (size_t t = 0, end = modebuf.length(); t < end; ++t) + for (auto mode : modebuf) { - switch (modebuf[t]) + switch (mode) { case 'p': ModeManager::AddChannelMode(new ChannelMode("PRIVATE", 'p')); @@ -979,7 +975,7 @@ struct IRCDMessageCapab : Message::Capab ModeManager::AddChannelMode(new ChannelModeOperOnly("PERM", 'P')); continue; default: - ModeManager::AddChannelMode(new ChannelMode("", modebuf[t])); + ModeManager::AddChannelMode(new ChannelMode("", mode)); } } } @@ -1475,14 +1471,20 @@ struct IRCDMessageSJoin : IRCDMessage *invex = ModeManager::FindChannelModeByName("INVITEOVERRIDE"); if (ban) - for (std::list<Anope::string>::iterator it = bans.begin(), it_end = bans.end(); it != it_end; ++it) - c->SetModeInternal(source, ban, *it); + { + for (const auto &entry : bans) + c->SetModeInternal(source, ban, entry); + } if (except) - for (std::list<Anope::string>::iterator it = excepts.begin(), it_end = excepts.end(); it != it_end; ++it) - c->SetModeInternal(source, except, *it); + { + for (const auto &entry : excepts) + c->SetModeInternal(source, except, entry); + } if (invex) - for (std::list<Anope::string>::iterator it = invites.begin(), it_end = invites.end(); it != it_end; ++it) - c->SetModeInternal(source, invex, *it); + { + for (const auto &entry : invites) + c->SetModeInternal(source, invex, entry); + } } } }; diff --git a/modules/pseudoclients/botserv.cpp b/modules/pseudoclients/botserv.cpp index 7fa60b8e6..25cf8ab88 100644 --- a/modules/pseudoclients/botserv.cpp +++ b/modules/pseudoclients/botserv.cpp @@ -34,8 +34,8 @@ class BotServCore : public Module if (chan->ci && chan->ci->bi == user) { const Anope::string &botmodes = Config->GetModule(this)->Get<const Anope::string>("botmodes"); - for (unsigned i = 0; i < botmodes.length(); ++i) - chan->SetMode(chan->ci->bi, ModeManager::FindChannelModeByChar(botmodes[i]), chan->ci->bi->GetUID()); + for (auto botmode : botmodes) + chan->SetMode(chan->ci->bi, ModeManager::FindChannelModeByChar(botmode), chan->ci->bi->GetUID()); } } @@ -56,12 +56,10 @@ class BotServCore : public Module BotInfo *bi = user->server == Me ? dynamic_cast<BotInfo *>(user) : NULL; if (bi && Config->GetModule(this)->Get<bool>("smartjoin")) { - std::vector<Anope::string> bans = c->GetModeList("BAN"); - /* We check for bans */ - for (unsigned int i = 0; i < bans.size(); ++i) + for (const auto &entry : c->GetModeList("BAN")) { - Entry ban("BAN", bans[i]); + Entry ban("BAN", entry); if (ban.Matches(user)) c->RemoveMode(NULL, "BAN", ban.GetMask()); } diff --git a/modules/pseudoclients/chanserv.cpp b/modules/pseudoclients/chanserv.cpp index 9349ee6bc..ca7c7b9ab 100644 --- a/modules/pseudoclients/chanserv.cpp +++ b/modules/pseudoclients/chanserv.cpp @@ -146,10 +146,8 @@ class ChanServCore : public Module, public ChanServService nc->GetChannelReferences(chans); int max_reg = Config->GetModule(this)->Get<int>("maxregistered"); - for (unsigned i = 0; i < chans.size(); ++i) + for (auto *ci : chans) { - ChannelInfo *ci = chans[i]; - if (ci->GetFounder() == nc) { NickCore *newowner = NULL; @@ -220,9 +218,9 @@ class ChanServCore : public Module, public ChanServService std::deque<Anope::string> chans; ci->GetChannelReferences(chans); - for (unsigned i = 0; i < chans.size(); ++i) + for (const auto &chan : chans) { - ChannelInfo *c = ChannelInfo::Find(chans[i]); + ChannelInfo *c = ChannelInfo::Find(chan); if (!c) continue; @@ -303,8 +301,8 @@ class ChanServCore : public Module, public ChanServService void OnCreateChan(ChannelInfo *ci) override { /* Set default chan flags */ - for (unsigned i = 0; i < defaults.size(); ++i) - ci->Extend<bool>(defaults[i].upper()); + for (const auto &def : defaults) + ci->Extend<bool>(def.upper()); } EventReturn OnCanSet(User *u, const ChannelMode *cm) override @@ -385,9 +383,8 @@ class ChanServCore : public Module, public ChanServService ChannelMode *perm = ModeManager::FindChannelModeByName("PERM"); /* Find all persistent channels and create them, as we are about to finish burst to our uplink */ - for (registered_channel_map::iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it) + for (const auto &[_, ci] : *RegisteredChannelList) { - ChannelInfo *ci = it->second; if (!persist->HasExt(ci)) continue; diff --git a/modules/pseudoclients/global.cpp b/modules/pseudoclients/global.cpp index 11c0a44fa..c720282c7 100644 --- a/modules/pseudoclients/global.cpp +++ b/modules/pseudoclients/global.cpp @@ -19,8 +19,8 @@ class GlobalCore : public Module, public GlobalService { if (s != Me && !s->IsJuped()) s->Notice(sender, message); - for (unsigned i = 0, j = s->GetLinks().size(); i < j; ++i) - this->ServerGlobal(sender, s->GetLinks()[i], message); + for (auto *link : s->GetLinks()) + this->ServerGlobal(sender, link, message); } public: diff --git a/modules/pseudoclients/memoserv.cpp b/modules/pseudoclients/memoserv.cpp index 4efd20ee6..d6946247f 100644 --- a/modules/pseudoclients/memoserv.cpp +++ b/modules/pseudoclients/memoserv.cpp @@ -94,10 +94,8 @@ class MemoServCore : public Module, public MemoServService if (ci->c) { - for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + for (const auto &[_, cu] : ci->c->users) { - ChanUserContainer *cu = it->second; - if (ci->AccessFor(cu->user).HasPriv("MEMO")) { if (cu->user->Account() && cu->user->Account()->HasExt("MEMO_RECEIVE")) @@ -112,9 +110,8 @@ class MemoServCore : public Module, public MemoServService if (nc->HasExt("MEMO_RECEIVE")) { - for (unsigned i = 0; i < nc->aliases->size(); ++i) + for (auto *na : *nc->aliases) { - const NickAlias *na = nc->aliases->at(i); User *user = User::Find(na->nick, true); if (user && user->IsIdentified()) user->SendMessage(MemoServ, MEMO_NEW_MEMO_ARRIVED, source.c_str(), Config->StrictPrivmsg.c_str(), MemoServ->nick.c_str(), mi->memos->size()); diff --git a/modules/pseudoclients/nickserv.cpp b/modules/pseudoclients/nickserv.cpp index e17f8a5ba..4cdb3a238 100644 --- a/modules/pseudoclients/nickserv.cpp +++ b/modules/pseudoclients/nickserv.cpp @@ -147,8 +147,8 @@ class NickServCore : public Module, public NickServService /* On shutdown, restart, or mod unload, remove all of our holds for nicks (svshold or qlines) * because some IRCds do not allow us to have these automatically expire */ - for (nickalias_map::const_iterator it = NickAliasList->begin(); it != NickAliasList->end(); ++it) - this->Release(it->second); + for (const auto &[_, na] : *NickAliasList) + this->Release(na); } void OnRestart() override @@ -340,14 +340,14 @@ class NickServCore : public Module, public NickServService Configuration::Block *block = Config->GetModule(this); if (block->Get<bool>("modeonid", "yes")) - - for (User::ChanUserList::iterator it = u->chans.begin(), it_end = u->chans.end(); it != it_end; ++it) + { + for (const auto &[_, cc] : u->chans) { - ChanUserContainer *cc = it->second; Channel *c = cc->chan; if (c) c->SetCorrectModes(u, true); } + } const Anope::string &modesonid = block->Get<const Anope::string>("modesonid"); if (!modesonid.empty()) @@ -363,9 +363,8 @@ class NickServCore : public Module, public NickServService "any third-party person."), Config->StrictPrivmsg.c_str(), NickServ->nick.c_str()); } - for (std::set<NickServCollide *>::iterator it = collides.begin(); it != collides.end(); ++it) + for (auto *c : collides) { - NickServCollide *c = *it; if (c->GetUser() == u && c->GetNick() && c->GetNick()->nc == u->Account()) { delete c; @@ -382,9 +381,8 @@ class NickServCore : public Module, public NickServService void OnNickUpdate(User *u) override { - for (User::ChanUserList::iterator it = u->chans.begin(), it_end = u->chans.end(); it != it_end; ++it) + for (const auto &[_, cc] : u->chans) { - ChanUserContainer *cc = it->second; Channel *c = cc->chan; if (c) c->SetCorrectModes(u, true); @@ -414,10 +412,8 @@ class NickServCore : public Module, public NickServService void OnServerSync(Server *s) override { - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (const auto &[_, u] : UserListByNick) { - User *u = it->second; - if (u->server == s) { if (u->HasMode("REGISTERED") && !u->IsIdentified(true)) @@ -498,8 +494,8 @@ class NickServCore : public Module, public NickServService void OnNickCoreCreate(NickCore *nc) override { /* Set default flags */ - for (unsigned i = 0; i < defaults.size(); ++i) - nc->Extend<bool>(defaults[i].upper()); + for (const auto &def : defaults) + nc->Extend<bool>(def.upper()); } void OnUserQuit(User *u, const Anope::string &msg) override diff --git a/modules/pseudoclients/operserv.cpp b/modules/pseudoclients/operserv.cpp index b37247864..0d6c719c8 100644 --- a/modules/pseudoclients/operserv.cpp +++ b/modules/pseudoclients/operserv.cpp @@ -122,10 +122,8 @@ class SQLineManager : public XLineManager XLine *CheckChannel(Channel *c) { - for (std::vector<XLine *>::const_iterator it = this->GetList().begin(), it_end = this->GetList().end(); it != it_end; ++it) + for (auto *x : this->GetList()) { - XLine *x = *it; - if (x->regex) { if (x->regex->Matches(c->name)) diff --git a/modules/webcpanel/pages/chanserv/drop.cpp b/modules/webcpanel/pages/chanserv/drop.cpp index 3416635d7..57be2055d 100644 --- a/modules/webcpanel/pages/chanserv/drop.cpp +++ b/modules/webcpanel/pages/chanserv/drop.cpp @@ -33,9 +33,8 @@ bool WebCPanel::ChanServ::Drop::OnRequest(HTTPProvider *server, const Anope::str std::deque<ChannelInfo *> queue; na->nc->GetChannelReferences(queue); - for (unsigned i = 0; i < queue.size(); ++i) + for (auto *ci : queue) { - ChannelInfo *ci = queue[i]; if ((ci->HasExt("SECUREFOUNDER") ? ci->AccessFor(na->nc).founder : ci->AccessFor(na->nc).HasPriv("FOUNDER")) || (na->nc->IsServicesOper() && na->nc->o->ot->HasCommand("chanserv/drop"))) { replacements["CHANNEL_NAMES"] = ci->name; diff --git a/modules/webcpanel/pages/chanserv/modes.cpp b/modules/webcpanel/pages/chanserv/modes.cpp index c9fc0c59e..7e3de86d2 100644 --- a/modules/webcpanel/pages/chanserv/modes.cpp +++ b/modules/webcpanel/pages/chanserv/modes.cpp @@ -57,10 +57,8 @@ bool WebCPanel::ChanServ::Modes::OnRequest(HTTPProvider *server, const Anope::st replacements["MODE"] = "YES"; /* build a list with the names of all listmodes */ - for (unsigned i = 0; i < ModeManager::GetChannelModes().size(); ++i) + for (auto *cm : ModeManager::GetChannelModes()) { - ChannelMode *cm = ModeManager::GetChannelModes()[i]; - if (cm->type == MODE_LIST && cm->mchar) replacements["LISTMODES"] = cm->mchar; } @@ -94,9 +92,8 @@ bool WebCPanel::ChanServ::Modes::OnRequest(HTTPProvider *server, const Anope::st WebPanel::RunCommand(client, na->nc->display, na->nc, "ChanServ", "chanserv/mode", params, replacements); } - std::vector<Anope::string> v = c->GetModeList(cm->name); - for (unsigned int i = 0; i < v.size(); ++i) - replacements["MASKS"] = v[i]; + for (const auto &mask : c->GetModeList(cm->name)) + replacements["MASKS"] = mask; } Page.Serve(server, page_name, client, message, reply, replacements); diff --git a/modules/webcpanel/pages/chanserv/utils.cpp b/modules/webcpanel/pages/chanserv/utils.cpp index 35b302ba6..c0b300541 100644 --- a/modules/webcpanel/pages/chanserv/utils.cpp +++ b/modules/webcpanel/pages/chanserv/utils.cpp @@ -27,10 +27,8 @@ void BuildChanList(NickAlias *na, TemplateFileServer::Replacements &replacements na->nc->GetChannelReferences(queue); std::sort(queue.begin(), queue.end(), ChannelSort); - for (unsigned i = 0; i < queue.size(); ++i) + for (auto *ci : queue) { - ChannelInfo *ci = queue[i]; - if (na->nc != ci->GetFounder() && ci->AccessFor(na->nc).empty()) continue; diff --git a/modules/webcpanel/pages/memoserv/memos.cpp b/modules/webcpanel/pages/memoserv/memos.cpp index b191f8e31..d134820b4 100644 --- a/modules/webcpanel/pages/memoserv/memos.cpp +++ b/modules/webcpanel/pages/memoserv/memos.cpp @@ -18,9 +18,9 @@ bool WebCPanel::MemoServ::Memos::OnRequest(HTTPProvider *server, const Anope::st const MemoInfo *mi; Memo *m; - for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it) + for (const auto &[_, ci2] : *RegisteredChannelList) { - ci = it->second; + ci = ci2; if (ci->AccessFor(na->nc).HasPriv("MEMO")) { diff --git a/modules/webcpanel/pages/nickserv/access.cpp b/modules/webcpanel/pages/nickserv/access.cpp index 101d28a38..0614009dc 100644 --- a/modules/webcpanel/pages/nickserv/access.cpp +++ b/modules/webcpanel/pages/nickserv/access.cpp @@ -30,8 +30,8 @@ bool WebCPanel::NickServ::Access::OnRequest(HTTPProvider *server, const Anope::s WebPanel::RunCommand(client, na->nc->display, na->nc, "NickServ", "nickserv/access", params, replacements); } - for (unsigned i = 0; i < na->nc->access.size(); ++i) - replacements["ACCESS"] = na->nc->access[i]; + for (const auto &access : na->nc->access) + replacements["ACCESS"] = access; TemplateFileServer page("nickserv/access.html"); page.Serve(server, page_name, client, message, reply, replacements); diff --git a/modules/webcpanel/pages/nickserv/alist.cpp b/modules/webcpanel/pages/nickserv/alist.cpp index 924323e05..71320f7d9 100644 --- a/modules/webcpanel/pages/nickserv/alist.cpp +++ b/modules/webcpanel/pages/nickserv/alist.cpp @@ -24,10 +24,8 @@ bool WebCPanel::NickServ::Alist::OnRequest(HTTPProvider *server, const Anope::st int chan_count = 0; - for (unsigned q = 0; q < queue.size(); ++q) + for (auto *ci : queue) { - ChannelInfo *ci = queue[q]; - if (ci->GetFounder() == na->nc) { ++chan_count; diff --git a/modules/webcpanel/template_fileserver.cpp b/modules/webcpanel/template_fileserver.cpp index a2ea495cc..da390bad8 100644 --- a/modules/webcpanel/template_fileserver.cpp +++ b/modules/webcpanel/template_fileserver.cpp @@ -25,28 +25,24 @@ struct ForLoop ForLoop(size_t s, TemplateFileServer::Replacements &r, const std::vector<Anope::string> &v, const std::vector<Anope::string> &r_names) : start(s), vars(v) { - for (unsigned i = 0; i < r_names.size(); ++i) - ranges.push_back(r.equal_range(r_names[i])); + for (const auto &r_name : r_names) + ranges.push_back(r.equal_range(r_name)); } void increment(const TemplateFileServer::Replacements &r) { - for (unsigned i = 0; i < ranges.size(); ++i) + for (auto &[begin, end] : ranges) { - range &ra = ranges[i]; - - if (ra.first != r.end() && ra.first != ra.second) - ++ra.first; + if (begin != r.end() && begin != end) + ++begin; } } bool finished(const TemplateFileServer::Replacements &r) const { - for (unsigned i = 0; i < ranges.size(); ++i) + for (const auto &[begin, end] : ranges) { - const range &ra = ranges[i]; - - if (ra.first != r.end() && ra.first != ra.second) + if (begin != r.end() && begin != end) return false; } diff --git a/modules/webcpanel/webcpanel.h b/modules/webcpanel/webcpanel.h index d73c6320d..e432264c8 100644 --- a/modules/webcpanel/webcpanel.h +++ b/modules/webcpanel/webcpanel.h @@ -105,16 +105,17 @@ class WebPanelProtectedPage : public WebPanelPage Anope::string sections, get; - for (std::map<Anope::string, Anope::string>::iterator it = message.get_data.begin(), it_end = message.get_data.end(); it != it_end; ++it) - if (this->GetData().count(it->first) > 0) - get += "&" + it->first + "=" + HTTPUtils::URLEncode(it->second); + for (const auto &[key, value] : message.get_data) + { + if (this->GetData().count(key) > 0) + get += "&" + key + "=" + HTTPUtils::URLEncode(value); + } if (get.empty() == false) get = "?" + get.substr(1); Section *ns = NULL; - for (unsigned i = 0; i < panel->sections.size(); ++i) + for (auto &s : panel->sections) { - Section& s = panel->sections[i]; if (s.name == this->category) ns = &s; replacements["CATEGORY_URLS"] = s.subsections[0].url; @@ -124,9 +125,8 @@ class WebPanelProtectedPage : public WebPanelPage if (ns) { sections = ""; - for (unsigned i = 0; i < ns->subsections.size(); ++i) + for (const auto &ss : ns->subsections) { - SubSection& ss = ns->subsections[i]; replacements["SUBCATEGORY_URLS"] = ss.url; replacements["SUBCATEGORY_GETS"] = get; replacements["SUBCATEGORY_NAMES"] = ss.name; diff --git a/src/access.cpp b/src/access.cpp index baa377a02..063280809 100644 --- a/src/access.cpp +++ b/src/access.cpp @@ -62,9 +62,13 @@ static struct Privilege::Privilege(const Anope::string &n, const Anope::string &d, int r) : name(n), desc(d), rank(r) { if (this->desc.empty()) - for (unsigned j = 0; j < sizeof(descriptions) / sizeof(*descriptions); ++j) - if (descriptions[j].name.equals_ci(name)) - this->desc = descriptions[j].desc; + { + for (const auto &description : descriptions) + { + if (description.name.equals_ci(name)) + this->desc = description.desc; + } + } } bool Privilege::operator==(const Privilege &other) const @@ -94,10 +98,10 @@ void PrivilegeManager::RemovePrivilege(Privilege &p) if (it != Privileges.end()) Privileges.erase(it); - for (registered_channel_map::const_iterator cit = RegisteredChannelList->begin(), cit_end = RegisteredChannelList->end(); cit != cit_end; ++cit) + for (const auto &[_, ci] : *RegisteredChannelList) { - cit->second->QueueUpdate(); - cit->second->RemoveLevel(p.name); + ci->QueueUpdate(); + ci->RemoveLevel(p.name); } } @@ -270,9 +274,8 @@ bool ChanAccess::Matches(const User *u, const NickCore *acc, ChannelInfo* &next) if (acc) { - for (unsigned i = 0; i < acc->aliases->size(); ++i) + for (auto *na : *acc->aliases) { - const NickAlias *na = acc->aliases->at(i); if (Anope::Match(na->nick, this->mask)) return true; } @@ -342,10 +345,8 @@ static bool HasPriv(const ChanAccess::Path &path, const Anope::string &name) if (path.empty()) return false; - for (unsigned int i = 0; i < path.size(); ++i) + for (auto *access : path) { - ChanAccess *access = path[i]; - EventReturn MOD_RESULT; FOREACH_RESULT(OnCheckPriv, MOD_RESULT, (access, name)); @@ -392,9 +393,9 @@ static ChanAccess *HighestInPath(const ChanAccess::Path &path) { ChanAccess *highest = NULL; - for (unsigned int i = 0; i < path.size(); ++i) - if (highest == NULL || *path[i] > *highest) - highest = path[i]; + for (auto *ca : path) + if (highest == NULL || *ca > *highest) + highest = ca; return highest; } @@ -403,9 +404,9 @@ const ChanAccess *AccessGroup::Highest() const { ChanAccess *highest = NULL; - for (unsigned int i = 0; i < paths.size(); ++i) + for (const auto &path : paths) { - ChanAccess *hip = HighestInPath(paths[i]); + ChanAccess *hip = HighestInPath(path); if (highest == NULL || *hip > *highest) highest = hip; diff --git a/src/base.cpp b/src/base.cpp index ba0d86d51..31b85a41c 100644 --- a/src/base.cpp +++ b/src/base.cpp @@ -17,8 +17,8 @@ Base::~Base() { if (this->references != NULL) { - for (std::set<ReferenceBase *>::iterator it = this->references->begin(), it_end = this->references->end(); it != it_end; ++it) - (*it)->Invalidate(); + for (auto *reference : *this->references) + reference->Invalidate(); delete this->references; } } diff --git a/src/bots.cpp b/src/bots.cpp index 6e78cd5d2..3a658ee17 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -131,8 +131,8 @@ void BotInfo::OnKill() IRCD->SendClientIntroduction(this); this->introduced = true; - for (User::ChanUserList::const_iterator cit = this->chans.begin(), cit_end = this->chans.end(); cit != cit_end; ++cit) - IRCD->SendJoin(this, cit->second->chan, &cit->second->status); + for (const auto &[_, chan] : this->chans) + IRCD->SendJoin(this, chan->chan, &chan->status); } void BotInfo::SetNewNick(const Anope::string &newnick) diff --git a/src/channels.cpp b/src/channels.cpp index e2249e528..5c6ba55e7 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -71,25 +71,23 @@ void Channel::Reset() { this->modes.clear(); - for (ChanUserList::const_iterator it = this->users.begin(), it_end = this->users.end(); it != it_end; ++it) + for (const auto &[_, uc] : this->users) { - ChanUserContainer *uc = it->second; - ChannelStatus f = uc->status; uc->status.Clear(); /* reset modes for my clients */ if (uc->user->server == Me) { - for (size_t i = 0; i < f.Modes().length(); ++i) - this->SetMode(NULL, ModeManager::FindChannelModeByChar(f.Modes()[i]), uc->user->GetUID(), false); + for (auto mode : f.Modes()) + this->SetMode(NULL, ModeManager::FindChannelModeByChar(mode), uc->user->GetUID(), false); /* Modes might not exist yet, so be sure the status is really reset */ uc->status = f; } } - for (ChanUserList::const_iterator it = this->users.begin(), it_end = this->users.end(); it != it_end; ++it) - this->SetCorrectModes(it->second->user, true); + for (auto &[_, cuc] : this->users) + this->SetCorrectModes(cuc->user, true); // If the channel is syncing now, do not force a sync due to Reset(), as we are probably iterating over users in Message::SJoin // A sync will come soon @@ -203,10 +201,12 @@ size_t Channel::HasMode(const Anope::string &mname, const Anope::string ¶m) { if (param.empty()) return modes.count(mname); - std::vector<Anope::string> v = this->GetModeList(mname); - for (unsigned int i = 0; i < v.size(); ++i) - if (v[i].equals_ci(param)) + + for (const auto &mode : this->GetModeList(mname)) + { + if (mode.equals_ci(param)) return 1; + } return 0; } @@ -214,22 +214,22 @@ Anope::string Channel::GetModes(bool complete, bool plus) { Anope::string res, params; - for (std::multimap<Anope::string, Anope::string>::const_iterator it = this->modes.begin(), it_end = this->modes.end(); it != it_end; ++it) + for (const auto &[mode, value] : this->modes) { - ChannelMode *cm = ModeManager::FindChannelModeByName(it->first); + ChannelMode *cm = ModeManager::FindChannelModeByName(mode); if (!cm || cm->type == MODE_LIST) continue; res += cm->mchar; - if (complete && !it->second.empty()) + if (complete && !value.empty()) { ChannelModeParam *cmp = NULL; if (cm->type == MODE_PARAM) cmp = anope_dynamic_static_cast<ChannelModeParam *>(cm); if (plus || !cmp || !cmp->minus_no_arg) - params += " " + it->second; + params += " " + value; } } @@ -728,10 +728,9 @@ bool Channel::MatchesList(User *u, const Anope::string &mode) if (!this->HasMode(mode)) return false; - std::vector<Anope::string> v = this->GetModeList(mode); - for (unsigned i = 0; i < v.size(); ++i) + for (const auto &entry : this->GetModeList(mode)) { - Entry e(mode, v[i]); + Entry e(mode, entry); if (e.Matches(u)) return true; } @@ -845,9 +844,8 @@ void Channel::SetCorrectModes(User *user, bool give_modes) bool giving = give_modes; /* whether or not we have given a mode */ bool given = false; - for (unsigned i = 0; i < ModeManager::GetStatusChannelModesByRank().size(); ++i) + for (auto *cm : ModeManager::GetStatusChannelModesByRank()) { - ChannelModeStatus *cm = ModeManager::GetStatusChannelModesByRank()[i]; bool has_priv = u_access.HasPriv("AUTO" + cm->name); if (give_modes && has_priv) @@ -880,10 +878,9 @@ bool Channel::Unban(User *u, const Anope::string &mode, bool full) bool ret = false; - std::vector<Anope::string> v = this->GetModeList(mode); - for (unsigned int i = 0; i < v.size(); ++i) + for (const auto &entry : this->GetModeList(mode)) { - Entry ban(mode, v[i]); + Entry ban(mode, entry); if (ban.Matches(u, full)) { this->RemoveMode(NULL, mode, ban.GetMask()); @@ -967,10 +964,8 @@ void Channel::QueueForDeletion() void Channel::DeleteChannels() { - for (unsigned int i = 0; i < deleting.size(); ++i) + for (auto *c : deleting) { - Channel *c = deleting[i]; - if (c->CheckDelete()) delete c; } diff --git a/src/command.cpp b/src/command.cpp index 94255ef4b..4205fc4a6 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -288,15 +288,10 @@ bool Command::FindCommandFromService(const Anope::string &command_service, BotIn { bot = NULL; - for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) + for (const auto &[_, bi] : *BotListByNick) { - BotInfo *bi = it->second; - - for (CommandInfo::map::const_iterator cit = bi->commands.begin(), cit_end = bi->commands.end(); cit != cit_end; ++cit) + for (const auto &[c_name, info] : bi->commands) { - const Anope::string &c_name = cit->first; - const CommandInfo &info = cit->second; - if (info.name != command_service) continue; diff --git a/src/config.cpp b/src/config.cpp index 1f0951183..08b82bbc2 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -154,9 +154,11 @@ Conf::Conf() : Block("") {"networkinfo", "chanlen"}, }; - for (unsigned i = 0; i < sizeof(noreload) / sizeof(noreload[0]); ++i) - if (this->GetBlock(noreload[i].block)->Get<const Anope::string>(noreload[i].name) != Config->GetBlock(noreload[i].block)->Get<const Anope::string>(noreload[i].name)) - throw ConfigException("<" + noreload[i].block + ":" + noreload[i].name + "> can not be modified once set"); + for (const auto &tag : noreload) + { + if (this->GetBlock(tag.block)->Get<const Anope::string>(tag.name) != Config->GetBlock(tag.block)->Get<const Anope::string>(tag.name)) + throw ConfigException("<" + tag.block + ":" + tag.name + "> can not be modified once set"); + } } const Block *serverinfo = this->GetBlock("serverinfo"), *options = this->GetBlock("options"), @@ -186,8 +188,8 @@ Conf::Conf() : Block("") if (mail->Get<bool>("usemail")) { Anope::string check[] = { "sendmailpath", "sendfrom", "registration_subject", "registration_message", "emailchange_subject", "emailchange_message", "memo_subject", "memo_message" }; - for (unsigned i = 0; i < sizeof(check) / sizeof(Anope::string); ++i) - ValidateNotEmpty("mail", check[i], mail->Get<const Anope::string>(check[i])); + for (const auto &field : check) + ValidateNotEmpty("mail", field, mail->Get<const Anope::string>(field)); } this->ReadTimeout = options->Get<time_t>("readtimeout"); @@ -276,10 +278,8 @@ Conf::Conf() : Block("") /* Strip leading ' ' after , */ if (str.length() > 1 && str[0] == ' ') str.erase(str.begin()); - for (unsigned j = 0; j < this->MyOperTypes.size(); ++j) + for (auto *ot2 : this->MyOperTypes) { - OperType *ot2 = this->MyOperTypes[j]; - if (ot2->GetName().equals_ci(str)) { Log() << "Inheriting commands and privs from " << ot2->GetName() << " to " << ot->GetName(); @@ -308,9 +308,11 @@ Conf::Conf() : Block("") ValidateNotEmpty("oper", "type", type); OperType *ot = NULL; - for (unsigned j = 0; j < this->MyOperTypes.size(); ++j) - if (this->MyOperTypes[j]->GetName() == type) - ot = this->MyOperTypes[j]; + for (auto *opertype : this->MyOperTypes) + { + if (opertype->GetName() == type) + ot = opertype; + } if (ot == NULL) throw ConfigException("Oper block for " + nname + " has invalid oper type " + type); @@ -324,8 +326,8 @@ Conf::Conf() : Block("") this->Opers.push_back(o); } - for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) - it->second->conf = false; + for (const auto &[_, bi] : *BotListByNick) + bi->conf = false; for (int i = 0; i < this->CountBlock("service"); ++i) { const Block *service = this->GetBlock("service", i); @@ -373,28 +375,30 @@ Conf::Conf() : Block("") /* Remove all existing modes */ ChanUserContainer *cu = c->FindUser(bi); if (cu != NULL) - for (size_t j = 0; j < cu->status.Modes().length(); ++j) - c->RemoveMode(bi, ModeManager::FindChannelModeByChar(cu->status.Modes()[j]), bi->GetUID()); + { + for (auto mode : cu->status.Modes()) + c->RemoveMode(bi, ModeManager::FindChannelModeByChar(mode), bi->GetUID()); + } /* Set the new modes */ - for (unsigned j = 0; j < want_modes.length(); ++j) + for (char want_mode : want_modes) { - ChannelMode *cm = ModeManager::FindChannelModeByChar(want_modes[j]); + ChannelMode *cm = ModeManager::FindChannelModeByChar(want_mode); if (cm == NULL) - cm = ModeManager::FindChannelModeByChar(ModeManager::GetStatusChar(want_modes[j])); + cm = ModeManager::FindChannelModeByChar(ModeManager::GetStatusChar(want_mode)); if (cm && cm->type == MODE_STATUS) c->SetMode(bi, cm, bi->GetUID()); } } - for (unsigned k = 0; k < oldchannels.size(); ++k) + for (const auto &oldchannel : oldchannels) { - size_t ch = oldchannels[k].find('#'); - Anope::string chname = oldchannels[k].substr(ch != Anope::string::npos ? ch : 0); + size_t ch = oldchannel.find('#'); + Anope::string chname = oldchannel.substr(ch != Anope::string::npos ? ch : 0); bool found = false; - for (unsigned j = 0; j < bi->botchannels.size(); ++j) + for (const auto &botchannel : bi->botchannels) { - ch = bi->botchannels[j].find('#'); - Anope::string ochname = bi->botchannels[j].substr(ch != Anope::string::npos ? ch : 0); + ch = botchannel.find('#'); + Anope::string ochname = botchannel.substr(ch != Anope::string::npos ? ch : 0); if (chname.equals_ci(ochname)) found = true; @@ -436,8 +440,8 @@ Conf::Conf() : Block("") this->LogInfos.push_back(l); } - for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) - it->second->commands.clear(); + for (const auto &[_, bi] : *BotListByNick) + bi->commands.clear(); for (int i = 0; i < this->CountBlock("command"); ++i) { const Block *command = this->GetBlock("command", i); @@ -514,17 +518,14 @@ Conf::Conf() : Block("") if (Config) /* Clear existing conf opers */ - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + for (const auto &[_, nc] : *NickCoreList) { - NickCore *nc = it->second; if (nc->o && std::find(Config->Opers.begin(), Config->Opers.end(), nc->o) != Config->Opers.end()) nc->o = NULL; } /* Apply new opers */ - for (unsigned i = 0; i < this->Opers.size(); ++i) + for (auto *o : this->Opers) { - Oper *o = this->Opers[i]; - NickAlias *na = NickAlias::Find(o->name); if (!na) continue; @@ -564,21 +565,27 @@ Conf::Conf() : Block("") Conf::~Conf() { - for (unsigned i = 0; i < MyOperTypes.size(); ++i) - delete MyOperTypes[i]; - for (unsigned i = 0; i < Opers.size(); ++i) - delete Opers[i]; + for (const auto *opertype : MyOperTypes) + delete opertype; + + for (const auto *oper : Opers) + delete oper; } void Conf::Post(Conf *old) { /* Apply module changes */ - for (unsigned i = 0; i < old->ModulesAutoLoad.size(); ++i) - if (std::find(this->ModulesAutoLoad.begin(), this->ModulesAutoLoad.end(), old->ModulesAutoLoad[i]) == this->ModulesAutoLoad.end()) - ModuleManager::UnloadModule(ModuleManager::FindModule(old->ModulesAutoLoad[i]), NULL); - for (unsigned i = 0; i < this->ModulesAutoLoad.size(); ++i) - if (std::find(old->ModulesAutoLoad.begin(), old->ModulesAutoLoad.end(), this->ModulesAutoLoad[i]) == old->ModulesAutoLoad.end()) - ModuleManager::LoadModule(this->ModulesAutoLoad[i], NULL); + for (const auto &mod : old->ModulesAutoLoad) + { + if (std::find(this->ModulesAutoLoad.begin(), this->ModulesAutoLoad.end(), mod) == this->ModulesAutoLoad.end()) + ModuleManager::UnloadModule(ModuleManager::FindModule(mod), NULL); + } + + for (const auto &mod : this->ModulesAutoLoad) + { + if (std::find(old->ModulesAutoLoad.begin(), old->ModulesAutoLoad.end(), mod) == old->ModulesAutoLoad.end()) + ModuleManager::LoadModule(mod, NULL); + } /* Apply opertype changes, as non-conf opers still point to the old oper types */ for (unsigned i = Oper::opers.size(); i > 0; --i) @@ -591,9 +598,11 @@ void Conf::Post(Conf *old) OperType *ot = o->ot; o->ot = NULL; - for (unsigned j = 0; j < MyOperTypes.size(); ++j) - if (ot->GetName() == MyOperTypes[j]->GetName()) - o->ot = MyOperTypes[j]; + for (auto *opertype : MyOperTypes) + { + if (ot->GetName() == opertype->GetName()) + o->ot = opertype; + } if (o->ot == NULL) { diff --git a/src/extensible.cpp b/src/extensible.cpp index 05ab7c5ac..06ffeeb3f 100644 --- a/src/extensible.cpp +++ b/src/extensible.cpp @@ -52,10 +52,9 @@ void Extensible::ExtensibleSerialize(const Extensible *e, const Serializable *s, void Extensible::ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) { - for (std::set<ExtensibleBase *>::iterator it = extensible_items.begin(); it != extensible_items.end(); ++it) + for (auto *extensible_item : extensible_items) { - ExtensibleBase *eb = *it; - eb->ExtensibleUnserialize(e, s, data); + extensible_item->ExtensibleUnserialize(e, s, data); } } diff --git a/src/init.cpp b/src/init.cpp index cb94d77f6..a0c46cb2f 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -71,11 +71,11 @@ static bool GetCommandLineArgument(const Anope::string &name, char shortname, An { param.clear(); - for (std::vector<std::pair<Anope::string, Anope::string> >::iterator it = CommandLineArguments.begin(), it_end = CommandLineArguments.end(); it != it_end; ++it) + for (const auto &[argument, value] : CommandLineArguments) { - if (it->first.equals_ci(name) || (it->first.length() == 1 && it->first[0] == shortname)) + if (argument.equals_ci(name) || (argument.length() == 1 && argument[0] == shortname)) { - param = it->second; + param = argument; return true; } } @@ -258,14 +258,10 @@ static void setuidgid() gid = g->gr_gid; } - for (unsigned i = 0; i < Config->LogInfos.size(); ++i) + for (const auto &li : Config->LogInfos) { - LogInfo& li = Config->LogInfos[i]; - - for (unsigned j = 0; j < li.logfiles.size(); ++j) + for (const auto *lf : li.logfiles) { - LogFile* lf = li.logfiles[j]; - errno = 0; if (chown(lf->filename.c_str(), uid, gid) != 0) Log() << "Unable to change the ownership of " << lf->filename << " to " << uid << "/" << gid << ": " << Anope::LastError(); @@ -489,9 +485,9 @@ void Anope::Init(int ac, char **av) /* Create me */ Configuration::Block *block = Config->GetBlock("serverinfo"); Me = new Server(NULL, block->Get<const Anope::string>("name"), 0, block->Get<const Anope::string>("description"), block->Get<const Anope::string>("id")); - for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) + for (const auto &[_, bi] : *BotListByNick) { - it->second->server = Me; + bi->server = Me; ++Me->users; } @@ -547,8 +543,8 @@ void Anope::Init(int ac, char **av) Anope::string sid = IRCD->SID_Retrieve(); if (Me->GetSID() == Me->GetName()) Me->SetSID(sid); - for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) - it->second->GenerateUID(); + for (const auto &[_, bi] : *BotListByNick) + bi->GenerateUID(); } /* Load up databases */ @@ -560,8 +556,8 @@ void Anope::Init(int ac, char **av) FOREACH_MOD(OnPostInit, ()); - for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it) - it->second->Sync(); + for (const auto &[_, ci] : ChannelList) + ci->Sync(); Serialize::CheckTypes(); } diff --git a/src/logger.cpp b/src/logger.cpp index 532369c3b..fb4b4bea8 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -130,9 +130,13 @@ Log::~Log() FOREACH_MOD(OnLog, (this)); if (Config) - for (unsigned i = 0; i < Config->LogInfos.size(); ++i) - if (Config->LogInfos[i].HasType(this->type, this->category)) - Config->LogInfos[i].ProcessMessage(this); + { + for (auto &li : Config->LogInfos) + { + if (li.HasType(this->type, this->category)) + li.ProcessMessage(this); + } + } } Anope::string Log::FormatSource() const @@ -232,8 +236,8 @@ LogInfo::LogInfo(int la, bool rio, bool ldebug) : log_age(la), raw_io(rio), debu LogInfo::~LogInfo() { - for (unsigned i = 0; i < this->logfiles.size(); ++i) - delete this->logfiles[i]; + for (const auto *logfile : this->logfiles) + delete logfile; this->logfiles.clear(); } @@ -280,16 +284,15 @@ bool LogInfo::HasType(LogType ltype, const Anope::string &type) const if (list == NULL) return false; - for (unsigned i = 0; i < list->size(); ++i) + for (auto value : *list) { - Anope::string cat = list->at(i); bool inverse = false; - if (cat[0] == '~') + if (value[0] == '~') { - cat.erase(cat.begin()); + value.erase(value.begin()); inverse = true; } - if (Anope::Match(type, cat)) + if (Anope::Match(type, value)) { return !inverse; } @@ -300,14 +303,12 @@ bool LogInfo::HasType(LogType ltype, const Anope::string &type) const void LogInfo::OpenLogFiles() { - for (unsigned i = 0; i < this->logfiles.size(); ++i) - delete this->logfiles[i]; + for (const auto *logfile : this->logfiles) + delete logfile; this->logfiles.clear(); - for (unsigned i = 0; i < this->targets.size(); ++i) + for (const auto &target : this->targets) { - const Anope::string &target = this->targets[i]; - if (target.empty() || target[0] == '#' || target == "globops" || target.find(":") != Anope::string::npos) continue; @@ -352,10 +353,8 @@ void LogInfo::ProcessMessage(const Log *l) FOREACH_MOD(OnLogMessage, (this, l, buffer)); - for (unsigned i = 0; i < this->targets.size(); ++i) + for (const auto &target : this->targets) { - const Anope::string &target = this->targets[i]; - if (!target.empty() && target[0] == '#') { if (UplinkSock && l->type <= LOG_NORMAL && Me && Me->IsSynced()) @@ -393,11 +392,10 @@ void LogInfo::ProcessMessage(const Log *l) this->OpenLogFiles(); if (this->log_age) - for (unsigned i = 0; i < this->targets.size(); ++i) + { + for (const auto &target : this->targets) { - const Anope::string &target = this->targets[i]; - - if (target.empty() || target[0] == '#' || target == "globops" || target.find(":") != Anope::string::npos) + if (target.empty() || target[0] == '#' || target == "globops" || target.find(":") != Anope::string::npos) continue; Anope::string oldlog = CreateLogName(target, Anope::CurTime - 86400 * this->log_age); @@ -407,11 +405,11 @@ void LogInfo::ProcessMessage(const Log *l) Log(LOG_DEBUG) << "Deleted old logfile " << oldlog; } } + } } - for (unsigned i = 0; i < this->logfiles.size(); ++i) + for (auto *lf : this->logfiles) { - LogFile *lf = this->logfiles[i]; lf->stream << GetTimeStamp() << " " << buffer << std::endl; } } diff --git a/src/mail.cpp b/src/mail.cpp index 7ad9c75f2..3f24e3a54 100644 --- a/src/mail.cpp +++ b/src/mail.cpp @@ -144,13 +144,15 @@ bool Mail::Validate(const Anope::string &email) return false; /* Check for forbidden characters in the name */ - for (unsigned i = 0, end = copy.length(); i < end; ++i) + for (auto chr : copy) { - if (copy[i] <= 31 || copy[i] >= 127) + if (chr <= 31 || chr >= 127) return false; - for (unsigned int j = 0; j < 13; ++j) - if (copy[i] == specials[j]) + for (auto special : specials) + { + if (chr == special) return false; + } } /* Check for forbidden characters in the domain */ @@ -158,9 +160,11 @@ bool Mail::Validate(const Anope::string &email) { if (domain[i] <= 31 || domain[i] >= 127) return false; - for (unsigned int j = 0; j < 13; ++j) - if (domain[i] == specials[j]) + for (auto special : specials) + { + if (domain[i] == special) return false; + } if (domain[i] == '.') { if (!i || i == end - 1) diff --git a/src/memos.cpp b/src/memos.cpp index 3393e958b..03cd7f77d 100644 --- a/src/memos.cpp +++ b/src/memos.cpp @@ -113,9 +113,11 @@ void MemoInfo::Del(unsigned index) bool MemoInfo::HasIgnore(User *u) { - for (unsigned i = 0; i < this->ignores.size(); ++i) - if (u->nick.equals_ci(this->ignores[i]) || (u->Account() && u->Account()->display.equals_ci(this->ignores[i])) || Anope::Match(u->GetMask(), Anope::string(this->ignores[i]))) + for (const auto &ignore : this->ignores) + { + if (u->nick.equals_ci(ignore) || (u->Account() && u->Account()->display.equals_ci(ignore)) || Anope::Match(u->GetMask(), Anope::string(ignore))) return true; + } return false; } diff --git a/src/messages.cpp b/src/messages.cpp index 701df60a1..2aaae177f 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -43,8 +43,10 @@ void Capab::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, Servers::Capab.insert(token); } else - for (unsigned i = 0; i < params.size(); ++i) - Servers::Capab.insert(params[i]); + { + for (const auto ¶m : params) + Servers::Capab.insert(param); + } } void Error::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, const Anope::map<Anope::string> &tags) @@ -127,10 +129,8 @@ void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, co */ c->SetModesInternal(source, modes, ts, !c->syncing); - for (std::list<SJoinUser>::const_iterator it = users.begin(), it_end = users.end(); it != it_end; ++it) + for (const auto &[status, u] : users) { - const ChannelStatus &status = it->first; - User *u = it->second; keep_their_modes = ts <= c->creation_time; // OnJoinChannel can call modules which can modify this channel's ts if (c->FindUser(u)) @@ -426,10 +426,8 @@ void Stats::Run(MessageSource &source, const std::vector<Anope::string> ¶ms, IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]); else { - for (unsigned i = 0; i < Oper::opers.size(); ++i) + for (auto *o : Oper::opers) { - Oper *o = Oper::opers[i]; - const NickAlias *na = NickAlias::Find(o->name); if (na) IRCD->SendNumeric(243, source.GetSource(), "O * * %s %s 0", o->name.c_str(), o->ot->GetName().replace_all_cs(" ", "_").c_str()); diff --git a/src/misc.cpp b/src/misc.cpp index 0728daab1..39c688ea6 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -102,8 +102,8 @@ void NumberList::Process() } else { - for (std::set<unsigned>::iterator it = numbers.begin(), it_end = numbers.end(); it != it_end; ++it) - this->HandleNumber(*it); + for (unsigned int number : numbers) + this->HandleNumber(number); } } @@ -141,29 +141,30 @@ void ListFormatter::Process(std::vector<Anope::string> &buffer) std::vector<Anope::string> tcolumns; std::map<Anope::string, size_t> lengths; std::set<Anope::string> breaks; - for (unsigned i = 0; i < this->columns.size(); ++i) + for (const auto &column : this->columns) { - tcolumns.emplace_back(Language::Translate(this->nc, this->columns[i].c_str())); - lengths[this->columns[i]] = tcolumns[i].length(); + tcolumns.emplace_back(Language::Translate(this->nc, column.c_str())); + lengths[column] = column.length(); } - for (unsigned i = 0; i < this->entries.size(); ++i) + for (auto &entry : this->entries) { - ListEntry &e = this->entries[i]; - for (unsigned j = 0; j < this->columns.size(); ++j) - if (e[this->columns[j]].length() > lengths[this->columns[j]]) - lengths[this->columns[j]] = e[this->columns[j]].length(); + for (const auto &column : this->columns) + { + if (entry[column].length() > lengths[column]) + lengths[column] = entry[column].length(); + } } - unsigned length = 0; - for (std::map<Anope::string, size_t>::iterator it = lengths.begin(), it_end = lengths.end(); it != it_end; ++it) + unsigned total_length = 0; + for (const auto &[column, length] : lengths) { /* Break lines at 80 chars */ - if (length > 80) + if (total_length > 80) { - breaks.insert(it->first); - length = 0; + breaks.insert(column); + total_length = 0; } else - length += it->second; + total_length += length; } /* Only put a list header if more than 1 column */ @@ -187,10 +188,8 @@ void ListFormatter::Process(std::vector<Anope::string> &buffer) buffer.push_back(s); } - for (unsigned i = 0; i < this->entries.size(); ++i) + for (auto &entry : this->entries) { - ListEntry &e = this->entries[i]; - Anope::string s; for (unsigned j = 0; j < this->columns.size(); ++j) { @@ -201,9 +200,9 @@ void ListFormatter::Process(std::vector<Anope::string> &buffer) } else if (!s.empty()) s += " "; - s += e[this->columns[j]]; + s += entry[this->columns[j]]; if (j + 1 != this->columns.size()) - for (unsigned k = e[this->columns[j]].length(); k < lengths[this->columns[j]]; ++k) + for (unsigned k = entry[this->columns[j]].length(); k < lengths[this->columns[j]]; ++k) s += " "; } buffer.push_back(s); @@ -218,12 +217,12 @@ void InfoFormatter::Process(std::vector<Anope::string> &buffer) { buffer.clear(); - for (std::vector<std::pair<Anope::string, Anope::string> >::iterator it = this->replies.begin(), it_end = this->replies.end(); it != it_end; ++it) + for (const auto &[key, value] : this->replies) { Anope::string s; - for (unsigned i = it->first.length(); i < this->longest; ++i) + for (unsigned i = key.length(); i < this->longest; ++i) s += " "; - s += it->first + ": " + Language::Translate(this->nc, it->second.c_str()); + s += key + ": " + Language::Translate(this->nc, value.c_str()); buffer.push_back(s); } @@ -242,11 +241,11 @@ void InfoFormatter::AddOption(const Anope::string &opt) { Anope::string options = Language::Translate(this->nc, "Options"); Anope::string *optstr = NULL; - for (std::vector<std::pair<Anope::string, Anope::string> >::iterator it = this->replies.begin(), it_end = this->replies.end(); it != it_end; ++it) + for (auto &[option, value] : this->replies) { - if (it->first == options) + if (option == options) { - optstr = &it->second; + optstr = &value; break; } } diff --git a/src/modes.cpp b/src/modes.cpp index be2a5fab1..6c46302de 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -95,9 +95,9 @@ Anope::string ChannelStatus::BuildModePrefixList() const { Anope::string ret; - for (size_t i = 0; i < modes.length(); ++i) + for (auto mode : modes) { - ChannelMode *cm = ModeManager::FindChannelModeByChar(modes[i]); + ChannelMode *cm = ModeManager::FindChannelModeByChar(mode); if (cm != NULL && cm->type == MODE_STATUS) { ChannelModeStatus *cms = anope_dynamic_static_cast<ChannelModeStatus *>(cm); @@ -144,9 +144,9 @@ ChannelMode *ChannelMode::Wrap(Anope::string ¶m) ChannelMode *ChannelMode::Unwrap(Anope::string ¶m) { - for (unsigned i = 0; i < listeners.size(); ++i) + for (auto *listener : listeners) { - ChannelMode *cm = listeners[i]->Unwrap(this, param); + ChannelMode *cm = listener->Unwrap(this, param); if (cm != this) return cm; } @@ -446,8 +446,8 @@ bool ModeManager::AddChannelMode(ChannelMode *cm) FOREACH_MOD(OnChannelModeAdd, (cm)); - for (unsigned int i = 0; i < ChannelModes.size(); ++i) - ChannelModes[i]->Check(); + for (auto *cmode : ChannelModes) + cmode->Check(); return true; } @@ -590,10 +590,8 @@ static struct StatusSort void ModeManager::RebuildStatusModes() { ChannelModesByStatus.clear(); - for (unsigned j = 0; j < ChannelModesIdx.size(); ++j) + for (auto *cm : ChannelModesIdx) { - ChannelMode *cm = ChannelModesIdx[j]; - if (cm && cm->type == MODE_STATUS && std::find(ChannelModesByStatus.begin(), ChannelModesByStatus.end(), cm) == ChannelModesByStatus.end()) ChannelModesByStatus.push_back(anope_dynamic_static_cast<ChannelModeStatus *>(cm)); } @@ -630,30 +628,22 @@ void ModeManager::ProcessModes() { if (!UserStackerObjects.empty()) { - for (std::map<User *, StackerInfo *>::const_iterator it = UserStackerObjects.begin(), it_end = UserStackerObjects.end(); it != it_end; ++it) + for (const auto &[u, s] : UserStackerObjects) { - User *u = it->first; - StackerInfo *s = it->second; - - std::list<Anope::string> ModeStrings = BuildModeStrings(s); - for (std::list<Anope::string>::iterator lit = ModeStrings.begin(), lit_end = ModeStrings.end(); lit != lit_end; ++lit) - IRCD->SendMode(s->bi, u, "%s", lit->c_str()); - delete it->second; + for (const auto &modestr : BuildModeStrings(s)) + IRCD->SendMode(s->bi, u, "%s", modestr.c_str()); + delete s; } UserStackerObjects.clear(); } if (!ChannelStackerObjects.empty()) { - for (std::map<Channel *, StackerInfo *>::const_iterator it = ChannelStackerObjects.begin(), it_end = ChannelStackerObjects.end(); it != it_end; ++it) + for (const auto &[c, s] : ChannelStackerObjects) { - Channel *c = it->first; - StackerInfo *s = it->second; - - std::list<Anope::string> ModeStrings = BuildModeStrings(s); - for (std::list<Anope::string>::iterator lit = ModeStrings.begin(), lit_end = ModeStrings.end(); lit != lit_end; ++lit) - IRCD->SendMode(s->bi, c, "%s", lit->c_str()); - delete it->second; + for (const auto &modestr : BuildModeStrings(s)) + IRCD->SendMode(s->bi, c, "%s", modestr.c_str()); + delete s; } ChannelStackerObjects.clear(); } @@ -666,9 +656,8 @@ static void StackerDel(std::map<T *, StackerInfo *> &map, T *obj) if (it != map.end()) { StackerInfo *si = it->second; - std::list<Anope::string> ModeStrings = BuildModeStrings(si); - for (std::list<Anope::string>::iterator lit = ModeStrings.begin(), lit_end = ModeStrings.end(); lit != lit_end; ++lit) - IRCD->SendMode(si->bi, obj, "%s", lit->c_str()); + for (const auto &modestr : BuildModeStrings(si)) + IRCD->SendMode(si->bi, obj, "%s", modestr.c_str()); delete si; map.erase(it); diff --git a/src/module.cpp b/src/module.cpp index 3aab9f46f..7722c7748 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -40,11 +40,11 @@ Module::Module(const Anope::string &modname, const Anope::string &, ModType modt ModuleManager::Modules.push_back(this); #if HAVE_LOCALIZATION - for (unsigned i = 0; i < Language::Languages.size(); ++i) + for (const auto &language : Language::Languages) { /* Remove .UTF-8 or any other suffix */ Anope::string lang; - sepstream(Language::Languages[i], '.').GetToken(lang); + sepstream(language, '.').GetToken(lang); if (Anope::IsFile(Anope::LocaleDir + "/" + lang + "/LC_MESSAGES/" + modname + ".mo")) { diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index 600e7910e..38ed130f7 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -267,8 +267,8 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u) Log(LOG_DEBUG) << "Module " << modname << " loaded."; /* Attach module to all events */ - for (unsigned i = 0; i < I_SIZE; ++i) - EventHandlers[i].push_back(m); + for (auto &mods : EventHandlers) + mods.push_back(m); m->Prioritize(); @@ -307,10 +307,8 @@ ModuleReturn ModuleManager::UnloadModule(Module *m, User *u) Module *ModuleManager::FindModule(const Anope::string &name) { - for (std::list<Module *>::const_iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it) + for (auto *m : Modules) { - Module *m = *it; - if (m->name.equals_ci(name)) return m; } @@ -320,10 +318,8 @@ Module *ModuleManager::FindModule(const Anope::string &name) Module *ModuleManager::FindFirstOf(ModType type) { - for (std::list<Module *>::const_iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it) + for (auto *m : Modules) { - Module *m = *it; - if (m->type & type) return m; } @@ -389,9 +385,8 @@ ModuleReturn ModuleManager::DeleteModule(Module *m) void ModuleManager::DetachAll(Module *mod) { - for (unsigned i = 0; i < I_SIZE; ++i) + for (auto &mods : EventHandlers) { - std::vector<Module *> &mods = EventHandlers[i]; std::vector<Module *>::iterator it2 = std::find(mods.begin(), mods.end(), mod); if (it2 != mods.end()) mods.erase(it2); @@ -504,16 +499,17 @@ void ModuleManager::UnloadAll() { std::vector<Anope::string> modules; for (size_t i = 1, j = 0; i != MT_END; j |= i, i <<= 1) - for (std::list<Module *>::iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it) + { + for (auto *m : Modules) { - Module *m = *it; if ((m->type & j) == m->type) modules.push_back(m->name); } + } - for (unsigned i = 0; i < modules.size(); ++i) + for (auto &module : modules) { - Module *m = FindModule(modules[i]); + Module *m = FindModule(module); if (m != NULL) UnloadModule(m, NULL); } diff --git a/src/nickcore.cpp b/src/nickcore.cpp index 4c14d8591..9d292bbf3 100644 --- a/src/nickcore.cpp +++ b/src/nickcore.cpp @@ -78,11 +78,11 @@ void NickCore::Serialize(Serialize::Data &data) const data["pass"] << this->pass; data["email"] << this->email; data["language"] << this->language; - for (unsigned i = 0; i < this->access.size(); ++i) - data["access"] << this->access[i] << " "; + for (const auto &mask : this->access) + data["access"] << mask << " "; data["memomax"] << this->memos.memomax; - for (unsigned i = 0; i < this->memos.ignores.size(); ++i) - data["memoignores"] << this->memos.ignores[i] << " "; + for (const auto &ignore : this->memos.ignores) + data["memoignores"] << ignore << " "; Extensible::ExtensibleSerialize(this, this, data); } @@ -171,8 +171,8 @@ void NickCore::SetDisplay(const NickAlias *na) FOREACH_MOD(OnChangeCoreDisplay, (this, na->nick)); /* this affects the serialized aliases */ - for (unsigned i = 0; i < aliases->size(); ++i) - aliases->at(i)->QueueUpdate(); + for (auto *alias : *aliases) + alias->QueueUpdate(); /* Remove the core from the list */ NickCoreList->erase(this->display); @@ -207,9 +207,11 @@ unsigned NickCore::GetAccessCount() const bool NickCore::FindAccess(const Anope::string &entry) { - for (unsigned i = 0, end = this->access.size(); i < end; ++i) - if (this->access[i] == entry) + for (const auto &mask : this->access) + { + if (mask == entry) return true; + } return false; } @@ -263,8 +265,8 @@ void NickCore::RemoveChannelReference(ChannelInfo *ci) void NickCore::GetChannelReferences(std::deque<ChannelInfo *> &queue) { queue.clear(); - for (std::map<ChannelInfo *, int>::iterator it = this->chanaccess->begin(), it_end = this->chanaccess->end(); it != it_end; ++it) - queue.push_back(it->first); + for (const auto &[ci, _] : *this->chanaccess) + queue.push_back(ci); } NickCore* NickCore::Find(const Anope::string &nick) @@ -300,8 +302,8 @@ uint64_t NickCore::GetId() { // Generate a random key for SipHash. char key[16]; - for (size_t i = 0; i < sizeof(key); ++i) - key[i] = rand() % CHAR_MAX; + for (auto &chr : key) + chr = rand() % CHAR_MAX; uint64_t newid = Anope::SipHash24(secretid.c_str(), secretid.length(), key); nickcoreid_map::const_iterator it = NickCoreIdList.find(newid); diff --git a/src/opertype.cpp b/src/opertype.cpp index 6a144fd3c..e7708f99f 100644 --- a/src/opertype.cpp +++ b/src/opertype.cpp @@ -27,10 +27,8 @@ Oper::~Oper() Oper *Oper::Find(const Anope::string &name) { - for (unsigned i = 0; i < opers.size(); ++i) + for (auto *o : opers) { - Oper *o = opers[i]; - if (o->name.equals_ci(name)) return o; } @@ -40,10 +38,8 @@ Oper *Oper::Find(const Anope::string &name) OperType *OperType::Find(const Anope::string &name) { - for (unsigned i = 0; i < Config->MyOperTypes.size(); ++i) + for (auto *ot : Config->MyOperTypes) { - OperType *ot = Config->MyOperTypes[i]; - if (ot->GetName() == name) return ot; } @@ -57,19 +53,15 @@ OperType::OperType(const Anope::string &nname) : name(nname) bool OperType::HasCommand(const Anope::string &cmdstr) const { - for (std::list<Anope::string>::const_iterator it = this->commands.begin(), it_end = this->commands.end(); it != it_end; ++it) + for (const auto &command : this->commands) { - const Anope::string &s = *it; - - if (!s.find('~') && Anope::Match(cmdstr, s.substr(1))) + if (!command.find('~') && Anope::Match(cmdstr, command.substr(1))) return false; - else if (Anope::Match(cmdstr, s)) + else if (Anope::Match(cmdstr, command)) return true; } - for (std::set<OperType *>::const_iterator iit = this->inheritances.begin(), iit_end = this->inheritances.end(); iit != iit_end; ++iit) + for (auto *ot : this->inheritances) { - OperType *ot = *iit; - if (ot->HasCommand(cmdstr)) return true; } @@ -79,19 +71,15 @@ bool OperType::HasCommand(const Anope::string &cmdstr) const bool OperType::HasPriv(const Anope::string &privstr) const { - for (std::list<Anope::string>::const_iterator it = this->privs.begin(), it_end = this->privs.end(); it != it_end; ++it) + for (const auto &priv : this->privs) { - const Anope::string &s = *it; - - if (!s.find('~') && Anope::Match(privstr, s.substr(1))) + if (!priv.find('~') && Anope::Match(privstr, priv.substr(1))) return false; - else if (Anope::Match(privstr, s)) + else if (Anope::Match(privstr, priv)) return true; } - for (std::set<OperType *>::const_iterator iit = this->inheritances.begin(), iit_end = this->inheritances.end(); iit != iit_end; ++iit) + for (auto *ot : this->inheritances) { - OperType *ot = *iit; - if (ot->HasPriv(privstr)) return true; } @@ -123,12 +111,10 @@ void OperType::Inherits(OperType *ot) const std::list<Anope::string> OperType::GetCommands() const { std::list<Anope::string> cmd_list = this->commands; - for (std::set<OperType *>::const_iterator it = this->inheritances.begin(), it_end = this->inheritances.end(); it != it_end; ++it) + for (auto *ot : this->inheritances) { - OperType *ot = *it; - std::list<Anope::string> cmds = ot->GetCommands(); - for (std::list<Anope::string>::const_iterator it2 = cmds.begin(), it2_end = cmds.end(); it2 != it2_end; ++it2) - cmd_list.push_back(*it2); + for (const auto &cmd : ot->GetCommands()) + cmd_list.push_back(cmd); } return cmd_list; } @@ -136,12 +122,10 @@ const std::list<Anope::string> OperType::GetCommands() const const std::list<Anope::string> OperType::GetPrivs() const { std::list<Anope::string> priv_list = this->privs; - for (std::set<OperType *>::const_iterator it = this->inheritances.begin(), it_end = this->inheritances.end(); it != it_end; ++it) + for (auto *ot : this->inheritances) { - OperType *ot = *it; - std::list<Anope::string> priv = ot->GetPrivs(); - for (std::list<Anope::string>::const_iterator it2 = priv.begin(), it2_end = priv.end(); it2 != it2_end; ++it2) - priv_list.push_back(*it2); + for (const auto &priv : ot->GetPrivs()) + priv_list.push_back(priv); } return priv_list; } diff --git a/src/protocol.cpp b/src/protocol.cpp index 6cba86a9b..090187819 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -389,10 +389,8 @@ bool IRCDProto::IsIdentValid(const Anope::string &ident) if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen")) return false; - for (unsigned i = 0; i < ident.length(); ++i) + for (auto c : ident) { - const char &c = ident[i]; - if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-') continue; @@ -416,11 +414,11 @@ bool IRCDProto::IsHostValid(const Anope::string &host) return false; int dots = 0; - for (unsigned i = 0; i < host.length(); ++i) + for (auto chr : host) { - if (host[i] == '.') + if (chr == '.') ++dots; - if (vhostchars.find_first_of(host[i]) == Anope::string::npos) + if (vhostchars.find_first_of(chr) == Anope::string::npos) return false; } diff --git a/src/regchannel.cpp b/src/regchannel.cpp index 984da55ab..966f3e1b4 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -194,16 +194,16 @@ void ChannelInfo::Serialize(Serialize::Data &data) const data.SetType("bantype", Serialize::Data::DT_INT); data["bantype"] << this->bantype; { Anope::string levels_buffer; - for (Anope::map<int16_t>::const_iterator it = this->levels.begin(), it_end = this->levels.end(); it != it_end; ++it) - levels_buffer += it->first + " " + stringify(it->second) + " "; + for (const auto &[name, level] : this->levels) + levels_buffer += name + " " + stringify(level) + " "; data["levels"] << levels_buffer; } if (this->bi) data["bi"] << this->bi->nick; data.SetType("banexpire", Serialize::Data::DT_INT); data["banexpire"] << this->banexpire; data["memomax"] << this->memos.memomax; - for (unsigned i = 0; i < this->memos.ignores.size(); ++i) - data["memoignores"] << this->memos.ignores[i] << " "; + for (const auto &ignore : this->memos.ignores) + data["memoignores"] << ignore << " "; Extensible::ExtensibleSerialize(this, this, data); } @@ -443,12 +443,10 @@ AccessGroup ChannelInfo::AccessFor(const User *u, bool updateLastUsed) if (updateLastUsed) this->last_used = Anope::CurTime; - for (unsigned i = 0; i < group.paths.size(); ++i) + for (auto &p : group.paths) { - ChanAccess::Path &p = group.paths[i]; - - for (unsigned int j = 0; j < p.size(); ++j) - p[j]->last_seen = Anope::CurTime; + for (auto *ca : p) + ca->last_seen = Anope::CurTime; } } @@ -688,6 +686,6 @@ void ChannelInfo::RemoveChannelReference(const Anope::string &what) void ChannelInfo::GetChannelReferences(std::deque<Anope::string> &chans) { chans.clear(); - for (Anope::map<int>::iterator it = references.begin(); it != references.end(); ++it) - chans.push_back(it->first); + for (auto &[chan, _] : references) + chans.push_back(chan); } diff --git a/src/serialize.cpp b/src/serialize.cpp index b43be2dcf..03d9ed626 100644 --- a/src/serialize.cpp +++ b/src/serialize.cpp @@ -34,9 +34,8 @@ void Serialize::RegisterTypes() void Serialize::CheckTypes() { - for (std::map<Anope::string, Serialize::Type *>::const_iterator it = Serialize::Type::GetTypes().begin(), it_end = Serialize::Type::GetTypes().end(); it != it_end; ++it) + for (const auto &[_, t] : Serialize::Type::GetTypes()) { - Serialize::Type *t = it->second; t->Check(); } } @@ -124,13 +123,13 @@ Type::~Type() { /* null the type of existing serializable objects of this type */ if (Serializable::SerializableItems != NULL) - for (std::list<Serializable *>::iterator it = Serializable::SerializableItems->begin(); it != Serializable::SerializableItems->end(); ++it) + { + for (auto *s : *Serializable::SerializableItems) { - Serializable *s = *it; - if (s->s_type == this) s->s_type = NULL; } + } std::vector<Anope::string>::iterator it = std::find(TypeOrder.begin(), TypeOrder.end(), this->name); if (it != TypeOrder.end()) diff --git a/src/servers.cpp b/src/servers.cpp index 397ed8fe1..e8547015a 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -48,27 +48,26 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano if (Me == this->uplink && !juped) { /* Now do mode related stuff as we know what modes exist .. */ - for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) + for (auto &[_, bi] : *BotListByNick) { - BotInfo *bi = it->second; Anope::string modes = !bi->botmodes.empty() ? ("+" + bi->botmodes) : IRCD->DefaultPseudoclientModes; bi->SetModesInternal(bi, modes.c_str()); - for (unsigned i = 0; i < bi->botchannels.size(); ++i) + for (const auto &botchannel : bi->botchannels) { - size_t h = bi->botchannels[i].find('#'); + size_t h = botchannel.find('#'); if (h == Anope::string::npos) continue; - Anope::string chname = bi->botchannels[i].substr(h); + Anope::string chname = botchannel.substr(h); Channel *c = Channel::Find(chname); if (c && c->FindUser(bi)) { - Anope::string want_modes = bi->botchannels[i].substr(0, h); - for (unsigned j = 0; j < want_modes.length(); ++j) + Anope::string want_modes = botchannel.substr(0, h); + for (char want_mode : want_modes) { - ChannelMode *cm = ModeManager::FindChannelModeByChar(want_modes[j]); + ChannelMode *cm = ModeManager::FindChannelModeByChar(want_mode); if (cm == NULL) - cm = ModeManager::FindChannelModeByChar(ModeManager::GetStatusChar(want_modes[j])); + cm = ModeManager::FindChannelModeByChar(ModeManager::GetStatusChar(want_mode)); if (cm && cm->type == MODE_STATUS) { MessageSource ms = bi; @@ -81,19 +80,15 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano IRCD->SendBOB(); - for (unsigned i = 0; i < Me->GetLinks().size(); ++i) + for (auto *link : Me->GetLinks()) { - Server *s = Me->GetLinks()[i]; - - if (s->juped) - IRCD->SendServer(s); + if (link->juped) + IRCD->SendServer(link); } /* We make the bots go online */ - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (const auto &[_, u] : UserListByNick) { - User *u = it->second; - BotInfo *bi = BotInfo::Find(u->GetUID()); if (bi) { @@ -106,22 +101,22 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano bi->introduced = true; } - for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it) + for (const auto &[_, c] : ChannelList) { - Channel *c = it->second; - if (c->users.empty()) IRCD->SendChannel(c); else - for (Channel::ChanUserList::const_iterator cit = c->users.begin(), cit_end = c->users.end(); cit != cit_end; ++cit) - IRCD->SendJoin(cit->second->user, c, &cit->second->status); + { + for (const auto &[_, uc] : c->users) + IRCD->SendJoin(uc->user, c, &uc->status); + } - for (Channel::ModeList::const_iterator it2 = c->GetModes().begin(); it2 != c->GetModes().end(); ++it2) + for (const auto &[mode, value] : c->GetModes()) { - ChannelMode *cm = ModeManager::FindChannelModeByName(it2->first); + ChannelMode *cm = ModeManager::FindChannelModeByName(mode); if (!cm || cm->type != MODE_LIST) continue; - ModeManager::StackerAdd(c->WhoSends(), c, cm, true, it2->second); + ModeManager::StackerAdd(c->WhoSends(), c, cm, true, value); } if (!c->topic.empty() && !c->topic_setter.empty()) @@ -139,10 +134,8 @@ Server::~Server() { Log(this, "quit") << "quit from " << (this->uplink ? this->uplink->GetName() : "no uplink") << " for " << this->quit_reason; - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (const auto &[_, u] : UserListByNick) { - User *u = it->second; - if (u->server == this) { u->Quit(this->quit_reason); @@ -259,8 +252,8 @@ void Server::Sync(bool sync_links) if (sync_links && !this->links.empty()) { - for (unsigned i = 0, j = this->links.size(); i < j; ++i) - this->links[i]->Sync(true); + for (auto *link : this->links) + link->Sync(true); } bool me = this->GetUplink() && this->GetUplink() == Me; @@ -309,9 +302,11 @@ bool Server::IsULined() const if (this == Me) return true; - for (unsigned i = 0; i < Config->Ulines.size(); ++i) - if (Config->Ulines[i].equals_ci(this->GetName())) + for (const auto &uline : Config->Ulines) + { + if (uline.equals_ci(this->GetName())) return true; + } return false; } @@ -353,8 +348,10 @@ Server *Server::Find(const Anope::string &name, bool name_only) Server* Servers::GetUplink() { - for (unsigned i = 0; Me && i < Me->GetLinks().size(); ++i) - if (!Me->GetLinks()[i]->IsJuped()) - return Me->GetLinks()[i]; + for (auto *link : Me->GetLinks()) + { + if (!link->IsJuped()) + return link; + } return NULL; } diff --git a/src/uplink.cpp b/src/uplink.cpp index 019ca8454..67599c2d6 100644 --- a/src/uplink.cpp +++ b/src/uplink.cpp @@ -79,10 +79,8 @@ UplinkSocket::~UplinkSocket() { FOREACH_MOD(OnServerDisconnect, ()); - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (const auto &[_, u] : UserListByNick) { - User *u = it->second; - if (u->server == Me) { /* Don't use quitmsg here, it may contain information you don't want people to see */ diff --git a/src/users.cpp b/src/users.cpp index 2b7aacd9b..ce22828a9 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -468,9 +468,8 @@ bool User::IsServicesOper() bool match = false; Anope::string match_host = this->GetIdent() + "@" + this->host; Anope::string match_ip = this->GetIdent() + "@" + this->ip.addr(); - for (unsigned i = 0; i < this->nc->o->hosts.size(); ++i) + for (const auto &userhost : this->nc->o->hosts) { - const Anope::string &userhost = this->nc->o->hosts[i]; if (Anope::Match(match_host, userhost) || Anope::Match(match_ip, userhost)) { match = true; @@ -629,11 +628,11 @@ void User::SetModes(BotInfo *bi, const char *umodes, ...) spacesepstream sep(buf); sep.GetToken(modebuf); - for (unsigned i = 0, end = modebuf.length(); i < end; ++i) + for (auto mode : modebuf) { UserMode *um; - switch (modebuf[i]) + switch (mode) { case '+': add = 1; @@ -644,7 +643,7 @@ void User::SetModes(BotInfo *bi, const char *umodes, ...) default: if (add == -1) continue; - um = ModeManager::FindUserModeByChar(modebuf[i]); + um = ModeManager::FindUserModeByChar(mode); if (!um) continue; } @@ -676,11 +675,11 @@ void User::SetModesInternal(const MessageSource &source, const char *umodes, ... spacesepstream sep(buf); sep.GetToken(modebuf); - for (unsigned i = 0, end = modebuf.length(); i < end; ++i) + for (auto mode : modebuf) { UserMode *um; - switch (modebuf[i]) + switch (mode) { case '+': add = 1; @@ -691,7 +690,7 @@ void User::SetModesInternal(const MessageSource &source, const char *umodes, ... default: if (add == -1) continue; - um = ModeManager::FindUserModeByChar(modebuf[i]); + um = ModeManager::FindUserModeByChar(mode); if (!um) continue; } @@ -712,16 +711,16 @@ Anope::string User::GetModes() const { Anope::string m, params; - for (ModeList::const_iterator it = this->modes.begin(), it_end = this->modes.end(); it != it_end; ++it) + for (const auto &[mode, value] : this->modes) { - UserMode *um = ModeManager::FindUserModeByName(it->first); + UserMode *um = ModeManager::FindUserModeByName(mode); if (um == NULL) continue; m += um->mchar; - if (!it->second.empty()) - params += " " + it->second; + if (!value.empty()) + params += " " + value; } return m + params; @@ -852,7 +851,7 @@ User* User::Find(const Anope::string &name, bool nick_only) void User::QuitUsers() { - for (std::list<User *>::iterator it = quitting_users.begin(), it_end = quitting_users.end(); it != it_end; ++it) - delete *it; + for (const auto *quitting_user : quitting_users) + delete quitting_user; quitting_users.clear(); } diff --git a/src/xline.cpp b/src/xline.cpp index 26e39fa5d..1e39e9840 100644 --- a/src/xline.cpp +++ b/src/xline.cpp @@ -224,10 +224,8 @@ void XLineManager::UnregisterXLineManager(XLineManager *xlm) void XLineManager::CheckAll(User *u) { - for (std::list<XLineManager *>::iterator it = XLineManagers.begin(), it_end = XLineManagers.end(); it != it_end; ++it) + for (auto *xlm : XLineManagers) { - XLineManager *xlm = *it; - if (xlm->CheckAllXLines(u)) break; } @@ -361,9 +359,8 @@ void XLineManager::Clear() std::vector<XLine *> xl; this->xlines->swap(xl); - for (unsigned i = 0; i < xl.size(); ++i) + for (auto *x : xl) { - XLine *x = xl[i]; if (!x->id.empty()) XLinesByUID->erase(x->id); delete x; @@ -427,10 +424,8 @@ XLine* XLineManager::HasEntry(const Anope::string &mask) it->second->QueueUpdate(); return it->second; } - for (unsigned i = 0, end = this->xlines->size(); i < end; ++i) + for (auto *x : *this->xlines) { - XLine *x = this->xlines->at(i); - if (x->mask.equals_ci(mask)) { x->QueueUpdate(); |