]> granicus.if.org Git - clang/commitdiff
clang-format: Don't generate unnecessary replacements for \r\n line endings.
authorDaniel Jasper <djasper@google.com>
Wed, 17 Jun 2015 12:23:15 +0000 (12:23 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 17 Jun 2015 12:23:15 +0000 (12:23 +0000)
Patch by Mathieu Champlon. Thank you.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239900 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/BreakableToken.cpp
unittests/Format/FormatTest.cpp

index e3e162d070f809703e1d838385cb7d1caca1e7a6..e364986783bcd3060c58a8da9de22b1e80c71e2a 100644 (file)
@@ -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.
index acb120962e45a248e23757cd058cb4104c98d794..f129bbbd4256ca01e83d72571a6ba6caa5efabf5 100644 (file)
@@ -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) {