forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobPattern.h
More file actions
93 lines (75 loc) · 3.1 KB
/
globPattern.h
File metadata and controls
93 lines (75 loc) · 3.1 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file globPattern.h
* @author drose
* @date 2000-05-30
*/
#ifndef GLOBPATTERN_H
#define GLOBPATTERN_H
#include "dtoolbase.h"
#include "filename.h"
#include "vector_string.h"
/**
* This class can be used to test for string matches against standard Unix-
* shell filename globbing conventions. It serves as a portable standin for
* the Posix fnmatch() call.
*
* A GlobPattern is given a pattern string, which can contain operators like
* *, ?, and []. Then it can be tested against any number of candidate
* strings; for each candidate, it will indicate whether the string matches
* the pattern or not. It can be used, for example, to scan a directory for
* all files matching a particular pattern.
*/
class EXPCL_DTOOL_DTOOLUTIL GlobPattern {
PUBLISHED:
INLINE GlobPattern(const std::string &pattern = std::string());
INLINE GlobPattern(const GlobPattern ©);
INLINE void operator = (const GlobPattern ©);
INLINE bool operator == (const GlobPattern &other) const;
INLINE bool operator != (const GlobPattern &other) const;
INLINE bool operator < (const GlobPattern &other) const;
INLINE void set_pattern(const std::string &pattern);
INLINE const std::string &get_pattern() const;
MAKE_PROPERTY(pattern, get_pattern, set_pattern);
INLINE void set_case_sensitive(bool case_sensitive);
INLINE bool get_case_sensitive() const;
MAKE_PROPERTY(case_sensitive, get_case_sensitive, set_case_sensitive);
INLINE void set_nomatch_chars(const std::string &nomatch_chars);
INLINE const std::string &get_nomatch_chars() const;
MAKE_PROPERTY(nomatch_chars, get_nomatch_chars, set_nomatch_chars);
INLINE bool matches(const std::string &candidate) const;
bool matches_file(Filename candidate) const;
INLINE void output(std::ostream &out) const;
bool has_glob_characters() const;
std::string get_const_prefix() const;
int match_files(vector_string &results, const Filename &cwd = Filename()) const;
#ifdef HAVE_PYTHON
EXTENSION(PyObject *match_files(const Filename &cwd = Filename()) const);
#endif
private:
bool matches_substr(std::string::const_iterator pi,
std::string::const_iterator pend,
std::string::const_iterator ci,
std::string::const_iterator cend) const;
bool matches_set(std::string::const_iterator &pi,
std::string::const_iterator pend,
char ch) const;
int r_match_files(const Filename &prefix, const std::string &suffix,
vector_string &results, const Filename &cwd);
bool r_matches_file(const std::string &suffix, const Filename &candidate) const;
std::string _pattern;
bool _case_sensitive;
std::string _nomatch_chars;
};
INLINE std::ostream &operator << (std::ostream &out, const GlobPattern &glob) {
glob.output(out);
return out;
}
#include "globPattern.I"
#endif