Panda3D
|
00001 // Filename: globPattern.h 00002 // Created by: drose (30May00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef GLOBPATTERN_H 00016 #define GLOBPATTERN_H 00017 00018 #include "dtoolbase.h" 00019 #include "filename.h" 00020 #include "vector_string.h" 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Class : GlobPattern 00024 // Description : This class can be used to test for string matches 00025 // against standard Unix-shell filename globbing 00026 // conventions. It serves as a portable standin for the 00027 // Posix fnmatch() call. 00028 // 00029 // A GlobPattern is given a pattern string, which can 00030 // contain operators like *, ?, and []. Then it can be 00031 // tested against any number of candidate strings; for 00032 // each candidate, it will indicate whether the string 00033 // matches the pattern or not. It can be used, for 00034 // example, to scan a directory for all files matching a 00035 // particular pattern. 00036 //////////////////////////////////////////////////////////////////// 00037 class EXPCL_DTOOL GlobPattern { 00038 PUBLISHED: 00039 INLINE GlobPattern(const string &pattern = string()); 00040 INLINE GlobPattern(const GlobPattern ©); 00041 INLINE void operator = (const GlobPattern ©); 00042 00043 INLINE bool operator == (const GlobPattern &other) const; 00044 INLINE bool operator != (const GlobPattern &other) const; 00045 INLINE bool operator < (const GlobPattern &other) const; 00046 00047 INLINE void set_pattern(const string &pattern); 00048 INLINE const string &get_pattern() const; 00049 00050 INLINE void set_case_sensitive(bool case_sensitive); 00051 INLINE bool get_case_sensitive() const; 00052 00053 INLINE void set_nomatch_chars(const string &nomatch_chars); 00054 INLINE const string &get_nomatch_chars() const; 00055 00056 INLINE bool matches(const string &candidate) const; 00057 00058 INLINE void output(ostream &out) const; 00059 00060 bool has_glob_characters() const; 00061 string get_const_prefix() const; 00062 int match_files(vector_string &results, const Filename &cwd = Filename()) const; 00063 #ifdef HAVE_PYTHON 00064 PyObject *match_files(const Filename &cwd = Filename()) const; 00065 #endif 00066 00067 private: 00068 bool matches_substr(string::const_iterator pi, 00069 string::const_iterator pend, 00070 string::const_iterator ci, 00071 string::const_iterator cend) const; 00072 00073 bool matches_set(string::const_iterator &pi, 00074 string::const_iterator pend, 00075 char ch) const; 00076 00077 int r_match_files(const Filename &prefix, const string &suffix, 00078 vector_string &results, const Filename &cwd); 00079 00080 string _pattern; 00081 bool _case_sensitive; 00082 string _nomatch_chars; 00083 }; 00084 00085 INLINE ostream &operator << (ostream &out, const GlobPattern &glob) { 00086 glob.output(out); 00087 return out; 00088 } 00089 00090 00091 #include "globPattern.I" 00092 00093 #endif