• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- GlobPattern.h - glob pattern matcher implementation -*- C++ -*-----===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements a glob pattern matcher. The glob pattern is the
11 // rule used by the shell.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_SUPPORT_GLOB_PATTERN_H
16 #define LLVM_SUPPORT_GLOB_PATTERN_H
17 
18 #include "llvm/ADT/BitVector.h"
19 #include "llvm/ADT/Optional.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/Support/Error.h"
22 #include <vector>
23 
24 // This class represents a glob pattern. Supported metacharacters
25 // are "*", "?", "[<chars>]" and "[^<chars>]".
26 namespace llvm {
27 class BitVector;
28 template <typename T> class ArrayRef;
29 
30 class GlobPattern {
31 public:
32   static Expected<GlobPattern> create(StringRef Pat);
33   bool match(StringRef S) const;
34 
35 private:
36   bool matchOne(ArrayRef<BitVector> Pat, StringRef S) const;
37 
38   // Parsed glob pattern.
39   std::vector<BitVector> Tokens;
40 
41   // The following members are for optimization.
42   Optional<StringRef> Exact;
43   Optional<StringRef> Prefix;
44   Optional<StringRef> Suffix;
45 };
46 }
47 
48 #endif // LLVM_SUPPORT_GLOB_PATTERN_H
49