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

source code of clang-tools-extra/clang-tidy/utils/OptionsUtils.cpp