diff options
author | Tobias Markmann <tm@ayena.de> | 2016-04-04 14:41:44 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2016-04-04 14:41:44 (GMT) |
commit | 3c560e31b0f168da917e8d566db01fd1cd997d86 (patch) | |
tree | a6d1c5c276d3571c6303a31af9f3cefd34b13d52 /Swiften | |
parent | 4f3821a090931499b9c68b3b3ad785a98ea9d742 (diff) | |
download | swift-3c560e31b0f168da917e8d566db01fd1cd997d86.zip swift-3c560e31b0f168da917e8d566db01fd1cd997d86.tar.bz2 |
Modernize code to use range based for loops using clang-tidy
Run 'clang-tidy -fix -checks=modernize-loop-convert' on all
source code files on OS X. This does not modernize platform
specific code on Linux and Windows
Test-Information:
Code builds and unit tests pass on OS X 10.11.4.
Change-Id: I65b99e0978cfab8ca6de2a3e5342e7a81416c12c
Diffstat (limited to 'Swiften')
-rw-r--r-- | Swiften/Base/String.cpp | 8 | ||||
-rw-r--r-- | Swiften/Config/swiften-config.cpp | 20 | ||||
-rw-r--r-- | Swiften/Elements/JingleContentPayload.h | 8 | ||||
-rw-r--r-- | Swiften/Elements/JinglePayload.h | 8 | ||||
-rw-r--r-- | Swiften/Elements/Stanza.cpp | 6 | ||||
-rw-r--r-- | Swiften/Elements/Stanza.h | 8 | ||||
-rw-r--r-- | Swiften/Examples/BenchTool/BenchTool.cpp | 8 | ||||
-rw-r--r-- | Swiften/Jingle/Jingle.h | 8 | ||||
-rw-r--r-- | Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h | 8 | ||||
-rw-r--r-- | Swiften/LinkLocal/LinkLocalServiceBrowser.cpp | 4 | ||||
-rw-r--r-- | Swiften/MUC/MUCBookmarkManager.cpp | 6 | ||||
-rw-r--r-- | Swiften/Network/MacOSXProxyProvider.cpp | 4 | ||||
-rw-r--r-- | Swiften/Network/StaticDomainNameResolver.cpp | 6 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/IBBParser.cpp | 5 | ||||
-rw-r--r-- | Swiften/QA/FileTransferTest/FileTransferTest.cpp | 4 | ||||
-rw-r--r-- | Swiften/SASL/DIGESTMD5Properties.cpp | 4 | ||||
-rw-r--r-- | Swiften/SASL/SCRAMSHA1ClientAuthenticator.cpp | 8 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/BlockSerializer.h | 4 | ||||
-rw-r--r-- | Swiften/StreamStack/StreamStack.h | 4 | ||||
-rw-r--r-- | Swiften/StringCodecs/Hexify.cpp | 6 |
20 files changed, 68 insertions, 69 deletions
diff --git a/Swiften/Base/String.cpp b/Swiften/Base/String.cpp index 91128ff..4a5e4c9 100644 --- a/Swiften/Base/String.cpp +++ b/Swiften/Base/String.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2013 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -90,13 +90,13 @@ std::vector<std::string> String::split(const std::string& s, char c) { assert((c & 0x80) == 0); std::vector<std::string> result; std::string accumulator; - for (size_t i = 0; i < s.size(); ++i) { - if (s[i] == c) { + for (char i : s) { + if (i == c) { result.push_back(accumulator); accumulator = ""; } else { - accumulator += s[i]; + accumulator += i; } } result.push_back(accumulator); diff --git a/Swiften/Config/swiften-config.cpp b/Swiften/Config/swiften-config.cpp index 1a15702..2b66989 100644 --- a/Swiften/Config/swiften-config.cpp +++ b/Swiften/Config/swiften-config.cpp @@ -88,29 +88,29 @@ int main(int argc, char* argv[]) { bool inPlace = !boost::filesystem::exists(topInstallPath / "include" / "Swiften" / "Swiften.h"); // Replace "#" variables with the correct path - for(size_t i = 0; i < libs.size(); ++i) { + for(auto & i : libs) { if (inPlace) { - std::string lib = libs[i]; + std::string lib = i; boost::replace_all(lib, "#", pathToString(topSourcePath)); - libs[i] = lib; + i = lib; } else { - std::string lib = libs[i]; + std::string lib = i; boost::replace_all(lib, "#", pathToString(topInstallPath / "lib")); boost::erase_all(lib, "/Swiften"); - libs[i] = lib; + i = lib; } } - for(size_t i = 0; i < cflags.size(); ++i) { + for(auto & i : cflags) { if (inPlace) { - std::string cflag = cflags[i]; + std::string cflag = i; boost::replace_all(cflag, "#", pathToString(topSourcePath)); - cflags[i] = cflag; + i = cflag; } else { - std::string cflag = cflags[i]; + std::string cflag = i; boost::replace_all(cflag, "#", pathToString(topInstallPath / "include")); - cflags[i] = cflag; + i = cflag; } } diff --git a/Swiften/Elements/JingleContentPayload.h b/Swiften/Elements/JingleContentPayload.h index 286e08b..744ac09 100644 --- a/Swiften/Elements/JingleContentPayload.h +++ b/Swiften/Elements/JingleContentPayload.h @@ -72,8 +72,8 @@ namespace Swift { template<typename T> std::shared_ptr<T> getDescription() const { - for (size_t i = 0; i < descriptions.size(); ++i) { - std::shared_ptr<T> result(std::dynamic_pointer_cast<T>(descriptions[i])); + for (const auto& description : descriptions) { + std::shared_ptr<T> result(std::dynamic_pointer_cast<T>(description)); if (result) { return result; } @@ -83,8 +83,8 @@ namespace Swift { template<typename T> std::shared_ptr<T> getTransport() const { - for (size_t i = 0; i < transports.size(); ++i) { - std::shared_ptr<T> result(std::dynamic_pointer_cast<T>(transports[i])); + for (const auto& transport : transports) { + std::shared_ptr<T> result(std::dynamic_pointer_cast<T>(transport)); if (result) { return result; } diff --git a/Swiften/Elements/JinglePayload.h b/Swiften/Elements/JinglePayload.h index d1dfb44..a1e8500 100644 --- a/Swiften/Elements/JinglePayload.h +++ b/Swiften/Elements/JinglePayload.h @@ -124,8 +124,8 @@ namespace Swift { template<typename T> const std::vector<std::shared_ptr<T> > getPayloads() const { std::vector<std::shared_ptr<T> > matched_payloads; - for (std::vector<std::shared_ptr<Payload> >::const_iterator i = payloads.begin(); i != payloads.end(); ++i) { - std::shared_ptr<T> result = std::dynamic_pointer_cast<T>(*i); + for (const auto& payload : payloads) { + std::shared_ptr<T> result = std::dynamic_pointer_cast<T>(payload); if (result) { matched_payloads.push_back(result); } @@ -138,8 +138,8 @@ namespace Swift { template<typename T> const std::shared_ptr<T> getPayload() const { std::shared_ptr<T> result; - for (std::vector<std::shared_ptr<Payload> >::const_iterator i = payloads.begin(); i != payloads.end(); ++i) { - result = std::dynamic_pointer_cast<T>(*i); + for (const auto& payload : payloads) { + result = std::dynamic_pointer_cast<T>(payload); if (result) { return result; } diff --git a/Swiften/Elements/Stanza.cpp b/Swiften/Elements/Stanza.cpp index 5d1229c..f5a1b58 100644 --- a/Swiften/Elements/Stanza.cpp +++ b/Swiften/Elements/Stanza.cpp @@ -58,9 +58,9 @@ boost::optional<boost::posix_time::ptime> Stanza::getTimestamp() const { boost::optional<boost::posix_time::ptime> Stanza::getTimestampFrom(const JID& jid) const { std::vector< std::shared_ptr<Delay> > delays = getPayloads<Delay>(); - for (size_t i = 0; i < delays.size(); ++i) { - if (delays[i]->getFrom() == jid) { - return delays[i]->getStamp(); + for (auto& delay : delays) { + if (delay->getFrom() == jid) { + return delay->getStamp(); } } return getTimestamp(); diff --git a/Swiften/Elements/Stanza.h b/Swiften/Elements/Stanza.h index 2df64a1..9a69696 100644 --- a/Swiften/Elements/Stanza.h +++ b/Swiften/Elements/Stanza.h @@ -33,8 +33,8 @@ namespace Swift { template<typename T> std::shared_ptr<T> getPayload() const { - for (size_t i = 0; i < payloads_.size(); ++i) { - std::shared_ptr<T> result(std::dynamic_pointer_cast<T>(payloads_[i])); + for (const auto& payload : payloads_) { + std::shared_ptr<T> result(std::dynamic_pointer_cast<T>(payload)); if (result) { return result; } @@ -45,8 +45,8 @@ namespace Swift { template<typename T> std::vector< std::shared_ptr<T> > getPayloads() const { std::vector< std::shared_ptr<T> > results; - for (size_t i = 0; i < payloads_.size(); ++i) { - std::shared_ptr<T> result(std::dynamic_pointer_cast<T>(payloads_[i])); + for (const auto& payload : payloads_) { + std::shared_ptr<T> result(std::dynamic_pointer_cast<T>(payload)); if (result) { results.push_back(result); } diff --git a/Swiften/Examples/BenchTool/BenchTool.cpp b/Swiften/Examples/BenchTool/BenchTool.cpp index f7337b9..d56baed 100644 --- a/Swiften/Examples/BenchTool/BenchTool.cpp +++ b/Swiften/Examples/BenchTool/BenchTool.cpp @@ -53,14 +53,14 @@ int main(int, char**) { clients.push_back(client); } - for (size_t i = 0; i < clients.size(); ++i) { - clients[i]->connect(); + for (auto& client : clients) { + client->connect(); } eventLoop.run(); - for (size_t i = 0; i < clients.size(); ++i) { - delete clients[i]; + for (auto& client : clients) { + delete client; } return 0; diff --git a/Swiften/Jingle/Jingle.h b/Swiften/Jingle/Jingle.h index 13c235b..0cd1a23 100644 --- a/Swiften/Jingle/Jingle.h +++ b/Swiften/Jingle/Jingle.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 Isode Limited. + * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -14,9 +14,9 @@ namespace Swift { namespace Jingle { template<typename T> JingleContentPayload::ref getContentWithDescription(const std::vector<JingleContentPayload::ref>& contents) { - for (size_t i = 0; i < contents.size(); ++i) { - if (contents[i]->getDescription<T>()) { - return contents[i]; + for (const auto& content : contents) { + if (content->getDescription<T>()) { + return content; } } return JingleContentPayload::ref(); diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h index 85fdc3a..633ca6d 100644 --- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h +++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h @@ -62,8 +62,8 @@ namespace Swift { template<typename T> std::vector< std::shared_ptr<T> > getAllQueriesEverRun() const { std::vector< std::shared_ptr<T> > result; - for (QueryList::const_iterator i = allQueriesEverRun.begin(); i != allQueriesEverRun.end(); ++i) { - if (std::shared_ptr<T> resultQuery = std::dynamic_pointer_cast<T>(*i)) { + for (const auto& i : allQueriesEverRun) { + if (std::shared_ptr<T> resultQuery = std::dynamic_pointer_cast<T>(i)) { result.push_back(resultQuery); } } @@ -74,8 +74,8 @@ namespace Swift { template<typename T> std::vector< std::shared_ptr<T> > getQueries() const { std::vector< std::shared_ptr<T> > result; - for (QueryList::const_iterator i = runningQueries.begin(); i != runningQueries.end(); ++i) { - if (std::shared_ptr<T> resultQuery = std::dynamic_pointer_cast<T>(*i)) { + for (const auto& runningQuerie : runningQueries) { + if (std::shared_ptr<T> resultQuery = std::dynamic_pointer_cast<T>(runningQuerie)) { result.push_back(resultQuery); } } diff --git a/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp b/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp index e3b6028..b79f184 100644 --- a/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp +++ b/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp @@ -87,8 +87,8 @@ void LinkLocalServiceBrowser::unregisterService() { std::vector<LinkLocalService> LinkLocalServiceBrowser::getServices() const { std::vector<LinkLocalService> result; - for (ServiceMap::const_iterator i = services.begin(); i != services.end(); ++i) { - result.push_back(LinkLocalService(i->first, i->second)); + for (const auto& service : services) { + result.push_back(LinkLocalService(service.first, service.second)); } return result; } diff --git a/Swiften/MUC/MUCBookmarkManager.cpp b/Swiften/MUC/MUCBookmarkManager.cpp index 570c613..602e876 100644 --- a/Swiften/MUC/MUCBookmarkManager.cpp +++ b/Swiften/MUC/MUCBookmarkManager.cpp @@ -65,9 +65,9 @@ bool MUCBookmarkManager::containsEquivalent(const std::vector<MUCBookmark>& list void MUCBookmarkManager::replaceBookmark(const MUCBookmark& oldBookmark, const MUCBookmark& newBookmark) { if (!ready_) return; - for (size_t i = 0; i < bookmarks_.size(); i++) { - if (bookmarks_[i] == oldBookmark) { - bookmarks_[i] = newBookmark; + for (auto& bookmark : bookmarks_) { + if (bookmark == oldBookmark) { + bookmark = newBookmark; flush(); onBookmarkRemoved(oldBookmark); onBookmarkAdded(newBookmark); diff --git a/Swiften/Network/MacOSXProxyProvider.cpp b/Swiften/Network/MacOSXProxyProvider.cpp index 69c6335..acea480 100644 --- a/Swiften/Network/MacOSXProxyProvider.cpp +++ b/Swiften/Network/MacOSXProxyProvider.cpp @@ -56,8 +56,8 @@ static HostAddressPort getFromDictionary(CFDictionaryRef dict, CFStringRef enabl CFIndex length = CFStringGetLength(stringValue) + 1; buffer.resize(boost::numeric_cast<size_t>(length)); if(CFStringGetCString(stringValue, &buffer[0], length, kCFStringEncodingMacRoman)) { - for(std::vector<char>::iterator iter = buffer.begin(); iter != buffer.end(); ++iter) { - host += *iter; + for(char& iter : buffer) { + host += iter; } } } diff --git a/Swiften/Network/StaticDomainNameResolver.cpp b/Swiften/Network/StaticDomainNameResolver.cpp index 3601bf2..95b3dd9 100644 --- a/Swiften/Network/StaticDomainNameResolver.cpp +++ b/Swiften/Network/StaticDomainNameResolver.cpp @@ -25,9 +25,9 @@ namespace { return; } std::vector<DomainNameServiceQuery::Result> results; - for(StaticDomainNameResolver::ServicesCollection::const_iterator i = resolver->getServices().begin(); i != resolver->getServices().end(); ++i) { - if (i->first == service) { - results.push_back(i->second); + for(const auto& i : resolver->getServices()) { + if (i.first == service) { + results.push_back(i.second); } } eventLoop->postEvent(boost::bind(&ServiceQuery::emitOnResult, shared_from_this(), results), owner); diff --git a/Swiften/Parser/PayloadParsers/IBBParser.cpp b/Swiften/Parser/PayloadParsers/IBBParser.cpp index 3aeb04c..4a6b841 100644 --- a/Swiften/Parser/PayloadParsers/IBBParser.cpp +++ b/Swiften/Parser/PayloadParsers/IBBParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -58,8 +58,7 @@ void IBBParser::handleEndElement(const std::string& element, const std::string&) if (level == TopLevel) { if (element == "data") { std::vector<char> data; - for (size_t i = 0; i < currentText.size(); ++i) { - char c = currentText[i]; + for (char c : currentText) { if ((c >= 48 && c <= 122) || c == 47 || c == 43) { data.push_back(c); } diff --git a/Swiften/QA/FileTransferTest/FileTransferTest.cpp b/Swiften/QA/FileTransferTest/FileTransferTest.cpp index dd8c139..4cf4048 100644 --- a/Swiften/QA/FileTransferTest/FileTransferTest.cpp +++ b/Swiften/QA/FileTransferTest/FileTransferTest.cpp @@ -80,8 +80,8 @@ class FileTransferTest { size_t size = 1024 + boost::numeric_cast<size_t>(randGen.generateRandomInteger(1024 * 10)); sendData_.resize(size); - for (size_t n = 0; n < sendData_.size(); n++) { - sendData_[n] = boost::numeric_cast<unsigned char>(randGen.generateRandomInteger(255)); + for (unsigned char& n : sendData_) { + n = boost::numeric_cast<unsigned char>(randGen.generateRandomInteger(255)); } std::ofstream outfile(sendFilePath_.native().c_str(), std::ios::out | std::ios::binary); diff --git a/Swiften/SASL/DIGESTMD5Properties.cpp b/Swiften/SASL/DIGESTMD5Properties.cpp index baf0197..1f33c8f 100644 --- a/Swiften/SASL/DIGESTMD5Properties.cpp +++ b/Swiften/SASL/DIGESTMD5Properties.cpp @@ -48,8 +48,8 @@ DIGESTMD5Properties DIGESTMD5Properties::parse(const ByteArray& data) { bool inKey = true; ByteArray currentKey; ByteArray currentValue; - for (size_t i = 0; i < data.size(); ++i) { - char c = static_cast<char>(data[i]); + for (unsigned char i : data) { + char c = static_cast<char>(i); if (inKey) { if (c == '=') { inKey = false; diff --git a/Swiften/SASL/SCRAMSHA1ClientAuthenticator.cpp b/Swiften/SASL/SCRAMSHA1ClientAuthenticator.cpp index 2374d15..3c00402 100644 --- a/Swiften/SASL/SCRAMSHA1ClientAuthenticator.cpp +++ b/Swiften/SASL/SCRAMSHA1ClientAuthenticator.cpp @@ -21,15 +21,15 @@ namespace Swift { static std::string escape(const std::string& s) { std::string result; - for (size_t i = 0; i < s.size(); ++i) { - if (s[i] == ',') { + for (char i : s) { + if (i == ',') { result += "=2C"; } - else if (s[i] == '=') { + else if (i == '=') { result += "=3D"; } else { - result += s[i]; + result += i; } } return result; diff --git a/Swiften/Serializer/PayloadSerializers/BlockSerializer.h b/Swiften/Serializer/PayloadSerializers/BlockSerializer.h index 86aa321..f034c46 100644 --- a/Swiften/Serializer/PayloadSerializers/BlockSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/BlockSerializer.h @@ -23,9 +23,9 @@ namespace Swift { virtual std::string serializePayload(std::shared_ptr<BLOCK_ELEMENT> payload) const { XMLElement element(tag, "urn:xmpp:blocking"); const std::vector<JID>& items = payload->getItems(); - for (std::vector<JID>::const_iterator i = items.begin(); i != items.end(); ++i) { + for (const auto& i : items) { std::shared_ptr<XMLElement> item = std::make_shared<XMLElement>("item"); - item->setAttribute("jid", *i); + item->setAttribute("jid", i); element.addNode(item); } return element.serialize(); diff --git a/Swiften/StreamStack/StreamStack.h b/Swiften/StreamStack/StreamStack.h index 718aa32..62bd026 100644 --- a/Swiften/StreamStack/StreamStack.h +++ b/Swiften/StreamStack/StreamStack.h @@ -30,8 +30,8 @@ namespace Swift { } template<typename T> T* getLayer() { - for (size_t i = 0; i < layers_.size(); ++i) { - T* layer = dynamic_cast<T*>(layers_[i]); + for (auto& i : layers_) { + T* layer = dynamic_cast<T*>(i); if (layer) { return layer; } diff --git a/Swiften/StringCodecs/Hexify.cpp b/Swiften/StringCodecs/Hexify.cpp index f4e4ecc..907c240 100644 --- a/Swiften/StringCodecs/Hexify.cpp +++ b/Swiften/StringCodecs/Hexify.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -27,8 +27,8 @@ std::string Hexify::hexify(const ByteArray& data) { std::ostringstream result; result << std::hex; - for (unsigned int i = 0; i < data.size(); ++i) { - result << std::setw(2) << std::setfill('0') << boost::numeric_cast<unsigned int>(static_cast<unsigned char>(data[i])); + for (unsigned char i : data) { + result << std::setw(2) << std::setfill('0') << boost::numeric_cast<unsigned int>(static_cast<unsigned char>(i)); } return std::string(result.str()); } |