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
This commit is contained in:
Lars Gullik Bjønnes 2004-01-26 17:00:09 +00:00
parent 1eaa3eb913
commit 7ea6f6e883
10 changed files with 59 additions and 57 deletions

View File

@ -1,3 +1,7 @@
2004-01-26 Lars Gullik Bjonnes <larsbj@gullik.net>
* libs/regex/src/Makefile.am: remove trailing backslash
2004-01-08 Lars Gullik Bjonnes <larsbj@gullik.net> 2004-01-08 Lars Gullik Bjonnes <larsbj@gullik.net>
* add boost::filesystem. * add boost::filesystem.

View File

@ -19,4 +19,4 @@ libboostregex_la_SOURCES = \
# posix_api.cpp \ # posix_api.cpp \
# wide_posix_api.cpp \ # wide_posix_api.cpp \
# regex_debug.cpp # regex_debug.cpp
# winstances.cpp \ # winstances.cpp

View File

@ -27,9 +27,7 @@ src/frontends/controllers/ControlLog.C
src/frontends/controllers/ControlPreamble.C src/frontends/controllers/ControlPreamble.C
src/frontends/controllers/ControlPrefs.C src/frontends/controllers/ControlPrefs.C
src/frontends/controllers/ControlPrint.C src/frontends/controllers/ControlPrint.C
src/frontends/controllers/ControlSearch.C
src/frontends/controllers/ControlSpellchecker.C src/frontends/controllers/ControlSpellchecker.C
src/frontends/controllers/ControlThesaurus.C
src/frontends/controllers/biblio.C src/frontends/controllers/biblio.C
src/frontends/controllers/character.C src/frontends/controllers/character.C
src/frontends/controllers/frnt_lang.C src/frontends/controllers/frnt_lang.C
@ -141,7 +139,7 @@ src/frontends/xforms/xformsBC.h
src/frontends/xforms/xforms_helpers.C src/frontends/xforms/xforms_helpers.C
src/gettext.h src/gettext.h
src/importer.C src/importer.C
src/insets/inset.C src/insets/insetbase.C
src/insets/insetbibtex.C src/insets/insetbibtex.C
src/insets/insetbox.C src/insets/insetbox.C
src/insets/insetbranch.C src/insets/insetbranch.C
@ -185,6 +183,7 @@ src/mathed/formulabase.C
src/mathed/formulamacro.C src/mathed/formulamacro.C
src/mathed/math_hullinset.C src/mathed/math_hullinset.C
src/mathed/math_macrotemplate.C src/mathed/math_macrotemplate.C
src/mathed/math_nestinset.C
src/mathed/math_parboxinset.C src/mathed/math_parboxinset.C
src/mathed/ref_inset.C src/mathed/ref_inset.C
src/output.C src/output.C
@ -194,6 +193,9 @@ src/output_plaintext.C
src/paragraph.C src/paragraph.C
src/paragraph_funcs.C src/paragraph_funcs.C
src/rowpainter.C src/rowpainter.C
src/support/globbing.C
src/support/path_defines.C
src/tex2lyx/lengthcommon.C
src/text.C src/text.C
src/text2.C src/text2.C
src/text3.C src/text3.C

View File

@ -1,4 +1,11 @@
2004-01-26 Lars Gullik Bjonnes <larsbj@gullik.net>
* 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 <poenitz@gmx.net> 2004-01-26 André Pönitz <poenitz@gmx.net>
@ -102,7 +109,7 @@
* lyxcursor.[hC]: remove, it's CursorSlice now. * lyxcursor.[hC]: remove, it's CursorSlice now.
* Makefile.am: * Makefile.am:
* BufferView_pimpl.[Ch]: * BufferView_pimpl.[Ch]:
* bufferview_funcs.C: * bufferview_funcs.C:
* cursor_slice.C: * cursor_slice.C:
@ -122,7 +129,7 @@
* BufferView_pimpl.C (MenuInsertLyXFile): * BufferView_pimpl.C (MenuInsertLyXFile):
* lyx_cb.C (WriteAs, getContentsOfAsciiFile): * lyx_cb.C (WriteAs, getContentsOfAsciiFile):
* lyxfunc.C (menuNew, open, doImport): * lyxfunc.C (menuNew, open, doImport):
FileFilterList change to the FileDialog open and save functions. FileFilterList change to the FileDialog open and save functions.
2004-01-07 Lars Gullik Bjonnes <larsbj@gullik.net> 2004-01-07 Lars Gullik Bjonnes <larsbj@gullik.net>

View File

@ -33,7 +33,7 @@ PosIterator & PosIterator::operator++()
BOOST_ASSERT(!stack_.empty()); BOOST_ASSERT(!stack_.empty());
while (true) { while (true) {
PosIteratorItem & p = stack_.back(); PosIteratorItem & p = stack_.back();
if (p.pos < p.pit->size()) { if (p.pos < p.pit->size()) {
if (InsetBase * inset = p.pit->getInset(p.pos)) { if (InsetBase * inset = p.pit->getInset(p.pos)) {
if (LyXText * text = inset->getText(p.index)) { if (LyXText * text = inset->getText(p.index)) {
@ -49,10 +49,10 @@ PosIterator & PosIterator::operator++()
++p.pit; ++p.pit;
p.pos = 0; p.pos = 0;
} }
if (p.pit != p.pl->end() || stack_.size() == 1) if (p.pit != p.pl->end() || stack_.size() == 1)
return *this; return *this;
stack_.pop_back(); stack_.pop_back();
} }
return *this; return *this;
@ -62,9 +62,9 @@ PosIterator & PosIterator::operator++()
PosIterator & PosIterator::operator--() PosIterator & PosIterator::operator--()
{ {
BOOST_ASSERT(!stack_.empty()); BOOST_ASSERT(!stack_.empty());
// try to go one position backwards: if on the start of the // try to go one position backwards: if on the start of the
// ParagraphList, pops an item // ParagraphList, pops an item
PosIteratorItem & p = stack_.back(); PosIteratorItem & p = stack_.back();
if (p.pos > 0) { if (p.pos > 0) {
--p.pos; --p.pos;
@ -105,10 +105,10 @@ bool operator!=(PosIterator const & lhs, PosIterator const & rhs)
bool operator==(PosIterator const & lhs, PosIterator const & rhs) bool operator==(PosIterator const & lhs, PosIterator const & rhs)
{ {
PosIteratorItem const & li = lhs.stack_.back(); PosIteratorItem const & li = lhs.stack_.back();
PosIteratorItem const & ri = rhs.stack_.back(); PosIteratorItem const & ri = rhs.stack_.back();
return (li.pl == ri.pl && li.pit == ri.pit && return (li.pl == ri.pl && li.pit == ri.pit &&
(li.pit == li.pl->end() || li.pos == ri.pos)); (li.pit == li.pl->end() || li.pos == ri.pos));
} }
@ -132,7 +132,7 @@ PosIterator::PosIterator(BufferView & bv)
LyXText * text = bv.getLyXText(); LyXText * text = bv.getLyXText();
lyx::pos_type pos = bv.cursor().pos(); lyx::pos_type pos = bv.cursor().pos();
ParagraphList::iterator pit = text->cursorPar(); ParagraphList::iterator pit = text->cursorPar();
ParIterator par = bv.buffer()->par_iterator_begin(); ParIterator par = bv.buffer()->par_iterator_begin();
ParIterator end = bv.buffer()->par_iterator_end(); ParIterator end = bv.buffer()->par_iterator_end();
for ( ; par != end; ++par) { for ( ; par != end; ++par) {
@ -151,21 +151,3 @@ InsetBase * PosIterator::inset() const
PosIteratorItem const & pi = stack_[stack_.size() - 2]; PosIteratorItem const & pi = stack_[stack_.size() - 2];
return pi.pit->getInset(pi.pos); 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;
}

View File

@ -35,7 +35,9 @@ struct PosIteratorItem {
}; };
class PosIterator { class PosIterator : public std::iterator<
std::bidirectional_iterator_tag,
ParagraphList::value_type> {
public: public:
PosIterator(BufferView & bv); PosIterator(BufferView & bv);
PosIterator(ParIterator & par, lyx::pos_type pos); PosIterator(ParIterator & par, lyx::pos_type pos);
@ -52,7 +54,7 @@ public:
InsetBase * inset() const; InsetBase * inset() const;
friend PosIterator ParIterator::asPosIterator(lyx::pos_type) const; friend PosIterator ParIterator::asPosIterator(lyx::pos_type) const;
friend ParIterator::ParIterator(PosIterator const &); friend ParIterator::ParIterator(PosIterator const &);
private: private:
PosIterator() {}; PosIterator() {};
//this is conceptually a stack, but we need random access sometimes //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 &);
bool operator==(PosIterator const &, PosIterator const &); bool operator==(PosIterator const &, PosIterator const &);
int distance(PosIterator const &, PosIterator const &);
void advance(PosIterator &, int);
#endif #endif

View File

@ -1,3 +1,8 @@
2004-01-26 Lars Gullik Bjonnes <larsbj@gullik.net>
* ControlSpellchecker.C (check): use std::distance and
std::advance
2004-01-25 Angus Leeming <leeming@lyx.org> 2004-01-25 Angus Leeming <leeming@lyx.org>
* ControlSearch.[Ch]: derive from Dialog::Controller rather than * ControlSearch.[Ch]: derive from Dialog::Controller rather than

View File

@ -154,7 +154,7 @@ bool isLetter(PosIterator & cur)
return !cur.at_end() return !cur.at_end()
&& cur.pit()->isLetter(cur.pos()) && cur.pit()->isLetter(cur.pos())
&& !isDeletedText(*cur.pit(), 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) // skip until we have real text (will jump paragraphs)
for (; cur != end && !isLetter(cur); ++cur, ++progress); for (; cur != end && !isLetter(cur); ++cur, ++progress);
if (cur == end) if (cur == end)
return WordLangTuple(string(), string()); return WordLangTuple(string(), string());
@ -195,8 +195,8 @@ void ControlSpellchecker::check()
PosIterator const beg = buffer()->pos_iterator_begin(); PosIterator const beg = buffer()->pos_iterator_begin();
PosIterator const end = buffer()->pos_iterator_end(); PosIterator const end = buffer()->pos_iterator_end();
int start = distance(beg, cur); int start = std::distance(beg, cur);
int const total = start + distance(cur, end); int const total = start + std::distance(cur, end);
if (cur != buffer()->pos_iterator_begin()) if (cur != buffer()->pos_iterator_begin())
for (; cur != end && isLetter(cur); ++cur, ++start); for (; cur != end && isLetter(cur); ++cur, ++start);
@ -235,9 +235,9 @@ void ControlSpellchecker::check()
if (!word_.word().empty()) { if (!word_.word().empty()) {
int const size = word_.word().size(); int const size = word_.word().size();
advance(cur, -size); std::advance(cur, -size);
bufferview()->putSelectionAt(cur, size, false); bufferview()->putSelectionAt(cur, size, false);
advance(cur, size); std::advance(cur, size);
} else { } else {
showSummary(); showSummary();
endSession(); endSession();

View File

@ -25,7 +25,9 @@ class BufferView;
class PosIterator; class PosIterator;
class ParIterator { class ParIterator : public std::iterator<
std::forward_iterator_tag,
ParagraphList::value_type> {
public: public:
/// ///
ParIterator(ParagraphList::iterator pit, ParagraphList const & pl); 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); bool operator!=(ParIterator const & iter1, ParIterator const & iter2);
class ParConstIterator { class ParConstIterator : public std::iterator<
std::forward_iterator_tag,
ParagraphList::value_type> {
public: public:
/// ///
ParConstIterator(ParagraphList::iterator pit, ParagraphList const & pl); ParConstIterator(ParagraphList::iterator pit, ParagraphList const & pl);

View File

@ -78,7 +78,7 @@ namespace lyx {
namespace find { namespace find {
string const find2string(string const & search, string const find2string(string const & search,
bool casesensitive, bool matchword, bool forward) bool casesensitive, bool matchword, bool forward)
{ {
ostringstream ss; ostringstream ss;
ss << search << '\n' ss << search << '\n'
@ -88,7 +88,7 @@ string const find2string(string const & search,
return ss.str(); return ss.str();
} }
string const replace2string(string const & search, string const & replace, string const replace2string(string const & search, string const & replace,
bool casesensitive, bool matchword, bool casesensitive, bool matchword,
@ -155,7 +155,7 @@ void replace(BufferView * bv, FuncRequest const & ev)
casesensitive, matchword) : casesensitive, matchword) :
::replace(bv, search, replace, ::replace(bv, search, replace,
casesensitive, matchword, forward); casesensitive, matchword, forward);
if (replace_count == 0) { if (replace_count == 0) {
lv->message(_("String not found!")); lv->message(_("String not found!"));
} else { } else {
@ -180,10 +180,10 @@ bool findNextChange(BufferView * bv)
if (!findChange(cur, endit)) if (!findChange(cur, endit))
return false; return false;
ParagraphList::iterator pit = cur.pit(); ParagraphList::iterator pit = cur.pit();
pos_type pos = cur.pos(); pos_type pos = cur.pos();
Change orig_change = pit->lookupChangeFull(pos); Change orig_change = pit->lookupChangeFull(pos);
pos_type parsize = pit->size(); pos_type parsize = pit->size();
pos_type end = pos; pos_type end = pos;
@ -243,7 +243,7 @@ public:
return true; return true;
} }
private: private:
// search string // search string
string str; string str;
@ -328,9 +328,9 @@ int replaceAll(BufferView * bv,
if (!searchAllowed(bv, searchstr) || buf.isReadonly()) if (!searchAllowed(bv, searchstr) || buf.isReadonly())
return 0; return 0;
recordUndo(Undo::ATOMIC, bv->text(), 0, buf.paragraphs().size() - 1); recordUndo(Undo::ATOMIC, bv->text(), 0, buf.paragraphs().size() - 1);
PosIterator cur = buf.pos_iterator_begin(); PosIterator cur = buf.pos_iterator_begin();
PosIterator const end = buf.pos_iterator_end(); PosIterator const end = buf.pos_iterator_end();
MatchString const match(searchstr, cs, mw); MatchString const match(searchstr, cs, mw);
@ -345,7 +345,7 @@ int replaceAll(BufferView * bv,
= cur.pit()->getFontSettings(buf.params(), pos); = cur.pit()->getFontSettings(buf.params(), pos);
int striked = ssize - cur.pit()->erase(pos, pos + ssize); int striked = ssize - cur.pit()->erase(pos, pos + ssize);
cur.pit()->insert(pos, replacestr, font); cur.pit()->insert(pos, replacestr, font);
advance(cur, rsize + striked); std::advance(cur, rsize + striked);
++num; ++num;
} }
@ -359,7 +359,7 @@ int replaceAll(BufferView * bv,
bool stringSelected(BufferView * bv, bool stringSelected(BufferView * bv,
string const & searchstr, string const & searchstr,
bool cs, bool mw, bool fw) bool cs, bool mw, bool fw)
{ {
LyXText * text = bv->getLyXText(); LyXText * text = bv->getLyXText();
@ -395,7 +395,7 @@ int replace(BufferView * bv,
bv->buffer()->markDirty(); bv->buffer()->markDirty();
find(bv, searchstr, cs, mw, fw); find(bv, searchstr, cs, mw, fw);
bv->update(); bv->update();
return 1; return 1;
} }