]> git.lyx.org Git - features.git/commitdiff
Fix another problem related to bug #6284.
authorEnrico Forestieri <forenr@lyx.org>
Sat, 24 Oct 2009 15:54:03 +0000 (15:54 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Sat, 24 Oct 2009 15:54:03 +0000 (15:54 +0000)
When pasting "# a" within \mbox{} through Ctrl+Shift+V, the space is
correctly retained. However, using Ctrl+Shift+V for pasting "^ a" into
\mbox{}, the space gets swallowed. This is fixed by this patch.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31708 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/MathParser.cpp

index 85f0f08fd59e47bd61e67eba76658f34425ac9fa..32da4448a54c8a8fd924d7a7743bdc9df05d08e0 100644 (file)
@@ -70,7 +70,6 @@ following hack as starting point to write some macros:
 #include "support/debug.h"
 #include "support/convert.h"
 #include "support/docstream.h"
-#include "support/lstrings.h"
 
 #include <sstream>
 
@@ -80,8 +79,6 @@ using namespace std;
 
 namespace lyx {
 
-using support::subst;
-
 namespace {
 
 InsetMath::mode_type asMode(InsetMath::mode_type oldmode, docstring const & str)
@@ -102,23 +99,52 @@ bool stared(docstring const & s)
 }
 
 
+docstring const repl(docstring const & oldstr, char_type const c,
+                    docstring const & macro, bool textmode = false)
+{
+       docstring newstr;
+       size_t i;
+       size_t j;
+
+       for (i = 0, j = 0; i < oldstr.size(); ++i) {
+               if (c == oldstr[i]) {
+                       newstr.append(oldstr, j, i - j);
+                       newstr.append(macro);
+                       j = i + 1;
+                       if (macro.size() > 2 && j < oldstr.size())
+                               newstr += (textmode && oldstr[j] == ' ' ? '\\' : ' ');
+               }
+       }
+
+       // Any substitution?
+       if (j == 0)
+               return oldstr;
+
+       newstr.append(oldstr, j, i - j);
+       return newstr;
+}
+
+
 docstring escapeSpecialChars(docstring const & str, bool textmode)
 {
-       docstring const backslash = textmode ? from_ascii("\\textbackslash ")
-                                            : from_ascii("\\backslash ");
-       docstring const caret = textmode ? from_ascii("\\textasciicircum ")
-                                        : from_ascii("\\mathcircumflex ");
-
-       return subst(subst(subst(subst(subst(subst(subst(subst(subst(str,
-                       from_ascii("\\"), backslash),
-                       from_ascii("^"), caret),
-                       from_ascii("_"), from_ascii("\\_")),
-                       from_ascii("$"), from_ascii("\\$")),
-                       from_ascii("#"), from_ascii("\\#")),
-                       from_ascii("&"), from_ascii("\\&")),
-                       from_ascii("%"), from_ascii("\\%")),
-                       from_ascii("{"), from_ascii("\\{")),
-                       from_ascii("}"), from_ascii("\\}"));
+       docstring const backslash = textmode ? from_ascii("\\textbackslash")
+                                            : from_ascii("\\backslash");
+       docstring const caret = textmode ? from_ascii("\\textasciicircum")
+                                        : from_ascii("\\mathcircumflex");
+       docstring const tilde = textmode ? from_ascii("\\textasciitilde")
+                                        : from_ascii("\\sim");
+
+       return repl(repl(repl(repl(repl(repl(repl(repl(repl(repl(str,
+                       '\\', backslash, textmode),
+                       '^', caret, textmode),
+                       '~', tilde, textmode),
+                       '_', from_ascii("\\_")),
+                       '$', from_ascii("\\$")),
+                       '#', from_ascii("\\#")),
+                       '&', from_ascii("\\&")),
+                       '%', from_ascii("\\%")),
+                       '{', from_ascii("\\{")),
+                       '}', from_ascii("\\}"));
 }