From 942fd2bcfd384a12c900999fe663202c87319a68 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Tue, 6 Apr 2021 20:06:18 +0100 Subject: Switch simple iterator loops to use range-based for loops. --- src/modules/m_httpd_stats.cpp | 83 +++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 50 deletions(-) (limited to 'src/modules/m_httpd_stats.cpp') diff --git a/src/modules/m_httpd_stats.cpp b/src/modules/m_httpd_stats.cpp index 4a565f79e..df127fe8b 100644 --- a/src/modules/m_httpd_stats.cpp +++ b/src/modules/m_httpd_stats.cpp @@ -60,21 +60,20 @@ namespace Stats std::string ret; ret.reserve(str.length() * 2); - for (std::string::const_iterator x = str.begin(); x != str.end(); ++x) + for (const auto& chr : str) { - insp::flat_map::const_iterator it = Entities::entities.find(*x); - + insp::flat_map::const_iterator it = Entities::entities.find(chr); if (it != Entities::entities.end()) { ret += '&'; ret += it->second; ret += ';'; } - else if (*x == 0x09 || *x == 0x0A || *x == 0x0D || ((*x >= 0x20) && (*x <= 0x7e))) + else if (chr == 0x09 || chr == 0x0A || chr == 0x0D || ((chr >= 0x20) && (chr <= 0x7e))) { // The XML specification defines the following characters as valid inside an XML document: // Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] - ret += *x; + ret += chr; } else { @@ -94,10 +93,9 @@ namespace Stats void DumpMeta(std::ostream& data, Extensible* ext) { data << ""; - for (Extensible::ExtensibleStore::const_iterator i = ext->GetExtList().begin(); i != ext->GetExtList().end(); i++) + for (const auto& [item, obj] : ext->GetExtList()) { - ExtensionItem* item = i->first; - std::string value = item->ToHuman(ext, i->second); + const std::string value = item->ToHuman(ext, obj); if (!value.empty()) data << "name << "\">" << Sanitize(value) << ""; else if (!item->name.empty()) @@ -119,10 +117,10 @@ namespace Stats ISupport::TokenMap tokens; isevprov->Call(&ISupport::EventListener::OnBuildISupport, tokens); - for (ISupport::TokenMap::const_iterator it = tokens.begin(); it != tokens.end(); ++it) + for (const auto& [key, value] : tokens) { - data << "" << Sanitize(it->first) - << "" << Sanitize(it->second) + data << "" << Sanitize(key) + << "" << Sanitize(value) << ""; } return data << ""; @@ -146,19 +144,18 @@ namespace Stats std::ostream& XLines(std::ostream& data) { data << ""; - std::vector xltypes = ServerInstance->XLines->GetAllTypes(); - for (std::vector::iterator it = xltypes.begin(); it != xltypes.end(); ++it) + for (const auto& xltype : ServerInstance->XLines->GetAllTypes()) { - XLineLookup* lookup = ServerInstance->XLines->GetAll(*it); - + XLineLookup* lookup = ServerInstance->XLines->GetAll(xltype); if (!lookup) continue; - for (LookupIter i = lookup->begin(); i != lookup->end(); ++i) + + for (const auto& [_, xline] : *lookup) { - data << "c_str() << "\">" - << Sanitize(i->second->Displayable()) << "" - << i->second->set_time << "" << i->second->duration - << "" << Sanitize(i->second->reason) + data << "" + << Sanitize(xline->Displayable()) << "" + << xline->set_time << "" << xline->duration + << "" << Sanitize(xline->reason) << ""; } } @@ -168,12 +165,10 @@ namespace Stats std::ostream& Modules(std::ostream& data) { data << ""; - const ModuleManager::ModuleMap& mods = ServerInstance->Modules.GetModules(); - - for (ModuleManager::ModuleMap::const_iterator i = mods.begin(); i != mods.end(); ++i) + for (const auto& [modname, mod] : ServerInstance->Modules.GetModules()) { - Module* mod = i->second; - data << "" << i->first << "" << Sanitize(mod->description) << ""; + data << "" << modname << "" + << Sanitize(mod->description) << ""; } return data << ""; } @@ -182,11 +177,8 @@ namespace Stats { data << ""; - const chan_hash& chans = ServerInstance->GetChans(); - for (chan_hash::const_iterator i = chans.begin(); i != chans.end(); ++i) + for (const auto& [_, c] : ServerInstance->GetChans()) { - Channel* c = i->second; - data << ""; data << "" << c->GetUsers().size() << "" << Sanitize(c->name) << ""; data << ""; @@ -196,10 +188,8 @@ namespace Stats data << ""; data << "" << Sanitize(c->ChanModes(true)) << ""; - const Channel::MemberMap& ulist = c->GetUsers(); - for (Channel::MemberMap::const_iterator x = ulist.begin(); x != ulist.end(); ++x) + for (const auto& [__, memb] : c->GetUsers()) { - Membership* memb = x->second; data << "" << memb->user->uuid << "" << Sanitize(memb->GetAllPrefixChars()) << "" << memb->modes << ""; @@ -249,11 +239,8 @@ namespace Stats std::ostream& Users(std::ostream& data) { data << ""; - const user_hash& users = ServerInstance->Users.GetUsers(); - for (user_hash::const_iterator i = users.begin(); i != users.end(); ++i) + for (const auto& [_, u] : ServerInstance->Users.GetUsers()) { - User* u = i->second; - if (u->registered != REG_ALL) continue; @@ -269,16 +256,15 @@ namespace Stats ProtocolInterface::ServerList sl; ServerInstance->PI->GetServerList(sl); - for (ProtocolInterface::ServerList::const_iterator b = sl.begin(); b != sl.end(); ++b) + for (const auto& server : sl) { data << ""; - data << "" << b->servername << ""; - data << "" << b->parentname << ""; - data << "" << Sanitize(b->description) << ""; - data << "" << b->usercount << ""; -// This is currently not implemented, so, commented out. -// data << "" << b->opercount << ""; - data << "" << b->latencyms << ""; + data << "" << server.servername << ""; + data << "" << server.parentname << ""; + data << "" << Sanitize(server.description) << ""; + data << "" << server.usercount << ""; + data << "" << server.opercount << ""; + data << "" << server.latencyms << ""; data << ""; } @@ -289,10 +275,9 @@ namespace Stats { data << ""; - const CommandParser::CommandMap& commands = ServerInstance->Parser.GetCommands(); - for (CommandParser::CommandMap::const_iterator i = commands.begin(); i != commands.end(); ++i) + for (const auto& [cmdname, cmd] : ServerInstance->Parser.GetCommands()) { - data << "" << i->second->name << "" << i->second->use_count << ""; + data << "" << cmdname << "" << cmd->use_count << ""; } return data << ""; } @@ -370,10 +355,8 @@ namespace Stats typedef std::list NewUserList; NewUserList user_list; - user_hash users = ServerInstance->Users.GetUsers(); - for (user_hash::iterator i = users.begin(); i != users.end(); ++i) + for (const auto& [_, u] : ServerInstance->Users.GetUsers()) { - User* u = i->second; if (!showunreg && u->registered != REG_ALL) continue; -- cgit v1.3.1-10-gc9f91