From 7ea6f6e8833c0fac0aab13dd45436ebbf2916cb8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Mon, 26 Jan 2004 17:00:09 +0000 Subject: [PATCH] use std::advance and std::distance instead of home-grown versions git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8372 a592a061-630c-0410-9148-cb99ea01b6c8 --- boost/ChangeLog | 4 +++ boost/libs/regex/src/Makefile.am | 2 +- po/POTFILES.in | 8 +++-- src/ChangeLog | 11 ++++-- src/PosIterator.C | 34 +++++-------------- src/PosIterator.h | 10 +++--- src/frontends/controllers/ChangeLog | 5 +++ .../controllers/ControlSpellchecker.C | 12 +++---- src/iterators.h | 8 +++-- src/lyxfind.C | 22 ++++++------ 10 files changed, 59 insertions(+), 57 deletions(-) diff --git a/boost/ChangeLog b/boost/ChangeLog index 14b47d2349..9eb0bca777 100644 --- a/boost/ChangeLog +++ b/boost/ChangeLog @@ -1,3 +1,7 @@ +2004-01-26 Lars Gullik Bjonnes + + * libs/regex/src/Makefile.am: remove trailing backslash + 2004-01-08 Lars Gullik Bjonnes * add boost::filesystem. diff --git a/boost/libs/regex/src/Makefile.am b/boost/libs/regex/src/Makefile.am index 37c388ccc4..3b58c4952e 100644 --- a/boost/libs/regex/src/Makefile.am +++ b/boost/libs/regex/src/Makefile.am @@ -19,4 +19,4 @@ libboostregex_la_SOURCES = \ # posix_api.cpp \ # wide_posix_api.cpp \ # regex_debug.cpp -# winstances.cpp \ +# winstances.cpp diff --git a/po/POTFILES.in b/po/POTFILES.in index 98c98ecb2a..491c498a97 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -27,9 +27,7 @@ src/frontends/controllers/ControlLog.C src/frontends/controllers/ControlPreamble.C src/frontends/controllers/ControlPrefs.C src/frontends/controllers/ControlPrint.C -src/frontends/controllers/ControlSearch.C src/frontends/controllers/ControlSpellchecker.C -src/frontends/controllers/ControlThesaurus.C src/frontends/controllers/biblio.C src/frontends/controllers/character.C src/frontends/controllers/frnt_lang.C @@ -141,7 +139,7 @@ src/frontends/xforms/xformsBC.h src/frontends/xforms/xforms_helpers.C src/gettext.h src/importer.C -src/insets/inset.C +src/insets/insetbase.C src/insets/insetbibtex.C src/insets/insetbox.C src/insets/insetbranch.C @@ -185,6 +183,7 @@ src/mathed/formulabase.C src/mathed/formulamacro.C src/mathed/math_hullinset.C src/mathed/math_macrotemplate.C +src/mathed/math_nestinset.C src/mathed/math_parboxinset.C src/mathed/ref_inset.C src/output.C @@ -194,6 +193,9 @@ src/output_plaintext.C src/paragraph.C src/paragraph_funcs.C src/rowpainter.C +src/support/globbing.C +src/support/path_defines.C +src/tex2lyx/lengthcommon.C src/text.C src/text2.C src/text3.C diff --git a/src/ChangeLog b/src/ChangeLog index 6a8d627ad5..6d7672c9f5 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,4 +1,11 @@ +2004-01-26 Lars Gullik Bjonnes + * lyxfind.C (replaceAll): use std::advance + + * iterators.h: inherit from std::iterator. + + * PosIterator.C (advance, distance): remove + * PosIterator.h: interit from std::iterator. 2004-01-26 André Pönitz @@ -102,7 +109,7 @@ * lyxcursor.[hC]: remove, it's CursorSlice now. - * Makefile.am: + * Makefile.am: * BufferView_pimpl.[Ch]: * bufferview_funcs.C: * cursor_slice.C: @@ -122,7 +129,7 @@ * BufferView_pimpl.C (MenuInsertLyXFile): * lyx_cb.C (WriteAs, getContentsOfAsciiFile): - * lyxfunc.C (menuNew, open, doImport): + * lyxfunc.C (menuNew, open, doImport): FileFilterList change to the FileDialog open and save functions. 2004-01-07 Lars Gullik Bjonnes diff --git a/src/PosIterator.C b/src/PosIterator.C index d806e60dbf..28f7111f8e 100644 --- a/src/PosIterator.C +++ b/src/PosIterator.C @@ -33,7 +33,7 @@ PosIterator & PosIterator::operator++() BOOST_ASSERT(!stack_.empty()); while (true) { PosIteratorItem & p = stack_.back(); - + if (p.pos < p.pit->size()) { if (InsetBase * inset = p.pit->getInset(p.pos)) { if (LyXText * text = inset->getText(p.index)) { @@ -49,10 +49,10 @@ PosIterator & PosIterator::operator++() ++p.pit; p.pos = 0; } - + if (p.pit != p.pl->end() || stack_.size() == 1) return *this; - + stack_.pop_back(); } return *this; @@ -62,9 +62,9 @@ PosIterator & PosIterator::operator++() PosIterator & PosIterator::operator--() { BOOST_ASSERT(!stack_.empty()); - + // try to go one position backwards: if on the start of the - // ParagraphList, pops an item + // ParagraphList, pops an item PosIteratorItem & p = stack_.back(); if (p.pos > 0) { --p.pos; @@ -105,10 +105,10 @@ bool operator!=(PosIterator const & lhs, PosIterator const & rhs) bool operator==(PosIterator const & lhs, PosIterator const & rhs) { - + PosIteratorItem const & li = lhs.stack_.back(); PosIteratorItem const & ri = rhs.stack_.back(); - + return (li.pl == ri.pl && li.pit == ri.pit && (li.pit == li.pl->end() || li.pos == ri.pos)); } @@ -132,7 +132,7 @@ PosIterator::PosIterator(BufferView & bv) LyXText * text = bv.getLyXText(); lyx::pos_type pos = bv.cursor().pos(); ParagraphList::iterator pit = text->cursorPar(); - + ParIterator par = bv.buffer()->par_iterator_begin(); ParIterator end = bv.buffer()->par_iterator_end(); for ( ; par != end; ++par) { @@ -151,21 +151,3 @@ InsetBase * PosIterator::inset() const PosIteratorItem const & pi = stack_[stack_.size() - 2]; return pi.pit->getInset(pi.pos); } - - -int distance(PosIterator const & cur, PosIterator const & end) -{ - int count = 0; - for (PosIterator p = cur; p != end; ++p, ++count) - ; - return count; -} - - -void advance(PosIterator & cur, int howmuch) -{ - for (int i = 0; i < howmuch; ++i) - ++cur; - for (int i = 0; i > howmuch; --i) - --cur; -} diff --git a/src/PosIterator.h b/src/PosIterator.h index 19449c1c0b..f71e707936 100644 --- a/src/PosIterator.h +++ b/src/PosIterator.h @@ -35,7 +35,9 @@ struct PosIteratorItem { }; -class PosIterator { +class PosIterator : public std::iterator< + std::bidirectional_iterator_tag, + ParagraphList::value_type> { public: PosIterator(BufferView & bv); PosIterator(ParIterator & par, lyx::pos_type pos); @@ -52,7 +54,7 @@ public: InsetBase * inset() const; friend PosIterator ParIterator::asPosIterator(lyx::pos_type) const; friend ParIterator::ParIterator(PosIterator const &); - + private: PosIterator() {}; //this is conceptually a stack, but we need random access sometimes @@ -63,8 +65,4 @@ private: bool operator!=(PosIterator const &, PosIterator const &); bool operator==(PosIterator const &, PosIterator const &); -int distance(PosIterator const &, PosIterator const &); -void advance(PosIterator &, int); - #endif - diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 21dc9b5d0e..be5691b826 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,8 @@ +2004-01-26 Lars Gullik Bjonnes + + * ControlSpellchecker.C (check): use std::distance and + std::advance + 2004-01-25 Angus Leeming * ControlSearch.[Ch]: derive from Dialog::Controller rather than diff --git a/src/frontends/controllers/ControlSpellchecker.C b/src/frontends/controllers/ControlSpellchecker.C index 1de7fb2c30..835aa4c1e9 100644 --- a/src/frontends/controllers/ControlSpellchecker.C +++ b/src/frontends/controllers/ControlSpellchecker.C @@ -154,7 +154,7 @@ bool isLetter(PosIterator & cur) return !cur.at_end() && cur.pit()->isLetter(cur.pos()) && !isDeletedText(*cur.pit(), cur.pos()) - && (!cur.inset() || cur.inset()->allowSpellCheck()); + && (!cur.inset() || cur.inset()->allowSpellCheck()); } @@ -163,7 +163,7 @@ WordLangTuple nextWord(PosIterator & cur, PosIterator const & end, { // skip until we have real text (will jump paragraphs) for (; cur != end && !isLetter(cur); ++cur, ++progress); - + if (cur == end) return WordLangTuple(string(), string()); @@ -195,8 +195,8 @@ void ControlSpellchecker::check() PosIterator const beg = buffer()->pos_iterator_begin(); PosIterator const end = buffer()->pos_iterator_end(); - int start = distance(beg, cur); - int const total = start + distance(cur, end); + int start = std::distance(beg, cur); + int const total = start + std::distance(cur, end); if (cur != buffer()->pos_iterator_begin()) for (; cur != end && isLetter(cur); ++cur, ++start); @@ -235,9 +235,9 @@ void ControlSpellchecker::check() if (!word_.word().empty()) { int const size = word_.word().size(); - advance(cur, -size); + std::advance(cur, -size); bufferview()->putSelectionAt(cur, size, false); - advance(cur, size); + std::advance(cur, size); } else { showSummary(); endSession(); diff --git a/src/iterators.h b/src/iterators.h index 22dec98f17..7dc35fea57 100644 --- a/src/iterators.h +++ b/src/iterators.h @@ -25,7 +25,9 @@ class BufferView; class PosIterator; -class ParIterator { +class ParIterator : public std::iterator< + std::forward_iterator_tag, + ParagraphList::value_type> { public: /// ParIterator(ParagraphList::iterator pit, ParagraphList const & pl); @@ -77,7 +79,9 @@ bool operator==(ParIterator const & iter1, ParIterator const & iter2); bool operator!=(ParIterator const & iter1, ParIterator const & iter2); -class ParConstIterator { +class ParConstIterator : public std::iterator< + std::forward_iterator_tag, + ParagraphList::value_type> { public: /// ParConstIterator(ParagraphList::iterator pit, ParagraphList const & pl); diff --git a/src/lyxfind.C b/src/lyxfind.C index c17cb34495..043a45d753 100644 --- a/src/lyxfind.C +++ b/src/lyxfind.C @@ -78,7 +78,7 @@ namespace lyx { namespace find { string const find2string(string const & search, - bool casesensitive, bool matchword, bool forward) + bool casesensitive, bool matchword, bool forward) { ostringstream ss; ss << search << '\n' @@ -88,7 +88,7 @@ string const find2string(string const & search, return ss.str(); } - + string const replace2string(string const & search, string const & replace, bool casesensitive, bool matchword, @@ -155,7 +155,7 @@ void replace(BufferView * bv, FuncRequest const & ev) casesensitive, matchword) : ::replace(bv, search, replace, casesensitive, matchword, forward); - + if (replace_count == 0) { lv->message(_("String not found!")); } else { @@ -180,10 +180,10 @@ bool findNextChange(BufferView * bv) if (!findChange(cur, endit)) return false; - + ParagraphList::iterator pit = cur.pit(); pos_type pos = cur.pos(); - + Change orig_change = pit->lookupChangeFull(pos); pos_type parsize = pit->size(); pos_type end = pos; @@ -243,7 +243,7 @@ public: return true; } - + private: // search string string str; @@ -328,9 +328,9 @@ int replaceAll(BufferView * bv, if (!searchAllowed(bv, searchstr) || buf.isReadonly()) return 0; - + recordUndo(Undo::ATOMIC, bv->text(), 0, buf.paragraphs().size() - 1); - + PosIterator cur = buf.pos_iterator_begin(); PosIterator const end = buf.pos_iterator_end(); MatchString const match(searchstr, cs, mw); @@ -345,7 +345,7 @@ int replaceAll(BufferView * bv, = cur.pit()->getFontSettings(buf.params(), pos); int striked = ssize - cur.pit()->erase(pos, pos + ssize); cur.pit()->insert(pos, replacestr, font); - advance(cur, rsize + striked); + std::advance(cur, rsize + striked); ++num; } @@ -359,7 +359,7 @@ int replaceAll(BufferView * bv, bool stringSelected(BufferView * bv, - string const & searchstr, + string const & searchstr, bool cs, bool mw, bool fw) { LyXText * text = bv->getLyXText(); @@ -395,7 +395,7 @@ int replace(BufferView * bv, bv->buffer()->markDirty(); find(bv, searchstr, cs, mw, fw); bv->update(); - + return 1; } -- 2.39.2