================
@@ -27,6 +27,113 @@ namespace format {
static constexpr StringRef Blanks(" \t\v\f\r");
+static bool lineContainsContent(StringRef Line) {
+ return Line.find_first_not_of(Blanks) != StringRef::npos;
+}
+
+static StringRef stripTrailingCarriageReturn(StringRef Line) {
+ if (!Line.empty() && Line.back() == '\r')
+ Line = Line.drop_back();
+ return Line;
+}
+
+static FormatStyle::CommentSpaceMode
+resolveCommentSpaceMode(CommentKind Kind,
+ FormatStyle::CommentSpaceMode GeneralMode,
+ FormatStyle::CommentSpaceMode ParamMode) {
+ switch (Kind) {
+ case CommentKind::Plain:
+ return GeneralMode;
+ case CommentKind::Parameter:
+ return ParamMode;
+
+ case CommentKind::DocString:
+ return FormatStyle::CommentSpaceMode::Leave;
+ }
+ llvm_unreachable("Unhandled CommentKind");
+}
+
+static void applySpaceInBlockComment(const FormatToken &Tok,
+ const FormatStyle &Style,
+ WhitespaceManager &Whitespaces,
+ bool InPPDirective) {
+ StringRef Text = Tok.TokenText;
+ if (!Text.starts_with("/*") || !Text.ends_with("*/") || Text.size() < 4)
+ return;
+
+ const CommentKind Kind = Tok.getBlockCommentKind();
+ const auto OpeningMode =
+ resolveCommentSpaceMode(Kind, Style.SpaceInComments.AfterOpeningComment,
+ Style.SpaceInComments.AfterOpeningParamComment);
+ const auto ClosingMode =
+ resolveCommentSpaceMode(Kind, Style.SpaceInComments.BeforeClosingComment,
+ Style.SpaceInComments.BeforeClosingParamComment);
+
+ StringRef Body = Text.substr(2, Text.size() - 4);
+ if (Body.empty())
+ return;
+
+ const auto applyReplacement = [&](unsigned Offset, unsigned Length,
+ StringRef Replacement) {
+ Whitespaces.replaceWhitespaceInToken(Tok, Offset, Length, "", Replacement,
+ InPPDirective,
+ /*Newlines=*/0, /*Spaces=*/0);
+ };
+
+ if (Body.find_first_not_of(Blanks) == StringRef::npos) {
----------------
HazardyKnusperkeks wrote:
```suggestion
if (!lineContainsContent(Body)) {
```
https://github.com/llvm/llvm-project/pull/162105
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits