1 //===-- OptionsUtils.cpp - clang-tidy -------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "OptionsUtils.h"
10 #include "llvm/ADT/StringExtras.h"
12 namespace clang::tidy::utils::options
{
14 static const char StringsDelimiter
[] = ";";
16 std::vector
<StringRef
> parseStringList(StringRef Option
) {
17 Option
= Option
.trim().trim(StringsDelimiter
);
20 std::vector
<StringRef
> Result
;
21 Result
.reserve(Option
.count(StringsDelimiter
) + 1);
23 while (std::tie(Cur
, Option
) = Option
.split(StringsDelimiter
),
27 Result
.push_back(Cur
);
31 Result
.push_back(Cur
);
35 std::vector
<StringRef
> parseListPair(StringRef L
, StringRef R
) {
36 L
= L
.trim().trim(StringsDelimiter
);
38 return parseStringList(R
);
39 R
= R
.trim().trim(StringsDelimiter
);
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
}) {
46 while (std::tie(Cur
, Option
) = Option
.split(StringsDelimiter
),
50 Result
.push_back(Cur
);
54 Result
.push_back(Cur
);
59 std::string
serializeStringList(ArrayRef
<StringRef
> Strings
) {
60 return llvm::join(Strings
, StringsDelimiter
);
63 } // namespace clang::tidy::utils::options