]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfind.cpp
Compile fix for qt versions below 4.6.
[lyx.git] / src / lyxfind.cpp
index ac3db2d6e34d6675ea773e4fd77aa9ecbe81d2bb..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,11 @@ 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 ", "")
-              || regex_replace(t, t, "^\\\\begin\\{[a-zA-Z_]*\\} ", ""))
+              || regex_replace(t, t, "^\\\\begin\\{[a-zA-Z_]*\\*?\\} ", ""))
                LYXERR(Debug::FIND, "  after removing leading $, \\[ , \\emph{, \\textbf{, etc.: '" << t << "'");
        return s.find(t);
 }
@@ -795,7 +796,7 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const &
                        // @todo need to account for open square braces as well ?
                        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")) {
                                ++open_braces;
@@ -824,7 +825,7 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const &
                                || 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")
                ) {
@@ -966,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();
@@ -1027,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