Skip to content

Commit 137f614

Browse files
author
hnakamura5
committed
Fixed the revied points of redundant substr's param and line detection
1 parent bba0a09 commit 137f614

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

clang/lib/Format/FormatTokenLexer.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -787,23 +787,21 @@ void FormatTokenLexer::handleTableGenMultilineString() {
787787
MultiLineString->TokenText = Text;
788788
resetLexer(SourceMgr.getFileOffset(
789789
Lex->getSourceLocation(Lex->getBufferLocation() - 2 + Text.size())));
790-
// Set ColumnWidth and LastLineColumnWidth.
791790
auto FirstLineText = Text;
792791
auto FirstBreak = Text.find('\n');
792+
// Set ColumnWidth and LastLineColumnWidth when it has multiple lines.
793793
if (FirstBreak != StringRef::npos) {
794794
MultiLineString->IsMultiline = true;
795795
FirstLineText = Text.substr(0, FirstBreak + 1);
796+
// LastLineColumnWidth holds the width of the last line.
797+
auto LastBreak = Text.rfind('\n');
798+
MultiLineString->LastLineColumnWidth = encoding::columnWidthWithTabs(
799+
Text.substr(LastBreak + 1), MultiLineString->OriginalColumn,
800+
Style.TabWidth, Encoding);
796801
}
797802
// ColumnWidth holds only the width of the first line.
798803
MultiLineString->ColumnWidth = encoding::columnWidthWithTabs(
799804
FirstLineText, MultiLineString->OriginalColumn, Style.TabWidth, Encoding);
800-
auto LastBreak = Text.rfind('\n');
801-
if (LastBreak != StringRef::npos) {
802-
// Set LastLineColumnWidth if it has multiple lines.
803-
MultiLineString->LastLineColumnWidth = encoding::columnWidthWithTabs(
804-
Text.substr(LastBreak + 1, Text.size()),
805-
MultiLineString->OriginalColumn, Style.TabWidth, Encoding);
806-
}
807805
}
808806

809807
void FormatTokenLexer::handleTemplateStrings() {

0 commit comments

Comments
 (0)