| Eric Liu | 99eeab7 | 2016-10-19 08:19:46 +0000 | [diff] [blame] | 1 | //===--- Comments.cpp - Comment Manipulation -------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// |
| 10 | /// \file |
| 11 | /// \brief Implements comment manipulation. |
| 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "Comments.h" |
| 16 | |
| 17 | namespace clang { |
| 18 | namespace format { |
| 19 | |
| 20 | StringRef getLineCommentIndentPrefix(StringRef Comment) { |
| 21 | static const char *const KnownPrefixes[] = {"///", "//", "//!"}; |
| 22 | StringRef LongestPrefix; |
| 23 | for (StringRef KnownPrefix : KnownPrefixes) { |
| 24 | if (Comment.startswith(KnownPrefix)) { |
| 25 | size_t PrefixLength = KnownPrefix.size(); |
| 26 | while (PrefixLength < Comment.size() && Comment[PrefixLength] == ' ') |
| 27 | ++PrefixLength; |
| 28 | if (PrefixLength > LongestPrefix.size()) |
| 29 | LongestPrefix = Comment.substr(0, PrefixLength); |
| 30 | } |
| 31 | } |
| 32 | return LongestPrefix; |
| 33 | } |
| 34 | |
| 35 | } // namespace format |
| 36 | } // namespace clang |