diff options
author | Eric Liu <ioeric@google.com> | 2016-10-19 08:19:46 +0000 |
---|---|---|
committer | Eric Liu <ioeric@google.com> | 2016-10-19 08:19:46 +0000 |
commit | 99eeab7ff3aca9a2e0827349b5ce2e7c71a69373 (patch) | |
tree | 71652a10b661bb04dbe7832be0b200f6a878c524 /clang/lib/Format/Comments.cpp | |
parent | 3f5111d363b4b4829445e8b251cf28b9bd53164e (diff) | |
download | bcm5719-llvm-99eeab7ff3aca9a2e0827349b5ce2e7c71a69373.tar.gz bcm5719-llvm-99eeab7ff3aca9a2e0827349b5ce2e7c71a69373.zip |
[clang-format] Add comment manipulation header
Summary:
Introduces a separate target for comment manipulation.
Currently, comment manipulation is in BreakableComment.cpp.
Towards implementing comment reflowing, we want to factor out the
comment-related functionality, so it can be reused.
Start simple by just moving out getLineCommentIndentPrefix.
Patch by Krasimir Georgiev!
Reviewers: djasper
Subscribers: klimek, beanz, mgorny, modocache
Differential Revision: https://reviews.llvm.org/D25725
llvm-svn: 284573
Diffstat (limited to 'clang/lib/Format/Comments.cpp')
-rw-r--r-- | clang/lib/Format/Comments.cpp | 36 |
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 |