Last batch of C++11 range-based for loops (#816)

This commit is contained in:
J-P Nurmi
2015-02-26 10:52:56 +01:00
parent 05c96a16d1
commit 1d09b41540
8 changed files with 47 additions and 57 deletions
+7 -7
View File
@@ -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();
}
}
@@ -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();
}
}
+15 -17
View File
@@ -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;
@@ -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;
}
}
@@ -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 = "*";
}
}
@@ -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++;
}
}
@@ -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]]++;
@@ -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);
+2 -2
View File
@@ -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;
}
+8 -8
View File
@@ -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");
}
}
}
+1 -3
View File
@@ -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);
}
+3 -4
View File
@@ -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;
}
+2 -2
View File
@@ -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();
+9 -14
View File
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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();
@@ -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;
}
@@ -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 {