LLVM 20.0.0git
OptionStrCmp.cpp
Go to the documentation of this file.
1//===- OptionStrCmp.cpp - Option String Comparison --------------*- C++ -*-===//
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
10#include "llvm/ADT/STLExtras.h"
11
12using namespace llvm;
13
14// Comparison function for Option strings (option names & prefixes).
15// The ordering is *almost* case-insensitive lexicographic, with an exception.
16// '\0' comes at the end of the alphabet instead of the beginning (thus options
17// precede any other options which prefix them). Additionally, if two options
18// are identical ignoring case, they are ordered according to case sensitive
19// ordering if `FallbackCaseSensitive` is true.
21 bool FallbackCaseSensitive) {
22 size_t MinSize = std::min(A.size(), B.size());
23 if (int Res = A.substr(0, MinSize).compare_insensitive(B.substr(0, MinSize)))
24 return Res;
25
26 // If they are identical ignoring case, use case sensitive ordering.
27 if (A.size() == B.size())
28 return FallbackCaseSensitive ? A.compare(B) : 0;
29
30 return (A.size() == MinSize) ? 1 /* A is a prefix of B. */
31 : -1 /* B is a prefix of A */;
32}
33
34// Comparison function for Option prefixes.
36 ArrayRef<StringRef> BPrefixes) {
37 for (const auto &[APre, BPre] : zip(APrefixes, BPrefixes)) {
38 if (int Cmp = StrCmpOptionName(APre, BPre))
39 return Cmp;
40 }
41 // Both prefixes are identical.
42 return 0;
43}
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains some templates that are useful if you are working with the STL at all.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&...args)
zip iterator for two or more iteratable types.
Definition: STLExtras.h:854
int StrCmpOptionName(StringRef A, StringRef B, bool FallbackCaseSensitive=true)
int StrCmpOptionPrefixes(ArrayRef< StringRef > APrefixes, ArrayRef< StringRef > BPrefixes)