forked from OSchip/llvm-project
clang-format: Properly align ObjC string literals.
Before: NSString s = @"a" "b" "c"; NSString s = @"a" @"b" @"c"; After: NSString s = @"a" "b" "c"; NSString s = @"a" @"b" @"c"; This fixes llvm.org/PR23536. llvm-svn: 237538
This commit is contained in:
parent
a8200603d4
commit
0928553eec
|
@ -546,10 +546,11 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
|
|||
if (Current.is(tok::identifier) && Current.Next &&
|
||||
Current.Next->is(TT_DictLiteral))
|
||||
return State.Stack.back().Indent;
|
||||
if ((NextNonComment->isStringLiteral() ||
|
||||
NextNonComment->is(TT_ObjCStringLiteral)) &&
|
||||
State.StartOfStringLiteral != 0)
|
||||
if (NextNonComment->isStringLiteral() && State.StartOfStringLiteral != 0)
|
||||
return State.StartOfStringLiteral;
|
||||
if (NextNonComment->is(TT_ObjCStringLiteral) &&
|
||||
State.StartOfStringLiteral != 0)
|
||||
return State.StartOfStringLiteral - 1;
|
||||
if (NextNonComment->is(tok::lessless) &&
|
||||
State.Stack.back().FirstLessLess != 0)
|
||||
return State.Stack.back().FirstLessLess;
|
||||
|
@ -702,13 +703,13 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
|
|||
moveStatePastScopeCloser(State);
|
||||
moveStatePastFakeRParens(State);
|
||||
|
||||
if ((Current.isStringLiteral() || Current.is(TT_ObjCStringLiteral)) &&
|
||||
State.StartOfStringLiteral == 0) {
|
||||
if (Current.isStringLiteral() && State.StartOfStringLiteral == 0)
|
||||
State.StartOfStringLiteral = State.Column;
|
||||
} else if (!Current.isOneOf(tok::comment, tok::identifier, tok::hash) &&
|
||||
!Current.isStringLiteral()) {
|
||||
if (Current.is(TT_ObjCStringLiteral) && State.StartOfStringLiteral == 0)
|
||||
State.StartOfStringLiteral = State.Column + 1;
|
||||
else if (!Current.isOneOf(tok::comment, tok::identifier, tok::hash) &&
|
||||
!Current.isStringLiteral())
|
||||
State.StartOfStringLiteral = 0;
|
||||
}
|
||||
|
||||
State.Column += Current.ColumnWidth;
|
||||
State.NextToken = State.NextToken->Next;
|
||||
|
|
|
@ -4768,7 +4768,11 @@ TEST_F(FormatTest, AlignsStringLiterals) {
|
|||
verifyFormat("f(@\"a\"\n"
|
||||
" @\"b\");");
|
||||
verifyFormat("NSString s = @\"a\"\n"
|
||||
" @\"b\";");
|
||||
" @\"b\"\n"
|
||||
" @\"c\";");
|
||||
verifyFormat("NSString s = @\"a\"\n"
|
||||
" \"b\"\n"
|
||||
" \"c\";");
|
||||
}
|
||||
|
||||
TEST_F(FormatTest, AlwaysBreakAfterDefinitionReturnType) {
|
||||
|
|
Loading…
Reference in New Issue