blob: 1b27f5b30a60393effb6511bdbee899f16842024 [file] [log] [blame]
Eric Liu99eeab72016-10-19 08:19:46 +00001//===--- 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
17namespace clang {
18namespace format {
19
20StringRef 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