From: Daniel Jasper Date: Wed, 17 Jun 2015 12:23:15 +0000 (+0000) Subject: clang-format: Don't generate unnecessary replacements for \r\n line endings. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=86666d6bf20c3c536e33b13e2b7e1eb77c68a5a9;p=clang clang-format: Don't generate unnecessary replacements for \r\n line endings. Patch by Mathieu Champlon. Thank you. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239900 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/BreakableToken.cpp b/lib/Format/BreakableToken.cpp index e3e162d070..e364986783 100644 --- a/lib/Format/BreakableToken.cpp +++ b/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/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index acb120962e..f129bbbd42 100644 --- a/unittests/Format/FormatTest.cpp +++ b/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) {