globPattern.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 bool operator == (const GlobPattern &other) const;
  40. INLINE bool operator != (const GlobPattern &other) const;
  41. INLINE bool operator < (const GlobPattern &other) const;
  42. INLINE void set_pattern(const string &pattern);
  43. INLINE const string &get_pattern() const;
  44. INLINE void set_case_sensitive(bool case_sensitive);
  45. INLINE bool get_case_sensitive() const;
  46. INLINE void set_nomatch_chars(const string &nomatch_chars);
  47. INLINE const string &get_nomatch_chars() const;
  48. INLINE bool matches(const string &candidate) const;
  49. INLINE void output(ostream &out) const;
  50. bool has_glob_characters() const;
  51. string get_const_prefix() const;
  52. int match_files(vector_string &results, const Filename &cwd = Filename());
  53. private:
  54. bool matches_substr(string::const_iterator pi,
  55. string::const_iterator pend,
  56. string::const_iterator ci,
  57. string::const_iterator cend) const;
  58. bool matches_set(string::const_iterator &pi,
  59. string::const_iterator pend,
  60. char ch) const;
  61. int r_match_files(const Filename &prefix, const string &suffix,
  62. vector_string &results, const Filename &cwd);
  63. string _pattern;
  64. bool _case_sensitive;
  65. string _nomatch_chars;
  66. };
  67. INLINE ostream &operator << (ostream &out, const GlobPattern &glob) {
  68. glob.output(out);
  69. return out;
  70. }
  71. #include "globPattern.I"
  72. #endif