[AMDGPU][AsmParser][NFC] Translate parsed MIMG instructions to MCInsts automatically.
[llvm-project.git] / clang-tools-extra / clang-tidy / utils / OptionsUtils.cpp
blob1866ea3f5b58ae55c7c521425c01e0ec30d9f760
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 //===----------------------------------------------------------------------===//
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);
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);
29 Cur = Cur.trim();
30 if (!Cur.empty())
31 Result.push_back(Cur);
32 return Result;
35 std::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);
52 Cur = Cur.trim();
53 if (!Cur.empty())
54 Result.push_back(Cur);
56 return Result;
59 std::string serializeStringList(ArrayRef<StringRef> Strings) {
60 return llvm::join(Strings, StringsDelimiter);
63 } // namespace clang::tidy::utils::options