|
Class for matching regular expressions. More...
#include <patternMatcher.h>
Public Member Functions | |
TF_API | TfPatternMatcher () |
Construct an empty (invalid) TfPatternMatcher. | |
TF_API | TfPatternMatcher (TfPatternMatcher &&) noexcept=default |
TF_API TfPatternMatcher & | operator= (TfPatternMatcher &&)=default |
TF_API | TfPatternMatcher (const std::string &pattern, bool caseSensitive=false, bool isGlob=false) |
Construct a TfPatternMatcher with a default configuration. | |
TF_API | ~TfPatternMatcher () |
Destructor. | |
TF_API std::string | GetInvalidReason () const |
If IsValid() returns true, this will return the reason why (if any). | |
bool | IsCaseSensitive () const |
Returns true if the matcher has been set to be case sensitive, false otherwise. | |
bool | IsGlobPattern () const |
Returns true if the matcher has been set to treat patterns as glob patterns, false otherwise. | |
TF_API const std::string & | GetPattern () const |
Returns the matcher's pattern string. | |
TF_API bool | IsValid () const |
Returns true if the matcher has a valid pattern. | |
TF_API bool | Match (const std::string &query, std::string *errorMsg=NULL) const |
Returns true if query matches the matcher's pattern. | |
TF_API void | SetIsCaseSensitive (bool sensitive) |
Set this matcher to match case-sensitively or not. | |
TF_API void | SetIsGlobPattern (bool isGlob) |
Set this matcher to treat its pattern as a glob pattern. | |
TF_API void | SetPattern (const std::string &pattern) |
Set the pattern that this matcher will use to match against. | |
Class for matching regular expressions.
A matcher is good to use when you have many strings to match against one pattern. This is because the matcher will only compile the regular expression once.
Definition at line 31 of file patternMatcher.h.
TF_API TfPatternMatcher | ( | ) |
Construct an empty (invalid) TfPatternMatcher.
TF_API TfPatternMatcher | ( | const std::string & | pattern, |
bool | caseSensitive = false , |
||
bool | isGlob = false |
||
) |
Construct a TfPatternMatcher with a default configuration.
Note that pattern compilation will not occur until the first call to Match() or IsValid().
TF_API ~TfPatternMatcher | ( | ) |
Destructor.
TF_API std::string GetInvalidReason | ( | ) | const |
If IsValid() returns true, this will return the reason why (if any).
|
inline |
Returns the matcher's pattern string.
Definition at line 69 of file patternMatcher.h.
|
inline |
Returns true if the matcher has been set to be case sensitive, false otherwise.
Definition at line 58 of file patternMatcher.h.
|
inline |
Returns true if the matcher has been set to treat patterns as glob patterns, false otherwise.
Definition at line 64 of file patternMatcher.h.
TF_API bool IsValid | ( | ) | const |
Returns true if the matcher has a valid pattern.
Note that empty patterns are considered invalid. This will cause a compile of
TF_API bool Match | ( | const std::string & | query, |
std::string * | errorMsg = NULL |
||
) | const |
Returns true if query matches the matcher's pattern.
If there is an error in matching and errorMsg is not NULL, it will be set with the error message. If the matcher is not valid, this will return false. Note that this will cause a compile of the matcher's pattern if it was not already compiled.
TF_API void SetIsCaseSensitive | ( | bool | sensitive | ) |
Set this matcher to match case-sensitively or not.
TF_API void SetIsGlobPattern | ( | bool | isGlob | ) |
Set this matcher to treat its pattern as a glob pattern.
Currently, this means that the pattern will be transformed by replacing all instances of '.' with '.', '*' with '.*', and '?' with '.', in that order before being compiled as a normal regular expression.
TF_API void SetPattern | ( | const std::string & | pattern | ) |
Set the pattern that this matcher will use to match against.