summaryrefslogtreecommitdiffstats
path: root/lib/Format/BreakableToken.cpp
diff options
context:
space:
mode:
authorOwen Pan <owenpiano@gmail.com>2019-04-23 20:29:46 +0000
committerOwen Pan <owenpiano@gmail.com>2019-04-23 20:29:46 +0000
commit9ba05e9897f48e3ba766dc37f395b3b67056b071 (patch)
tree97a786f4b365a708ce33b0a21c26afbdc3b5c59e /lib/Format/BreakableToken.cpp
parent6d8d10abc8dd6f6db37fd6065d71b2f70b04210f (diff)
[clang-format] Fix bug in reflow of block comments containing CR/LF
Fix PR36119 Differential Revision: https://reviews.llvm.org/D60996 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359029 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/BreakableToken.cpp')
-rw-r--r--lib/Format/BreakableToken.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/Format/BreakableToken.cpp b/lib/Format/BreakableToken.cpp
index ec197aa541..5172c97f8a 100644
--- a/lib/Format/BreakableToken.cpp
+++ b/lib/Format/BreakableToken.cpp
@@ -329,7 +329,7 @@ static bool mayReflowContent(StringRef Content) {
BreakableBlockComment::BreakableBlockComment(
const FormatToken &Token, unsigned StartColumn,
unsigned OriginalStartColumn, bool FirstInLine, bool InPPDirective,
- encoding::Encoding Encoding, const FormatStyle &Style)
+ encoding::Encoding Encoding, const FormatStyle &Style, bool UseCRLF)
: BreakableComment(Token, StartColumn, InPPDirective, Encoding, Style),
DelimitersOnNewline(false),
UnbreakableTailLength(Token.UnbreakableTailLength) {
@@ -338,7 +338,8 @@ BreakableBlockComment::BreakableBlockComment(
StringRef TokenText(Tok.TokenText);
assert(TokenText.startswith("/*") && TokenText.endswith("*/"));
- TokenText.substr(2, TokenText.size() - 4).split(Lines, "\n");
+ TokenText.substr(2, TokenText.size() - 4).split(Lines,
+ UseCRLF ? "\r\n" : "\n");
int IndentDelta = StartColumn - OriginalStartColumn;
Content.resize(Lines.size());
@@ -472,7 +473,7 @@ void BreakableBlockComment::adjustWhitespace(unsigned LineIndex,
// Calculate the start of the non-whitespace text in the current line.
size_t StartOfLine = Lines[LineIndex].find_first_not_of(Blanks);
if (StartOfLine == StringRef::npos)
- StartOfLine = Lines[LineIndex].rtrim("\r\n").size();
+ StartOfLine = Lines[LineIndex].size();
StringRef Whitespace = Lines[LineIndex].substr(0, StartOfLine);
// Adjust Lines to only contain relevant text.