aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/CommentBriefParser.cpp
diff options
context:
space:
mode:
authorDmitri Gribenko <gribozavr@gmail.com>2012-06-28 01:38:21 +0000
committerDmitri Gribenko <gribozavr@gmail.com>2012-06-28 01:38:21 +0000
commitd558b5238df74ef3cb76d7125375a5c28fe0eaa9 (patch)
tree5ee6efdb0e2758b9bb98523670935adfa6267074 /lib/AST/CommentBriefParser.cpp
parentda970d2fe086ed44198e1edd5d7d59ff19e747fe (diff)
Cleanup \brief comment. Since it is a single paragraph, no need to save newlines there.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159325 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/CommentBriefParser.cpp')
-rw-r--r--lib/AST/CommentBriefParser.cpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/lib/AST/CommentBriefParser.cpp b/lib/AST/CommentBriefParser.cpp
index f647309246..4040a99924 100644
--- a/lib/AST/CommentBriefParser.cpp
+++ b/lib/AST/CommentBriefParser.cpp
@@ -12,6 +12,34 @@
namespace clang {
namespace comments {
+namespace {
+/// Convert all whitespace into spaces, remove leading and trailing spaces,
+/// compress multiple spaces into one.
+void cleanupBrief(std::string &S) {
+ bool PrevWasSpace = true;
+ std::string::iterator O = S.begin();
+ for (std::string::iterator I = S.begin(), E = S.end();
+ I != E; ++I) {
+ const char C = *I;
+ if (C == ' ' || C == '\n' || C == '\r' ||
+ C == '\t' || C == '\v' || C == '\f') {
+ if (!PrevWasSpace) {
+ *O++ = ' ';
+ PrevWasSpace = true;
+ }
+ continue;
+ } else {
+ *O++ = C;
+ PrevWasSpace = false;
+ }
+ }
+ if (O != S.begin() && *(O - 1) == ' ')
+ --O;
+
+ S.resize(O - S.begin());
+}
+} // unnamed namespace
+
std::string BriefParser::Parse() {
std::string Paragraph;
bool InFirstParagraph = true;
@@ -47,7 +75,7 @@ std::string BriefParser::Parse() {
if (Tok.is(tok::newline)) {
if (InFirstParagraph || InBrief)
- Paragraph += '\n';
+ Paragraph += ' ';
ConsumeToken();
if (Tok.is(tok::newline)) {
@@ -66,6 +94,7 @@ std::string BriefParser::Parse() {
ConsumeToken();
}
+ cleanupBrief(Paragraph);
return Paragraph;
}