Le 23/08/2017 à 11:55, Jean-Marc Lasgouttes a écrit :
This is what the code tries to do, but there are bugs (see notes below).
[...]
[*] the original code only considered spaces, which is of course wrong
and should be corrected.
[**] a further random change was added to remove all leading tabs
(6bba977f42), which is probably the bug you are seeing.
I would add the amusing
[***] the code removes all the spaces of the prefix except one.
All in all, I would propose to apply the following âtch, although I am
not completely sure I understood what issues Haim was encountering.
Richard, could you test it a bit?
JMarc
From 5d9ddfd5b3611fdc2d8b46109c1b08d1ae0aa2af Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date: Wed, 23 Aug 2017 12:25:29 +0200
Subject: [PATCH] Fix Lexer::getLongString prefix pruning logic
This fixes 3 bugs:
1/ only spaces are considered as part of the prefix
2/ leading tabs are removed unconditionally
3/ off-by-one error in the removal
The new intended behavior is:
1/ find the prefix (sequence of spaces and tabs) before the first
line; remove this prefix from the line
2/ on the next lines, check whether they start with the same prefix,
and if they do, strip this prefix
---
src/Lexer.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/Lexer.cpp b/src/Lexer.cpp
index becd157..098faa9 100644
--- a/src/Lexer.cpp
+++ b/src/Lexer.cpp
@@ -738,7 +738,7 @@ docstring Lexer::getLongString(docstring const & endtoken)
break;
if (firstline) {
- size_t i = tmpstr.find_first_not_of(char_type(' '));
+ size_t i = tmpstr.find_first_not_of(from_ascii(" \t"));
if (i != string::npos)
prefix = tmpstr.substr(0, i);
firstline = false;
@@ -747,10 +747,10 @@ docstring Lexer::getLongString(docstring const & endtoken)
// further lines in long strings may have the same
// whitespace prefix as the first line. Remove it.
- if (prefix.length() && prefixIs(tmpstr, prefix))
- tmpstr.erase(0, prefix.length() - 1);
+ if (!prefix.empty() && prefixIs(tmpstr, prefix))
+ tmpstr.erase(0, prefix.length());
- str += ltrim(tmpstr, "\t") + '\n';
+ str += tmpstr + '\n';
}
if (!pimpl_->is)
--
2.7.4