r237538 - clang-format: Properly align ObjC string literals.
Daniel Jasper
djasper at google.com
Sun May 17 01:13:23 PDT 2015
Author: djasper
Date: Sun May 17 03:13:23 2015
New Revision: 237538
URL: http://llvm.org/viewvc/llvm-project?rev=237538&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=237538&r1=237537&r2=237538&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Sun May 17 03:13:23 2015
@@ -546,10 +546,11 @@ unsigned ContinuationIndenter::getNewLin
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::moveState
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;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=237538&r1=237537&r2=237538&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sun May 17 03:13:23 2015
@@ -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) {
More information about the cfe-commits
mailing list