clang-tools  15.0.0git
OptionsUtils.cpp
Go to the documentation of this file.
1 //===-- OptionsUtils.cpp - clang-tidy -------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "OptionsUtils.h"
10 #include "llvm/ADT/StringExtras.h"
11 
12 namespace clang {
13 namespace tidy {
14 namespace utils {
15 namespace options {
16 
17 static const char StringsDelimiter[] = ";";
18 
19 std::vector<StringRef> parseStringList(StringRef Option) {
20  Option = Option.trim().trim(StringsDelimiter);
21  if (Option.empty())
22  return {};
23  std::vector<StringRef> Result;
24  Result.reserve(Option.count(StringsDelimiter) + 1);
25  StringRef Cur;
26  while (std::tie(Cur, Option) = Option.split(StringsDelimiter),
27  !Option.empty()) {
28  Cur = Cur.trim();
29  if (!Cur.empty())
30  Result.push_back(Cur);
31  }
32  Cur = Cur.trim();
33  if (!Cur.empty())
34  Result.push_back(Cur);
35  return Result;
36 }
37 
38 std::vector<StringRef> parseListPair(StringRef L, StringRef R) {
39  L = L.trim().trim(StringsDelimiter);
40  if (L.empty())
41  return parseStringList(R);
42  R = R.trim().trim(StringsDelimiter);
43  if (R.empty())
44  return parseStringList(L);
45  std::vector<StringRef> Result;
46  Result.reserve(2 + L.count(StringsDelimiter) + R.count(StringsDelimiter));
47  for (StringRef Option : {L, R}) {
48  StringRef Cur;
49  while (std::tie(Cur, Option) = Option.split(StringsDelimiter),
50  !Option.empty()) {
51  Cur = Cur.trim();
52  if (!Cur.empty())
53  Result.push_back(Cur);
54  }
55  Cur = Cur.trim();
56  if (!Cur.empty())
57  Result.push_back(Cur);
58  }
59  return Result;
60 }
61 
62 std::string serializeStringList(ArrayRef<StringRef> Strings) {
64 }
65 
66 } // namespace options
67 } // namespace utils
68 } // namespace tidy
69 } // namespace clang
clang::tidy::utils::options::parseListPair
std::vector< StringRef > parseListPair(StringRef L, StringRef R)
Definition: OptionsUtils.cpp:38
clang::tidy::cppcoreguidelines::join
static std::string join(ArrayRef< SpecialMemberFunctionsCheck::SpecialMemberFunctionKind > SMFS, llvm::StringRef AndOr)
Definition: SpecialMemberFunctionsCheck.cpp:78
clang::tidy::utils::options::StringsDelimiter
static const char StringsDelimiter[]
Definition: OptionsUtils.cpp:17
OptionsUtils.h
Strings
std::vector< llvm::StringRef > Strings
Definition: Serialization.cpp:213
clang::tidy::utils::options::serializeStringList
std::string serializeStringList(ArrayRef< StringRef > Strings)
Serialize a sequence of names that can be parsed by parseStringList.
Definition: OptionsUtils.cpp:62
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::utils::options::parseStringList
std::vector< StringRef > parseStringList(StringRef Option)
Parse a semicolon separated list of strings.
Definition: OptionsUtils.cpp:19