diff options
| -rw-r--r-- | clang/include/clang/Format/Format.h | 4 | ||||
| -rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 3 | ||||
| -rw-r--r-- | clang/lib/Format/Format.cpp | 6 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 6 |
4 files changed, 17 insertions, 2 deletions
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index 6d051e09cb6..9f3f0326d45 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -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 && diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 07b90090ac2..76a458db9bd 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -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 diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 2689368da51..acd520ef546 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -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; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 057871b7021..17db98fe79f 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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"); |

