diff options
author | George Hazan <ghazan@miranda.im> | 2018-02-21 18:36:58 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-02-21 18:40:14 +0300 |
commit | 40dc4c27f7d2ea66ff570281a992415a0e6578a2 (patch) | |
tree | 3251fec6eb55fac7e7c63bb7555d17f9269aba87 /protocols | |
parent | e8f69d4e566a3e73ff656beebcae9916e9148589 (diff) |
IRC: C++'11 iterators
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/IRCG/src/commandmonitor.cpp | 13 | ||||
-rw-r--r-- | protocols/IRCG/src/irclib.cpp | 70 | ||||
-rw-r--r-- | protocols/IRCG/src/ircproto.cpp | 11 | ||||
-rw-r--r-- | protocols/IRCG/src/options.cpp | 36 | ||||
-rw-r--r-- | protocols/IRCG/src/output.cpp | 38 | ||||
-rw-r--r-- | protocols/IRCG/src/services.cpp | 6 | ||||
-rw-r--r-- | protocols/IRCG/src/windows.cpp | 6 |
7 files changed, 75 insertions, 105 deletions
diff --git a/protocols/IRCG/src/commandmonitor.cpp b/protocols/IRCG/src/commandmonitor.cpp index 005d9cd96f..72db70fc6f 100644 --- a/protocols/IRCG/src/commandmonitor.cpp +++ b/protocols/IRCG/src/commandmonitor.cpp @@ -2129,8 +2129,8 @@ bool CIrcProto::OnIrc_USERHOST_REPLY(const CIrcMessage *pmsg) // Status-check post-processing: make buddies in ckeck-list offline
if (command[0] == 'S') {
- for (int i = 0; i < checklist.getCount(); i++) {
- finduser.name = checklist[i].GetBuffer();
+ for (auto &it : checklist) {
+ finduser.name = it->GetBuffer();
finduser.ExactNick = true;
CList_SetOffline(&finduser);
}
@@ -2202,10 +2202,9 @@ bool CIrcProto::OnIrc_SUPPORT(const CIrcMessage *pmsg) if (pmsg->m_bIncoming && !bPerformDone)
DoOnConnect(pmsg);
- if (pmsg->m_bIncoming && pmsg->parameters.getCount() > 0) {
- CMStringW S;
- for (int i = 0; i < pmsg->parameters.getCount(); i++) {
- wchar_t* temp = mir_wstrdup(pmsg->parameters[i]);
+ if (pmsg->m_bIncoming) {
+ for (auto &it : pmsg->parameters) {
+ wchar_t* temp = mir_wstrdup(it->GetString());
if (wcsstr(temp, L"CHANTYPES=")) {
wchar_t* p1 = wcschr(temp, '=');
p1++;
@@ -2408,7 +2407,7 @@ int CIrcProto::IsIgnored(const CMStringW& nick, const CMStringW& address, const int CIrcProto::IsIgnored(CMStringW user, char type)
{
for (int i = 0; i < m_ignoreItems.getCount(); i++) {
- const CIrcIgnoreItem& C = m_ignoreItems[i];
+ const CIrcIgnoreItem &C = m_ignoreItems[i];
if (type == 0 && !mir_wstrcmpi(user, C.mask))
return i + 1;
diff --git a/protocols/IRCG/src/irclib.cpp b/protocols/IRCG/src/irclib.cpp index 38e6944131..681e1b19ba 100644 --- a/protocols/IRCG/src/irclib.cpp +++ b/protocols/IRCG/src/irclib.cpp @@ -58,8 +58,8 @@ CIrcMessage::CIrcMessage(const CIrcMessage& m) : prefix.sUser = m.prefix.sUser; prefix.sHost = m.prefix.sHost; - for (int i = 0; i < m.parameters.getCount(); i++) - parameters.insert(new CMStringW(m.parameters[i])); + for (auto &it : m.parameters) + parameters.insert(new CMStringW(*it)); } CIrcMessage::~CIrcMessage() @@ -468,9 +468,9 @@ void CIrcProto::RemoveDCCSession(MCONTACT hContact) { mir_cslock lck(m_dcc); - for (int i = 0; i < m_dcc_chats.getCount(); i++) - if (m_dcc_chats[i]->di->hContact == hContact) { - m_dcc_chats.remove(i); + for (auto &it : m_dcc_chats) + if (it->di->hContact == hContact) { + m_dcc_chats.remove(it); break; } } @@ -479,9 +479,9 @@ void CIrcProto::RemoveDCCSession(DCCINFO *pdci) { mir_cslock lck(m_dcc); - for (int i = 0; i < m_dcc_xfers.getCount(); i++) { - if (m_dcc_xfers[i]->di == pdci) { - m_dcc_xfers.remove(i); + for (auto &it : m_dcc_xfers) { + if (it->di == pdci) { + m_dcc_xfers.remove(it); break; } } @@ -491,9 +491,9 @@ CDccSession* CIrcProto::FindDCCSession(MCONTACT hContact) { mir_cslock lck(m_dcc); - for (int i = 0; i < m_dcc_chats.getCount(); i++) - if (m_dcc_chats[i]->di->hContact == hContact) - return m_dcc_chats[i]; + for (auto &it : m_dcc_chats) + if (it->di->hContact == hContact) + return it; return nullptr; } @@ -502,9 +502,9 @@ CDccSession* CIrcProto::FindDCCSession(DCCINFO *pdci) { mir_cslock lck(m_dcc); - for (int i = 0; i < m_dcc_xfers.getCount(); i++) - if (m_dcc_xfers[i]->di == pdci) - return m_dcc_xfers[i]; + for (auto &it : m_dcc_xfers) + if (it->di == pdci) + return it; return nullptr; } @@ -513,11 +513,9 @@ CDccSession* CIrcProto::FindDCCSendByPort(int iPort) { mir_cslock lck(m_dcc); - for (int i = 0; i < m_dcc_xfers.getCount(); i++) { - CDccSession *p = m_dcc_xfers[i]; + for (auto &p : m_dcc_xfers) if (p->di->iType == DCC_SEND && p->di->bSender && iPort == p->di->iPort) return p; - } return nullptr; } @@ -526,8 +524,7 @@ CDccSession* CIrcProto::FindDCCRecvByPortAndName(int iPort, const wchar_t* szNam { mir_cslock lck(m_dcc); - for (int i = 0; i < m_dcc_xfers.getCount(); i++) { - CDccSession* p = m_dcc_xfers[i]; + for (auto &p : m_dcc_xfers) { DBVARIANT dbv; if (!getWString(p->di->hContact, "Nick", &dbv)) { if (p->di->iType == DCC_SEND && !p->di->bSender && !mir_wstrcmpi(szName, dbv.ptszVal) && iPort == p->di->iPort) { @@ -545,9 +542,9 @@ CDccSession* CIrcProto::FindPassiveDCCSend(int iToken) { mir_cslock lck(m_dcc); - for (int i = 0; i < m_dcc_xfers.getCount(); i++) - if (m_dcc_xfers[i]->iToken == iToken) - return m_dcc_xfers[i]; + for (auto &it : m_dcc_xfers) + if (it->iToken == iToken) + return it; return nullptr; } @@ -556,39 +553,33 @@ CDccSession* CIrcProto::FindPassiveDCCRecv(CMStringW sName, CMStringW sToken) { mir_cslock lck(m_dcc); - for (int i = 0; i < m_dcc_xfers.getCount(); i++) { - CDccSession *p = m_dcc_xfers[i]; + for (auto &p : m_dcc_xfers) if (sToken == p->di->sToken && sName == p->di->sContactName) return p; - } return nullptr; } void CIrcProto::DisconnectAllDCCSessions(bool Shutdown) { - mir_cslock lck(m_dcc); - - for (int i = 0; i < m_dcc_chats.getCount(); i++) - if (m_disconnectDCCChats || Shutdown) - m_dcc_chats[i]->Disconnect(); + if (m_disconnectDCCChats || Shutdown) { + mir_cslock lck(m_dcc); + for (auto &it : m_dcc_chats) + it->Disconnect(); + } } void CIrcProto::CheckDCCTimeout(void) { mir_cslock lck(m_dcc); - for (int i = 0; i < m_dcc_chats.getCount(); i++) { - CDccSession* p = m_dcc_chats[i]; + for (auto &p : m_dcc_chats) if (time(nullptr) > p->tLastActivity + DCCCHATTIMEOUT) p->Disconnect(); - } - for (int j = 0; j < m_dcc_xfers.getCount(); j++) { - CDccSession* p = m_dcc_xfers[j]; + for (auto &p : m_dcc_xfers) if (time(nullptr) > p->tLastActivity + DCCSENDTIMEOUT) p->Disconnect(); - } } //////////////////////////////////////////////////////////////////// @@ -1421,13 +1412,12 @@ LBL_Parse: if (iParamCnt != 2) cbLen = mir_snprintf(buf, "%s : ERROR : UNKNOWN-ERROR\r\n", szBuf); else { - for (int i = 0; i < g_Instances.getCount(); i++) { - if (PeerPortNrRcvd == g_Instances[i]->m_info.iPort && LocalPortNrRcvd == g_Instances[i]->m_myLocalPort) { + for (auto &it : g_Instances) + if (PeerPortNrRcvd == it->m_info.iPort && LocalPortNrRcvd == it->m_myLocalPort) { cbLen = mir_snprintf(buf, "%s : USERID : %S : %S\r\n", - szBuf, g_Instances[i]->m_info.sIdentServerType.c_str(), g_Instances[i]->m_info.sUserID.c_str()); + szBuf, it->m_info.sIdentServerType.c_str(), it->m_info.sUserID.c_str()); break; } - } if (cbLen == 0) cbLen = mir_snprintf(buf, "%s : ERROR : INVALID-PORT\r\n", szBuf); diff --git a/protocols/IRCG/src/ircproto.cpp b/protocols/IRCG/src/ircproto.cpp index 69b19da59b..323e1dd587 100644 --- a/protocols/IRCG/src/ircproto.cpp +++ b/protocols/IRCG/src/ircproto.cpp @@ -242,13 +242,12 @@ int CIrcProto::OnModulesLoaded(WPARAM, LPARAM) OBJLIST<CMStringA> performToConvert(10);
db_enum_settings(NULL, sttCheckPerform, m_szModuleName, &performToConvert);
- for (int i = 0; i < performToConvert.getCount(); i++) {
- CMStringA s = performToConvert[i];
+ for (auto &it : performToConvert) {
DBVARIANT dbv;
- if (!getWString(s, &dbv)) {
- db_unset(NULL, m_szModuleName, s);
- s.MakeUpper();
- setWString(s, dbv.ptszVal);
+ if (!getWString(*it, &dbv)) {
+ db_unset(NULL, m_szModuleName, *it);
+ it->MakeUpper();
+ setWString(*it, dbv.ptszVal);
db_free(&dbv);
}
}
diff --git a/protocols/IRCG/src/options.cpp b/protocols/IRCG/src/options.cpp index 3378b84e5f..137bd722cc 100644 --- a/protocols/IRCG/src/options.cpp +++ b/protocols/IRCG/src/options.cpp @@ -485,10 +485,8 @@ void CConnectPrefsDlg::OnInitDialog() m_proto->m_hwndConnect = m_hwnd;
// Fill the servers combo box and create SERVER_INFO structures
- for (int i = 0; i < g_servers.getCount(); i++) {
- SERVER_INFO &si = g_servers[i];
- m_serverCombo.AddStringA(si.m_name, LPARAM(&si));
- }
+ for (auto &si : g_servers)
+ m_serverCombo.AddStringA(si->m_name, LPARAM(si));
m_serverCombo.SetCurSel(m_proto->m_serverComboSelection);
m_server.SetTextA(m_proto->m_serverName);
@@ -1022,17 +1020,15 @@ void COtherPrefsDlg::OnInitDialog() break;
}
}
-
-
+
if (m_proto->m_codepage == CP_UTF8)
m_autodetect.Disable();
- for (int i = 0; i < g_servers.getCount(); i++) {
- SERVER_INFO& si = g_servers[i];
- int idx = m_performCombo.FindStringA(si.m_group, -1, true);
+ for (auto &si : g_servers) {
+ int idx = m_performCombo.FindStringA(si->m_group, -1, true);
if (idx == CB_ERR) {
- idx = m_performCombo.AddStringA(si.m_group);
- addPerformComboValue(idx, si.m_group);
+ idx = m_performCombo.AddStringA(si->m_group);
+ addPerformComboValue(idx, si->m_group);
}
}
@@ -1588,9 +1584,8 @@ void CIgnorePrefsDlg::RebuildList() {
m_list.DeleteAllItems();
- for (int i = 0; i < m_proto->m_ignoreItems.getCount(); i++) {
- CIrcIgnoreItem& C = m_proto->m_ignoreItems[i];
- if (C.mask.IsEmpty() || C.flags[0] != '+')
+ for (auto &C : m_proto->m_ignoreItems) {
+ if (C->mask.IsEmpty() || C->flags[0] != '+')
continue;
LVITEM lvItem;
@@ -1598,17 +1593,17 @@ void CIgnorePrefsDlg::RebuildList() lvItem.mask = LVIF_TEXT | LVIF_PARAM;
lvItem.iSubItem = 0;
lvItem.lParam = lvItem.iItem;
- lvItem.pszText = (wchar_t*)C.mask.c_str();
+ lvItem.pszText = (wchar_t*)C->mask.c_str();
lvItem.iItem = m_list.InsertItem(&lvItem);
lvItem.mask = LVIF_TEXT;
lvItem.iSubItem = 1;
- lvItem.pszText = (wchar_t*)C.flags.c_str();
+ lvItem.pszText = (wchar_t*)C->flags.c_str();
m_list.SetItem(&lvItem);
lvItem.mask = LVIF_TEXT;
lvItem.iSubItem = 2;
- lvItem.pszText = (wchar_t*)C.network.c_str();
+ lvItem.pszText = (wchar_t*)C->network.c_str();
m_list.SetItem(&lvItem);
}
@@ -1754,10 +1749,9 @@ struct CDlgAccMgrUI : public CProtoDlgBase<CIrcProto> virtual void OnInitDialog()
{
- for (int i = 0; i < g_servers.getCount(); i++) {
- SERVER_INFO& si = g_servers[i];
- m_serverCombo.AddStringA(si.m_name, LPARAM(&si));
- }
+ for (auto &si : g_servers)
+ m_serverCombo.AddStringA(si->m_name, LPARAM(si));
+
m_serverCombo.SetCurSel(m_proto->m_serverComboSelection);
m_server.SetTextA(m_proto->m_serverName);
m_port.SetTextA(m_proto->m_portStart);
diff --git a/protocols/IRCG/src/output.cpp b/protocols/IRCG/src/output.cpp index 49958b1fd9..fe0c8b97f4 100644 --- a/protocols/IRCG/src/output.cpp +++ b/protocols/IRCG/src/output.cpp @@ -27,10 +27,8 @@ static CMStringW FormatOutput(const CIrcMessage* pmsg) if (pmsg->m_bIncoming) { // Is it an incoming message?
if (pmsg->sCommand == L"WALLOPS" && pmsg->parameters.getCount() > 0) {
- wchar_t temp[200]; *temp = 0;
- mir_snwprintf(temp, TranslateT("WallOps from %s: "), pmsg->prefix.sNick.c_str());
- sMessage = temp;
- for (int i = 0; i < (int)pmsg->parameters.getCount(); i++) {
+ sMessage.Format(TranslateT("WallOps from %s: "), pmsg->prefix.sNick.c_str());
+ for (int i = 0; i < pmsg->parameters.getCount(); i++) {
sMessage += pmsg->parameters[i];
if (i != pmsg->parameters.getCount() - 1)
sMessage += L" ";
@@ -39,10 +37,8 @@ static CMStringW FormatOutput(const CIrcMessage* pmsg) }
if (pmsg->sCommand == L"INVITE" && pmsg->parameters.getCount() > 1) {
- wchar_t temp[256]; *temp = 0;
- mir_snwprintf(temp, TranslateT("%s invites you to %s"), pmsg->prefix.sNick.c_str(), pmsg->parameters[1].c_str());
- sMessage = temp;
- for (int i = 2; i < (int)pmsg->parameters.getCount(); i++) {
+ sMessage.Format(TranslateT("%s invites you to %s"), pmsg->prefix.sNick.c_str(), pmsg->parameters[1].c_str());
+ for (int i = 2; i < pmsg->parameters.getCount(); i++) {
sMessage += L": " + pmsg->parameters[i];
if (i != pmsg->parameters.getCount() - 1)
sMessage += L" ";
@@ -52,10 +48,8 @@ static CMStringW FormatOutput(const CIrcMessage* pmsg) int index = _wtoi(pmsg->sCommand.c_str());
if (index == 301 && pmsg->parameters.getCount() > 0) {
- wchar_t temp[500]; *temp = 0;
- mir_snwprintf(temp, TranslateT("%s is away"), pmsg->parameters[1].c_str());
- sMessage = temp;
- for (int i = 2; i < (int)pmsg->parameters.getCount(); i++) {
+ sMessage.Format(TranslateT("%s is away"), pmsg->parameters[1].c_str());
+ for (int i = 2; i < pmsg->parameters.getCount(); i++) {
sMessage += L": " + pmsg->parameters[i];
if (i != pmsg->parameters.getCount() - 1)
sMessage += L" ";
@@ -68,7 +62,7 @@ static CMStringW FormatOutput(const CIrcMessage* pmsg) if (index == 303) { // ISON command
sMessage = TranslateT("These are online: ");
- for (int i = 1; i < (int)pmsg->parameters.getCount(); i++) {
+ for (int i = 1; i < pmsg->parameters.getCount(); i++) {
sMessage += pmsg->parameters[i];
if (i != pmsg->parameters.getCount() - 1)
sMessage += L", ";
@@ -80,8 +74,6 @@ static CMStringW FormatOutput(const CIrcMessage* pmsg) return pmsg->parameters[2] + L": " + pmsg->parameters[1];
}
else if (pmsg->sCommand == L"NOTICE" && pmsg->parameters.getCount() > 1) {
- wchar_t temp[500]; *temp = 0;
-
int l = pmsg->parameters[1].GetLength();
if (l > 3 && pmsg->parameters[1][0] == 1 && pmsg->parameters[1][l - 1] == 1) {
// CTCP reply
@@ -90,15 +82,13 @@ static CMStringW FormatOutput(const CIrcMessage* pmsg) tempstr.Delete(tempstr.GetLength() - 1, 1);
CMStringW type = GetWord(tempstr.c_str(), 0);
if (mir_wstrcmpi(type.c_str(), L"ping") == 0)
- mir_snwprintf(temp, TranslateT("CTCP %s reply sent to %s"), type.c_str(), pmsg->parameters[0].c_str());
+ sMessage.Format(TranslateT("CTCP %s reply sent to %s"), type.c_str(), pmsg->parameters[0].c_str());
else
- mir_snwprintf(temp, TranslateT("CTCP %s reply sent to %s: %s"), type.c_str(), pmsg->parameters[0].c_str(), GetWordAddress(tempstr.c_str(), 1));
- sMessage = temp;
+ sMessage.Format(TranslateT("CTCP %s reply sent to %s: %s"), type.c_str(), pmsg->parameters[0].c_str(), GetWordAddress(tempstr.c_str(), 1));
}
else {
- mir_snwprintf(temp, TranslateT("Notice to %s: "), pmsg->parameters[0].c_str());
- sMessage = temp;
- for (int i = 1; i < (int)pmsg->parameters.getCount(); i++) {
+ sMessage.Format(TranslateT("Notice to %s: "), pmsg->parameters[0].c_str());
+ for (int i = 1; i < pmsg->parameters.getCount(); i++) {
sMessage += pmsg->parameters[i];
if (i != pmsg->parameters.getCount() - 1)
sMessage += L" ";
@@ -114,15 +104,15 @@ static CMStringW FormatOutput(const CIrcMessage* pmsg) return pmsg->sCommand + L" : " + pmsg->parameters[0];
if (pmsg->parameters.getCount() > 1)
- for (int i = 1; i < (int)pmsg->parameters.getCount(); i++)
+ for (int i = 1; i < pmsg->parameters.getCount(); i++)
sMessage += pmsg->parameters[i] + L" ";
}
else {
if (pmsg->prefix.sNick.GetLength())
sMessage = pmsg->prefix.sNick + L" ";
sMessage += pmsg->sCommand + L" ";
- for (int i = 0; i < (int)pmsg->parameters.getCount(); i++)
- sMessage += pmsg->parameters[i] + L" ";
+ for (auto &it : pmsg->parameters)
+ sMessage += *it + L" ";
}
THE_END:
diff --git a/protocols/IRCG/src/services.cpp b/protocols/IRCG/src/services.cpp index 07097155ce..1bb2274f9c 100644 --- a/protocols/IRCG/src/services.cpp +++ b/protocols/IRCG/src/services.cpp @@ -70,9 +70,9 @@ static CIrcProto* IrcGetInstanceByHContact(MCONTACT hContact) if (szProto == nullptr)
return nullptr;
- for (int i = 0; i < g_Instances.getCount(); i++)
- if (!mir_strcmp(szProto, g_Instances[i]->m_szModuleName))
- return g_Instances[i];
+ for (auto &it : g_Instances)
+ if (!mir_strcmp(szProto, it->m_szModuleName))
+ return it;
return nullptr;
}
diff --git a/protocols/IRCG/src/windows.cpp b/protocols/IRCG/src/windows.cpp index 759436f5fc..598bb17d69 100644 --- a/protocols/IRCG/src/windows.cpp +++ b/protocols/IRCG/src/windows.cpp @@ -563,10 +563,8 @@ void CQuickDlg::OnInitDialog() CCoolIrcDlg::OnInitDialog();
if (g_servers.getCount() > 0) {
- for (int i = 0; i < g_servers.getCount(); i++) {
- const SERVER_INFO& si = g_servers[i];
- m_serverCombo.AddStringA(si.m_name, (LPARAM)&si);
- }
+ for (auto &si : g_servers)
+ m_serverCombo.AddStringA(si->m_name, (LPARAM)si);
}
else EnableWindow(GetDlgItem(m_hwnd, IDOK), false);
|