[LyX/master] Use ranges, fix warning
Richard Kimberly Heck
rikiheck at lyx.org
Fri Feb 28 06:33:50 UTC 2020
commit 8d26ae57ba66b4518985cf3430de2dcf37096568
Author: Richard Kimberly Heck <rikiheck at lyx.org>
Date: Fri Feb 28 01:55:05 2020 -0500
Use ranges, fix warning
---
src/Cursor.cpp | 4 +-
src/Cursor.h | 2 +-
src/CursorSlice.cpp | 2 +-
src/CutAndPaste.cpp | 52 ++++++++++++++++++--------------------------------
4 files changed, 23 insertions(+), 37 deletions(-)
diff --git a/src/Cursor.cpp b/src/Cursor.cpp
index 1a3ee3b..41cf26e 100644
--- a/src/Cursor.cpp
+++ b/src/Cursor.cpp
@@ -1839,13 +1839,13 @@ bool Cursor::inMacroMode() const
InsetMathUnknown * Cursor::activeMacro()
{
- return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
+ return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : nullptr;
}
InsetMathUnknown const * Cursor::activeMacro() const
{
- return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : 0;
+ return inMacroMode() ? prevAtom().nucleus()->asUnknownInset() : nullptr;
}
diff --git a/src/Cursor.h b/src/Cursor.h
index ba353b6..fc4daeb 100644
--- a/src/Cursor.h
+++ b/src/Cursor.h
@@ -190,7 +190,7 @@ public:
/// containing the cursor
void recordUndo(UndoKind kind = ATOMIC_UNDO) const;
/// Convenience: prepare undo for the inset containing the cursor
- void recordUndoInset(Inset const * inset = 0) const;
+ void recordUndoInset(Inset const * inset = nullptr) const;
/// Convenience: prepare undo for the whole buffer
void recordUndoFullBuffer() const;
/// Convenience: prepare undo for buffer parameters
diff --git a/src/CursorSlice.cpp b/src/CursorSlice.cpp
index c5be12f..62fd92f 100644
--- a/src/CursorSlice.cpp
+++ b/src/CursorSlice.cpp
@@ -37,7 +37,7 @@ namespace lyx {
CursorSlice::CursorSlice()
- : inset_(0), idx_(0), pit_(0), pos_(0)
+ : inset_(nullptr), idx_(0), pit_(0), pos_(0)
{}
diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp
index 8e0a72d..0e620aa 100644
--- a/src/CutAndPaste.cpp
+++ b/src/CutAndPaste.cpp
@@ -222,23 +222,19 @@ pasteSelectionHelper(DocIterator const & cur, ParagraphList const & parlist,
bool forcePlainLayout = target_inset->forcePlainLayout();
Layout const & plainLayout = newDocClass->plainLayout();
Layout const & defaultLayout = newDocClass->defaultLayout();
- ParagraphList::iterator const end = insertion.end();
- ParagraphList::iterator par = insertion.begin();
- for (; par != end; ++par) {
- Layout const & parLayout = par->layout();
+ for (auto & par : insertion) {
+ Layout const & parLayout = par.layout();
if (forcePlainLayout || parLayout == defaultLayout)
- par->setLayout(plainLayout);
+ par.setLayout(plainLayout);
}
} else {
// check if we need to reset from plain layout
Layout const & defaultLayout = newDocClass->defaultLayout();
Layout const & plainLayout = newDocClass->plainLayout();
- ParagraphList::iterator const end = insertion.end();
- ParagraphList::iterator par = insertion.begin();
- for (; par != end; ++par) {
- Layout const & parLayout = par->layout();
+ for (auto & par : insertion) {
+ Layout const & parLayout = par.layout();
if (parLayout == plainLayout)
- par->setLayout(defaultLayout);
+ par.setLayout(defaultLayout);
}
}
@@ -700,20 +696,17 @@ void copySelectionHelper(Buffer const & buf, Text const & text,
Paragraph & front = copy_pars.front();
front.eraseChars(0, start, false);
- ParagraphList::iterator it = copy_pars.begin();
- ParagraphList::iterator it_end = copy_pars.end();
-
- for (; it != it_end; ++it) {
+ for (auto & par : copy_pars) {
// Since we have a copy of the paragraphs, the insets
// do not have a proper buffer reference. It makes
// sense to add them temporarily, because the
// operations below depend on that (acceptChanges included).
- it->setInsetBuffers(const_cast<Buffer &>(buf));
+ par.setInsetBuffers(const_cast<Buffer &>(buf));
// PassThru paragraphs have the Language
// latex_language. This is invalid for others, so we
// need to change it to the buffer language.
- if (it->isPassThru())
- it->changeLanguage(buf.params(),
+ if (par.isPassThru())
+ par.changeLanguage(buf.params(),
latex_language, buf.language());
}
@@ -729,10 +722,9 @@ void copySelectionHelper(Buffer const & buf, Text const & text,
// do some final cleanup now, to make sure that the paragraphs
// are not linked to something else.
- it = copy_pars.begin();
- for (; it != it_end; ++it) {
- it->resetBuffer();
- it->setInsetOwner(nullptr);
+ for (auto & par : copy_pars) {
+ par.resetBuffer();
+ par.setInsetOwner(nullptr);
}
cutstack.push(make_pair(copy_pars, dc));
@@ -894,17 +886,13 @@ vector<docstring> availableSelections(Buffer const * buf)
if (!buf)
return selList;
- CutStack::const_iterator cit = theCuts.begin();
- CutStack::const_iterator end = theCuts.end();
- for (; cit != end; ++cit) {
+ for (auto const & cut : theCuts) {
// we do not use cit-> here because gcc 2.9x does not
// like it (JMarc)
- ParagraphList const & pars = (*cit).first;
+ ParagraphList const & pars = cut.first;
docstring textSel;
- ParagraphList::const_iterator pit = pars.begin();
- ParagraphList::const_iterator pend = pars.end();
- for (; pit != pend; ++pit) {
- Paragraph par(*pit, 0, 46);
+ for (auto const & para : pars) {
+ Paragraph par(para, 0, 46);
// adapt paragraph to current buffer.
par.setInsetBuffers(const_cast<Buffer &>(*buf));
textSel += par.asString(AS_STR_INSETS);
@@ -1376,10 +1364,8 @@ void replaceSelectionWithString(Cursor & cur, docstring const & str)
// Insert the new string
pos_type pos = cur.selEnd().pos();
Paragraph & par = cur.selEnd().paragraph();
- docstring::const_iterator cit = str.begin();
- docstring::const_iterator end = str.end();
- for (; cit != end; ++cit, ++pos)
- par.insertChar(pos, *cit, font, cur.buffer()->params().track_changes);
+ for (auto const & c : str)
+ par.insertChar(pos, c, font, cur.buffer()->params().track_changes);
// Cut the selection
cutSelection(cur, false);
More information about the lyx-cvs
mailing list