forked from OSchip/llvm-project
clang-format: Add option to disable string literal formatting.
llvm-svn: 259352
This commit is contained in:
parent
bb37a2f6f3
commit
e1a7b76338
|
@ -285,6 +285,9 @@ struct FormatStyle {
|
|||
/// \brief Break after each annotation on a field in Java files.
|
||||
bool BreakAfterJavaFieldAnnotations;
|
||||
|
||||
/// \brief Allow breaking string literals when formatting.
|
||||
bool BreakStringLiterals;
|
||||
|
||||
/// \brief The column limit.
|
||||
///
|
||||
/// A column limit of \c 0 means that there is no column limit. In this case,
|
||||
|
@ -619,6 +622,7 @@ struct FormatStyle {
|
|||
BreakConstructorInitializersBeforeComma ==
|
||||
R.BreakConstructorInitializersBeforeComma &&
|
||||
BreakAfterJavaFieldAnnotations == R.BreakAfterJavaFieldAnnotations &&
|
||||
BreakStringLiterals == R.BreakStringLiterals &&
|
||||
ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas &&
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine ==
|
||||
R.ConstructorInitializerAllOnOneLineOrOnePerLine &&
|
||||
|
|
|
@ -1061,7 +1061,8 @@ unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current,
|
|||
// FIXME: String literal breaking is currently disabled for Java and JS, as
|
||||
// it requires strings to be merged using "+" which we don't support.
|
||||
if (Style.Language == FormatStyle::LK_Java ||
|
||||
Style.Language == FormatStyle::LK_JavaScript)
|
||||
Style.Language == FormatStyle::LK_JavaScript ||
|
||||
!Style.BreakStringLiterals)
|
||||
return 0;
|
||||
|
||||
// Don't break string literals inside preprocessor directives (except for
|
||||
|
|
|
@ -275,6 +275,9 @@ template <> struct MappingTraits<FormatStyle> {
|
|||
Style.BreakBeforeTernaryOperators);
|
||||
IO.mapOptional("BreakConstructorInitializersBeforeComma",
|
||||
Style.BreakConstructorInitializersBeforeComma);
|
||||
IO.mapOptional("BreakAfterJavaFieldAnnotations",
|
||||
Style.BreakAfterJavaFieldAnnotations);
|
||||
IO.mapOptional("BreakStringLiterals", Style.BreakStringLiterals);
|
||||
IO.mapOptional("ColumnLimit", Style.ColumnLimit);
|
||||
IO.mapOptional("CommentPragmas", Style.CommentPragmas);
|
||||
IO.mapOptional("ConstructorInitializerAllOnOneLineOrOnePerLine",
|
||||
|
@ -488,8 +491,9 @@ FormatStyle getLLVMStyle() {
|
|||
LLVMStyle.BreakBeforeBraces = FormatStyle::BS_Attach;
|
||||
LLVMStyle.BraceWrapping = {false, false, false, false, false, false,
|
||||
false, false, false, false, false};
|
||||
LLVMStyle.BreakConstructorInitializersBeforeComma = false;
|
||||
LLVMStyle.BreakAfterJavaFieldAnnotations = false;
|
||||
LLVMStyle.BreakConstructorInitializersBeforeComma = false;
|
||||
LLVMStyle.BreakStringLiterals = true;
|
||||
LLVMStyle.ColumnLimit = 80;
|
||||
LLVMStyle.CommentPragmas = "^ IWYU pragma:";
|
||||
LLVMStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = false;
|
||||
|
|
|
@ -7958,6 +7958,10 @@ TEST_F(FormatTest, BreaksStringLiterals) {
|
|||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"});",
|
||||
getGoogleStyle()));
|
||||
|
||||
FormatStyle Style = getLLVMStyleWithColumns(12);
|
||||
Style.BreakStringLiterals = false;
|
||||
EXPECT_EQ("\"some text other\";", format("\"some text other\";", Style));
|
||||
|
||||
FormatStyle AlignLeft = getLLVMStyleWithColumns(12);
|
||||
AlignLeft.AlignEscapedNewlinesLeft = true;
|
||||
EXPECT_EQ("#define A \\\n"
|
||||
|
@ -9823,8 +9827,10 @@ TEST_F(FormatTest, ParsesConfigurationBools) {
|
|||
CHECK_PARSE_BOOL(AlwaysBreakTemplateDeclarations);
|
||||
CHECK_PARSE_BOOL(BinPackArguments);
|
||||
CHECK_PARSE_BOOL(BinPackParameters);
|
||||
CHECK_PARSE_BOOL(BreakAfterJavaFieldAnnotations);
|
||||
CHECK_PARSE_BOOL(BreakBeforeTernaryOperators);
|
||||
CHECK_PARSE_BOOL(BreakConstructorInitializersBeforeComma);
|
||||
CHECK_PARSE_BOOL(BreakStringLiterals);
|
||||
CHECK_PARSE_BOOL(ConstructorInitializerAllOnOneLineOrOnePerLine);
|
||||
CHECK_PARSE_BOOL(DerivePointerAlignment);
|
||||
CHECK_PARSE_BOOL_FIELD(DerivePointerAlignment, "DerivePointerBinding");
|
||||
|
|
Loading…
Reference in New Issue