!Current.isTrailingComment() &&
!Current.isOneOf(tok::r_paren, tok::r_brace))
return true;
+ if (Style.AlwaysBreakBeforeMultilineStrings &&
+ State.Column > State.Stack.back().Indent &&
+ Current.is(tok::string_literal) && Previous.isNot(tok::lessless) &&
+ Previous.Type != TT_InlineASMColon &&
+ ((Current.getNextNonComment() &&
+ Current.getNextNonComment()->is(tok::string_literal)) ||
+ (Current.TokenText.find("\\\n") != StringRef::npos)))
+ return true;
// If we need to break somewhere inside the LHS of a binary expression, we
// should also break after the operator. Otherwise, the formatting would
} else if (Current->Previous->ClosesTemplateDeclaration &&
Style.AlwaysBreakTemplateDeclarations) {
Current->MustBreakBefore = true;
- } else if (Style.AlwaysBreakBeforeMultilineStrings &&
- Current->is(tok::string_literal) &&
- Current->Previous->isNot(tok::lessless) &&
- Current->Previous->Type != TT_InlineASMColon &&
- ((Current->getNextNonComment() &&
- Current->getNextNonComment()->is(tok::string_literal)) ||
- (Current->TokenText.find("\\\n") != StringRef::npos))) {
- Current->MustBreakBefore = true;
}
Current->CanBreakBefore =
Current->MustBreakBefore || canBreakBefore(Line, *Current);
- if (Current->MustBreakBefore)
+ if (Current->MustBreakBefore ||
+ (Current->is(tok::string_literal) &&
+ Current->TokenText.find("\\\n") != StringRef::npos))
Current->TotalLength = Current->Previous->TotalLength + Style.ColumnLimit;
else
Current->TotalLength = Current->Previous->TotalLength +
NoBreak.AlwaysBreakBeforeMultilineStrings = false;
FormatStyle Break = getLLVMStyle();
Break.AlwaysBreakBeforeMultilineStrings = true;
- EXPECT_EQ("aaaa = \"bbbb\"\n"
- " \"cccc\";",
- format("aaaa=\"bbbb\" \"cccc\";", NoBreak));
- EXPECT_EQ("aaaa =\n"
- " \"bbbb\"\n"
- " \"cccc\";",
- format("aaaa=\"bbbb\" \"cccc\";", Break));
- EXPECT_EQ("aaaa(\"bbbb\"\n"
- " \"cccc\");",
- format("aaaa(\"bbbb\" \"cccc\");", NoBreak));
- EXPECT_EQ("aaaa(\n"
- " \"bbbb\"\n"
- " \"cccc\");",
- format("aaaa(\"bbbb\" \"cccc\");", Break));
- EXPECT_EQ("aaaa(qqq, \"bbbb\"\n"
- " \"cccc\");",
- format("aaaa(qqq, \"bbbb\" \"cccc\");", NoBreak));
- EXPECT_EQ("aaaa(qqq,\n"
- " \"bbbb\"\n"
- " \"cccc\");",
- format("aaaa(qqq, \"bbbb\" \"cccc\");", Break));
+ verifyFormat("aaaa = \"bbbb\"\n"
+ " \"cccc\";",
+ NoBreak);
+ verifyFormat("aaaa =\n"
+ " \"bbbb\"\n"
+ " \"cccc\";",
+ Break);
+ verifyFormat("aaaa(\"bbbb\"\n"
+ " \"cccc\");",
+ NoBreak);
+ verifyFormat("aaaa(\n"
+ " \"bbbb\"\n"
+ " \"cccc\");",
+ Break);
+ verifyFormat("aaaa(qqq, \"bbbb\"\n"
+ " \"cccc\");",
+ NoBreak);
+ verifyFormat("aaaa(qqq,\n"
+ " \"bbbb\"\n"
+ " \"cccc\");",
+ Break);
+
+ // Don't break if there is no column gain.
+ verifyFormat("f(\"aaaa\"\n"
+ " \"bbbb\");",
+ Break);
+
+ // Treat literals with escaped newlines like multi-line string literals.
EXPECT_EQ("x = \"a\\\n"
"b\\\n"
"c\";",