patternMatcher.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_BASE_TF_PATTERN_MATCHER_H
8 #define PXR_BASE_TF_PATTERN_MATCHER_H
9 
13 
14 #include "pxr/pxr.h"
15 #include "pxr/base/tf/api.h"
16 #include "pxr/base/arch/regex.h"
17 
18 #include <string>
19 
20 PXR_NAMESPACE_OPEN_SCOPE
21 
32 {
33 
34  public:
35 
37  TF_API TfPatternMatcher();
38 
39  TF_API TfPatternMatcher(TfPatternMatcher &&) noexcept = default;
40  TF_API TfPatternMatcher& operator=(TfPatternMatcher &&) = default;
41 
45  TF_API
46  TfPatternMatcher( const std::string &pattern,
47  bool caseSensitive = false,
48  bool isGlob = false );
49 
51  TF_API ~TfPatternMatcher();
52 
54  TF_API std::string GetInvalidReason() const;
55 
58  bool IsCaseSensitive() const {
59  return _caseSensitive;
60  }
61 
64  bool IsGlobPattern() const {
65  return _isGlob;
66  }
67 
69  TF_API const std::string& GetPattern() const {
70  return _pattern;
71  }
72 
75  TF_API bool IsValid() const;
76 
89  TF_API bool Match( const std::string &query,
90  std::string *errorMsg = NULL ) const;
91 
93  TF_API void SetIsCaseSensitive( bool sensitive );
94 
99  TF_API void SetIsGlobPattern( bool isGlob );
100 
102  TF_API void SetPattern( const std::string &pattern );
103 
104  private:
105  void _Compile() const;
106 
107  bool _caseSensitive;
108  bool _isGlob;
109  std::string _pattern;
110  mutable bool _recompile;
111  mutable ArchRegex _regex;
112 
113 };
114 
115 PXR_NAMESPACE_CLOSE_SCOPE
116 
117 #endif // PXR_BASE_TF_PATTERN_MATCHER_H
bool IsCaseSensitive() const
Returns true if the matcher has been set to be case sensitive, false otherwise.
TF_API void SetIsGlobPattern(bool isGlob)
Set this matcher to treat its pattern as a glob pattern.
TF_API const std::string & GetPattern() const
Returns the matcher's pattern string.
TF_API std::string GetInvalidReason() const
If IsValid() returns true, this will return the reason why (if any).
TF_API void SetIsCaseSensitive(bool sensitive)
Set this matcher to match case-sensitively or not.
TF_API TfPatternMatcher()
Construct an empty (invalid) TfPatternMatcher.
TF_API bool Match(const std::string &query, std::string *errorMsg=NULL) const
Returns true if query matches the matcher's pattern.
TF_API bool IsValid() const
Returns true if the matcher has a valid pattern.
TF_API ~TfPatternMatcher()
Destructor.
TF_API void SetPattern(const std::string &pattern)
Set the pattern that this matcher will use to match against.
Class for matching regular expressions.
bool IsGlobPattern() const
Returns true if the matcher has been set to treat patterns as glob patterns, false otherwise.