diff options
| -rw-r--r-- | clang/lib/Format/BreakableToken.cpp | 2 | ||||
| -rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 12 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 5 |
3 files changed, 15 insertions, 4 deletions
diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp index 29deff95699..8ca97d37a27 100644 --- a/clang/lib/Format/BreakableToken.cpp +++ b/clang/lib/Format/BreakableToken.cpp @@ -149,7 +149,7 @@ BreakableSingleLineToken::BreakableSingleLineToken( encoding::Encoding Encoding, const FormatStyle &Style) : BreakableToken(Tok, IndentLevel, InPPDirective, Encoding, Style), StartColumn(StartColumn), Prefix(Prefix), Postfix(Postfix) { - assert(Tok.TokenText.startswith(Prefix) && Tok.TokenText.endswith(Postfix)); + assert(Tok.TokenText.endswith(Postfix)); Line = Tok.TokenText.substr( Prefix.size(), Tok.TokenText.size() - Prefix.size() - Postfix.size()); } diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index acd670b945a..8510d1dde5a 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -804,13 +804,21 @@ unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current, StringRef Text = Current.TokenText; StringRef Prefix; StringRef Postfix; + bool IsNSStringLiteral = false; // FIXME: Handle whitespace between '_T', '(', '"..."', and ')'. // FIXME: Store Prefix and Suffix (or PrefixLength and SuffixLength to // reduce the overhead) for each FormatToken, which is a string, so that we // don't run multiple checks here on the hot path. + if (Text.startswith("\"") && Current.Previous && + Current.Previous->is(tok::at)) { + IsNSStringLiteral = true; + Prefix = "@\""; + --StartColumn; + } if ((Text.endswith(Postfix = "\"") && - (Text.startswith(Prefix = "\"") || Text.startswith(Prefix = "u\"") || - Text.startswith(Prefix = "U\"") || Text.startswith(Prefix = "u8\"") || + (IsNSStringLiteral || Text.startswith(Prefix = "\"") || + Text.startswith(Prefix = "u\"") || Text.startswith(Prefix = "U\"") || + Text.startswith(Prefix = "u8\"") || Text.startswith(Prefix = "L\""))) || (Text.startswith(Prefix = "_T(\"") && Text.endswith(Postfix = "\")")) || getRawStringLiteralPrefixPostfix(Text, Prefix, Postfix)) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 22b27037cfd..c66dd9819b3 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -6239,7 +6239,7 @@ TEST_F(FormatTest, BreakStringLiterals) { format("#define A \"some text other\";", AlignLeft)); } -TEST_F(FormatTest, BreaksWideStringLiterals) { +TEST_F(FormatTest, BreaksWideAndNSStringLiterals) { EXPECT_EQ( "u8\"utf8 string \"\n" "u8\"literal\";", @@ -6255,6 +6255,9 @@ TEST_F(FormatTest, BreaksWideStringLiterals) { EXPECT_EQ("L\"wide string \"\n" "L\"literal\";", format("L\"wide string literal\";", getGoogleStyleWithColumns(16))); + EXPECT_EQ("@\"NSString \"\n" + "@\"literal\";", + format("@\"NSString literal\";", getGoogleStyleWithColumns(16))); } TEST_F(FormatTest, BreaksRawStringLiterals) { |

