globPattern.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Filename: globPattern.h
  2. // Created by: drose (30May00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. #ifndef GLOBPATTERN_H
  15. #define GLOBPATTERN_H
  16. #include "ppremake.h"
  17. #include "filename.h"
  18. #include "vector_string.h"
  19. ////////////////////////////////////////////////////////////////////
  20. // Class : GlobPattern
  21. // Description : This class can be used to test for string matches
  22. // against standard Unix-shell filename globbing
  23. // conventions. It serves as a portable standin for the
  24. // Posix fnmatch() call.
  25. //
  26. // A GlobPattern is given a pattern string, which can
  27. // contain operators like *, ?, and []. Then it can be
  28. // tested against any number of candidate strings; for
  29. // each candidate, it will indicate whether the string
  30. // matches the pattern or not. It can be used, for
  31. // example, to scan a directory for all files matching a
  32. // particular pattern.
  33. ////////////////////////////////////////////////////////////////////
  34. class EXPCL_PANDA GlobPattern {
  35. public:
  36. INLINE GlobPattern(const string &pattern = string());
  37. INLINE GlobPattern(const GlobPattern &copy);
  38. INLINE void operator = (const GlobPattern &copy);
  39. INLINE void set_pattern(const string &pattern);
  40. INLINE const string &get_pattern() const;
  41. INLINE bool matches(const string &candidate) const;
  42. INLINE void output(ostream &out) const;
  43. bool has_glob_characters() const;
  44. int match_files(vector_string &results, const Filename &cwd = Filename());
  45. private:
  46. bool matches_substr(string::const_iterator pi,
  47. string::const_iterator pend,
  48. string::const_iterator ci,
  49. string::const_iterator cend) const;
  50. bool matches_set(string::const_iterator &pi,
  51. string::const_iterator pend,
  52. char ch) const;
  53. int r_match_files(const Filename &prefix, const string &suffix,
  54. vector_string &results, const Filename &cwd);
  55. string _pattern;
  56. };
  57. INLINE ostream &operator << (ostream &out, const GlobPattern &glob) {
  58. glob.output(out);
  59. return out;
  60. }
  61. #include "globPattern.I"
  62. #endif