]> git.lyx.org Git - features.git/commitdiff
Use ranges, fix warning
authorRichard Kimberly Heck <rikiheck@lyx.org>
Fri, 28 Feb 2020 06:55:05 +0000 (01:55 -0500)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:53 +0000 (15:48 +0200)
src/Cursor.cpp
src/Cursor.h
src/CursorSlice.cpp
src/CutAndPaste.cpp

index 1a3ee3b6cbd5613d9b5a9f2f11298774daead09f..41cf26ec1758fa0b1caa72d2994616f03aba556a 100644 (file)
@@ -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;
 }
 
 
index ba353b6cb8ad247d14fb52004d7d74ad6d45498b..fc4daeb93b7a7f3b0619fd4a2573e20f565a3c3a 100644 (file)
@@ -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
index c5be12f5000a6c6b6dc771036b5228609837a078..62fd92f362456fbd3810670fe22e1b0b4c5f0638 100644 (file)
@@ -37,7 +37,7 @@ namespace lyx {
 
 
 CursorSlice::CursorSlice()
-       : inset_(0), idx_(0), pit_(0), pos_(0)
+       : inset_(nullptr), idx_(0), pit_(0), pos_(0)
 {}
 
 
index 8e0a72d6dda5068d155af22cb8081521f1b8a120..0e620aab8ace717858849652b242a27c9475145d 100644 (file)
@@ -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);