add set_nomatch_chars

This commit is contained in:
David Rose 2009-10-09 18:49:49 +00:00
parent f3e620677e
commit f4107d22ac
3 changed files with 35 additions and 3 deletions

View File

@ -125,6 +125,28 @@ get_case_sensitive() const {
return _case_sensitive;
}
////////////////////////////////////////////////////////////////////
// Function: GlobPattern::set_nomatch_chars
// Access: Public
// Description: Specifies a set of characters that are not matched by
// * or ?.
////////////////////////////////////////////////////////////////////
INLINE void GlobPattern::
set_nomatch_chars(const string &nomatch_chars) {
_nomatch_chars = nomatch_chars;
}
////////////////////////////////////////////////////////////////////
// Function: GlobPattern::get_nomatch_chars
// Access: Public
// Description: Returns the set of characters that are not matched by
// * or ?.
////////////////////////////////////////////////////////////////////
INLINE const string &GlobPattern::
get_nomatch_chars() const {
return _nomatch_chars;
}
////////////////////////////////////////////////////////////////////
// Function: GlobPattern::matches
// Access: Public

View File

@ -227,9 +227,15 @@ matches_substr(string::const_iterator pi, string::const_iterator pend,
// to recurse twice: either consume one character of the candidate
// string and continue to try matching the *, or stop trying to
// match the * here.
return
matches_substr(pi, pend, ci + 1, cend) ||
matches_substr(pi + 1, pend, ci, cend);
if (_nomatch_chars.find(*ci) == string::npos) {
return
matches_substr(pi, pend, ci + 1, cend) ||
matches_substr(pi + 1, pend, ci, cend);
} else {
// On the other hand, if this is one of the nomatch chars, we
// can only stop here.
return matches_substr(pi + 1, pend, ci, cend);
}
case '?':
// A '?' in the pattern string means to match exactly one

View File

@ -50,6 +50,9 @@ PUBLISHED:
INLINE void set_case_sensitive(bool case_sensitive);
INLINE bool get_case_sensitive() const;
INLINE void set_nomatch_chars(const string &nomatch_chars);
INLINE const string &get_nomatch_chars() const;
INLINE bool matches(const string &candidate) const;
INLINE void output(ostream &out) const;
@ -73,6 +76,7 @@ private:
string _pattern;
bool _case_sensitive;
string _nomatch_chars;
};
INLINE ostream &operator << (ostream &out, const GlobPattern &glob) {