]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfind.cpp
Compile fix for qt versions below 4.6.
[lyx.git] / src / lyxfind.cpp
index 1aa228b4a56c83c53634574e052b982d95c4447e..86d8b9818189f11ded597a7e93c991317e18d07c 100644 (file)
@@ -40,6 +40,7 @@
 #include "mathed/InsetMathGrid.h"
 #include "mathed/InsetMathHull.h"
 #include "mathed/MathStream.h"
+#include "mathed/MathSupport.h"
 
 #include "support/convert.h"
 #include "support/debug.h"
@@ -766,11 +767,12 @@ static docstring stringifySearchBuffer(Buffer & buffer, FindAndReplaceOptions co
 static size_t identifyLeading(string const & s)  {
        string t = s;
        // @TODO Support \item[text]
-       while (regex_replace(t, t, "\\\\(emph|textbf|subsubsection|subsection|section|subparagraph|paragraph|part)\\{", "")
+       while (regex_replace(t, t, "\\\\(emph|textbf|subsubsection|subsection|section|subparagraph|paragraph|part)\\*?\\{", "")
               || regex_replace(t, t, "^\\$", "")
               || regex_replace(t, t, "^\\\\\\[ ", "")
-              || regex_replace(t, t, "^\\\\item ", ""))
-               LYXERR(Debug::FIND, "  after removing leading $, \\[ , \\emph{, \\textbf{, etc.: " << t);
+              || regex_replace(t, t, "^\\\\item ", "")
+              || regex_replace(t, t, "^\\\\begin\\{[a-zA-Z_]*\\*?\\} ", ""))
+               LYXERR(Debug::FIND, "  after removing leading $, \\[ , \\emph{, \\textbf{, etc.: '" << t << "'");
        return s.find(t);
 }
 
@@ -789,14 +791,14 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const &
                // Remove trailing closure of math, macros and environments, so to catch parts of them.
                do {
                        LYXERR(Debug::FIND, "par_as_string now is '" << par_as_string << "'");
-                       if (regex_replace(par_as_string, par_as_string, "(.*[^\\\\]) ?\\$\\'", "$1"))
+                       if (regex_replace(par_as_string, par_as_string, "(.*[^\\\\])\\$\\'", "$1"))
                                        continue;
                        // @todo need to account for open square braces as well ?
-                       if (regex_replace(par_as_string, par_as_string, "(.*[^\\\\]) ?\\\\\\]\\'", "$1"))
+                       if (regex_replace(par_as_string, par_as_string, "(.*[^\\\\]) \\\\\\]\\'", "$1"))
                                        continue;
-                       if (regex_replace(par_as_string, par_as_string, "(.*[^\\\\]) ?\\\\end\\{[a-zA-Z_]*\\}\\'", "$1"))
+                       if (regex_replace(par_as_string, par_as_string, "(.*[^\\\\]) \\\\end\\{[a-zA-Z_]*\\*?\\}\\'", "$1"))
                                        continue;
-                       if (regex_replace(par_as_string, par_as_string, "(.*[^\\\\]) ?\\}\\'", "$1")) {
+                       if (regex_replace(par_as_string, par_as_string, "(.*[^\\\\])\\}\\'", "$1")) {
                                ++open_braces;
                                continue;
                        }
@@ -820,10 +822,10 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const &
                        // Insert .* before trailing '\$' ('$' has been escaped by escape_for_regex)
                        regex_replace(par_as_string, par_as_string, "(.*[^\\\\])(\\\\\\$)\\'", "$1(.*?)$2")
                                // Insert .* before trailing '\\\]' ('\]' has been escaped by escape_for_regex)
-                               || regex_replace(par_as_string, par_as_string, "(.*[^\\\\])(\\\\\\\\\\\\\\])\\'", "$1(.*?)$2")
+                               || regex_replace(par_as_string, par_as_string, "(.*[^\\\\])( \\\\\\\\\\\\\\])\\'", "$1(.*?)$2")
                                // Insert .* before trailing '\\end\{...}' ('\end{...}' has been escaped by escape_for_regex)
                                || regex_replace(par_as_string, par_as_string, 
-                                       "(.*[^\\\\])(\\\\\\\\end\\\\\\{[a-zA-Z_]*\\\\\\})\\'", "$1(.*?)$2")
+                                       "(.*[^\\\\])( \\\\\\\\end\\\\\\{[a-zA-Z_]*)(\\\\\\*)?(\\\\\\})\\'", "$1(.*?)$2$3$4")
                                // Insert .* before trailing '\}' ('}' has been escaped by escape_for_regex)
                                || regex_replace(par_as_string, par_as_string, "(.*[^\\\\])(\\\\\\})\\'", "$1(.*?)$2")
                ) {
@@ -965,15 +967,16 @@ docstring stringifyFromCursor(DocIterator const & cur, int len)
                                << cur << ", from pos: " << cur.pos() << ", end: " << end);
                        return par.stringify(cur.pos(), end, AS_STR_INSETS, runparams);
        } else if (cur.inMathed()) {
-                       odocstringstream os;
+                       docstring s;
                        CursorSlice cs = cur.top();
                        MathData md = cs.cell();
                        MathData::const_iterator it_end = 
                                ( ( len == -1 || cs.pos() + len > int(md.size()) )
                                        ? md.end() : md.begin() + cs.pos() + len );
                        for (MathData::const_iterator it = md.begin() + cs.pos(); it != it_end; ++it)
-                                       os << *it;
-                       return os.str();
+                               s = s + asString(*it);
+                       LYXERR(Debug::FIND, "Stringified math: '" << s << "'");
+                       return s;
        }
        LYXERR(Debug::FIND, "Don't know how to stringify from here: " << cur);
        return docstring();
@@ -1026,7 +1029,7 @@ docstring latexifyFromCursor(DocIterator const & cur, int len)
                MathData::const_iterator it_end = ( ( len == -1 || cs.pos() + len > int(md.size()) )
                        ? md.end() : md.begin() + cs.pos() + len );
                for (MathData::const_iterator it = md.begin() + cs.pos(); it != it_end; ++it)
-                               ods << *it;
+                       ods << asString(*it);
 
                // Retrieve the math environment type, and add '$' or '$]'
                // or others (\end{equation}) accordingly
@@ -1096,10 +1099,14 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match)
                return 0;
        while (cur) {
                LYXERR(Debug::FIND, "findForwardAdv() cur: " << cur);
-               if (match(cur, -1, false)) {
+               int match_len = match(cur, -1, false);
+               LYXERR(Debug::FIND, "match_len: " << match_len);
+               if (match_len) {
                        for (; cur; cur.forwardPos()) {
                                LYXERR(Debug::FIND, "Advancing cur: " << cur);
-                               if (match(cur)) {
+                               int match_len = match(cur);
+                               LYXERR(Debug::FIND, "match_len: " << match_len);
+                               if (match_len) {
                                        // Sometimes in finalize we understand it wasn't a match
                                        // and we need to continue the outest loop
                                        int len = findAdvFinalize(cur, match);