]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfind.cpp
Workaround for #6865: smarter FontList::setMisspelled implementation
[lyx.git] / src / lyxfind.cpp
index a556a491732852fdd07a41f32d32359147b2660a..2ba1d2802905f43b7af323a8f92b2ee4931a424e 100644 (file)
@@ -47,7 +47,7 @@
 #include "support/lassert.h"
 #include "support/lstrings.h"
 
-#include <boost/regex.hpp>
+#include "support/regex.h"
 #include <boost/next_prior.hpp>
 
 using namespace std;
@@ -196,7 +196,6 @@ int replaceAll(BufferView * bv,
                ++num;
        }
 
-       buf.updateBuffer();
        bv->putSelectionAt(doc_iterator_begin(&buf), 0, false);
        if (num)
                buf.markDirty();
@@ -285,7 +284,7 @@ docstring const replace2string(docstring const & replace,
 
 bool find(BufferView * bv, FuncRequest const & ev)
 {
-       if (!bv || ev.action_ != LFUN_WORD_FIND)
+       if (!bv || ev.action() != LFUN_WORD_FIND)
                return false;
 
        //lyxerr << "find called, cmd: " << ev << endl;
@@ -306,7 +305,7 @@ bool find(BufferView * bv, FuncRequest const & ev)
 
 void replace(BufferView * bv, FuncRequest const & ev, bool has_deleted)
 {
-       if (!bv || ev.action_ != LFUN_WORD_REPLACE)
+       if (!bv || ev.action() != LFUN_WORD_REPLACE)
                return;
 
        // data is of the form
@@ -371,7 +370,7 @@ bool findChange(BufferView * bv, bool next)
        if (bv->cursor().selection()) {
                // set the cursor at the beginning or at the end of the selection
                // before searching. Otherwise, the current change will be found.
-               if (next != (bv->cursor().top() > bv->cursor().anchor()))
+               if (next != (bv->cursor().top() > bv->cursor().normalAnchor()))
                        bv->cursor().setCursorToAnchor();
        }
 
@@ -559,14 +558,14 @@ string escape_for_regex(string s)
        return s;
 }
 
-/// Wrapper for boost::regex_replace with simpler interface
+/// Wrapper for lyx::regex_replace with simpler interface
 bool regex_replace(string const & s, string & t, string const & searchstr,
        string const & replacestr)
 {
-       boost::regex e(searchstr);
+       lyx::regex e(searchstr);
        ostringstream oss;
        ostream_iterator<char, char> it(oss);
-       boost::regex_replace(it, s.begin(), s.end(), e, replacestr);
+       lyx::regex_replace(it, s.begin(), s.end(), e, replacestr);
        // tolerate t and s be references to the same variable
        bool rv = (s != oss.str());
        t = oss.str();
@@ -661,9 +660,9 @@ private:
        // normalized string to search
        string par_as_string;
        // regular expression to use for searching
-       boost::regex regexp;
+       lyx::regex regexp;
        // same as regexp, but prefixed with a ".*"
-       boost::regex regexp2;
+       lyx::regex regexp2;
        // unmatched open braces in the search string/regexp
        int open_braces;
        // number of (.*?) subexpressions added at end of search regexp for closing
@@ -722,9 +721,9 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const &
                LYXERR(Debug::FIND, "Close .*?  : " << close_wildcards);
                LYXERR(Debug::FIND, "Replaced text (to be used as regex): " << par_as_string);
                // If entered regexp must match at begin of searched string buffer
-               regexp = boost::regex(string("\\`") + par_as_string);
+               regexp = lyx::regex(string("\\`") + par_as_string);
                // If entered regexp may match wherever in searched string buffer
-               regexp2 = boost::regex(string("\\`.*") + par_as_string);
+               regexp2 = lyx::regex(string("\\`.*") + par_as_string);
        }
 }
 
@@ -747,11 +746,11 @@ int MatchStringAdv::findAux(DocIterator const & cur, int len, bool at_begin) con
        } else {
                // Try all possible regexp matches, 
                //until one that verifies the braces match test is found
-               boost::regex const *p_regexp = at_begin ? &regexp : &regexp2;
-               boost::sregex_iterator re_it(str.begin(), str.end(), *p_regexp);
-               boost::sregex_iterator re_it_end;
+               regex const *p_regexp = at_begin ? &regexp : &regexp2;
+               sregex_iterator re_it(str.begin(), str.end(), *p_regexp);
+               sregex_iterator re_it_end;
                for (; re_it != re_it_end; ++re_it) {
-                       boost::match_results<string::const_iterator> const & m = *re_it;
+                       match_results<string::const_iterator> const & m = *re_it;
                        // Check braces on the segment that matched the entire regexp expression,
                        // plus the last subexpression, if a (.*?) was inserted in the constructor.
                        if (! braces_match(m[0].first, m[0].second, open_braces))
@@ -983,11 +982,11 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match)
 
 
 /// Find the most backward consecutive match within same paragraph while searching backwards.
-void findMostBackwards(DocIterator & cur, MatchStringAdv const & match, int & len)
+int findMostBackwards(DocIterator & cur, MatchStringAdv const & match)
 {
        DocIterator cur_begin = doc_iterator_begin(cur.buffer());
        DocIterator tmp_cur = cur;
-       len = findAdvFinalize(tmp_cur, match);
+       int len = findAdvFinalize(tmp_cur, match);
        Inset & inset = cur.inset();
        for (; cur != cur_begin; cur.backwardPos()) {
                LYXERR(Debug::FIND, "findMostBackwards(): cur=" << cur);
@@ -1001,6 +1000,7 @@ void findMostBackwards(DocIterator & cur, MatchStringAdv const & match, int & le
                len = new_len;
        }
        LYXERR(Debug::FIND, "findMostBackwards(): exiting with cur=" << cur);
+       return len;
 }
 
 
@@ -1032,11 +1032,9 @@ int findBackwardsAdv(DocIterator & cur, MatchStringAdv & match) {
                                found_match = match(cur);
                                LYXERR(Debug::FIND, "findBackAdv3: found_match=" 
                                       << found_match << ", cur: " << cur);
-                               if (found_match) {
-                                       int len;
-                                       findMostBackwards(cur, match, len);
-                                       return len;
-                               }
+                               if (found_match)
+                                       return findMostBackwards(cur, match);
+
                                // Stop if begin of document reached
                                if (cur == cur_begin)
                                        break;
@@ -1223,7 +1221,7 @@ bool findAdv(BufferView * bv, FindAndReplaceOptions const & opt)
                else
                                match_len = findBackwardsAdv(cur, matchAdv);
        } catch (...) {
-               // This may only be raised by boost::regex()
+               // This may only be raised by lyx::regex()
                bv->message(_("Invalid regular expression!"));
                return false;
        }