[clang-format] Put '/**' and '*/' on own lines in jsdocs ending in comment pragmas
Summary:
This handles a case where the trailing '*/' of a multiline jsdoc eding in a
comment pragma wouldn't be put on a new line.
Reviewers: mprobst
Reviewed By: mprobst
Subscribers: cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D36359
llvm-svn: 310458
diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp
index 3844c8e..20e3e5b 100644
--- a/clang/lib/Format/BreakableToken.cpp
+++ b/clang/lib/Format/BreakableToken.cpp
@@ -681,12 +681,18 @@
InPPDirective, /*Newlines=*/1, ContentColumn[LineIndex] - Prefix.size());
}
-BreakableToken::Split BreakableBlockComment::getSplitAfterLastLine(
- unsigned TailOffset, unsigned ColumnLimit,
- llvm::Regex &CommentPragmasRegex) const {
- if (DelimitersOnNewline)
- return getSplit(Lines.size() - 1, TailOffset, ColumnLimit,
- CommentPragmasRegex);
+BreakableToken::Split
+BreakableBlockComment::getSplitAfterLastLine(unsigned TailOffset,
+ unsigned ColumnLimit) const {
+ if (DelimitersOnNewline) {
+ // Replace the trailing whitespace of the last line with a newline.
+ // In case the last line is empty, the ending '*/' is already on its own
+ // line.
+ StringRef Line = Content.back().substr(TailOffset);
+ StringRef TrimmedLine = Line.rtrim(Blanks);
+ if (!TrimmedLine.empty())
+ return Split(TrimmedLine.size(), Line.size() - TrimmedLine.size());
+ }
return Split(StringRef::npos, 0);
}