globPattern.h 2.7 KB

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