Loop refactoring

This commit is contained in:
Yuriy Skalko 2020-10-09 09:04:20 +03:00
parent 6b86a5a395
commit 7d38a4d126
40 changed files with 166 additions and 199 deletions

View 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);
}

View 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!");

View 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 '"

View 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);

View 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;
}

View 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);
}

View 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;
}
}

View 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

View 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);

View 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;
}
}

View 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};
};

View 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_));

View 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;

View 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);

View 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);

View 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;
}

View 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);

View 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);

View 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;
}
}

View 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);
}
}

View 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)

View 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());
}

View 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;
}

View 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;

View 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;

View 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]]");

View 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;
}

View 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

View 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

View 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;
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View 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)));

View 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);
}

View 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 == '\\') {

View 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

View 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";

View 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;
}
}

View 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);
}