clang-tools 20.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
13
14static const char StringsDelimiter[] = ";";
15
16std::vector<StringRef> parseStringList(StringRef Option) {
17 Option = Option.trim().trim(StringsDelimiter);
18 if (Option.empty())
19 return {};
20 std::vector<StringRef> Result;
21 Result.reserve(Option.count(StringsDelimiter) + 1);
22 StringRef Cur;
23 while (std::tie(Cur, Option) = Option.split(StringsDelimiter),
24 !Option.empty()) {
25 Cur = Cur.trim();
26 if (!Cur.empty())
27 Result.push_back(Cur);
28 }
29 Cur = Cur.trim();
30 if (!Cur.empty())
31 Result.push_back(Cur);
32 return Result;
33}
34
35std::vector<StringRef> parseListPair(StringRef L, StringRef R) {
36 L = L.trim().trim(StringsDelimiter);
37 if (L.empty())
38 return parseStringList(R);
39 R = R.trim().trim(StringsDelimiter);
40 if (R.empty())
41 return parseStringList(L);
42 std::vector<StringRef> Result;
43 Result.reserve(2 + L.count(StringsDelimiter) + R.count(StringsDelimiter));
44 for (StringRef Option : {L, R}) {
45 StringRef Cur;
46 while (std::tie(Cur, Option) = Option.split(StringsDelimiter),
47 !Option.empty()) {
48 Cur = Cur.trim();
49 if (!Cur.empty())
50 Result.push_back(Cur);
51 }
52 Cur = Cur.trim();
53 if (!Cur.empty())
54 Result.push_back(Cur);
55 }
56 return Result;
57}
58
59std::string serializeStringList(ArrayRef<StringRef> Strings) {
60 return llvm::join(Strings, StringsDelimiter);
61}
62
63} // namespace clang::tidy::utils::options
std::vector< llvm::StringRef > Strings
std::string serializeStringList(ArrayRef< StringRef > Strings)
Serialize a sequence of names that can be parsed by parseStringList.
static const char StringsDelimiter[]
std::vector< StringRef > parseListPair(StringRef L, StringRef R)
std::vector< StringRef > parseStringList(StringRef Option)
Parse a semicolon separated list of strings.