blob: c9436a13c1a3d91ec3a31b7f1185ebc5e3dbe7bd [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===-- 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>]".
26namespace llvm {
27class BitVector;
28template <typename T> class ArrayRef;
29
30class GlobPattern {
31public:
32 static Expected<GlobPattern> create(StringRef Pat);
33 bool match(StringRef S) const;
34
35private:
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