diff options
author | Daniel Jasper <djasper@google.com> | 2015-06-17 12:23:15 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2015-06-17 12:23:15 +0000 |
commit | d6e618892f75946a7557a3d2159c9de80d3d8956 (patch) | |
tree | 0cc4e56badc2d1653d30ecdc8e6b89f4eb0afb97 /clang | |
parent | 6a1e0eb27d01731aca1e861ed968db0e072a2ad5 (diff) | |
download | bcm5719-llvm-d6e618892f75946a7557a3d2159c9de80d3d8956.tar.gz bcm5719-llvm-d6e618892f75946a7557a3d2159c9de80d3d8956.zip |
clang-format: Don't generate unnecessary replacements for \r\n line endings.
Patch by Mathieu Champlon. Thank you.
llvm-svn: 239900
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Format/BreakableToken.cpp | 2 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp index e3e162d070f..e364986783b 100644 --- a/clang/lib/Format/BreakableToken.cpp +++ b/clang/lib/Format/BreakableToken.cpp @@ -345,7 +345,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].size(); + StartOfLine = Lines[LineIndex].rtrim("\r\n").size(); StringRef Whitespace = Lines[LineIndex].substr(0, StartOfLine); // Adjust Lines to only contain relevant text. diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index acb120962e4..f129bbbd425 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -146,6 +146,13 @@ TEST_F(FormatTest, OnlyGeneratesNecessaryReplacements) { " f();\n" "}")); EXPECT_EQ(0, ReplacementCount); + EXPECT_EQ("/*\r\n" + "\r\n" + "*/\r\n", + format("/*\r\n" + "\r\n" + "*/\r\n")); + EXPECT_EQ(0, ReplacementCount); } TEST_F(FormatTest, RemovesEmptyLines) { |