From f4107d22ac400ff78da33053f5a376f857ea2e96 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 9 Oct 2009 18:49:49 +0000 Subject: [PATCH] add set_nomatch_chars --- dtool/src/prc/globPattern.I | 22 ++++++++++++++++++++++ dtool/src/prc/globPattern.cxx | 12 +++++++++--- dtool/src/prc/globPattern.h | 4 ++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/dtool/src/prc/globPattern.I b/dtool/src/prc/globPattern.I index 43891a9266..72d0c7e118 100644 --- a/dtool/src/prc/globPattern.I +++ b/dtool/src/prc/globPattern.I @@ -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 diff --git a/dtool/src/prc/globPattern.cxx b/dtool/src/prc/globPattern.cxx index c24c2c96a3..911bc47c81 100644 --- a/dtool/src/prc/globPattern.cxx +++ b/dtool/src/prc/globPattern.cxx @@ -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 diff --git a/dtool/src/prc/globPattern.h b/dtool/src/prc/globPattern.h index 7500a9b413..af03539a10 100644 --- a/dtool/src/prc/globPattern.h +++ b/dtool/src/prc/globPattern.h @@ -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) {