summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2023-10-10 21:14:50 +0100
committerSadie Powell <sadie@witchery.services>2023-10-11 15:51:52 +0100
commita3241065c55fd2a69e8793b89a5d0b1a957b3fd0 (patch)
tree82f80ce2f3bbbdc1c1ef05fe611093cf0b34eab6 /src
parentdc371aad6d059dbf7f30f6878c680532bedd4146 (diff)
Start migrating to range-based for loops.
Diffstat (limited to 'src')
-rw-r--r--src/access.cpp33
-rw-r--r--src/base.cpp4
-rw-r--r--src/bots.cpp4
-rw-r--r--src/channels.cpp45
-rw-r--r--src/command.cpp9
-rw-r--r--src/config.cpp97
-rw-r--r--src/extensible.cpp5
-rw-r--r--src/init.cpp26
-rw-r--r--src/logger.cpp46
-rw-r--r--src/mail.cpp16
-rw-r--r--src/memos.cpp6
-rw-r--r--src/messages.cpp14
-rw-r--r--src/misc.cpp53
-rw-r--r--src/modes.cpp45
-rw-r--r--src/module.cpp4
-rw-r--r--src/modulemanager.cpp24
-rw-r--r--src/nickcore.cpp26
-rw-r--r--src/opertype.cpp48
-rw-r--r--src/protocol.cpp10
-rw-r--r--src/regchannel.cpp20
-rw-r--r--src/serialize.cpp9
-rw-r--r--src/servers.cpp67
-rw-r--r--src/uplink.cpp4
-rw-r--r--src/users.cpp27
-rw-r--r--src/xline.cpp11
25 files changed, 302 insertions, 351 deletions
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 &param)
{
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> &params,
Servers::Capab.insert(token);
}
else
- for (unsigned i = 0; i < params.size(); ++i)
- Servers::Capab.insert(params[i]);
+ {
+ for (const auto &param : params)
+ Servers::Capab.insert(param);
+ }
}
void Error::Run(MessageSource &source, const std::vector<Anope::string> &params, 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> &params,
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