1 //===-- GlobPattern.h - glob pattern matcher implementation -*- 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 // 9 // This file implements a glob pattern matcher. The glob pattern is the 10 // rule used by the shell. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_SUPPORT_GLOB_PATTERN_H 15 #define LLVM_SUPPORT_GLOB_PATTERN_H 16 17 #include "llvm/ADT/BitVector.h" 18 #include "llvm/ADT/Optional.h" 19 #include "llvm/ADT/StringRef.h" 20 #include "llvm/Support/Error.h" 21 #include <vector> 22 23 // This class represents a glob pattern. Supported metacharacters 24 // are "*", "?", "\", "[<chars>]", "[^<chars>]", and "[!<chars>]". 25 namespace llvm { 26 class BitVector; 27 template <typename T> class ArrayRef; 28 29 class GlobPattern { 30 public: 31 static Expected<GlobPattern> create(StringRef Pat); 32 bool match(StringRef S) const; 33 34 private: 35 bool matchOne(ArrayRef<BitVector> Pat, StringRef S) const; 36 37 // Parsed glob pattern. 38 std::vector<BitVector> Tokens; 39 40 // The following members are for optimization. 41 Optional<StringRef> Exact; 42 Optional<StringRef> Prefix; 43 Optional<StringRef> Suffix; 44 }; 45 } 46 47 #endif // LLVM_SUPPORT_GLOB_PATTERN_H 48