All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TfPatternMatcher Class Reference

Class for matching regular expressions. More...

Public Member Functions

TF_API TfPatternMatcher ()
 Construct an empty (invalid) TfPatternMatcher. More...
 
TF_API TfPatternMatcher (TfPatternMatcher &&) noexcept=default
 
TF_API TfPatternMatcheroperator= (TfPatternMatcher &&)=default
 
TF_API TfPatternMatcher (const std::string &pattern, bool caseSensitive=false, bool isGlob=false)
 Construct a TfPatternMatcher with a default configuration. More...
 
TF_API ~TfPatternMatcher ()
 Destructor. More...
 
TF_API std::string GetInvalidReason () const
 If IsValid() returns true, this will return the reason why (if any). More...
 
bool IsCaseSensitive () const
 Returns true if the matcher has been set to be case sensitive, false otherwise. More...
 
bool IsGlobPattern () const
 Returns true if the matcher has been set to treat patterns as glob patterns, false otherwise. More...
 
TF_API const std::string & GetPattern () const
 Returns the matcher's pattern string. More...
 
TF_API bool IsValid () const
 Returns true if the matcher has a valid pattern. More...
 
TF_API bool Match (const std::string &query, std::string *errorMsg=NULL) const
 Returns true if query matches the matcher's pattern. More...
 
TF_API void SetIsCaseSensitive (bool sensitive)
 Set this matcher to match case-sensitively or not. More...
 
TF_API void SetIsGlobPattern (bool isGlob)
 Set this matcher to treat its pattern as a glob pattern. More...
 
TF_API void SetPattern (const std::string &pattern)
 Set the pattern that this matcher will use to match against. More...
 

Detailed Description

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 48 of file patternMatcher.h.

Constructor & Destructor Documentation

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.

Member Function Documentation

TF_API std::string GetInvalidReason ( ) const

If IsValid() returns true, this will return the reason why (if any).

TF_API const std::string& GetPattern ( ) const
inline

Returns the matcher's pattern string.

Definition at line 86 of file patternMatcher.h.

bool IsCaseSensitive ( ) const
inline

Returns true if the matcher has been set to be case sensitive, false otherwise.

Definition at line 75 of file patternMatcher.h.

bool IsGlobPattern ( ) const
inline

Returns true if the matcher has been set to treat patterns as glob patterns, false otherwise.

Definition at line 81 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.

Warning
Unlike 'match' functions in other regular expression libraries, this method does not implicitly anchor the pattern. If a partial match is not acceptable, it is necessary to anchor the pattern passed to the constructor, e.g. "^mypattern$".
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.


The documentation for this class was generated from the following file: