[PATCH] Loop refactoring
Yuriy Skalko
yuriy.skalko at gmail.com
Wed Oct 7 14:31:25 UTC 2020
And the last patch based on the static analyzers output.
Yuriy
-------------- next part --------------
From 763c67bba79be0b3d08f7f86b6935bba81e25a9e Mon Sep 17 00:00:00 2001
From: Yuriy Skalko <yuriy.skalko at gmail.com>
Date: Wed, 7 Oct 2020 17:27:09 +0300
Subject: [PATCH] Loop refactoring
---
src/Author.cpp | 4 +-
src/Buffer.cpp | 6 +--
src/BufferParams.cpp | 6 +--
src/Encoding.cpp | 15 +++---
src/LaTeXFeatures.cpp | 17 ++++---
src/LaTeXFonts.cpp | 12 ++---
src/PDFOptions.cpp | 4 +-
src/Paragraph.cpp | 6 +--
src/Session.cpp | 8 ++--
src/Trans.cpp | 4 +-
src/frontends/qt/ButtonController.cpp | 20 ++++----
src/frontends/qt/Dialog.cpp | 4 --
src/frontends/qt/Dialog.h | 2 +-
src/frontends/qt/FancyLineEdit.cpp | 4 --
src/frontends/qt/FancyLineEdit.h | 2 +-
src/frontends/qt/GuiApplication.cpp | 6 +--
src/frontends/qt/GuiCitation.cpp | 6 +--
src/frontends/qt/GuiDocument.cpp | 14 +++---
src/frontends/qt/GuiLyXFiles.cpp | 8 ++--
src/frontends/qt/GuiPrefs.cpp | 65 +++++++++++++-------------
src/frontends/qt/GuiToolbar.cpp | 8 ++--
src/frontends/qt/InsetParamsDialog.cpp | 6 +--
src/frontends/qt/Menus.cpp | 4 +-
src/insets/InsetCommandParams.cpp | 3 +-
src/insets/InsetGraphics.cpp | 3 +-
src/insets/InsetInfo.cpp | 3 +-
src/insets/InsetListingsParams.cpp | 8 ++--
src/lyxfind.cpp | 4 +-
src/mathed/InsetMathGrid.cpp | 6 +--
src/mathed/InsetMathHull.cpp | 12 ++---
src/mathed/InsetMathMacro.cpp | 8 ++--
src/mathed/InsetMathMacroTemplate.cpp | 8 ++--
src/mathed/MathData.cpp | 6 +--
src/mathed/MathParser.cpp | 4 +-
src/mathed/MathSupport.cpp | 8 ++--
src/support/lstrings.cpp | 3 +-
src/support/qstring_helpers.cpp | 6 +--
src/tex2lyx/table.cpp | 34 +++++++-------
src/tex2lyx/tex2lyx.cpp | 6 +--
src/tex2lyx/text.cpp | 8 ++--
40 files changed, 166 insertions(+), 195 deletions(-)
diff --git a/src/Author.cpp b/src/Author.cpp
index 9a2dc1ea43..b4cf9fd97b 100644
--- a/src/Author.cpp
+++ b/src/Author.cpp
@@ -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);
}
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 6d25d51908..1ccb263014 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -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!");
diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index 58a02c8683..5f5a4cb231 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -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 '"
diff --git a/src/Encoding.cpp b/src/Encoding.cpp
index b24c31366f..64bb3c0b64 100644
--- a/src/Encoding.cpp
+++ b/src/Encoding.cpp
@@ -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);
diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index 3d67128f58..f9261fd4a3 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -1258,9 +1258,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 (auto & feature : simplefeatures) {
+ if (mustProvide(feature))
+ packages << "\\usepackage{" << feature << "}\n";
}
// The rest of these packages are somewhat more complicated
@@ -1420,10 +1420,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 (auto & feature : bibliofeatures) {
+ if (mustProvide(feature))
+ packages << "\\usepackage{" << feature << "}\n";
}
// Compatibility between achicago and natbib
@@ -1944,8 +1943,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;
}
diff --git a/src/LaTeXFonts.cpp b/src/LaTeXFonts.cpp
index cb68634981..16470cc2d9 100644
--- a/src/LaTeXFonts.cpp
+++ b/src/LaTeXFonts.cpp
@@ -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);
}
diff --git a/src/PDFOptions.cpp b/src/PDFOptions.cpp
index 026c22db91..1ec97fdbb5 100644
--- a/src/PDFOptions.cpp
+++ b/src/PDFOptions.cpp
@@ -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;
}
}
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index 520a9f838a..c4d7c46822 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -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 & change : changes) {
+ insertChar(pos, change.first, change.second, trackChanges);
if (!eraseChar(erasePos, trackChanges)) {
++erasePos;
++pos; // advance
diff --git a/src/Session.cpp b/src/Session.cpp
index 8fc8fa23d8..43c1b9b93e 100644
--- a/src/Session.cpp
+++ b/src/Session.cpp
@@ -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);
diff --git a/src/Trans.cpp b/src/Trans.cpp
index 2f0f317355..b33fa756ed 100644
--- a/src/Trans.cpp
+++ b/src/Trans.cpp
@@ -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;
}
}
diff --git a/src/frontends/qt/ButtonController.cpp b/src/frontends/qt/ButtonController.cpp
index 940db32d0d..e21d260a38 100644
--- a/src/frontends/qt/ButtonController.cpp
+++ b/src/frontends/qt/ButtonController.cpp
@@ -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};
};
diff --git a/src/frontends/qt/Dialog.cpp b/src/frontends/qt/Dialog.cpp
index a646a898f5..b09163b25a 100644
--- a/src/frontends/qt/Dialog.cpp
+++ b/src/frontends/qt/Dialog.cpp
@@ -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_));
diff --git a/src/frontends/qt/Dialog.h b/src/frontends/qt/Dialog.h
index 260eaeb59a..b4a3c8d4e6 100644
--- a/src/frontends/qt/Dialog.h
+++ b/src/frontends/qt/Dialog.h
@@ -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;
diff --git a/src/frontends/qt/FancyLineEdit.cpp b/src/frontends/qt/FancyLineEdit.cpp
index dae7444899..b8d761bf49 100644
--- a/src/frontends/qt/FancyLineEdit.cpp
+++ b/src/frontends/qt/FancyLineEdit.cpp
@@ -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);
diff --git a/src/frontends/qt/FancyLineEdit.h b/src/frontends/qt/FancyLineEdit.h
index 053ad1ce3e..c28a028a11 100644
--- a/src/frontends/qt/FancyLineEdit.h
+++ b/src/frontends/qt/FancyLineEdit.h
@@ -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);
diff --git a/src/frontends/qt/GuiApplication.cpp b/src/frontends/qt/GuiApplication.cpp
index 1763abdfc0..9981f7f70b 100644
--- a/src/frontends/qt/GuiApplication.cpp
+++ b/src/frontends/qt/GuiApplication.cpp
@@ -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;
}
diff --git a/src/frontends/qt/GuiCitation.cpp b/src/frontends/qt/GuiCitation.cpp
index 16b958b4be..a4853ff9e8 100644
--- a/src/frontends/qt/GuiCitation.cpp
+++ b/src/frontends/qt/GuiCitation.cpp
@@ -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 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 idx : qmil) {
if (!handled.contains(idx)) {
selected_model_.setItem(idx.row(), 2, si);
handled.append(idx);
diff --git a/src/frontends/qt/GuiDocument.cpp b/src/frontends/qt/GuiDocument.cpp
index 28e4a0a969..d776ad5e3b 100644
--- a/src/frontends/qt/GuiDocument.cpp
+++ b/src/frontends/qt/GuiDocument.cpp
@@ -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);
diff --git a/src/frontends/qt/GuiLyXFiles.cpp b/src/frontends/qt/GuiLyXFiles.cpp
index 8269c4d218..f723158141 100644
--- a/src/frontends/qt/GuiLyXFiles.cpp
+++ b/src/frontends/qt/GuiLyXFiles.cpp
@@ -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 pcat : pcats) {
+ for (int cit = 0; cit < pcat->childCount(); ++cit) {
+ if (pcat->child(cit)->text(0) == subcat) {
+ subcatItem = pcat->child(cit);
break;
}
}
diff --git a/src/frontends/qt/GuiPrefs.cpp b/src/frontends/qt/GuiPrefs.cpp
index c17110ecae..1ccadd8726 100644
--- a/src/frontends/qt/GuiPrefs.cpp
+++ b/src/frontends/qt/GuiPrefs.cpp
@@ -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 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 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);
}
}
diff --git a/src/frontends/qt/GuiToolbar.cpp b/src/frontends/qt/GuiToolbar.cpp
index 5c8c603daf..cb6c057c47 100644
--- a/src/frontends/qt/GuiToolbar.cpp
+++ b/src/frontends/qt/GuiToolbar.cpp
@@ -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 & 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 & action : actions_)
+ action->update();
LayoutBox * layout = owner_.getLayoutDialog();
if (layout)
diff --git a/src/frontends/qt/InsetParamsDialog.cpp b/src/frontends/qt/InsetParamsDialog.cpp
index 1abed922f9..7899ceee8f 100644
--- a/src/frontends/qt/InsetParamsDialog.cpp
+++ b/src/frontends/qt/InsetParamsDialog.cpp
@@ -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());
}
diff --git a/src/frontends/qt/Menus.cpp b/src/frontends/qt/Menus.cpp
index 8d0529a919..5098994d62 100644
--- a/src/frontends/qt/Menus.cpp
+++ b/src/frontends/qt/Menus.cpp
@@ -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;
}
diff --git a/src/insets/InsetCommandParams.cpp b/src/insets/InsetCommandParams.cpp
index 727ab5d484..69671c222b 100644
--- a/src/insets/InsetCommandParams.cpp
+++ b/src/insets/InsetCommandParams.cpp
@@ -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;
diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp
index b20e9a71b9..ff4ac6e550 100644
--- a/src/insets/InsetGraphics.cpp
+++ b/src/insets/InsetGraphics.cpp
@@ -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;
diff --git a/src/insets/InsetInfo.cpp b/src/insets/InsetInfo.cpp
index 4edf0eb1e0..b96d7c9d89 100644
--- a/src/insets/InsetInfo.cpp
+++ b/src/insets/InsetInfo.cpp
@@ -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]]");
diff --git a/src/insets/InsetListingsParams.cpp b/src/insets/InsetListingsParams.cpp
index 9c87a58c77..54707418df 100644
--- a/src/insets/InsetListingsParams.cpp
+++ b/src/insets/InsetListingsParams.cpp
@@ -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;
}
diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp
index f36e02bf77..5d336b0abc 100644
--- a/src/lyxfind.cpp
+++ b/src/lyxfind.cpp
@@ -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
diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp
index 3de72abcb1..fef88a9943 100644
--- a/src/mathed/InsetMathGrid.cpp
+++ b/src/mathed/InsetMathGrid.cpp
@@ -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
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index 156cbec2fd..2d6589d94c 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -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 row : numbered_)
+ if (row == NOTAG)
return true;
return false;
}
diff --git a/src/mathed/InsetMathMacro.cpp b/src/mathed/InsetMathMacro.cpp
index 862ee8a4d7..57294c0753 100644
--- a/src/mathed/InsetMathMacro.cpp
+++ b/src/mathed/InsetMathMacro.cpp
@@ -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;
}
}
diff --git a/src/mathed/InsetMathMacroTemplate.cpp b/src/mathed/InsetMathMacroTemplate.cpp
index e48d169ce0..a152222cb6 100644
--- a/src/mathed/InsetMathMacroTemplate.cpp
+++ b/src/mathed/InsetMathMacroTemplate.cpp
@@ -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;
}
}
diff --git a/src/mathed/MathData.cpp b/src/mathed/MathData.cpp
index a128520067..868321b086 100644
--- a/src/mathed/MathData.cpp
+++ b/src/mathed/MathData.cpp
@@ -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;
}
}
diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp
index 32d7ef6424..89c742aed9 100644
--- a/src/mathed/MathParser.cpp
+++ b/src/mathed/MathParser.cpp
@@ -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)));
diff --git a/src/mathed/MathSupport.cpp b/src/mathed/MathSupport.cpp
index f5278b15d0..4f276856e5 100644
--- a/src/mathed/MathSupport.cpp
+++ b/src/mathed/MathSupport.cpp
@@ -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);
}
diff --git a/src/support/lstrings.cpp b/src/support/lstrings.cpp
index df356ba993..ad19d7f35d 100644
--- a/src/support/lstrings.cpp
+++ b/src/support/lstrings.cpp
@@ -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 == '\\') {
diff --git a/src/support/qstring_helpers.cpp b/src/support/qstring_helpers.cpp
index 8c47b7a441..2f9bb15832 100644
--- a/src/support/qstring_helpers.cpp
+++ b/src/support/qstring_helpers.cpp
@@ -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 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 c : filter) {
if (c.isLower())
re += "["+ QRegExp::escape(c) + QRegExp::escape(c.toUpper()) + "]";
else
diff --git a/src/tex2lyx/table.cpp b/src/tex2lyx/table.cpp
index bd7225db0f..a790582066 100644
--- a/src/tex2lyx/table.cpp
+++ b/src/tex2lyx/table.cpp
@@ -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 & 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 & 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";
diff --git a/src/tex2lyx/tex2lyx.cpp b/src/tex2lyx/tex2lyx.cpp
index 8197068c3a..55a64af28a 100644
--- a/src/tex2lyx/tex2lyx.cpp
+++ b/src/tex2lyx/tex2lyx.cpp
@@ -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;
}
}
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index 208e1497c7..bfa9bcd908 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -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);
}
--
2.28.0.windows.1
More information about the lyx-devel
mailing list