summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Comments.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Format/Comments.cpp')
-rw-r--r--clang/lib/Format/Comments.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/clang/lib/Format/Comments.cpp b/clang/lib/Format/Comments.cpp
new file mode 100644
index 00000000000..1b27f5b30a6
--- /dev/null
+++ b/clang/lib/Format/Comments.cpp
@@ -0,0 +1,36 @@
+//===--- Comments.cpp - Comment Manipulation -------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Implements comment manipulation.
+///
+//===----------------------------------------------------------------------===//
+
+#include "Comments.h"
+
+namespace clang {
+namespace format {
+
+StringRef getLineCommentIndentPrefix(StringRef Comment) {
+ static const char *const KnownPrefixes[] = {"///", "//", "//!"};
+ StringRef LongestPrefix;
+ 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);
+ }
+ }
+ return LongestPrefix;
+}
+
+} // namespace format
+} // namespace clang
OpenPOWER on IntegriCloud