Skip to content

Commit e4d57c3

Browse files
authored
Merge pull request swiftlang#69178 from bulbazord/warning-line-list
[Markup] Fix warning in measureIndentation
2 parents d2b9ca0 + 62200c1 commit e4d57c3

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

lib/Markup/LineList.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,11 @@ std::string LineList::str() const {
4343
}
4444

4545
size_t swift::markup::measureIndentation(StringRef Text) {
46-
size_t Col = 0;
47-
for (size_t i = 0, e = Text.size(); i != e; ++i) {
48-
if (Text[i] == ' ' || Text[i] == '\v' || Text[i] == '\f') {
49-
++Col;
50-
continue;
51-
}
52-
53-
if (Text[i] == '\t') {
54-
Col += ((i + 8) / 8) * 8;
55-
continue;
56-
}
57-
return i;
58-
}
59-
return Text.size();
46+
static constexpr llvm::StringLiteral IndentChars(" \v\f\t");
47+
size_t FirstNonIndentPos = Text.find_first_not_of(IndentChars);
48+
if (FirstNonIndentPos == StringRef::npos)
49+
return Text.size();
50+
return FirstNonIndentPos;
6051
}
6152

6253
void LineListBuilder::addLine(llvm::StringRef Text, swift::SourceRange Range) {

0 commit comments

Comments
 (0)