aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-02-26 12:52:34 +0000
committerDaniel Jasper <djasper@google.com>2013-02-26 12:52:34 +0000
commit0fb382bfbfbfee73763a213b2257042ed342c4b0 (patch)
treee4b1fce3e2fb59728f8440eec3b3f6aa68a928bd
parent863fb3574468ef9fdc9f5ea3fa3d62671979ccf1 (diff)
Only break string literals as a last resort.
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
-rw-r--r--lib/Format/Format.cpp2
-rw-r--r--unittests/Format/FormatTest.cpp6
2 files changed, 7 insertions, 1 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 00ec79f5e4..7687aa347b 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -727,7 +727,7 @@ private:
TailOffset += SplitPoint + 1;
TailLength -= SplitPoint + 1;
OffsetFromStart = 1;
- Penalty += 100;
+ Penalty += Style.PenaltyExcessCharacter;
}
State.Column = StartColumn + TailLength;
return Penalty;
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 17dae0ffe6..a902466c4c 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -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