From 5e26133947bef3d55c42a88fffb77bd0711ebff7 Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Sat, 24 Oct 2009 15:54:03 +0000 Subject: [PATCH] Fix another problem related to bug #6284. 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 | 62 +++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp index 85f0f08fd5..32da4448a5 100644 --- a/src/mathed/MathParser.cpp +++ b/src/mathed/MathParser.cpp @@ -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 @@ -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("\\}")); } -- 2.39.2