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_DTOOLCONFIG 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()); 00063 00064 private: 00065 bool matches_substr(string::const_iterator pi, 00066 string::const_iterator pend, 00067 string::const_iterator ci, 00068 string::const_iterator cend) const; 00069 00070 bool matches_set(string::const_iterator &pi, 00071 string::const_iterator pend, 00072 char ch) const; 00073 00074 int r_match_files(const Filename &prefix, const string &suffix, 00075 vector_string &results, const Filename &cwd); 00076 00077 string _pattern; 00078 bool _case_sensitive; 00079 string _nomatch_chars; 00080 }; 00081 00082 INLINE ostream &operator << (ostream &out, const GlobPattern &glob) { 00083 glob.output(out); 00084 return out; 00085 } 00086 00087 00088 #include "globPattern.I" 00089 00090 #endif