This utility class implements so called wildcard string matching. Wildcard characters are
'*'
: Matches zero or more characters.'?'
: Matches exactly one character.Method Compile accepts the pattern string and translates it to an internal (simple) list of "matching commands". This way, the class is optimized for performance, because after compilation, subsequent invocations of Match do not need to parse the pattern string.
TChar | The character type. Implementations for nchar and wchar are provided with type definitions alib::WildcardMatcherN and alib::WildcardMatcherW. |
Definition at line 31 of file wildcardmatcher.hpp.
#include <wildcardmatcher.hpp>
Public Method Index: | |
TWildcardMatcher (const TString< TChar > &pattern=NULL_STRING) | |
ALIB_API void | Compile (const TString< TChar > &pattern) |
ALIB_API bool | Match (const TString< TChar > &haystack, lang::Case sensitivity=lang::Case::Sensitive) |
Private Field Index: | |
std::vector< std::pair< int, TString< TChar > > > | commands |
The result list of commands created with Compile and executed with Match. | |
|
private |
The result list of commands created with Compile and executed with Match.
Definition at line 34 of file wildcardmatcher.hpp.
|
inline |
Constructs a WildcardMatcher to work on a given string. Passes the optional parameters to method Compile.
pattern | The string pattern to match. Defaults to NULL_STRING to allow parameterless construction, with later invocation of Compile. |
Definition at line 45 of file wildcardmatcher.hpp.
Resets this object to use the given pattern.
pattern | The string pattern to match. |
Definition at line 20 of file wildcardmatcher.cpp.
template ALIB_API bool Match | ( | const TString< TChar > & | haystack, |
lang::Case | sensitivity = lang::Case::Sensitive ) |
Tests if given haystack matches the actual pattern. If Compile was not invoked or an empty pattern string was given, true
is returned.
haystack | The string to test. |
sensitivity | Denotes whether the matching is performed case-sensitive. Defaults to Case::Sensitive . |
true
if given haystack matches the actual pattern, false
otherwise. Definition at line 85 of file wildcardmatcher.cpp.