]> git.lyx.org Git - lyx.git/commitdiff
Loop refactoring
authorYuriy Skalko <yuriy.skalko@gmail.com>
Fri, 9 Oct 2020 06:04:20 +0000 (09:04 +0300)
committerYuriy Skalko <yuriy.skalko@gmail.com>
Fri, 9 Oct 2020 06:04:20 +0000 (09:04 +0300)
40 files changed:
src/Author.cpp
src/Buffer.cpp
src/BufferParams.cpp
src/Encoding.cpp
src/LaTeXFeatures.cpp
src/LaTeXFonts.cpp
src/PDFOptions.cpp
src/Paragraph.cpp
src/Session.cpp
src/Trans.cpp
src/frontends/qt/ButtonController.cpp
src/frontends/qt/Dialog.cpp
src/frontends/qt/Dialog.h
src/frontends/qt/FancyLineEdit.cpp
src/frontends/qt/FancyLineEdit.h
src/frontends/qt/GuiApplication.cpp
src/frontends/qt/GuiCitation.cpp
src/frontends/qt/GuiDocument.cpp
src/frontends/qt/GuiLyXFiles.cpp
src/frontends/qt/GuiPrefs.cpp
src/frontends/qt/GuiToolbar.cpp
src/frontends/qt/InsetParamsDialog.cpp
src/frontends/qt/Menus.cpp
src/insets/InsetCommandParams.cpp
src/insets/InsetGraphics.cpp
src/insets/InsetInfo.cpp
src/insets/InsetListingsParams.cpp
src/lyxfind.cpp
src/mathed/InsetMathGrid.cpp
src/mathed/InsetMathHull.cpp
src/mathed/InsetMathMacro.cpp
src/mathed/InsetMathMacroTemplate.cpp
src/mathed/MathData.cpp
src/mathed/MathParser.cpp
src/mathed/MathSupport.cpp
src/support/lstrings.cpp
src/support/qstring_helpers.cpp
src/tex2lyx/table.cpp
src/tex2lyx/tex2lyx.cpp
src/tex2lyx/text.cpp

index 9a2dc1ea432fca51a6241f633540614a8c2fb063..b4cf9fd97baa3c87a7cebddc19ff3ac00bf733ff 100644 (file)
@@ -31,8 +31,8 @@ static int computeHash(docstring const & name,
        string const full_author_string = to_utf8(name + email);
        // Bernstein's hash function
        unsigned int hash = 5381;
-       for (unsigned int i = 0; i < full_author_string.length(); ++i)
-               hash = ((hash << 5) + hash) + (unsigned int)(full_author_string[i]);
+       for (char c : full_author_string)
+               hash = ((hash << 5) + hash) + (unsigned int)c;
        return int(hash);
 }
 
index 6d25d51908cabbd10241d07ce432623fc43cf2ec..1ccb263014651595f417bb099d9ea820c8a4b522 100644 (file)
@@ -1903,9 +1903,9 @@ Buffer::ExportStatus Buffer::writeLaTeXSource(otexstream & os,
                        docstring uncodable_glyphs;
                        Encoding const * const enc = runparams.encoding;
                        if (enc) {
-                               for (size_t n = 0; n < inputpath.size(); ++n) {
-                                       if (!enc->encodable(inputpath[n])) {
-                                               docstring const glyph(1, inputpath[n]);
+                               for (char_type n : inputpath) {
+                                       if (!enc->encodable(n)) {
+                                               docstring const glyph(1, n);
                                                LYXERR0("Uncodable character '"
                                                        << glyph
                                                        << "' in input path!");
index 58a02c8683c6d47139efb955f679231e2f1aaf87..5f5a4cb23127a6d3cf576fdd2e60cd3f951b97de 100644 (file)
@@ -1741,8 +1741,7 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
                docstring options_encodable;
                Encoding const * const enc = features.runparams().encoding;
                if (enc) {
-                       for (size_t n = 0; n < strOptions.size(); ++n) {
-                               char_type c = strOptions[n];
+                       for (char_type c : strOptions) {
                                if (!enc->encodable(c)) {
                                        docstring const glyph(1, c);
                                        LYXERR0("Uncodable character '"
@@ -2184,8 +2183,7 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
                docstring uncodable_glyphs;
                Encoding const * const enc = features.runparams().encoding;
                if (enc) {
-                       for (size_t n = 0; n < preamble.size(); ++n) {
-                               char_type c = preamble[n];
+                       for (char_type c : preamble) {
                                if (!enc->encodable(c)) {
                                        docstring const glyph(1, c);
                                        LYXERR0("Uncodable character '"
index b24c31366fe6d800094422302c5debbac5d517c6..64bb3c0b64a4a9c4a5361596d5b51cd5d5afb09e 100644 (file)
@@ -228,8 +228,7 @@ pair<docstring, docstring> Encoding::latexString(docstring const & input, bool d
        docstring result;
        docstring uncodable;
        bool terminate = false;
-       for (size_t n = 0; n < input.size(); ++n) {
-               char_type const c = input[n];
+       for (char_type const c : input) {
                try {
                        pair<docstring, bool> latex_char = latexChar(c);
                        docstring const latex = latex_char.first;
@@ -252,10 +251,10 @@ pair<docstring, docstring> Encoding::latexString(docstring const & input, bool d
                        if (dryrun) {
                                result += "<" + _("LyX Warning: ")
                                           + _("uncodable character") + " '";
-                               result += docstring(1, input[n]);
+                               result += docstring(1, c);
                                result += "'>";
                        } else
-                               uncodable += input[n];
+                               uncodable += c;
                }
        }
        return make_pair(result, uncodable);
@@ -733,14 +732,14 @@ void Encodings::read(FileName const & encfile, FileName const & symbolsfile)
                        } else if (prefixIs(flag, "force=")) {
                                vector<string> encs =
                                        getVectorFromString(flag.substr(6), ";");
-                               for (size_t i = 0; i < encs.size(); ++i)
-                                       forcedselected[encs[i]].insert(symbol);
+                               for (auto const & enc : encs)
+                                       forcedselected[enc].insert(symbol);
                                flags |= CharInfoForceSelected;
                        } else if (prefixIs(flag, "force!=")) {
                                vector<string> encs =
                                        getVectorFromString(flag.substr(7), ";");
-                               for (size_t i = 0; i < encs.size(); ++i)
-                                       forcednotselected[encs[i]].insert(symbol);
+                               for (auto const & enc : encs)
+                                       forcednotselected[enc].insert(symbol);
                                flags |= CharInfoForceSelected;
                        } else if (flag == "mathalpha") {
                                mathalpha.insert(symbol);
index 3d67128f58069129dc7ed13364339a6e55971729..616e24ab8c40e835e05548af780a7d6812e1b77a 100644 (file)
@@ -1163,10 +1163,6 @@ char const * bibliofeatures[] = {
        "named"
 };
 
-int const nb_bibliofeatures = sizeof(bibliofeatures) / sizeof(char const *);
-
-int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
-
 } // namespace
 
 
@@ -1258,9 +1254,9 @@ string const LaTeXFeatures::getPackages() const
 
        //  These are all the 'simple' includes.  i.e
        //  packages which we just \usepackage{package}
-       for (int i = 0; i < nb_simplefeatures; ++i) {
-               if (mustProvide(simplefeatures[i]))
-                       packages << "\\usepackage{" << simplefeatures[i] << "}\n";
+       for (char const * feature : simplefeatures) {
+               if (mustProvide(feature))
+                       packages << "\\usepackage{" << feature << "}\n";
        }
 
        // The rest of these packages are somewhat more complicated
@@ -1420,10 +1416,9 @@ string const LaTeXFeatures::getPackages() const
                packages << "\\usepackage{esint}\n";
 
        // Known bibliography packages (simple \usepackage{package})
-       for (int i = 0; i < nb_bibliofeatures; ++i) {
-               if (mustProvide(bibliofeatures[i]))
-                       packages << "\\usepackage{"
-                                << bibliofeatures[i] << "}\n";
+       for (char const * feature : bibliofeatures) {
+               if (mustProvide(feature))
+                       packages << "\\usepackage{" << feature << "}\n";
        }
 
        // Compatibility between achicago and natbib
@@ -1944,8 +1939,8 @@ docstring const getFloatI18nPreamble(docstring const & type,
 {
        // Check whether name can be encoded in the buffer encoding
        bool encodable = true;
-       for (size_t i = 0; i < name.size(); ++i) {
-               if (!enc.encodable(name[i])) {
+       for (char_type c : name) {
+               if (!enc.encodable(c)) {
                        encodable = false;
                        break;
                }
index cb686349817e1683f62716985c416e0bdac977d5..16470cc2d9ce51570abe22fdeb64b6844272052b 100644 (file)
@@ -57,8 +57,8 @@ bool LaTeXFont::available(bool ot1, bool nomath)
                && LaTeXFeatures::isAvailable(to_ascii(package_)))
                return true;
        else if (!altfonts_.empty()) {
-               for (size_t i = 0; i < altfonts_.size(); ++i) {
-                       if (altFont(altfonts_[i]).available(ot1, nomath))
+               for (auto const & name : altfonts_) {
+                       if (altFont(name).available(ot1, nomath))
                                return true;
                }
        }
@@ -163,8 +163,8 @@ bool LaTeXFont::provides(std::string const & name, bool ot1, bool complete, bool
        else if (provides_.empty())
                return false;
 
-       for (size_t i = 0; i < provides_.size(); ++i) {
-               if (provides_[i] == name)
+       for (auto const & provide : provides_) {
+               if (provide == name)
                        return true;
        }
        return false;
@@ -200,8 +200,8 @@ docstring const LaTeXFont::getUsedFont(bool ot1, bool complete, bool nomath, boo
                        return name_;
        }
        else if (!altfonts_.empty()) {
-               for (size_t i = 0; i < altfonts_.size(); ++i) {
-                       LaTeXFont altf = altFont(altfonts_[i]);
+               for (auto const & name : altfonts_) {
+                       LaTeXFont altf = altFont(name);
                        if (altf.available(ot1, nomath))
                                return altf.getUsedFont(ot1, complete, nomath, osf);
                }
index 026c22db91cead550d2b078723203b2477549401..1ec97fdbb546cfedd83e93225d9d0876791914d1 100644 (file)
@@ -159,8 +159,8 @@ void PDFOptions::writeLaTeX(OutputParams & runparams, otexstream & os,
        docstring const hs = from_utf8(hyperset);
        bool need_unicode = false;
        if (enc) {
-               for (size_t n = 0; n < hs.size(); ++n) {
-                       if (!enc->encodable(hs[n]))
+               for (char_type h : hs) {
+                       if (!enc->encodable(h))
                                need_unicode = true;
                }
        }
index 520a9f838aad50f324231ea23ba0dc779ac06739..707e7701645a2c398c471f4e4d0ea6eb463e68df 100644 (file)
@@ -4368,10 +4368,8 @@ void Paragraph::changeCase(BufferParams const & bparams, pos_type pos,
                }
 
                int erasePos = pos - changes.size();
-               for (size_t i = 0; i < changes.size(); i++) {
-                       insertChar(pos, changes[i].first,
-                                  changes[i].second,
-                                  trackChanges);
+               for (auto const & change : changes) {
+                       insertChar(pos, change.first, change.second, trackChanges);
                        if (!eraseChar(erasePos, trackChanges)) {
                                ++erasePos;
                                ++pos; // advance
index 8fc8fa23d84e2523d487cbc3950ad96003ad308c..43c1b9b93edb2f64d4a40cc609a6d130038acbaa 100644 (file)
@@ -144,8 +144,8 @@ void LastOpenedSection::read(istream & is)
 void LastOpenedSection::write(ostream & os) const
 {
        os << '\n' << sec_lastopened << '\n';
-       for (size_t i = 0; i < lastopened.size(); ++i)
-               os << lastopened[i].active << ", " << lastopened[i].file_name << '\n';
+       for (auto const & last : lastopened)
+               os << last.active << ", " << last.file_name << '\n';
 }
 
 
@@ -158,8 +158,8 @@ void LastOpenedSection::add(FileName const & file, bool active)
        // currently, we even crash in some cases (see #9483).
        // FIXME: Add session support for multiple views of
        //        the same buffer (split-view etc.).
-       for (size_t i = 0; i < lastopened.size(); ++i) {
-               if (lastopened[i].file_name == file)
+       for (auto const & last : lastopened) {
+               if (last.file_name == file)
                        return;
        }
        lastopened.push_back(lof);
index 2f0f317355f5bcb49df054c740b685e9f348af00..b33fa756ed885d50abe21e9cc97e7984087ebe42 100644 (file)
@@ -186,14 +186,14 @@ void Trans::addDeadkey(tex_accent accent, docstring const & keys)
        tmp.accent = accent;
        kmod_list_[accent] = tmp;
 
-       for (docstring::size_type i = 0; i < keys.length(); ++i) {
+       for (char_type key : keys) {
                // FIXME This is a hack.
                // tmp is no valid UCS4 string, but misused to store the
                // accent.
                docstring tmpd;
                tmpd += char_type(0);
                tmpd += char_type(accent);
-               keymap_[keys[i]] = tmpd;
+               keymap_[key] = tmpd;
        }
 }
 
index 940db32d0da4ac8bde82a4329775289c979a6511..85facfd68870514d0a9747fde835bf2f4b33a73d 100644 (file)
@@ -81,11 +81,7 @@ class ButtonController::Private
 public:
        typedef QList<CheckedLineEdit> CheckedWidgetList;
 
-       Private()
-               : okay_(nullptr), apply_(nullptr), cancel_(nullptr),
-                       restore_(nullptr), auto_apply_(nullptr), default_(nullptr),
-                       policy_(ButtonPolicy::IgnorantPolicy)
-       {}
+       Private() {}
 
        /// \return true if all CheckedWidgets are in a valid state.
        bool checkWidgets() const
@@ -99,17 +95,17 @@ public:
 public:
        CheckedWidgetList checked_widgets_;
 
-       QPushButton * okay_;
-       QPushButton * apply_;
-       QPushButton * cancel_;
-       QPushButton * restore_;
-       QCheckBox * auto_apply_;
-       QPushButton * default_;
+       QPushButton * okay_ = nullptr;
+       QPushButton * apply_ = nullptr;
+       QPushButton * cancel_ = nullptr;
+       QPushButton * restore_ = nullptr;
+       QCheckBox * auto_apply_ = nullptr;
+       QPushButton * default_ = nullptr;
 
        typedef QList<QWidget *> Widgets;
        Widgets read_only_;
 
-       ButtonPolicy policy_;
+       ButtonPolicy policy_ {ButtonPolicy::IgnorantPolicy};
 };
 
 
index a646a898f550150f7e5ea10b1d166cd1a3e93aa8..b09163b25a438083888512067cf7b7abd1f20d4c 100644 (file)
@@ -49,10 +49,6 @@ Dialog::Dialog(GuiView & lv, QString const & name, QString const & title)
 {}
 
 
-Dialog::~Dialog()
-{}
-
-
 bool Dialog::canApply() const
 {
        FuncRequest const fr(getLfun(), fromqstr(name_));
index 260eaeb59a38c929958302477709f277797c8626..b4a3c8d4e645f6f28b9f0aeb3210b61162756c19 100644 (file)
@@ -56,7 +56,7 @@ public:
        /// \param title is the window title used for decoration.
        Dialog(GuiView & lv, QString const & name, QString const & title);
 
-       virtual ~Dialog();
+       virtual ~Dialog() {}
 
        virtual QWidget * asQWidget() = 0;
        virtual QWidget const * asQWidget() const = 0;
index dae744489962f41d2d15d43ce859f5632a07b197..b8d761bf49cd8ee47ea8b8115a707df6940b6b89 100644 (file)
@@ -123,10 +123,6 @@ void FancyLineEdit::checkButtons(const QString &text)
     }
 }
 
-FancyLineEdit::~FancyLineEdit()
-{
-}
-
 void FancyLineEdit::setButtonVisible(Side side, bool visible)
 {
     m_d->m_iconbutton[side]->setVisible(visible);
index 053ad1ce3ef841a947a827fc1c4d31c92d16aa01..c28a028a119b0d30743991735a2e3c93fd346eff 100644 (file)
@@ -69,7 +69,7 @@ Q_SIGNALS:
 
 public:
        explicit FancyLineEdit(QWidget *parent = 0);
-       ~FancyLineEdit();
+       ~FancyLineEdit() {}
 
        QPixmap buttonPixmap(Side side) const;
        void setButtonPixmap(Side side, const QPixmap &pixmap);
index 1763abdfc011910db4291d464aab541d6eb0ba33..9981f7f70b9e1911da5306ca749f108c0afb3c9e 100644 (file)
@@ -2645,8 +2645,8 @@ void GuiApplication::restoreGuiSession()
        // do not add to the lastfile list since these files are restored from
        // last session, and should be already there (regular files), or should
        // not be added at all (help files).
-       for (size_t i = 0; i < lastopened.size(); ++i) {
-               FileName const & file_name = lastopened[i].file_name;
+       for (auto const & last : lastopened) {
+               FileName const & file_name = last.file_name;
                if (!current_view_ || (!lyxrc.open_buffers_in_tabs
                          && current_view_->documentBufferView() != 0)) {
                        boost::crc_32_type crc;
@@ -2656,7 +2656,7 @@ void GuiApplication::restoreGuiSession()
                }
                current_view_->loadDocument(file_name, false);
 
-               if (lastopened[i].active)
+               if (last.active)
                        active_file = file_name;
        }
 
index 16b958b4bef855d812d55567b3cb833639a27dff..951bad86129a1522d898424b1c02e0d1bb05fe8a 100644 (file)
@@ -706,8 +706,7 @@ void GuiCitation::setPreTexts(vector<docstring> const & m)
                        selected_model_.match(selected_model_.index(0, 1),
                                             Qt::DisplayRole, toqstr(key), -1,
                                             Qt::MatchFlags(Qt::MatchExactly | Qt::MatchWrap));
-               for (int i = 0; i < qmil.size(); ++i){
-                       QModelIndex idx = qmil[i];
+               for (auto const & idx : qmil) {
                        if (!handled.contains(idx)) {
                                selected_model_.setItem(idx.row(), 0, si);
                                handled.append(idx);
@@ -745,8 +744,7 @@ void GuiCitation::setPostTexts(vector<docstring> const & m)
                        selected_model_.match(selected_model_.index(0, 1),
                                             Qt::DisplayRole, toqstr(key), -1,
                                             Qt::MatchFlags(Qt::MatchExactly | Qt::MatchWrap));
-               for (int i = 0; i < qmil.size(); ++i){
-                       QModelIndex idx = qmil[i];
+               for (auto const & idx : qmil) {
                        if (!handled.contains(idx)) {
                                selected_model_.setItem(idx.row(), 2, si);
                                handled.append(idx);
index 28e4a0a9695fc8cffb9232b786ccb181ec2bec07..d776ad5e3b17c41053f3b0eb7eff7adb393e00bb 100644 (file)
@@ -2623,10 +2623,10 @@ void GuiDocument::updateFontlist()
 
                QFontDatabase fontdb;
                QStringList families(fontdb.families());
-               for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
-                       fontModule->fontsRomanCO->addItem(*it, *it);
-                       fontModule->fontsSansCO->addItem(*it, *it);
-                       fontModule->fontsTypewriterCO->addItem(*it, *it);
+               for (auto const & family : families) {
+                       fontModule->fontsRomanCO->addItem(family, family);
+                       fontModule->fontsSansCO->addItem(family, family);
+                       fontModule->fontsTypewriterCO->addItem(family, family);
                }
                return;
        }
@@ -2754,9 +2754,9 @@ void GuiDocument::updatePagestyle(string const & items, string const & sel)
 
        int nn = 0;
 
-       for (size_t i = 0; i < pagestyles.size(); ++i)
-               if (pagestyles[i].first == sel)
-                       nn = pageLayoutModule->pagestyleCO->findText(pagestyles[i].second);
+       for (auto const & pagestyle : pagestyles)
+               if (pagestyle.first == sel)
+                       nn = pageLayoutModule->pagestyleCO->findText(pagestyle.second);
 
        if (nn > 0)
                pageLayoutModule->pagestyleCO->setCurrentIndex(nn);
index 8269c4d218523e4ae01ecbd4fb56f2d547dea9a6..f54c56bc9a95c97300db9ed5456f513623dc53f3 100644 (file)
@@ -463,10 +463,10 @@ void GuiLyXFiles::updateContents()
                        QTreeWidgetItem * subcatItem = nullptr;
                        if (cats.contains(catsave)) {
                                QList<QTreeWidgetItem *> pcats = filesLW->findItems(cat, Qt::MatchExactly);
-                               for (int iit = 0; iit < pcats.size(); ++iit) {
-                                       for (int cit = 0; cit < pcats.at(iit)->childCount(); ++cit) {
-                                               if (pcats.at(iit)->child(cit)->text(0) == subcat) {
-                                                       subcatItem = pcats.at(iit)->child(cit);
+                               for (auto const & pcat : pcats) {
+                                       for (int cit = 0; cit < pcat->childCount(); ++cit) {
+                                               if (pcat->child(cit)->text(0) == subcat) {
+                                                       subcatItem = pcat->child(cit);
                                                        break;
                                                }
                                        }
index c17110ecae7f0b49837cfbd7387830b4cf9b177f..01d7d9bf9dc403c81e1bfb2cd631126d1abaaf89 100644 (file)
@@ -923,10 +923,10 @@ PrefScreenFonts::PrefScreenFonts(GuiPreferences * form)
 
        QFontDatabase fontdb;
        QStringList families(fontdb.families());
-       for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
-               screenRomanCO->addItem(*it);
-               screenSansCO->addItem(*it);
-               screenTypewriterCO->addItem(*it);
+       for (auto const & family : families) {
+               screenRomanCO->addItem(family);
+               screenSansCO->addItem(family);
+               screenTypewriterCO->addItem(family);
        }
        connect(screenRomanCO, SIGNAL(activated(QString)),
                this, SIGNAL(changed()));
@@ -3039,9 +3039,9 @@ QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
        if (tag == KeyMap::UserUnbind) {
                QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
                        Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
-               for (int i = 0; i < items.size(); ++i) {
-                       if (items[i]->text(1) == shortcut) {
-                               newItem = items[i];
+               for (auto const & item : items) {
+                       if (item->text(1) == shortcut) {
+                               newItem = item;
                                break;
                        }
                }
@@ -3128,8 +3128,7 @@ void PrefShortcuts::unhideEmpty(QString const & lfun, bool select)
        // list of items that match lfun
        QList<QTreeWidgetItem*> items = shortcutsTW->findItems(lfun,
             Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
-       for (int i = 0; i < items.size(); ++i) {
-               QTreeWidgetItem * item = items[i];
+       for (auto const & item : items) {
                if (isAlwaysHidden(*item)) {
                        setItemType(item, KeyMap::System);
                        if (select)
@@ -3145,24 +3144,24 @@ void PrefShortcuts::removeShortcut()
        // it seems that only one item can be selected, but I am
        // removing all selected items anyway.
        QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
-       for (int i = 0; i < items.size(); ++i) {
-               string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
-               string lfun = fromqstr(items[i]->text(0));
+       for (auto & item : items) {
+               string shortcut = fromqstr(item->data(1, Qt::UserRole).toString());
+               string lfun = fromqstr(item->text(0));
                FuncRequest func = lyxaction.lookupFunc(lfun);
 
-               switch (itemType(*items[i])) {
+               switch (itemType(*item)) {
                case KeyMap::System: {
                        // for system bind, we do not touch the item
                        // but add an user unbind item
                        user_unbind_.bind(shortcut, func);
-                       setItemType(items[i], KeyMap::UserUnbind);
+                       setItemType(item, KeyMap::UserUnbind);
                        removePB->setText(qt_("Res&tore"));
                        break;
                }
                case KeyMap::UserBind: {
                        // for user_bind, we remove this bind
-                       QTreeWidgetItem * parent = items[i]->parent();
-                       int itemIdx = parent->indexOfChild(items[i]);
+                       QTreeWidgetItem * parent = item->parent();
+                       int itemIdx = parent->indexOfChild(item);
                        parent->takeChild(itemIdx);
                        if (itemIdx > 0)
                                shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
@@ -3171,7 +3170,7 @@ void PrefShortcuts::removeShortcut()
                        user_bind_.unbind(shortcut, func);
                        // If this user binding hid an empty system binding, unhide the
                        // latter and select it.
-                       unhideEmpty(items[i]->text(0), true);
+                       unhideEmpty(item->text(0), true);
                        break;
                }
                case KeyMap::UserUnbind: {
@@ -3183,15 +3182,15 @@ void PrefShortcuts::removeShortcut()
                        if (!validateNewShortcut(func, seq, QString()))
                                break;
                        user_unbind_.unbind(shortcut, func);
-                       setItemType(items[i], KeyMap::System);
+                       setItemType(item, KeyMap::System);
                        removePB->setText(qt_("Remo&ve"));
                        break;
                }
                case KeyMap::UserExtraUnbind: {
                        // for user unbind that is not in system bind file,
                        // remove this unbind file
-                       QTreeWidgetItem * parent = items[i]->parent();
-                       parent->takeChild(parent->indexOfChild(items[i]));
+                       QTreeWidgetItem * parent = item->parent();
+                       parent->takeChild(parent->indexOfChild(item));
                        user_unbind_.unbind(shortcut, func);
                }
                }
@@ -3201,26 +3200,26 @@ void PrefShortcuts::removeShortcut()
 
 void PrefShortcuts::deactivateShortcuts(QList<QTreeWidgetItem*> const & items)
 {
-       for (int i = 0; i < items.size(); ++i) {
-               string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
-               string lfun = fromqstr(items[i]->text(0));
+       for (auto item : items) {
+               string shortcut = fromqstr(item->data(1, Qt::UserRole).toString());
+               string lfun = fromqstr(item->text(0));
                FuncRequest func = lyxaction.lookupFunc(lfun);
 
-               switch (itemType(*items[i])) {
+               switch (itemType(*item)) {
                case KeyMap::System:
                        // for system bind, we do not touch the item
                        // but add an user unbind item
                        user_unbind_.bind(shortcut, func);
-                       setItemType(items[i], KeyMap::UserUnbind);
+                       setItemType(item, KeyMap::UserUnbind);
                        break;
 
                case KeyMap::UserBind: {
                        // for user_bind, we remove this bind
-                       QTreeWidgetItem * parent = items[i]->parent();
-                       int itemIdx = parent->indexOfChild(items[i]);
+                       QTreeWidgetItem * parent = item->parent();
+                       int itemIdx = parent->indexOfChild(item);
                        parent->takeChild(itemIdx);
                        user_bind_.unbind(shortcut, func);
-                       unhideEmpty(items[i]->text(0), false);
+                       unhideEmpty(item->text(0), false);
                        break;
                }
                default:
@@ -3287,11 +3286,11 @@ void PrefShortcuts::on_searchLE_textEdited()
        while (*it)
                (*it++)->setHidden(true);
        // show matched items
-       for (int i = 0; i < matched.size(); ++i)
-               if (!isAlwaysHidden(*matched[i])) {
-                       matched[i]->setHidden(false);
-                       if (matched[i]->parent())
-                               matched[i]->parent()->setExpanded(true);
+       for (auto & item : matched)
+               if (!isAlwaysHidden(*item)) {
+                       item->setHidden(false);
+                       if (item->parent())
+                               item->parent()->setExpanded(true);
                }
 }
 
index 5c8c603daf660a939b63bb621c13a17c4d9d0388..fbfa967c06f04c274788d67967fe3ce48c3db7f3 100644 (file)
@@ -276,8 +276,8 @@ void StaticMenuButton::updateTriggered()
 
        bool enabled = false;
        QList<QAction *> acts = menu()->actions();
-       for (int i = 0; i < acts.size(); ++i)
-               if (acts[i]->isEnabled()) {
+       for (auto const & act : acts)
+               if (act->isEnabled()) {
                        enabled = true;
                        break;
                }
@@ -561,8 +561,8 @@ void GuiToolbar::update(int context)
 
        // This is a speed bottleneck because this is called on every keypress
        // and update calls getStatus, which copies the cursor at least two times
-       for (int i = 0; i < actions_.size(); ++i)
-               actions_[i]->update();
+       for (auto const & action : actions_)
+               action->update();
 
        LayoutBox * layout = owner_.getLayoutDialog();
        if (layout)
index 1abed922f987e1fff45a942700e73a022bdca188..3bccd2235ea7b35165f86f2f8dcd1a351d4815ab 100644 (file)
@@ -204,9 +204,9 @@ docstring InsetParamsDialog::checkWidgets(bool immediate)
        immediateApplyCB->setEnabled(ins && !read_only);
        // This seems to be the only way to access custom buttons
        QList<QAbstractButton*> buttons = buttonBox->buttons();
-       for (int i = 0; i < buttons.size(); ++i) {
-               if (buttonBox->buttonRole(buttons.at(i)) == QDialogButtonBox::ActionRole)
-                       buttons.at(i)->setEnabled(widget_ok && !read_only
+       for (auto & button : buttons) {
+               if (buttonBox->buttonRole(button) == QDialogButtonBox::ActionRole)
+                       button->setEnabled(widget_ok && !read_only
                                                  && valid_argument
                                                  && newInsetAllowed());
        }
index 8d0529a919830140de57271a63a47370f557d39a..5098994d62e4e66f1294f24a41e906c190f82ef5 100644 (file)
@@ -712,8 +712,8 @@ void MenuDefinition::read(Lexer & lex)
 
 bool MenuDefinition::hasFunc(FuncRequest const & func) const
 {
-       for (const_iterator it = begin(), et = end(); it != et; ++it)
-               if (*it->func() == func)
+       for (auto const & it : *this)
+               if (*it.func() == func)
                        return true;
        return false;
 }
index 727ab5d484d5943e8ff4ec352f56084512ea989c..69671c222bbe96f966f5a2968d38f015cd17880b 100644 (file)
@@ -501,8 +501,7 @@ docstring InsetCommandParams::prepareCommand(OutputParams const & runparams,
                // we can only output characters covered by the current
                // encoding!
                docstring uncodable;
-               for (size_type i = 0 ; i < command.size() ; ++i) {
-                       char_type c = command[i];
+               for (char_type c : command) {
                        try {
                                if (runparams.encoding->encodable(c))
                                        result += c;
index b20e9a71b9c41780f75ed85cef2950d618b7a721..ff4ac6e5506a93076fd8d6bd54ca0c12e78253c1 100644 (file)
@@ -883,8 +883,7 @@ void InsetGraphics::latex(otexstream & os,
        // encoding!
        docstring uncodable;
        docstring encodable_file_path;
-       for (size_type i = 0 ; i < file_path.size() ; ++i) {
-               char_type c = file_path[i];
+       for (char_type c : file_path) {
                try {
                        if (runparams.encoding->encodable(c))
                                encodable_file_path += c;
index 4edf0eb1e08daae05ce7f0c7bfa5a86ede70de80..b96d7c9d898c437902ff57cee4c1cb1123a25e1b 100644 (file)
@@ -819,8 +819,7 @@ void InsetInfo::updateBuffer(ParIterator const & it, UpdateType utype, bool cons
                string const lcode = params_.lang->code();
                docstring trans;
                bool is_translated = sequence != seq_untranslated;
-               for (size_t n = 0; n < sequence.size(); ++n) {
-                       char_type const c = sequence[n];
+               for (char_type const c : sequence) {
                        switch(c) {
                        case 0x21b5://Return
                                gui = _("Return[[Key]]");
index 9c87a58c77cab75a2ebb39fe50af904331ffac8d..54707418dfa54a9091d1492b31a10de22543eaf1 100644 (file)
@@ -232,8 +232,8 @@ docstring ListingsParam::validate(string const & par) const
                                return bformat(_("Please specify one or more of '%1$s'."),
                                                           from_utf8(info_));
                }
-               for (size_t i = 0; i < par2.size(); ++i)
-                       if (info_.find(par2[i], 0) == string::npos)
+               for (char c : par2)
+                       if (info_.find(c, 0) == string::npos)
                                return bformat(_("Should be composed of one or more of %1$s."),
                                                from_utf8(info_));
                if (unclosed)
@@ -1073,8 +1073,8 @@ void InsetListingsParams::addParam(string const & key,
        // non-ascii/number characters, just to be safe
        else {
                bool has_special_char = false;
-               for (size_t i = 0; i < value.size(); ++i)
-                       if (!isAlnumASCII(value[i])) {
+               for (char c : value)
+                       if (!isAlnumASCII(c)) {
                                has_special_char = true;
                                break;
                        }
index f36e02bf77af83d35c0e48dc1fe657c138b525c8..5d336b0abcbee57267febc0e2aad8f4634a17dde 100644 (file)
@@ -1283,8 +1283,8 @@ static void buildaccent(string n, string param, string values)
   const char delim = '|';
   while (getline(s, name, delim)) {
     size_t start = 0;
-    for (size_t i = 0; i < param.size(); i++) {
-      string key = name + "{" + param[i] + "}";
+    for (char c : param) {
+      string key = name + "{" + c + "}";
       // get the corresponding utf8-value
       if ((values[start] & 0xc0) != 0xc0) {
         // should not happen, utf8 encoding starts at least with 11xxxxxx
index 3de72abcb194cd9dedb022fc108871d345a0977a..fef88a99439a10fcd18b03633b004a63945225f0 100644 (file)
@@ -281,9 +281,9 @@ void InsetMathGrid::setHorizontalAlignments(docstring const & hh)
 InsetMathGrid::col_type InsetMathGrid::guessColumns(docstring const & hh)
 {
        col_type col = 0;
-       for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it)
-               if (*it == 'c' || *it == 'l' || *it == 'r'||
-                   *it == 'p' || *it == 'm' || *it == 'b')
+       for (char_type const c : hh)
+               if (c == 'c' || c == 'l' || c == 'r'||
+                   c == 'p' || c == 'm' || c == 'b')
                        ++col;
        // let's have at least one column, even if we did not recognize its
        // alignment
index 156cbec2fd2dd7ad087d86dfcce37f9e0b1d7d86..ebf8843d7939a07191a902dcb5523c7df4e23b26 100644 (file)
@@ -228,8 +228,8 @@ InsetMathHull::InsetMathHull(InsetMathHull const & other) : InsetMathGrid(other)
 
 InsetMathHull::~InsetMathHull()
 {
-       for (size_t i = 0; i < label_.size(); ++i)
-               delete label_[i];
+       for (auto & i : label_)
+               delete i;
 }
 
 
@@ -248,8 +248,8 @@ InsetMathHull & InsetMathHull::operator=(InsetMathHull const & other)
        numbered_ = other.numbered_;
        numbers_ = other.numbers_;
        buffer_ = other.buffer_;
-       for (size_t i = 0; i < label_.size(); ++i)
-               delete label_[i];
+       for (auto & i : label_)
+               delete i;
        label_ = other.label_;
        for (size_t i = 0; i != label_.size(); ++i) {
                if (label_[i])
@@ -995,8 +995,8 @@ bool InsetMathHull::ams() const
        case hullEqnArray:
                break;
        }
-       for (size_t row = 0; row < numbered_.size(); ++row)
-               if (numbered_[row] == NOTAG)
+       for (auto const & row : numbered_)
+               if (row == NOTAG)
                        return true;
        return false;
 }
index 862ee8a4d78384e3c4a00424d06b7f99c38c7fd7..57294c075354d889ad4513b406b4fd9ebe22d717 100644 (file)
@@ -859,10 +859,10 @@ bool InsetMathMacro::validName() const
 
        // valid characters?
        if (n.size() > 1) {
-               for (size_t i = 0; i<n.size(); ++i) {
-                       if (!(n[i] >= 'a' && n[i] <= 'z')
-                           && !(n[i] >= 'A' && n[i] <= 'Z')
-                           && n[i] != '*')
+               for (char_type c : n) {
+                       if (!(c >= 'a' && c <= 'z')
+                           && !(c >= 'A' && c <= 'Z')
+                           && c != '*')
                                return false;
                }
        }
index e48d169ce0249f6bead756b16b7cdb202e216ce7..a152222cb6ce1a4232ccc494903e5b86fe1dea37 100644 (file)
@@ -1293,10 +1293,10 @@ bool InsetMathMacroTemplate::validName() const
 
        // valid characters?
        if (n.size() > 1) {
-               for (size_t i = 0; i < n.size(); ++i) {
-                       if (!(n[i] >= 'a' && n[i] <= 'z')
-                           && !(n[i] >= 'A' && n[i] <= 'Z')
-                           && n[i] != '*')
+               for (char_type c : n) {
+                       if (!(c >= 'a' && c <= 'z')
+                           && !(c >= 'A' && c <= 'Z')
+                           && c != '*')
                                return false;
                }
        }
index a128520067315c65aefb417c935f9014ab346db5..868321b086d5419eedd3891b6bac6ac2323adfa3 100644 (file)
@@ -372,9 +372,9 @@ void MathData::drawT(TextPainter & pain, int x, int y) const
        // FIXME: Abdel 16/10/2006
        // This drawT() method is never used, this is dead code.
 
-       for (const_iterator it = begin(), et = end(); it != et; ++it) {
-               (*it)->drawT(pain, x, y);
-               //x += (*it)->width_;
+       for (auto const & it : *this) {
+               it->drawT(pain, x, y);
+               //x += it->width_;
                x += 2;
        }
 }
index 32d7ef642468cdfb3c82b1e0052d115a13504518..89c742aed9024756b39bd54ea712123710531bbc 100644 (file)
@@ -1962,8 +1962,8 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                                cmd = Encodings::fromLaTeXCommand(cmd,
                                        Encodings::MATH_CMD | Encodings::TEXT_CMD,
                                        termination, rem);
-                               for (size_t i = 0; i < cmd.size(); ++i)
-                                       cell->push_back(MathAtom(new InsetMathChar(cmd[i])));
+                               for (char_type c : cmd)
+                                       cell->push_back(MathAtom(new InsetMathChar(c)));
                                if (!rem.empty()) {
                                        char_type c = rem[0];
                                        cell->push_back(MathAtom(new InsetMathChar(c)));
index f5278b15d031cc5ca1fe8d3f1f1b9cd667dab7fa..4f276856e58c8b008c9bb734962ecb62753d166b 100644 (file)
@@ -577,11 +577,9 @@ void mathed_string_dim(FontInfo const & font,
        frontend::FontMetrics const & fm = theFontMetrics(font);
        dim.asc = 0;
        dim.des = 0;
-       for (docstring::const_iterator it = s.begin();
-            it != s.end();
-            ++it) {
-               dim.asc = max(dim.asc, fm.ascent(*it));
-               dim.des = max(dim.des, fm.descent(*it));
+       for (char_type const c : s) {
+               dim.asc = max(dim.asc, fm.ascent(c));
+               dim.des = max(dim.des, fm.descent(c));
        }
        dim.wid = fm.width(s);
 }
index df356ba9937fa1fcbd93394f482b98d39fbaf356..ad19d7f35da9ba00d6a7c9ef4e0023f42b641df4 100644 (file)
@@ -1197,8 +1197,7 @@ docstring const escape(docstring const & lab)
        char_type hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
                                   '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
        docstring enc;
-       for (size_t i = 0; i < lab.length(); ++i) {
-               char_type c = lab[i];
+       for (char_type const c : lab) {
                if (c >= 128 || c == '=' || c == '%' || c == '#' || c == '$'
                    || c == '}' || c == '{' || c == ']' || c == '[' || c == '&'
                    || c == '\\') {
index 8c47b7a44191a0f74156b71a34eb909c4b156b38..d34e455640d012c13d660c6e67f0bd4374b384d3 100644 (file)
@@ -72,8 +72,7 @@ std::string fromqstr(QString const & str)
 QString charFilterRegExp(QString const & filter)
 {
        QString re = ".*";
-       for (int i = 0; i < filter.length(); ++i) {
-               QChar c = filter[i];
+       for (QChar const & c : filter) {
                if (c.isLower())
                        re +=  "["+ QRegExp::escape(c) + QRegExp::escape(c.toUpper()) + "]";
                else
@@ -85,8 +84,7 @@ QString charFilterRegExp(QString const & filter)
 QString charFilterRegExpC(QString const & filter)
 {
        QString re = "(";
-       for (int i = 0; i < filter.length(); ++i) {
-               QChar c = filter[i];
+       for (QChar const & c : filter) {
                if (c.isLower())
                        re +=  "["+ QRegExp::escape(c) + QRegExp::escape(c.toUpper()) + "]";
                else
index bd7225db0f25dcf20414cf2dd9bf7095498ea213..c9f910f70978f32a3a6d353821433147f8a0ef8b 100644 (file)
@@ -589,8 +589,8 @@ void fix_colalign(vector<ColInfo> & colinfo)
        }
        // Move the lines and alignment settings to the special field if
        // necessary
-       for (size_t col = 0; col < colinfo.size(); ++col)
-               fix_colalign(colinfo[col]);
+       for (auto & col : colinfo)
+               fix_colalign(col);
 }
 
 
@@ -921,16 +921,16 @@ void parse_table(Parser & p, ostream & os, bool is_long_tabular,
 void handle_hline_above(RowInfo & ri, vector<CellInfo> & ci)
 {
        ri.topline = true;
-       for (size_t col = 0; col < ci.size(); ++col)
-               ci[col].topline = true;
+       for (auto & col : ci)
+               col.topline = true;
 }
 
 
 void handle_hline_below(RowInfo & ri, vector<CellInfo> & ci)
 {
        ri.bottomline = true;
-       for (size_t col = 0; col < ci.size(); ++col)
-               ci[col].bottomline = true;
+       for (auto & col : ci)
+               col.bottomline = true;
 }
 
 
@@ -1516,8 +1516,8 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
        //cerr << "// output what we have\n";
        // output what we have
        size_type cols = colinfo.size();
-       for (size_t col = 0; col < colinfo.size(); ++col) {
-               if (colinfo[col].decimal_point != '\0' && colinfo[col].align != 'd')
+       for (auto const & col : colinfo) {
+               if (col.decimal_point != '\0' && col.align != 'd')
                        --cols;
        }
        os << "\n<lyxtabular version=\"3\" rows=\"" << rowinfo.size()
@@ -1545,18 +1545,18 @@ void handle_tabular(Parser & p, ostream & os, string const & name,
        os << write_attribute("tabularwidth", tabularwidth) << ">\n";
 
        //cerr << "// after header\n";
-       for (size_t col = 0; col < colinfo.size(); ++col) {
-               if (colinfo[col].decimal_point != '\0' && colinfo[col].align != 'd')
+       for (auto const & col : colinfo) {
+               if (col.decimal_point != '\0' && col.align != 'd')
                        continue;
                os << "<column alignment=\""
-                          << verbose_align(colinfo[col].align) << "\"";
-               if (colinfo[col].decimal_point != '\0')
-                       os << " decimal_point=\"" << colinfo[col].decimal_point << "\"";
+                          << verbose_align(col.align) << "\"";
+               if (col.decimal_point != '\0')
+                       os << " decimal_point=\"" << col.decimal_point << "\"";
                os << " valignment=\""
-                  << verbose_valign(colinfo[col].valign) << "\""
-                  << write_attribute("width", translate_len(colinfo[col].width))
-                  << write_attribute("special", colinfo[col].special)
-                  << write_attribute("varwidth", colinfo[col].varwidth)
+                  << verbose_valign(col.valign) << "\""
+                  << write_attribute("width", translate_len(col.width))
+                  << write_attribute("special", col.special)
+                  << write_attribute("varwidth", col.varwidth)
                   << ">\n";
        }
        //cerr << "// after cols\n";
index 8197068c3a22bdbb9632122ceb196575c54bc3c4..55a64af28a94ffb63c74aa2df91bbf751d191bcc 100644 (file)
@@ -927,10 +927,10 @@ bool tex2lyx(idocstream & is, ostream & os, string const & encoding,
        // class may not be known before. It neds to be done before parsing
        // body, since otherwise the commands/environments provided by the
        // modules would be parsed as ERT.
-       for (size_t i = 0; i < preloaded_modules.size(); ++i) {
-               if (!addModule(preloaded_modules[i])) {
+       for (auto const & module : preloaded_modules) {
+               if (!addModule(module)) {
                        cerr << "Error: Could not load module \""
-                            << preloaded_modules[i] << "\"." << endl;
+                            << module << "\"." << endl;
                        return false;
                }
        }
index 208e1497c72f812ddffc0054d6dec41a9b7614bf..bfa9bcd90853e81f523565a67fa4f14e6509cd7f 100644 (file)
@@ -695,14 +695,14 @@ string convert_literate_command_inset_arg(string s)
 void output_ert(ostream & os, string const & s, Context & context)
 {
        context.check_layout(os);
-       for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) {
-               if (*it == '\\')
+       for (char const c : s) {
+               if (c == '\\')
                        os << "\n\\backslash\n";
-               else if (*it == '\n') {
+               else if (c == '\n') {
                        context.new_paragraph(os);
                        context.check_layout(os);
                } else
-                       os << *it;
+                       os << c;
        }
        context.check_end_layout(os);
 }