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 37 of file wildcardmatcher.hpp.
#include <wildcardmatcher.hpp>
Public Method Index: | |
TWildcardMatcher (const TString< TChar > &pattern=NullString()) | |
ALIB_API void | Compile (const TString< TChar > &pattern) |
ALIB_API bool | Match (const TString< TChar > &haystack, lang::Case sensitivity=lang::Case::Sensitive) |
|
private |
The result list of commands created with Compile and executed with Match.
Definition at line 40 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 NullString() to allow parameterless construction, with later invocation of Compile. |
Definition at line 51 of file wildcardmatcher.hpp.
Resets this object to use the given pattern.
pattern | The string pattern to match. |
Definition at line 25 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 90 of file wildcardmatcher.cpp.