From 00e5c3f3a2a76fdb1c2098f1d394b6ef3a96060e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Sun, 27 Jul 2003 12:02:58 +0000 Subject: [PATCH] get rid of namesapce lyxfind and introduce namespace lyx::find git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7379 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 6 +- src/ChangeLog | 28 +- src/frontends/controllers/ChangeLog | 11 + src/frontends/controllers/ControlChanges.C | 6 +- src/frontends/controllers/ControlSearch.C | 4 +- src/frontends/controllers/ControlThesaurus.C | 2 +- src/insets/ChangeLog | 14 +- src/insets/insettext.C | 26 +- src/lyxfind.C | 256 +++++++++---------- src/lyxfind.h | 12 +- src/lyxfunc.C | 2 +- 11 files changed, 197 insertions(+), 170 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index e7518d7629..e1ccdc8b05 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -987,7 +987,7 @@ void BufferView::Pimpl::trackChanges() #warning changes FIXME //moveCursorUpdate(false); - bool found = lyxfind::findNextChange(bv_); + bool found = lyx::find::findNextChange(bv_); if (found) { owner_->getDialogs().show("changes"); return; @@ -1322,7 +1322,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in) #warning FIXME changes //moveCursorUpdate(false); - while (lyxfind::findNextChange(bv_)) { + while (lyx::find::findNextChange(bv_)) { bv_->getLyXText()->acceptChange(); } update(BufferView::SELECT); @@ -1335,7 +1335,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in) #warning FIXME changes //moveCursorUpdate(false); - while (lyxfind::findNextChange(bv_)) { + while (lyx::find::findNextChange(bv_)) { bv_->getLyXText()->rejectChange(); } update(BufferView::SELECT); diff --git a/src/ChangeLog b/src/ChangeLog index a8ea20e2b9..11d8197f58 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2003-07-27 Lars Gullik Bjønnes + + * lyxfunc.C (dispatch): adjust for lyx::find + + * lyxfind.[hC]: get rid of namespace lyxfind introduce namespace + lyx::find instead. Reorganize a bit. + (LyXReplace): rename to replace + (LyXFind): rename to find + + * BufferView_pimpl.C (trackChanges): adjust for lyx::find + (dispatch): ditto + 2003-07-26 André Pönitz * text.C (setHeightOfRow): restrict scope of temporary variable @@ -20,20 +32,20 @@ 2003-07-27 Jean-Marc Lasgouttes - * ispell.C: + * ispell.C: * encoding.h: add includes * lyxrc.C: remove reading of bind files * lyx_main.C (init): setup bindings and menus only if we have a - gui. + gui. * kbmap.C (read): new method. Do the actual reading of bind - files. + files. - * converter.C (dvipdfm_options): - * bufferparams.C: - * lyxrc.C (read): + * converter.C (dvipdfm_options): + * bufferparams.C: + * lyxrc.C (read): (output): adapt PAPER_* enums. * lyxrc.h: include paper.h instead of bufferparams.h (mucho lighter) @@ -49,7 +61,7 @@ 2003-07-27 José Matos * tabular.[Ch] (linuxdoc): add support for tables and figures - (linuxdoc). + (linuxdoc). 2003-07-27 José Matos @@ -65,7 +77,7 @@ 2003-07.26 Alfredo Braunstein - * buffer.C (openFileWrite): factorize some code + * buffer.C (openFileWrite): factorize some code 2003-07-26 Angus Leeming diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index d118a302d2..8ad00cdb73 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,14 @@ +2003-07-27 Lars Gullik Bjønnes + + * ControlThesaurus.C (replace): adjust for lyx::find + + * ControlSearch.C (find): adjust for lyx::find + (replace): ditto + + * ControlChanges.C (find): adjust for lyx::find + (accept): ditto + (reject): ditto + 2003-07-26 Jean-Marc Lasgouttes * ControlTabular.C (useMetricUnits): adapt PAPER_* enums diff --git a/src/frontends/controllers/ControlChanges.C b/src/frontends/controllers/ControlChanges.C index 1d5053ff1d..3d3d5c2125 100644 --- a/src/frontends/controllers/ControlChanges.C +++ b/src/frontends/controllers/ControlChanges.C @@ -27,7 +27,7 @@ ControlChanges::ControlChanges(Dialog & parent) bool ControlChanges::find() { - return lyxfind::findNextChange(kernel().bufferview()); + return lyx::find::findNextChange(kernel().bufferview()); } @@ -65,12 +65,12 @@ string const ControlChanges::getChangeAuthor() void ControlChanges::accept() { kernel().dispatch(FuncRequest(LFUN_ACCEPT_CHANGE)); - lyxfind::findNextChange(kernel().bufferview()); + lyx::find::findNextChange(kernel().bufferview()); } void ControlChanges::reject() { kernel().dispatch(FuncRequest(LFUN_REJECT_CHANGE)); - lyxfind::findNextChange(kernel().bufferview()); + lyx::find::findNextChange(kernel().bufferview()); } diff --git a/src/frontends/controllers/ControlSearch.C b/src/frontends/controllers/ControlSearch.C index a918eb1b1e..d432c3ef55 100644 --- a/src/frontends/controllers/ControlSearch.C +++ b/src/frontends/controllers/ControlSearch.C @@ -28,7 +28,7 @@ ControlSearch::ControlSearch(LyXView & lv, Dialogs & d) void ControlSearch::find(string const & search, bool casesensitive, bool matchword, bool forward) { - bool const found = lyxfind::LyXFind(bufferview(), search, + bool const found = lyx::find::find(bufferview(), search, forward, casesensitive, matchword); @@ -45,7 +45,7 @@ void ControlSearch::replace(string const & search, string const & replace, // changed bool const once = !all; int const replace_count = - lyxfind::LyXReplace(bufferview(), + lyx::find::replace(bufferview(), search, replace, true, casesensitive, matchword, all, once); diff --git a/src/frontends/controllers/ControlThesaurus.C b/src/frontends/controllers/ControlThesaurus.C index 457931c5ad..d578318b1e 100644 --- a/src/frontends/controllers/ControlThesaurus.C +++ b/src/frontends/controllers/ControlThesaurus.C @@ -43,7 +43,7 @@ void ControlThesaurus::replace(string const & newstr) * deletion/change ! */ int const replace_count = - lyxfind::LyXReplace(kernel().bufferview(), oldstr_, newstr, + lyx::find::replace(kernel().bufferview(), oldstr_, newstr, true, true, true, false, true); oldstr_ = newstr; diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 65895918e4..83b2aa170b 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,9 +1,15 @@ +2003-07-27 Lars Gullik Bjønnes + + * insettext.C (nextChange): adjust for lyx::find + (searchForward): ditto + (searchBackward): ditto + 2003-07-26 Jean-Marc Lasgouttes - * insetgraphicsParams.C: + * insetgraphicsParams.C: * insetexternal.C: declare extern displayTranslator - - * insetexternal.C: + + * insetexternal.C: * renderers.C: add #include "support/LAssert.h" 2003-07-27 José Matos @@ -12,7 +18,7 @@ * insetgraphics.C (linuxdoc): * insettabular.C (linuxdoc): * insettext.[Ch] (linuxdoc): add support for tables and figures - (linuxdoc). + (linuxdoc). 2003-07-27 José Matos diff --git a/src/insets/insettext.C b/src/insets/insettext.C index deff133a0b..b6055329ad 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -1319,7 +1319,7 @@ int InsetText::linuxdoc(Buffer const * buf, ostream & os) const // There is a confusion between the empty paragraph and the default paragraph // The default paragraph is

, the empty paragraph is *empty* - // Since none of the floats of linuxdoc accepts standard paragraphs + // Since none of the floats of linuxdoc accepts standard paragraphs // I disable them. I don't expect problems. (jamatos 2003/07/27) for (; pit != pend; ++pit) { const string name = pit->layout()->latexname(); @@ -2183,10 +2183,10 @@ bool InsetText::nextChange(BufferView * bv, lyx::pos_type & length) return true; text_.cursorRight(true); } - lyxfind::SearchResult result = - lyxfind::findNextChange(bv, &text_, length); + lyx::find::SearchResult result = + lyx::find::findNextChange(bv, &text_, length); - if (result == lyxfind::SR_FOUND) { + if (result == lyx::find::SR_FOUND) { LyXCursor cur = text_.cursor; bv->unlockInset(bv->theLockingInset()); if (bv->lockInset(this)) @@ -2195,7 +2195,7 @@ bool InsetText::nextChange(BufferView * bv, lyx::pos_type & length) text_.setSelectionRange(length); updateLocal(bv, SELECTION, false); } - return result != lyxfind::SR_NOT_FOUND; + return result != lyx::find::SR_NOT_FOUND; } @@ -2207,10 +2207,10 @@ bool InsetText::searchForward(BufferView * bv, string const & str, return true; text_.cursorRight(true); } - lyxfind::SearchResult result = - lyxfind::LyXFind(bv, &text_, str, true, cs, mw); + lyx::find::SearchResult result = + lyx::find::find(bv, &text_, str, true, cs, mw); - if (result == lyxfind::SR_FOUND) { + if (result == lyx::find::SR_FOUND) { LyXCursor cur = text_.cursor; bv->unlockInset(bv->theLockingInset()); if (bv->lockInset(this)) @@ -2219,7 +2219,7 @@ bool InsetText::searchForward(BufferView * bv, string const & str, text_.setSelectionRange(str.length()); updateLocal(bv, SELECTION, false); } - return (result != lyxfind::SR_NOT_FOUND); + return (result != lyx::find::SR_NOT_FOUND); } bool InsetText::searchBackward(BufferView * bv, string const & str, @@ -2238,10 +2238,10 @@ bool InsetText::searchBackward(BufferView * bv, string const & str, text_.setCursor(pit, pit->size()); } - lyxfind::SearchResult result = - lyxfind::LyXFind(bv, &text_, str, false, cs, mw); + lyx::find::SearchResult result = + lyx::find::find(bv, &text_, str, false, cs, mw); - if (result == lyxfind::SR_FOUND) { + if (result == lyx::find::SR_FOUND) { LyXCursor cur = text_.cursor; bv->unlockInset(bv->theLockingInset()); if (bv->lockInset(this)) @@ -2250,7 +2250,7 @@ bool InsetText::searchBackward(BufferView * bv, string const & str, text_.setSelectionRange(str.length()); updateLocal(bv, SELECTION, false); } - return (result != lyxfind::SR_NOT_FOUND); + return (result != lyx::find::SR_NOT_FOUND); } diff --git a/src/lyxfind.C b/src/lyxfind.C index a28129f97e..6468e77363 100644 --- a/src/lyxfind.C +++ b/src/lyxfind.C @@ -19,21 +19,125 @@ using namespace lyx::support; using lyx::pos_type; using std::endl; -namespace lyxfind { +namespace lyx { +namespace find { -/// returns true if the specified string is at the specified position -bool IsStringInText(Paragraph * par, pos_type pos, - string const & str, bool const & = true, - bool const & = false); +namespace { -/// if the string is found: return true and set the cursor to the new position -SearchResult SearchForward(BufferView *, LyXText * text, string const & str, - bool const & = true, bool const & = false); -/// -SearchResult SearchBackward(BufferView *, LyXText * text, string const & str, - bool const & = true, bool const & = false); +// returns true if the specified string is at the specified position +bool isStringInText(Paragraph const & par, pos_type pos, + string const & str, bool const & cs, + bool const & mw) +{ + string::size_type size = str.length(); + pos_type i = 0; + pos_type parsize = par.size(); + while (((pos + i) < parsize) + && (string::size_type(i) < size) + && (cs ? (str[i] == par.getChar(pos + i)) + : (uppercase(str[i]) == uppercase(par.getChar(pos + i))))) { + ++i; + } -int LyXReplace(BufferView * bv, + if (size == string::size_type(i)) { + // if necessary, check whether string matches word + if (!mw) + return true; + if ((pos <= 0 || !IsLetterCharOrDigit(par.getChar(pos - 1))) + && (pos + pos_type(size) >= parsize + || !IsLetterCharOrDigit(par.getChar(pos + size)))) { + return true; + } + } + return false; +} + +// forward search: +// if the string can be found: return true and set the cursor to +// the new position, cs = casesensitive, mw = matchword +SearchResult searchForward(BufferView * bv, LyXText * text, string const & str, + bool const & cs, bool const & mw) +{ + ParagraphList::iterator pit = text->cursor.par(); + ParagraphList::iterator pend = text->ownerParagraphs().end(); + pos_type pos = text->cursor.pos(); + UpdatableInset * inset; + + while (pit != pend && !isStringInText(*pit, pos, str, cs, mw)) { + if (pos < pit->size() + && pit->isInset(pos) + && (inset = (UpdatableInset *)pit->getInset(pos)) + && inset->isTextInset() + && inset->searchForward(bv, str, cs, mw)) + return SR_FOUND_NOUPDATE; + + if (++pos >= pit->size()) { + ++pit; + pos = 0; + } + } + + if (pit != pend) { + text->setCursor(pit, pos); + return SR_FOUND; + } else + return SR_NOT_FOUND; +} + + +// backward search: +// if the string can be found: return true and set the cursor to +// the new position, cs = casesensitive, mw = matchword +SearchResult searchBackward(BufferView * bv, LyXText * text, + string const & str, + bool const & cs, bool const & mw) +{ + ParagraphList::iterator pit = text->cursor.par(); + ParagraphList::iterator pbegin = text->ownerParagraphs().begin(); + pos_type pos = text->cursor.pos(); + + // skip past a match at the current cursor pos + if (pos > 0) { + --pos; + } else if (pit != pbegin) { + --pit; + pos = pit->size(); + } else { + return SR_NOT_FOUND; + } + + while (true) { + if (pos < pit->size()) { + if (pit->isInset(pos) && pit->getInset(pos)->isTextInset()) { + UpdatableInset * inset = (UpdatableInset *)pit->getInset(pos); + if (inset->searchBackward(bv, str, cs, mw)) + return SR_FOUND_NOUPDATE; + } + + if (isStringInText(*pit, pos, str, cs, mw)) { + text->setCursor(pit, pos); + return SR_FOUND; + } + } + + if (pos == 0 && pit == pbegin) + break; + + if (pos > 0) { + --pos; + } else if (pit != pbegin) { + --pit; + pos = pit->size(); + } + } + + return SR_NOT_FOUND; +} + +} // anon namespace + + +int replace(BufferView * bv, string const & searchstr, string const & replacestr, bool forward, bool casesens, bool matchwrd, bool replaceall, bool once) @@ -79,7 +183,7 @@ int LyXReplace(BufferView * bv, str2 = lowercase(text->selectionAsString(bv->buffer(), false)); } if (str1 != str2) { - if (!LyXFind(bv, searchstr, fw, casesens, matchwrd) || + if (!find(bv, searchstr, fw, casesens, matchwrd) || !replaceall) { return 0; } @@ -102,7 +206,7 @@ int LyXReplace(BufferView * bv, ++replace_count; } if (!once) - found = LyXFind(bv, searchstr, fw, casesens, matchwrd); + found = find(bv, searchstr, fw, casesens, matchwrd); } while (!once && replaceall && found); // FIXME: should be called via an LFUN @@ -113,7 +217,7 @@ int LyXReplace(BufferView * bv, } -bool LyXFind(BufferView * bv, +bool find(BufferView * bv, string const & searchstr, bool forward, bool casesens, bool matchwrd) { @@ -150,8 +254,8 @@ bool LyXFind(BufferView * bv, text->clearSelection(); SearchResult result = forward ? - SearchForward(bv, text, searchstr, casesens, matchwrd) : - SearchBackward(bv, text, searchstr, casesens, matchwrd); + searchForward(bv, text, searchstr, casesens, matchwrd) : + searchBackward(bv, text, searchstr, casesens, matchwrd); bool found = true; // If we found the cursor inside an inset we will get back @@ -175,7 +279,7 @@ bool LyXFind(BufferView * bv, } -SearchResult LyXFind(BufferView * bv, LyXText * text, +SearchResult find(BufferView * bv, LyXText * text, string const & searchstr, bool forward, bool casesens, bool matchwrd) { @@ -187,122 +291,13 @@ SearchResult LyXFind(BufferView * bv, LyXText * text, text->clearSelection(); SearchResult result = forward ? - SearchForward(bv, text, searchstr, casesens, matchwrd) : - SearchBackward(bv, text, searchstr, casesens, matchwrd); + searchForward(bv, text, searchstr, casesens, matchwrd) : + searchBackward(bv, text, searchstr, casesens, matchwrd); return result; } -// returns true if the specified string is at the specified position -bool IsStringInText(Paragraph const & par, pos_type pos, - string const & str, bool const & cs, - bool const & mw) -{ - string::size_type size = str.length(); - pos_type i = 0; - pos_type parsize = par.size(); - while (((pos + i) < parsize) - && (string::size_type(i) < size) - && (cs ? (str[i] == par.getChar(pos + i)) - : (uppercase(str[i]) == uppercase(par.getChar(pos + i))))) { - ++i; - } - - if (size == string::size_type(i)) { - // if necessary, check whether string matches word - if (!mw) - return true; - if ((pos <= 0 || !IsLetterCharOrDigit(par.getChar(pos - 1))) - && (pos + pos_type(size) >= parsize - || !IsLetterCharOrDigit(par.getChar(pos + size)))) { - return true; - } - } - return false; -} - -// forward search: -// if the string can be found: return true and set the cursor to -// the new position, cs = casesensitive, mw = matchword -SearchResult SearchForward(BufferView * bv, LyXText * text, string const & str, - bool const & cs, bool const & mw) -{ - ParagraphList::iterator pit = text->cursor.par(); - ParagraphList::iterator pend = text->ownerParagraphs().end(); - pos_type pos = text->cursor.pos(); - UpdatableInset * inset; - - while (pit != pend && !IsStringInText(*pit, pos, str, cs, mw)) { - if (pos < pit->size() - && pit->isInset(pos) - && (inset = (UpdatableInset *)pit->getInset(pos)) - && inset->isTextInset() - && inset->searchForward(bv, str, cs, mw)) - return SR_FOUND_NOUPDATE; - - if (++pos >= pit->size()) { - ++pit; - pos = 0; - } - } - - if (pit != pend) { - text->setCursor(pit, pos); - return SR_FOUND; - } else - return SR_NOT_FOUND; -} - - -// backward search: -// if the string can be found: return true and set the cursor to -// the new position, cs = casesensitive, mw = matchword -SearchResult SearchBackward(BufferView * bv, LyXText * text, - string const & str, - bool const & cs, bool const & mw) -{ - ParagraphList::iterator pit = text->cursor.par(); - ParagraphList::iterator pbegin = text->ownerParagraphs().begin(); - pos_type pos = text->cursor.pos(); - - // skip past a match at the current cursor pos - if (pos > 0) { - --pos; - } else if (pit != pbegin) { - --pit; - pos = pit->size(); - } else { - return SR_NOT_FOUND; - } - - while (true) { - if (pos < pit->size()) { - if (pit->isInset(pos) && pit->getInset(pos)->isTextInset()) { - UpdatableInset * inset = (UpdatableInset *)pit->getInset(pos); - if (inset->searchBackward(bv, str, cs, mw)) - return SR_FOUND_NOUPDATE; - } - - if (IsStringInText(*pit, pos, str, cs, mw)) { - text->setCursor(pit, pos); - return SR_FOUND; - } - } - - if (pos == 0 && pit == pbegin) - break; - - if (pos > 0) { - --pos; - } else if (pit != pbegin) { - --pit; - pos = pit->size(); - } - } - - return SR_NOT_FOUND; -} SearchResult nextChange(BufferView * bv, LyXText * text, pos_type & length) @@ -425,4 +420,5 @@ bool findNextChange(BufferView * bv) return found; } -} // end lyxfind namespace +} // find namespace +} // lyx namespace diff --git a/src/lyxfind.h b/src/lyxfind.h index 5177e8f6cb..49782c21b7 100644 --- a/src/lyxfind.h +++ b/src/lyxfind.h @@ -8,7 +8,8 @@ class BufferView; class LyXText; -namespace lyxfind { +namespace lyx { +namespace find { enum SearchResult { // @@ -20,7 +21,7 @@ enum SearchResult { }; -int LyXReplace(BufferView * bv, +int replace(BufferView * bv, string const &, string const &, bool, bool = true, bool = false, bool = false, bool = false); @@ -30,7 +31,7 @@ int LyXReplace(BufferView * bv, * text from the actual cursor position in whatever direction * we want to go. This does also update the screen. */ -bool LyXFind(BufferView *, +bool find(BufferView *, string const & searchstr, bool forward, bool casesens = true, bool matchwrd = false); @@ -42,7 +43,7 @@ bool LyXFind(BufferView *, * returning to the calling function. */ -SearchResult LyXFind(BufferView *, LyXText * text, +SearchResult find(BufferView *, LyXText * text, string const & searchstr, bool forward, bool casesens = true, bool matchwrd = false); @@ -53,6 +54,7 @@ SearchResult findNextChange(BufferView * bv, LyXText * text, lyx::pos_type & len SearchResult nextChange(BufferView * bv, LyXText * text, lyx::pos_type & length); -} // end namespace LyXFind +} // namespace find +} // namespace lyx #endif // LYXFIND_H diff --git a/src/lyxfunc.C b/src/lyxfunc.C index c8cd67f1e9..db6362dd76 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -1033,7 +1033,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) } bool fw = (action == LFUN_WORDFINDFORWARD); if (!searched_string.empty()) { - lyxfind::LyXFind(view(), searched_string, fw); + lyx::find::find(view(), searched_string, fw); } } break;