linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #05451
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2882: turn reverse iterations to range-based loops with some boost magic
------------------------------------------------------------
revno: 2882
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sun 2012-03-18 16:43:00 +0100
message:
turn reverse iterations to range-based loops with some boost magic
modified:
dcpp/ChatMessage.cpp
win32/ADLSearchFrame.cpp
win32/DirectoryListingFrame.cpp
win32/SearchFrame.cpp
win32/StringListDlg.cpp
win32/UserMatchPage.cpp
--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk
Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'dcpp/ChatMessage.cpp'
--- dcpp/ChatMessage.cpp 2012-03-18 15:21:56 +0000
+++ dcpp/ChatMessage.cpp 2012-03-18 15:43:00 +0000
@@ -110,8 +110,8 @@
auto addLink = [&tmp, &xmlTmp, &tags](size_t begin, size_t end) {
Tag openingTag = { "<a href=\"" + SimpleXML::escape(tmp.substr(begin, end - begin), xmlTmp, true) + "\">", true, end },
closingTag = { "</a>", false, begin };
- tags.emplace(begin, std::move(openingTag));
- tags.emplace(end, std::move(closingTag));
+ tags[begin] = std::move(openingTag);
+ tags[end] = std::move(closingTag);
};
static const string delimiters = " \t\r\n<>\"";
@@ -124,10 +124,10 @@
if((begin = tmp.find_last_of(delimiters, i)) == string::npos) begin = 0; else ++begin;
if((end = tmp.find_first_of(delimiters, i + 1)) == string::npos) end = n;
- if(i > 0 &&
+ if(i > 0 && (
(i + 4 < n && tmp[i + 1] == '/' && tmp[i + 2] == '/') || // "http://", etc
- (i >= begin + 6 && !tmp.compare(begin, 6, "magnet")) ||
- (i >= begin + 6 && !tmp.compare(begin, 6, "mailto")))
+ (i == begin + 6 && !tmp.compare(begin, 6, "magnet")) ||
+ (i == begin + 6 && !tmp.compare(begin, 6, "mailto"))))
{
addLink(begin, end);
i = end;
@@ -191,8 +191,6 @@
htmlMessage += "</span></span>";
- dcdebug("html: %s\n", htmlMessage.c_str());
-
/// @todo send this to plugins
}
=== modified file 'win32/ADLSearchFrame.cpp'
--- win32/ADLSearchFrame.cpp 2012-03-03 19:33:45 +0000
+++ win32/ADLSearchFrame.cpp 2012-03-18 15:43:00 +0000
@@ -19,6 +19,8 @@
#include "stdafx.h"
#include "ADLSearchFrame.h"
+#include <boost/range/adaptor/reversed.hpp>
+
#include <dcpp/Client.h>
#include <dcpp/version.h>
#include <dcpp/format.h>
@@ -225,15 +227,15 @@
HoldRedraw hold(items);
auto selected = items->getSelection();
- for(auto i = selected.rbegin(); i != selected.rend(); ++i) {
- if(*i < items->size() - 1) {
- ADLSearch search = collection[*i];
- swap(collection[*i], collection[*i + 1]);
+ for(auto i: selected | boost::adaptors::reversed) {
+ if(i < items->size() - 1) {
+ ADLSearch search = collection[i];
+ swap(collection[i], collection[i + 1]);
save = true;
- items->erase(*i);
- addEntry(search, *i + 1);
- items->select(*i + 1);
+ items->erase(i);
+ addEntry(search, i + 1);
+ items->select(i + 1);
}
}
=== modified file 'win32/DirectoryListingFrame.cpp'
--- win32/DirectoryListingFrame.cpp 2012-03-03 19:33:45 +0000
+++ win32/DirectoryListingFrame.cpp 2012-03-18 15:43:00 +0000
@@ -19,6 +19,8 @@
#include "stdafx.h"
#include "DirectoryListingFrame.h"
+#include <boost/range/adaptor/reversed.hpp>
+
#include <dcpp/ADLSearch.h>
#include <dcpp/ClientManager.h>
#include <dcpp/FavoriteManager.h>
@@ -637,8 +639,8 @@
searchGrid->setVisible(false);
grid->row(0).mode = GridInfo::STATIC;
} else {
- for(auto i = lastSearches.crbegin(), iend = lastSearches.crend(); i != iend; ++i) {
- auto p = i->get();
+ for(auto& i: lastSearches | boost::adaptors::reversed) {
+ auto p = i.get();
searchBox->setData(searchBox->addValue(p->first), reinterpret_cast<LPARAM>(p));
}
searchGrid->setEnabled(true);
=== modified file 'win32/SearchFrame.cpp'
--- win32/SearchFrame.cpp 2012-03-03 19:33:45 +0000
+++ win32/SearchFrame.cpp 2012-03-18 15:43:00 +0000
@@ -19,6 +19,8 @@
#include "stdafx.h"
#include "SearchFrame.h"
+#include <boost/range/adaptor/reversed.hpp>
+
#include <dcpp/ClientManager.h>
#include <dcpp/FavoriteManager.h>
#include <dcpp/GeoManager.h>
@@ -148,8 +150,8 @@
searchBox->getTextBox()->setCue(T_("Enter search here"));
addWidget(searchBox);
- for(auto i = lastSearches.crbegin(), iend = lastSearches.crend(); i != iend; ++i)
- searchBox->addValue(*i);
+ for(auto& i: lastSearches | boost::adaptors::reversed)
+ searchBox->addValue(i);
searchBox->getTextBox()->onKeyDown([this](int c) { return handleSearchKeyDown(c); });
searchBox->getTextBox()->onChar([this] (int c) { return handleSearchChar(c); });
=== modified file 'win32/StringListDlg.cpp'
--- win32/StringListDlg.cpp 2012-03-03 19:33:45 +0000
+++ win32/StringListDlg.cpp 2012-03-18 15:43:00 +0000
@@ -19,6 +19,8 @@
#include "stdafx.h"
#include "StringListDlg.h"
+#include <boost/range/adaptor/reversed.hpp>
+
#include <dwt/widgets/Button.h>
#include <dwt/widgets/Grid.h>
@@ -234,13 +236,13 @@
void StringListDlg::handleMoveUpClicked() {
HoldRedraw hold(list);
- std::vector<unsigned> selected = list->getSelection();
- for(auto i = selected.begin(); i != selected.end(); ++i) {
- if(*i > 0) {
- tstring selText = list->getText(*i, 0);
- list->erase(*i);
- insert(selText, *i - 1);
- list->select(*i - 1);
+ auto selected = list->getSelection();
+ for(auto i: selected) {
+ if(i > 0) {
+ tstring selText = list->getText(i, 0);
+ list->erase(i);
+ insert(selText, i - 1);
+ list->select(i - 1);
}
}
}
@@ -248,12 +250,12 @@
void StringListDlg::handleMoveDownClicked() {
HoldRedraw hold(list);
auto selected = list->getSelection();
- for(auto i = selected.rbegin(); i != selected.rend(); ++i) {
- if(*i < list->size() - 1) {
- tstring selText = list->getText(*i, 0);
- list->erase(*i);
- insert(selText, *i + 1);
- list->select(*i + 1);
+ for(auto i: selected | boost::adaptors::reversed) {
+ if(i < list->size() - 1) {
+ tstring selText = list->getText(i, 0);
+ list->erase(i);
+ insert(selText, i + 1);
+ list->select(i + 1);
}
}
}
=== modified file 'win32/UserMatchPage.cpp'
--- win32/UserMatchPage.cpp 2012-03-03 19:33:45 +0000
+++ win32/UserMatchPage.cpp 2012-03-18 15:43:00 +0000
@@ -19,6 +19,8 @@
#include "stdafx.h"
#include "UserMatchPage.h"
+#include <boost/range/adaptor/reversed.hpp>
+
#include <dcpp/format.h>
#include <dcpp/UserMatchManager.h>
#include <dcpp/version.h>
@@ -279,13 +281,13 @@
void UserMatchPage::handleMoveDownClicked() {
HoldRedraw hold(table);
auto sel = table->getSelection();
- for(auto i = sel.crbegin(), iend = sel.crend(); i != iend; ++i) {
- if(*i < table->size() - 1) {
- std::swap(list[*i], list[*i + 1]);
+ for(auto i: sel | boost::adaptors::reversed) {
+ if(i < table->size() - 1) {
+ std::swap(list[i], list[i + 1]);
- table->erase(*i);
- addEntry(list[*i + 1], *i + 1);
- table->select(*i + 1);
+ table->erase(i);
+ addEntry(list[i + 1], i + 1);
+ table->select(i + 1);
}
}