This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TfPatternMatcher Class Reference

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 TfPatternMatcheroperator= (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.
 

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

Constructor & Destructor Documentation

◆ TfPatternMatcher() [1/2]

TF_API TfPatternMatcher ( )

Construct an empty (invalid) TfPatternMatcher.

◆ TfPatternMatcher() [2/2]

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().

◆ ~TfPatternMatcher()

TF_API ~TfPatternMatcher ( )

Destructor.

Member Function Documentation

◆ GetInvalidReason()

TF_API std::string GetInvalidReason ( ) const

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

◆ GetPattern()

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

Returns the matcher's pattern string.

Definition at line 69 of file patternMatcher.h.

◆ IsCaseSensitive()

bool IsCaseSensitive ( ) const
inline

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

Definition at line 58 of file patternMatcher.h.

◆ IsGlobPattern()

bool IsGlobPattern ( ) const
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.

◆ IsValid()

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

◆ Match()

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$".

◆ SetIsCaseSensitive()

TF_API void SetIsCaseSensitive ( bool  sensitive)

Set this matcher to match case-sensitively or not.

◆ SetIsGlobPattern()

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.

◆ SetPattern()

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: