@@ -116,12 +116,9 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
116
116
!Current.isOneOf (tok::r_paren, tok::r_brace))
117
117
return true ;
118
118
if (Style.AlwaysBreakBeforeMultilineStrings &&
119
- State.Column > State.Stack .back ().Indent &&
120
- Current.is (tok::string_literal) && Previous.isNot (tok::lessless) &&
121
- Previous.Type != TT_InlineASMColon &&
122
- ((Current.getNextNonComment () &&
123
- Current.getNextNonComment ()->is (tok::string_literal)) ||
124
- (Current.TokenText .find (" \\\n " ) != StringRef::npos)))
119
+ State.Column > State.Stack .back ().Indent && // Breaking saves columns.
120
+ Previous.isNot (tok::lessless) && Previous.Type != TT_InlineASMColon &&
121
+ NextIsMultilineString (State))
125
122
return true ;
126
123
127
124
if (!Style.BreakBeforeBinaryOperators ) {
@@ -547,13 +544,8 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
547
544
}
548
545
549
546
State.Column += Current.CodePointCount ;
550
-
551
547
State.NextToken = State.NextToken ->Next ;
552
-
553
- unsigned Penalty = 0 ;
554
- if (Newline || !Style.AlwaysBreakBeforeMultilineStrings ||
555
- Current.isNot (tok::string_literal) || !Current.CanBreakBefore )
556
- Penalty += breakProtrudingToken (Current, State, DryRun);
548
+ unsigned Penalty = breakProtrudingToken (Current, State, DryRun);
557
549
558
550
// If the previous has a special role, let it consume tokens as appropriate.
559
551
// It is necessary to start at the previous token for the only implemented
@@ -688,5 +680,19 @@ unsigned ContinuationIndenter::getColumnLimit() const {
688
680
return Style.ColumnLimit - (Line.InPPDirective ? 2 : 0 );
689
681
}
690
682
683
+ bool ContinuationIndenter::NextIsMultilineString (const LineState &State) {
684
+ const FormatToken &Current = *State.NextToken ;
685
+ if (!Current.is (tok::string_literal))
686
+ return false ;
687
+ if (Current.getNextNonComment () &&
688
+ Current.getNextNonComment ()->is (tok::string_literal))
689
+ return true ; // Implicit concatenation.
690
+ if (State.Column + Current.CodePointCount + Current.UnbreakableTailLength >
691
+ Style.ColumnLimit )
692
+ return true ; // String will be split.
693
+ // String literal might have escaped newlines.
694
+ return Current.TokenText .find (" \\\n " ) != StringRef::npos;
695
+ }
696
+
691
697
} // namespace format
692
698
} // namespace clang
0 commit comments