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 | |
| 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
34 files changed, 120 insertions, 122 deletions
| diff --git a/QA/Checker/IO.cpp b/QA/Checker/IO.cpp index d8fcc96..4b43635 100644 --- a/QA/Checker/IO.cpp +++ b/QA/Checker/IO.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.   */ @@ -12,12 +12,12 @@  std::ostream& operator<<(std::ostream& os, const Swift::ByteArray& s) {      std::ios::fmtflags oldFlags = os.flags();      os << std::hex; -    for (Swift::ByteArray::const_iterator i = s.begin(); i != s.end(); ++i) { -        if (*i >= 32 && *i < 127) { -            os << *i; +    for (unsigned char i : s) { +        if (i >= 32 && i < 127) { +            os << i;          }          else { -            os << "\\x" << static_cast<unsigned int>(static_cast<unsigned char>(*i)); +            os << "\\x" << static_cast<unsigned int>(static_cast<unsigned char>(i));          }      }      os << std::endl; @@ -28,12 +28,12 @@ std::ostream& operator<<(std::ostream& os, const Swift::ByteArray& s) {  std::ostream& operator<<(std::ostream& os, const Swift::SafeByteArray& s) {      std::ios::fmtflags oldFlags = os.flags();      os << std::hex; -    for (Swift::SafeByteArray::const_iterator i = s.begin(); i != s.end(); ++i) { -        if (*i >= 32 && *i < 127) { -            os << *i; +    for (unsigned char i : s) { +        if (i >= 32 && i < 127) { +            os << i;          }          else { -            os << "\\x" << static_cast<unsigned int>(static_cast<unsigned char>(*i)); +            os << "\\x" << static_cast<unsigned int>(static_cast<unsigned char>(i));          }      }      os << std::endl; @@ -42,16 +42,16 @@ std::ostream& operator<<(std::ostream& os, const Swift::SafeByteArray& s) {  }  std::ostream& operator<<(std::ostream& os, const std::vector<int>& s) { -    for (std::vector<int>::const_iterator i = s.begin(); i != s.end(); ++i) { -        os << *i << " "; +    for (int i : s) { +        os << i << " ";      }      os << std::endl;      return os;  }  std::ostream& operator<<(std::ostream& os, const std::vector<size_t>& s) { -    for (std::vector<size_t>::const_iterator i = s.begin(); i != s.end(); ++i) { -        os << *i << " "; +    for (size_t i : s) { +        os << i << " ";      }      os << std::endl;      return os; diff --git a/Sluift/Lua/Value.cpp b/Sluift/Lua/Value.cpp index ed776c1..70fbb89 100644 --- a/Sluift/Lua/Value.cpp +++ b/Sluift/Lua/Value.cpp @@ -49,9 +49,9 @@ namespace {          void operator()(const std::map<std::string, std::shared_ptr<Value> >& table) const {              lua_createtable(state, 0, boost::numeric_cast<int>(table.size())); -            for(std::map<std::string, std::shared_ptr<Value> >::const_iterator i = table.begin(); i != table.end(); ++i) { -                boost::apply_visitor(PushVisitor(state), *i->second); -                lua_setfield(state, -2, i->first.c_str()); +            for(const auto& i : table) { +                boost::apply_visitor(PushVisitor(state), *i.second); +                lua_setfield(state, -2, i.first.c_str());              }          } diff --git a/Swift/Controllers/AdHocManager.cpp b/Swift/Controllers/AdHocManager.cpp index 4212b8a..81f80e2 100644 --- a/Swift/Controllers/AdHocManager.cpp +++ b/Swift/Controllers/AdHocManager.cpp @@ -33,8 +33,8 @@ AdHocManager::AdHocManager(const JID& jid, AdHocCommandWindowFactory* factory, I  AdHocManager::~AdHocManager() {      uiEventStream_->onUIEvent.disconnect(boost::bind(&AdHocManager::handleUIEvent, this, _1)); -    for (size_t i = 0; i < controllers_.size(); ++i) { -        controllers_[i]->onDeleting.disconnect(boost::bind(&AdHocManager::removeController, this, controllers_[i])); +    for (auto& controller : controllers_) { +        controller->onDeleting.disconnect(boost::bind(&AdHocManager::removeController, this, controller));      }  } diff --git a/Swift/Controllers/ContactSuggester.cpp b/Swift/Controllers/ContactSuggester.cpp index 04e9dc4..8a3a6fa 100644 --- a/Swift/Controllers/ContactSuggester.cpp +++ b/Swift/Controllers/ContactSuggester.cpp @@ -74,8 +74,8 @@ bool ContactSuggester::fuzzyMatch(std::string text, std::string match) {      std::string lowerMatch = match;      boost::algorithm::to_lower(lowerMatch);      size_t lastMatch = 0; -    for (size_t i = 0; i < lowerMatch.length(); ++i) { -        size_t where = lowerText.find_first_of(lowerMatch[i], lastMatch); +    for (char i : lowerMatch) { +        size_t where = lowerText.find_first_of(i, lastMatch);          if (where == std::string::npos) {              return false;          } diff --git a/Swift/Controllers/Roster/GroupRosterItem.cpp b/Swift/Controllers/Roster/GroupRosterItem.cpp index 5aa3a5e..ac40afd 100644 --- a/Swift/Controllers/Roster/GroupRosterItem.cpp +++ b/Swift/Controllers/Roster/GroupRosterItem.cpp @@ -183,8 +183,8 @@ bool GroupRosterItem::itemLessThanWithStatus(const RosterItem* left, const Roste  void GroupRosterItem::setDisplayed(RosterItem* item, bool displayed) {      bool found = false; -    for (size_t i = 0; i < displayedChildren_.size(); i++) { -        if (displayedChildren_[i] == item) { +    for (auto& i : displayedChildren_) { +        if (i == item) {              found = true;          }      } @@ -211,8 +211,8 @@ void GroupRosterItem::handleChildrenChanged(GroupRosterItem* group) {      size_t oldSize = getDisplayedChildren().size();      if (group->getDisplayedChildren().size() > 0) {          bool found = false; -        for (size_t i = 0; i < displayedChildren_.size(); i++) { -            if (displayedChildren_[i] == group) { +        for (auto& i : displayedChildren_) { +            if (i == group) {                  found = true;              }          } diff --git a/Swift/Controllers/SystemTrayController.cpp b/Swift/Controllers/SystemTrayController.cpp index 28dbf5e..8d4b2b7 100644 --- a/Swift/Controllers/SystemTrayController.cpp +++ b/Swift/Controllers/SystemTrayController.cpp @@ -22,8 +22,8 @@ SystemTrayController::SystemTrayController(EventController* eventController, Sys  void SystemTrayController::handleEventQueueLengthChange(int /*length*/) {      EventList events = eventController_->getEvents();      bool found = false; -    for (EventList::iterator it = events.begin(); it != events.end(); ++it) { -        if (std::dynamic_pointer_cast<MessageEvent>(*it)) { +    for (auto& event : events) { +        if (std::dynamic_pointer_cast<MessageEvent>(event)) {              found = true;              break;          } diff --git a/Swift/QtUI/QtChatTabs.cpp b/Swift/QtUI/QtChatTabs.cpp index 3609cc9..650d807 100644 --- a/Swift/QtUI/QtChatTabs.cpp +++ b/Swift/QtUI/QtChatTabs.cpp @@ -228,7 +228,7 @@ void QtChatTabs::handleRequestedNextTab() {  void QtChatTabs::handleRequestedActiveTab() {      QtTabbable::AlertType types[] = {QtTabbable::WaitingActivity, QtTabbable::ImpendingActivity};      bool finished = false; -    for (int j = 0; j < 2; j++) { +    for (auto& type : types) {          bool looped = false;          for (int i = dynamicGrid_->currentIndex() + 1; !finished && i != dynamicGrid_->currentIndex(); i++) {              if (i >= dynamicGrid_->count()) { @@ -238,7 +238,7 @@ void QtChatTabs::handleRequestedActiveTab() {                  looped = true;                  i = 0;              } -            if (qobject_cast<QtTabbable*>(dynamicGrid_->widget(i))->getWidgetAlertState() == types[j]) { +            if (qobject_cast<QtTabbable*>(dynamicGrid_->widget(i))->getWidgetAlertState() == type) {                  dynamicGrid_->setCurrentIndex(i);                  finished = true;                  break; diff --git a/Swift/QtUI/QtChatTabsShortcutOnlySubstitute.cpp b/Swift/QtUI/QtChatTabsShortcutOnlySubstitute.cpp index 2c064f8..fb41446 100644 --- a/Swift/QtUI/QtChatTabsShortcutOnlySubstitute.cpp +++ b/Swift/QtUI/QtChatTabsShortcutOnlySubstitute.cpp @@ -1,5 +1,5 @@  /* - * Copyright (c) 2015 Isode Limited. + * Copyright (c) 2015-2016 Isode Limited.   * All rights reserved.   * See the COPYING file for more information.   */ @@ -64,14 +64,14 @@ void QtChatTabsShortcutOnlySubstitute::handleRequestedActiveTab() {      QList<QtTabbable*> tabs = tabbableWindows(); -    for (int j = 0; j < 2; j++) { +    for (auto& type : types) {          int startIndex = tabs.indexOf(senderTab);          int currentIndex = startIndex;          do {              currentIndex = (currentIndex + 1) % tabs.size();              QtTabbable* currentTab = tabs.at(currentIndex); -            if (currentTab->getWidgetAlertState() == types[j]) { +            if (currentTab->getWidgetAlertState() == type) {                  currentTab->activateWindow();                  return;              } diff --git a/Swift/QtUI/QtLoginWindow.cpp b/Swift/QtUI/QtLoginWindow.cpp index b2778a1..bc859e9 100644 --- a/Swift/QtUI/QtLoginWindow.cpp +++ b/Swift/QtUI/QtLoginWindow.cpp @@ -372,8 +372,8 @@ void QtLoginWindow::setIsLoggingIn(bool loggingIn) {      /* Change the for loop as well if you add to this.*/      QWidget* widgets[5] = {username_, password_, remember_, loginAutomatically_, certificateButton_};      loginButton_->setText(loggingIn ? tr("Cancel") : tr("Connect")); -    for (int i = 0; i < 5; i++) { -        widgets[i]->setEnabled(!loggingIn); +    for (auto& widget : widgets) { +        widget->setEnabled(!loggingIn);      }      bool eagle = settings_->getSetting(SettingConstants::FORGET_PASSWORDS);      remember_->setEnabled(!eagle); diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp index e0ca619..846dcbc 100644 --- a/Swift/QtUI/QtTextEdit.cpp +++ b/Swift/QtUI/QtTextEdit.cpp @@ -107,9 +107,9 @@ void QtTextEdit::replaceMisspelledWord(const QString& word, int cursorPosition)  PositionPair QtTextEdit::getWordFromCursor(int cursorPosition) {      PositionPairList misspelledPositions = highlighter_->getMisspelledPositions(); -    for (PositionPairList::iterator it = misspelledPositions.begin(); it != misspelledPositions.end(); ++it) { -        if (cursorPosition >= boost::get<0>(*it) && cursorPosition <= boost::get<1>(*it)) { -            return *it; +    for (auto& misspelledPosition : misspelledPositions) { +        if (cursorPosition >= boost::get<0>(misspelledPosition) && cursorPosition <= boost::get<1>(misspelledPosition)) { +            return misspelledPosition;          }      }      return boost::make_tuple(-1,-1); @@ -134,9 +134,9 @@ void QtTextEdit::contextMenuEvent(QContextMenuEvent* event) {      if (result == settingsAction) {          spellCheckerSettingsWindow();      } -    for (std::vector<QAction*>::iterator it = replaceWordActions_.begin(); it != replaceWordActions_.end(); ++it) { -        if (*it == result) { -            replaceMisspelledWord((*it)->text(), cursor.position()); +    for (auto& replaceWordAction : replaceWordActions_) { +        if (replaceWordAction == result) { +            replaceMisspelledWord(replaceWordAction->text(), cursor.position());          }      }  #else @@ -167,8 +167,8 @@ void QtTextEdit::addSuggestions(QMenu* menu, QContextMenuEvent* event)              menu->insertAction(insertPoint, noSuggestions);          }          else { -            for (std::vector<std::string>::iterator it = wordList.begin(); it != wordList.end(); ++it) { -                QAction* wordAction = new QAction(it->c_str(), menu); +            for (auto& word : wordList) { +                QAction* wordAction = new QAction(word.c_str(), menu);                  menu->insertAction(insertPoint, wordAction);                  replaceWordActions_.push_back(wordAction);              } diff --git a/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.cpp b/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.cpp index 90d6e5e..eef6728 100644 --- a/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.cpp +++ b/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.cpp @@ -73,8 +73,8 @@ void QtVCardPhotoAndNameFields::setEditable(bool editable) {      QStringList fullname;      fullname << ui->lineEditPREFIX->text() << ui->lineEditGIVEN->text() << ui->lineEditMIDDLE->text();      fullname << ui->lineEditFAMILY->text() << ui->lineEditSUFFIX->text(); -    for (QStringList::iterator i = fullname.begin(); i != fullname.end(); i++) { -        *i = i->trimmed(); +    for (auto& i : fullname) { +        i = i.trimmed();      }      ui->labelFULLNAME->setText((fullname.filter(QRegExp(".+"))).join(" "));  } diff --git a/Swift/QtUI/QtWebView.cpp b/Swift/QtUI/QtWebView.cpp index 717310b..b8eb7a5 100644 --- a/Swift/QtUI/QtWebView.cpp +++ b/Swift/QtUI/QtWebView.cpp @@ -55,11 +55,10 @@ void QtWebView::contextMenuEvent(QContextMenuEvent* ev) {      QMenu* menu = page()->createStandardContextMenu();      QList<QAction*> actions(menu->actions()); -    for (int i = 0; i < actions.size(); ++i) { -        QAction* action = actions.at(i); +    for (auto action : actions) {          bool removeAction = true; -        for(size_t j = 0; j < filteredActions.size(); ++j) { -            if (action == pageAction(filteredActions[j])) { +        for(auto& filteredAction : filteredActions) { +            if (action == pageAction(filteredAction)) {                  removeAction = false;                  break;              } diff --git a/Swift/QtUI/UserSearch/QtContactListWidget.cpp b/Swift/QtUI/UserSearch/QtContactListWidget.cpp index 99bd791..1dbfc1f 100644 --- a/Swift/QtUI/UserSearch/QtContactListWidget.cpp +++ b/Swift/QtUI/UserSearch/QtContactListWidget.cpp @@ -86,9 +86,9 @@ bool QtContactListWidget::isFull() const {  void QtContactListWidget::updateContacts(const std::vector<Contact::ref>& contactUpdates) {      std::vector<Contact::ref> contacts = contactListModel_->getList();      foreach(const Contact::ref& contactUpdate, contactUpdates) { -        for(size_t n = 0; n < contacts.size(); n++) { -            if (contactUpdate->jid == contacts[n]->jid) { -                contacts[n] = contactUpdate; +        for(auto& contact : contacts) { +            if (contactUpdate->jid == contact->jid) { +                contact = contactUpdate;                  break;              }          } diff --git a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp index 83b8df6..6b56811 100644 --- a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp +++ b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp @@ -557,9 +557,9 @@ void QtUserSearchWindow::clearForm() {      fieldsPage_->fetchingThrobber_->movie()->start();      fieldsPage_->fetchingLabel_->show();      QWidget* legacySearchWidgets[8] = {fieldsPage_->nickInputLabel_, fieldsPage_->nickInput_, fieldsPage_->firstInputLabel_, fieldsPage_->firstInput_, fieldsPage_->lastInputLabel_, fieldsPage_->lastInput_, fieldsPage_->emailInputLabel_, fieldsPage_->emailInput_}; -    for (int i = 0; i < 8; i++) { -        legacySearchWidgets[i]->hide(); -        if (QLineEdit* edit = qobject_cast<QLineEdit*>(legacySearchWidgets[i])) { +    for (auto& legacySearchWidget : legacySearchWidgets) { +        legacySearchWidget->hide(); +        if (QLineEdit* edit = qobject_cast<QLineEdit*>(legacySearchWidget)) {              edit->clear();          }      } 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());  } | 
 Swift
 Swift