Skip to content

Commit

Permalink
Last batch of C++11 range-based for loops (#816)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpnurmi committed Mar 1, 2015
1 parent 05c96a1 commit 1d09b41
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 57 deletions.
14 changes: 7 additions & 7 deletions src/Buffer.cpp
Expand Up @@ -66,11 +66,11 @@ CBuffer::size_type CBuffer::AddLine(const CString& sFormat, const CString& sText
}

CBuffer::size_type CBuffer::UpdateLine(const CString& sMatch, const CString& sFormat, const CString& sText) {
for (iterator it = begin(); it != end(); ++it) {
if (it->GetFormat().compare(0, sMatch.length(), sMatch) == 0) {
it->SetFormat(sFormat);
it->SetText(sText);
it->UpdateTime();
for (CBufLine& Line : *this) {
if (Line.GetFormat().compare(0, sMatch.length(), sMatch) == 0) {
Line.SetFormat(sFormat);
Line.SetText(sText);
Line.UpdateTime();
return size();
}
}
Expand All @@ -79,8 +79,8 @@ CBuffer::size_type CBuffer::UpdateLine(const CString& sMatch, const CString& sFo
}

CBuffer::size_type CBuffer::UpdateExactLine(const CString& sFormat, const CString& sText) {
for (iterator it = begin(); it != end(); ++it) {
if (it->GetFormat() == sFormat && it->GetText() == sText) {
for (const CBufLine& Line : *this) {
if (Line.GetFormat() == sFormat && Line.GetText() == sText) {
return size();
}
}
Expand Down
32 changes: 15 additions & 17 deletions src/Chan.cpp
Expand Up @@ -156,10 +156,10 @@ void CChan::AttachUser(CClient* pClient) {
CString sPerm, sNick;

const vector<CClient*>& vpClients = m_pNetwork->GetClients();
for (vector<CClient*>::const_iterator it = vpClients.begin(); it != vpClients.end(); ++it) {
for (CClient* pEachClient : vpClients) {
CClient* pThisClient;
if (!pClient)
pThisClient = *it;
pThisClient = pEachClient;
else
pThisClient = pClient;

Expand Down Expand Up @@ -210,10 +210,10 @@ void CChan::DetachUser() {
CString CChan::GetModeString() const {
CString sModes, sArgs;

for (map<unsigned char, CString>::const_iterator it = m_musModes.begin(); it != m_musModes.end(); ++it) {
sModes += it->first;
if (it->second.size()) {
sArgs += " " + it->second;
for (const auto& it : m_musModes) {
sModes += it.first;
if (it.second.size()) {
sArgs += " " + it.second;
}
}

Expand All @@ -223,10 +223,10 @@ CString CChan::GetModeString() const {
CString CChan::GetModeForNames() const {
CString sMode;

for (map<unsigned char, CString>::const_iterator it = m_musModes.begin(); it != m_musModes.end(); ++it) {
if (it->first == 's') {
for (const auto& it : m_musModes) {
if (it.first == 's') {
sMode = "@";
} else if ((it->first == 'p') && sMode.empty()){
} else if ((it.first == 'p') && sMode.empty()){
sMode = "*";
}
}
Expand Down Expand Up @@ -457,12 +457,11 @@ void CChan::ClearNicks() {
int CChan::AddNicks(const CString& sNicks) {
int iRet = 0;
VCString vsNicks;
VCString::iterator it;

sNicks.Split(" ", vsNicks, false);

for (it = vsNicks.begin(); it != vsNicks.end(); ++it) {
if (AddNick(*it)) {
for (const CString& sNick : vsNicks) {
if (AddNick(sNick)) {
iRet++;
}
}
Expand Down Expand Up @@ -521,9 +520,8 @@ bool CChan::AddNick(const CString& sNick) {
map<char, unsigned int> CChan::GetPermCounts() const {
map<char, unsigned int> mRet;

map<CString,CNick>::const_iterator it;
for (it = m_msNicks.begin(); it != m_msNicks.end(); ++it) {
CString sPerms = it->second.GetPermStr();
for (const auto& it : m_msNicks) {
CString sPerms = it.second.GetPermStr();

for (unsigned int p = 0; p < sPerms.size(); p++) {
mRet[sPerms[p]]++;
Expand Down Expand Up @@ -599,8 +597,8 @@ void CChan::SendBuffer(CClient* pClient, const CBuffer& Buffer) {
// Rework this if you like ...
if (!Buffer.IsEmpty()) {
const vector<CClient*> & vClients = m_pNetwork->GetClients();
for (size_t uClient = 0; uClient < vClients.size(); ++uClient) {
CClient * pUseClient = (pClient ? pClient : vClients[uClient]);
for (CClient* pEachClient : vClients) {
CClient * pUseClient = (pClient ? pClient : pEachClient);

bool bWasPlaybackActive = pUseClient->IsPlaybackActive();
pUseClient->SetPlaybackActive(true);
Expand Down
4 changes: 2 additions & 2 deletions src/ClientCommand.cpp
Expand Up @@ -637,8 +637,8 @@ void CClient::UserCommand(CString& sLine) {
CString sNewModPath = pNewUser->GetUserPath() + "/networks/" + sNewNetwork + "/moddata/" + pMod->GetModName();

CDir oldDir(sOldModPath);
for (CDir::iterator it = oldDir.begin(); it != oldDir.end(); ++it) {
if ((*it)->GetShortName() != ".registry") {
for (CFile* pFile : oldDir) {
if (pFile->GetShortName() != ".registry") {
PutStatus("Some files seem to be in [" + sOldModPath + "]. You might want to move them to [" + sNewModPath + "]");
break;
}
Expand Down
16 changes: 8 additions & 8 deletions src/Config.cpp
Expand Up @@ -181,19 +181,19 @@ bool CConfig::Parse(CFile& file, CString& sErrorMsg)
void CConfig::Write(CFile& File, unsigned int iIndentation) {
CString sIndentation = CString(iIndentation, '\t');

for (EntryMapIterator it = m_ConfigEntries.begin(); it != m_ConfigEntries.end(); ++it) {
for (VCString::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
File.Write(sIndentation + it->first + " = " + *it2 + "\n");
for (const auto& it : m_ConfigEntries) {
for (const CString& sValue : it.second) {
File.Write(sIndentation + it.first + " = " + sValue + "\n");
}
}

for (SubConfigMapIterator it = m_SubConfigs.begin(); it != m_SubConfigs.end(); ++it) {
for (SubConfig::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
for (const auto& it : m_SubConfigs) {
for (const auto& it2 : it.second) {
File.Write("\n");

File.Write(sIndentation + "<" + it->first + " " + it2->first + ">\n");
it2->second.m_pSubConfig->Write(File, iIndentation + 1);
File.Write(sIndentation + "</" + it->first + ">\n");
File.Write(sIndentation + "<" + it.first + " " + it2.first + ">\n");
it2.second.m_pSubConfig->Write(File, iIndentation + 1);
File.Write(sIndentation + "</" + it.first + ">\n");
}
}
}
4 changes: 1 addition & 3 deletions src/HTTPSock.cpp
Expand Up @@ -111,9 +111,7 @@ void CHTTPSock::ReadLine(const CString& sData) {

sLine.Token(1, true).Split(";", vsNV, false, "", "", true, true);

for (unsigned int a = 0; a < vsNV.size(); a++) {
CString s(vsNV[a]);

for (const CString& s : vsNV) {
m_msRequestCookies[s.Token(0, false, "=").Escape_n(CString::EURL, CString::EASCII)] =
s.Token(1, true, "=").Escape_n(CString::EURL, CString::EASCII);
}
Expand Down
7 changes: 3 additions & 4 deletions src/Nick.cpp
Expand Up @@ -61,12 +61,11 @@ size_t CNick::GetCommonChans(vector<CChan*>& vRetChans, CIRCNetwork* pNetwork) c

const vector<CChan*>& vChans = pNetwork->GetChans();

for (unsigned int a = 0; a < vChans.size(); a++) {
CChan* pChan = vChans[a];
for (CChan* pChan : vChans) {
const map<CString,CNick>& msNicks = pChan->GetNicks();

for (map<CString,CNick>::const_iterator it = msNicks.begin(); it != msNicks.end(); ++it) {
if (it->first.Equals(m_sNick)) {
for (const auto& it : msNicks) {
if (it.first.Equals(m_sNick)) {
vRetChans.push_back(pChan);
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Query.cpp
Expand Up @@ -36,8 +36,8 @@ void CQuery::SendBuffer(CClient* pClient, const CBuffer& Buffer) {
// Based on CChan::SendBuffer()
if (!Buffer.IsEmpty()) {
const vector<CClient*> & vClients = m_pNetwork->GetClients();
for (size_t uClient = 0; uClient < vClients.size(); ++uClient) {
CClient * pUseClient = (pClient ? pClient : vClients[uClient]);
for (CClient* pEachClient : vClients) {
CClient * pUseClient = (pClient ? pClient : pEachClient);

MCString msParams;
msParams["target"] = pUseClient->GetNick();
Expand Down
23 changes: 9 additions & 14 deletions src/ZNCString.cpp
Expand Up @@ -144,8 +144,7 @@ bool CString::WildCmp(const CString& sWild, CaseSensitivity cs) const {
}

CString& CString::MakeUpper() {
for (size_type a = 0; a < length(); a++) {
char& c = (*this)[a];
for (char& c : *this) {
//TODO use unicode
c = (char)toupper(c);
}
Expand All @@ -154,8 +153,7 @@ CString& CString::MakeUpper() {
}

CString& CString::MakeLower() {
for (size_type a = 0; a < length(); a++) {
char& c = (*this)[a];
for (char& c : *this) {
//TODO use unicode
c = (char)tolower(c);
}
Expand Down Expand Up @@ -648,9 +646,7 @@ CString::size_type CString::URLSplit(MCString& msRet) const {
VCString vsPairs;
Split("&", vsPairs);

for (size_t a = 0; a < vsPairs.size(); a++) {
const CString& sPair = vsPairs[a];

for (const CString& sPair : vsPairs) {
msRet[sPair.Token(0, false, "=").Escape(CString::EURL, CString::EASCII)] = sPair.Token(1, true, "=").Escape(CString::EURL, CString::EASCII);
}

Expand Down Expand Up @@ -781,8 +777,8 @@ CString::size_type CString::Split(const CString& sDelim, SCString& ssRet, bool b

ssRet.clear();

for (size_t a = 0; a < vsTokens.size(); a++) {
ssRet.insert(vsTokens[a]);
for (const CString& sToken : vsTokens) {
ssRet.insert(sToken);
}

return ssRet.size();
Expand Down Expand Up @@ -1321,9 +1317,9 @@ MCString::status_t MCString::WriteToDisk(const CString& sPath, mode_t iMode) con
return MCS_EOPEN;
}

for (MCString::const_iterator it = this->begin(); it != this->end(); ++it) {
CString sKey = it->first;
CString sValue = it->second;
for (const auto& it : *this) {
CString sKey = it.first;
CString sValue = it.second;
if (!WriteFilter(sKey, sValue)) {
return MCS_EWRITEFIL;
}
Expand Down Expand Up @@ -1373,10 +1369,9 @@ static const char hexdigits[] = "0123456789abcdef";

CString& MCString::Encode(CString& sValue) const {
CString sTmp;
for (CString::iterator it = sValue.begin(); it != sValue.end(); ++it) {
for (unsigned char c : sValue) {
// isalnum() needs unsigned char as argument and this code
// assumes unsigned, too.
unsigned char c = *it;
if (isalnum(c)) {
sTmp += c;
} else {
Expand Down

0 comments on commit 1d09b41

Please sign in to comment.