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"));

llvm-svn: 176084
This commit is contained in:
Daniel Jasper 2013-02-26 12:52:34 +00:00
parent 46c0bc233b
commit 5497fce41c
2 changed files with 7 additions and 1 deletions

View 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;

View 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