2
0

globPattern.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 "pandabase.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_PANDAEXPRESS 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 void set_case_sensitive(bool case_sensitive);
  46. INLINE bool get_case_sensitive() const;
  47. INLINE bool matches(const string &candidate) const;
  48. INLINE void output(ostream &out) const;
  49. bool has_glob_characters() const;
  50. int match_files(vector_string &results, const Filename &cwd = Filename());
  51. private:
  52. bool matches_substr(string::const_iterator pi,
  53. string::const_iterator pend,
  54. string::const_iterator ci,
  55. string::const_iterator cend) const;
  56. bool matches_set(string::const_iterator &pi,
  57. string::const_iterator pend,
  58. char ch) const;
  59. int r_match_files(const Filename &prefix, const string &suffix,
  60. vector_string &results, const Filename &cwd);
  61. string _pattern;
  62. bool _case_sensitive;
  63. };
  64. INLINE ostream &operator << (ostream &out, const GlobPattern &glob) {
  65. glob.output(out);
  66. return out;
  67. }
  68. #include "globPattern.I"
  69. #endif