15 #include "globPattern.h" 27 string::const_iterator pi;
28 pi = _pattern.begin();
29 while (pi != _pattern.end()) {
38 if (pi == _pattern.end()) {
62 while (p < _pattern.size()) {
63 switch (_pattern[p]) {
67 return prefix + _pattern.substr(q, p - q);
71 prefix += _pattern.substr(q, p - q);
77 return prefix += _pattern.substr(q, p - q);
100 string prefix, pattern, suffix;
102 string source = _pattern;
103 if (!source.empty() && source[0] ==
'/') {
106 source = source.substr(1);
109 size_t slash = source.find(
'/');
110 if (slash == string::npos) {
113 pattern = source.substr(0, slash);
114 suffix = source.substr(slash + 1);
119 return glob.r_match_files(prefix, suffix, results, cwd);
128 r_match_files(
const Filename &prefix,
const string &suffix,
129 vector_string &results,
const Filename &cwd) {
130 string next_pattern, next_suffix;
132 size_t slash = suffix.find(
'/');
133 if (slash == string::npos) {
134 next_pattern = suffix;
136 next_pattern = suffix.substr(0, slash);
137 next_suffix = suffix.substr(slash + 1);
141 if (prefix.
is_local() && !cwd.empty()) {
153 if (suffix.empty()) {
155 Filename single_filename(parent_dir, _pattern);
156 if (single_filename.
exists()) {
157 results.push_back(
Filename(prefix, _pattern));
163 return next_glob.r_match_files(
Filename(prefix, _pattern),
164 next_suffix, results, cwd);
171 vector_string dir_files;
181 vector_string::const_iterator fi;
182 for (fi = dir_files.begin(); fi != dir_files.end(); ++fi) {
183 const string &local_file = (*fi);
184 if (_pattern[0] ==
'.' || (local_file.empty() || local_file[0] !=
'.')) {
187 if (suffix.empty()) {
188 results.push_back(
Filename(prefix, local_file));
191 num_matched += next_glob.r_match_files(
Filename(prefix, local_file),
192 next_suffix, results, cwd);
210 matches_substr(string::const_iterator pi, string::const_iterator pend,
211 string::const_iterator ci, string::const_iterator cend)
const {
214 if (pi == pend || ci == cend) {
218 if ((ci == cend) && (std::distance(pi, pend) == 1) && (*pi) ==
'*') {
221 return (pi == pend && ci == cend);
232 if (_nomatch_chars.find(*ci) == string::npos) {
234 matches_substr(pi, pend, ci + 1, cend) ||
235 matches_substr(pi + 1, pend, ci, cend);
239 return matches_substr(pi + 1, pend, ci, cend);
245 return matches_substr(pi + 1, pend, ci + 1, cend);
252 if (matches_set(pi, pend, *ci)) {
256 if (!matches_set(pi, pend, *ci)) {
264 return matches_substr(pi + 1, pend, ci + 1, cend);
276 if (_case_sensitive) {
277 if ((*pi) != (*ci)) {
281 if (tolower(*pi) != tolower(*ci)) {
285 return matches_substr(pi + 1, pend, ci + 1, cend);
301 matches_set(string::const_iterator &pi, string::const_iterator pend,
303 bool matched =
false;
305 while (pi != pend && (*pi) !=
']') {
321 if (pi != pend && (*pi) ==
'-') {
323 if (pi != pend && (*pi) !=
']') {
337 if ((ch >= start && ch <= end) ||
339 ((tolower(ch) >= start && tolower(ch) <= end) ||
340 (toupper(ch) >= start && toupper(ch) <= end)))) {
bool matches(const string &candidate) const
Returns true if the candidate string matches the pattern, false otherwise.
bool has_glob_characters() const
Returns true if the pattern includes any special globbing characters, or false if it is just a litera...
void set_case_sensitive(bool case_sensitive)
Sets whether the match is case sensitive (true) or case insensitive (false).
The name of a file, such as a texture file or an Egg file.
string get_const_prefix() const
Returns the initial part of the pattern before the first glob character.
int match_files(vector_string &results, const Filename &cwd=Filename()) const
Treats the GlobPattern as a filename pattern, and returns a list of any actual files that match the p...
bool is_local() const
Returns true if the filename is local, e.g.
bool scan_directory(vector_string &contents) const
Attempts to open the named filename as if it were a directory and looks for the non-hidden files with...
bool exists() const
Returns true if the filename exists on the disk, false otherwise.
This class can be used to test for string matches against standard Unix-shell filename globbing conve...