[PATCH] D95081: [clang-format] [NFC] Restructure getLineCommentIndentPrefix
Björn Schäpers via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 21 04:41:35 PST 2021
HazardyKnusperkeks updated this revision to Diff 318156.
HazardyKnusperkeks added a comment.
Empty lines removed.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D95081/new/
https://reviews.llvm.org/D95081
Files:
clang/lib/Format/BreakableToken.cpp
Index: clang/lib/Format/BreakableToken.cpp
===================================================================
--- clang/lib/Format/BreakableToken.cpp
+++ clang/lib/Format/BreakableToken.cpp
@@ -42,24 +42,26 @@
static StringRef getLineCommentIndentPrefix(StringRef Comment,
const FormatStyle &Style) {
static constexpr StringRef KnownCStylePrefixes[] = {"///<", "//!<", "///",
- "//", "//!", "//:"};
- static constexpr StringRef KnownTextProtoPrefixes[] = {"//", "#", "##", "###",
- "####"};
+ "//!", "//:", "//"};
+ static constexpr StringRef KnownTextProtoPrefixes[] = {"####", "###", "##",
+ "//", "#"};
ArrayRef<StringRef> KnownPrefixes(KnownCStylePrefixes);
if (Style.Language == FormatStyle::LK_TextProto)
KnownPrefixes = KnownTextProtoPrefixes;
- StringRef LongestPrefix;
+ assert(std::is_sorted(KnownPrefixes.begin(), KnownPrefixes.end(),
+ [](StringRef Lhs, StringRef Rhs) noexcept {
+ return Lhs.size() > Rhs.size();
+ }));
+
for (StringRef KnownPrefix : KnownPrefixes) {
if (Comment.startswith(KnownPrefix)) {
- size_t PrefixLength = KnownPrefix.size();
- while (PrefixLength < Comment.size() && Comment[PrefixLength] == ' ')
- ++PrefixLength;
- if (PrefixLength > LongestPrefix.size())
- LongestPrefix = Comment.substr(0, PrefixLength);
+ const auto PrefixLength =
+ Comment.find_first_not_of(' ', KnownPrefix.size());
+ return Comment.substr(0, PrefixLength);
}
}
- return LongestPrefix;
+ return {};
}
static BreakableToken::Split
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95081.318156.patch
Type: text/x-patch
Size: 1875 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210121/327694d7/attachment-0001.bin>
More information about the cfe-commits
mailing list