]> granicus.if.org Git - clang/commitdiff
Only break string literals as a last resort.
authorDaniel Jasper <djasper@google.com>
Tue, 26 Feb 2013 12:52:34 +0000 (12:52 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 26 Feb 2013 12:52:34 +0000 (12:52 +0000)
We might want to move towards doing this if the formatting can be
significantly improved, but we need to carefully evaluate the different
situations first.

Before (the string literal was split by clang-format here):
aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaa, aaaaaa("aaa aaaaa aaa aaa aaaaa aaa "
                                                  "aaaaa aaa aaa aaaaaa"));

After:
aaaaaaaaaaaaaaaaaaaa(
    aaaaaaaaaaaaaaaaaaaa,
    aaaaaa("aaa aaaaa aaa aaa aaaaa aaa aaaaa aaa aaa aaaaaa"));

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

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

index 00ec79f5e4592dc84678b2aa60526a339d0380c0..7687aa347bd60dc9a31abbd8dd874d5b86a6a9f7 100644 (file)
@@ -727,7 +727,7 @@ private:
       TailOffset += SplitPoint + 1;
       TailLength -= SplitPoint + 1;
       OffsetFromStart = 1;
-      Penalty += 100;
+      Penalty += Style.PenaltyExcessCharacter;
     }
     State.Column = StartColumn + TailLength;
     return Penalty;
index 17dae0ffe646fa32ffed3600a6c2ab37ab2818b4..a902466c4ce0a004ef36e4aa621afb36054345b8 100644 (file)
@@ -2984,6 +2984,12 @@ TEST_F(FormatTest, BreakStringLiterals) {
             "  \"text\",\n"
             "  other);",
             format("f(\"some text\", other);", getLLVMStyleWithColumns(10)));
+
+  // Only break as a last resort.
+  verifyFormat(
+      "aaaaaaaaaaaaaaaaaaaa(\n"
+      "    aaaaaaaaaaaaaaaaaaaa,\n"
+      "    aaaaaa(\"aaa aaaaa aaa aaa aaaaa aaa aaaaa aaa aaa aaaaaa\"));");
 }
 
 } // end namespace tooling