summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/FormatTokenLexer.cpp
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2017-10-30 14:41:34 +0000
committerKrasimir Georgiev <krasimir@google.com>2017-10-30 14:41:34 +0000
commit7f64fa8022befa17e50ae493e896fb8ecc85f301 (patch)
tree741668d6015a3c5c41e5abfb690623addea5aeff /clang/lib/Format/FormatTokenLexer.cpp
parent561ac06ff29f5890939394084c9b079d0d4d89ac (diff)
downloadbcm5719-llvm-7f64fa8022befa17e50ae493e896fb8ecc85f301.tar.gz
bcm5719-llvm-7f64fa8022befa17e50ae493e896fb8ecc85f301.zip
[clang-format] Handle CRLF correctly when formatting escaped newlines
Subscribers: klimek Differential Revision: https://reviews.llvm.org/D39420 Contributed by @peterbudai! llvm-svn: 316910
Diffstat (limited to 'clang/lib/Format/FormatTokenLexer.cpp')
-rw-r--r--clang/lib/Format/FormatTokenLexer.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/clang/lib/Format/FormatTokenLexer.cpp b/clang/lib/Format/FormatTokenLexer.cpp
index d37fcec6c5e..727437a2a58 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -554,13 +554,21 @@ FormatToken *FormatTokenLexer::getNextToken() {
// take them into account as whitespace - this pattern is quite frequent
// in macro definitions.
// FIXME: Add a more explicit test.
- while (FormatTok->TokenText.size() > 1 && FormatTok->TokenText[0] == '\\' &&
- FormatTok->TokenText[1] == '\n') {
+ while (FormatTok->TokenText.size() > 1 && FormatTok->TokenText[0] == '\\') {
+ unsigned SkippedWhitespace = 0;
+ if (FormatTok->TokenText.size() > 2 &&
+ (FormatTok->TokenText[1] == '\r' && FormatTok->TokenText[2] == '\n'))
+ SkippedWhitespace = 3;
+ else if (FormatTok->TokenText[1] == '\n')
+ SkippedWhitespace = 2;
+ else
+ break;
+
++FormatTok->NewlinesBefore;
- WhitespaceLength += 2;
- FormatTok->LastNewlineOffset = 2;
+ WhitespaceLength += SkippedWhitespace;
+ FormatTok->LastNewlineOffset = SkippedWhitespace;
Column = 0;
- FormatTok->TokenText = FormatTok->TokenText.substr(2);
+ FormatTok->TokenText = FormatTok->TokenText.substr(SkippedWhitespace);
}
FormatTok->WhitespaceRange = SourceRange(
OpenPOWER on IntegriCloud