globPattern.I 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // Filename: globPattern.I
  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. ////////////////////////////////////////////////////////////////////
  15. // Function: GlobPattern::Constructor
  16. // Access: Public
  17. // Description:
  18. ////////////////////////////////////////////////////////////////////
  19. INLINE GlobPattern::
  20. GlobPattern(const string &pattern) : _pattern(pattern) {
  21. _case_sensitive = true;
  22. }
  23. ////////////////////////////////////////////////////////////////////
  24. // Function: GlobPattern::Copy Constructor
  25. // Access: Public
  26. // Description:
  27. ////////////////////////////////////////////////////////////////////
  28. INLINE GlobPattern::
  29. GlobPattern(const GlobPattern &copy) :
  30. _pattern(copy._pattern),
  31. _case_sensitive(copy._case_sensitive)
  32. {
  33. }
  34. ////////////////////////////////////////////////////////////////////
  35. // Function: GlobPattern::Copy Assignment Operator
  36. // Access: Public
  37. // Description:
  38. ////////////////////////////////////////////////////////////////////
  39. INLINE void GlobPattern::
  40. operator = (const GlobPattern &copy) {
  41. _pattern = copy._pattern;
  42. _case_sensitive = copy._case_sensitive;
  43. }
  44. ////////////////////////////////////////////////////////////////////
  45. // Function: GlobPattern::operator ==
  46. // Access: Public
  47. // Description:
  48. ////////////////////////////////////////////////////////////////////
  49. INLINE bool GlobPattern::
  50. operator == (const GlobPattern &other) const {
  51. return (_pattern == other._pattern && _case_sensitive == other._case_sensitive);
  52. }
  53. ////////////////////////////////////////////////////////////////////
  54. // Function: GlobPattern::operator !=
  55. // Access: Public
  56. // Description:
  57. ////////////////////////////////////////////////////////////////////
  58. INLINE bool GlobPattern::
  59. operator != (const GlobPattern &other) const {
  60. return !operator == (other);
  61. }
  62. ////////////////////////////////////////////////////////////////////
  63. // Function: GlobPattern::operator <
  64. // Access: Public
  65. // Description:
  66. ////////////////////////////////////////////////////////////////////
  67. INLINE bool GlobPattern::
  68. operator < (const GlobPattern &other) const {
  69. if (_case_sensitive != other._case_sensitive) {
  70. return (int)_case_sensitive < (int)other._case_sensitive;
  71. }
  72. return _pattern < other._pattern;
  73. }
  74. ////////////////////////////////////////////////////////////////////
  75. // Function: GlobPattern::set_pattern
  76. // Access: Public
  77. // Description: Changes the pattern string that the GlobPattern
  78. // object matches.
  79. ////////////////////////////////////////////////////////////////////
  80. INLINE void GlobPattern::
  81. set_pattern(const string &pattern) {
  82. _pattern = pattern;
  83. }
  84. ////////////////////////////////////////////////////////////////////
  85. // Function: GlobPattern::get_pattern
  86. // Access: Public
  87. // Description: Returns the pattern string that the GlobPattern
  88. // object matches.
  89. ////////////////////////////////////////////////////////////////////
  90. INLINE const string &GlobPattern::
  91. get_pattern() const {
  92. return _pattern;
  93. }
  94. ////////////////////////////////////////////////////////////////////
  95. // Function: GlobPattern::set_case_sensitive
  96. // Access: Public
  97. // Description: Sets whether the match is case sensitive (true) or
  98. // case insensitive (false). The default is case
  99. // sensitive.
  100. ////////////////////////////////////////////////////////////////////
  101. INLINE void GlobPattern::
  102. set_case_sensitive(bool case_sensitive) {
  103. _case_sensitive = case_sensitive;
  104. }
  105. ////////////////////////////////////////////////////////////////////
  106. // Function: GlobPattern::get_case_sensitive
  107. // Access: Public
  108. // Description: Returns whether the match is case sensitive (true) or
  109. // case insensitive (false). The default is case
  110. // sensitive.
  111. ////////////////////////////////////////////////////////////////////
  112. INLINE bool GlobPattern::
  113. get_case_sensitive() const {
  114. return _case_sensitive;
  115. }
  116. ////////////////////////////////////////////////////////////////////
  117. // Function: GlobPattern::set_nomatch_chars
  118. // Access: Public
  119. // Description: Specifies a set of characters that are not matched by
  120. // * or ?.
  121. ////////////////////////////////////////////////////////////////////
  122. INLINE void GlobPattern::
  123. set_nomatch_chars(const string &nomatch_chars) {
  124. _nomatch_chars = nomatch_chars;
  125. }
  126. ////////////////////////////////////////////////////////////////////
  127. // Function: GlobPattern::get_nomatch_chars
  128. // Access: Public
  129. // Description: Returns the set of characters that are not matched by
  130. // * or ?.
  131. ////////////////////////////////////////////////////////////////////
  132. INLINE const string &GlobPattern::
  133. get_nomatch_chars() const {
  134. return _nomatch_chars;
  135. }
  136. ////////////////////////////////////////////////////////////////////
  137. // Function: GlobPattern::matches
  138. // Access: Public
  139. // Description: Returns true if the candidate string matches the
  140. // pattern, false otherwise.
  141. ////////////////////////////////////////////////////////////////////
  142. INLINE bool GlobPattern::
  143. matches(const string &candidate) const {
  144. return matches_substr(_pattern.begin(), _pattern.end(),
  145. candidate.begin(), candidate.end());
  146. }
  147. ////////////////////////////////////////////////////////////////////
  148. // Function: GlobPattern::output
  149. // Access: Public
  150. // Description:
  151. ////////////////////////////////////////////////////////////////////
  152. INLINE void GlobPattern::
  153. output(ostream &out) const {
  154. out << _pattern;
  155. }