-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathwildcard.h
75 lines (59 loc) · 1.61 KB
/
wildcard.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (c) 2010, The Toft Authors.
// All rights reserved.
//
// Author: CHEN Feng <[email protected]>
#ifndef TOFT_TEXT_WILDCARD_H
#define TOFT_TEXT_WILDCARD_H
#include <string>
namespace toft {
// Wildcard match static class
struct Wildcard {
private:
Wildcard();
~Wildcard();
public:
enum MatchFlags
{
// Wildcards in string cannot match `/', match filename only
// *.c not match dir/name.c
MATCH_FILE_NAME_ONLY = 1<<0,
// Don't treat the `\' character as escape
NO_ESCAPE = 1<<1,
// Not match `.' as the first character of string
MATCH_PERIOD = 1<<2,
// Match leading dir part
MATCH_LEADING_DIR = 1<<3,
// Ignore case
// *.c match filename.C
IGNORE_CASE = 1<<4,
};
public:
// Wildcard match
// @param pattern wildcard string to be matched
// @param string string to match
// @param flags MatchFlags combination
static bool Match(const char* pattern, const char* string, int flags = 0);
static bool Match(
const std::string& pattern,
const std::string& string,
int flags = 0)
{
return Match(pattern.c_str(), string.c_str(), flags);
}
static bool Match(
const std::string& pattern,
const char* string,
int flags = 0)
{
return Match(pattern.c_str(), string, flags);
}
static bool Match(
const char* pattern,
const std::string& string,
int flags = 0)
{
return Match(pattern, string.c_str(), flags);
}
};
} // namespace toft
#endif // TOFT_TEXT_WILDCARD_H