ALib C++ Framework
by
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::strings::util::TWildcardMatcher< TChar > Class Template Reference

Description:

template<typename TChar>
class alib::strings::util::TWildcardMatcher< TChar >

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.

Template Parameters
TCharThe character type. Implementations for nchar and wchar are provided with type definitions WildcardMatcherN and WildcardMatcherW.

Definition at line 25 of file wildcardmatcher.inl.

Public Method Index:

 TWildcardMatcher (const TString< TChar > &pattern=NULL_STRING)
void Compile (const TString< TChar > &pattern)
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.

Field Details:

◆ commands

template<typename TChar>
std::vector<std::pair<int,TString<TChar> > > alib::strings::util::TWildcardMatcher< TChar >::commands
private

The result list of commands created with Compile and executed with Match.

Definition at line 28 of file wildcardmatcher.inl.

Constructor(s) / Destructor Details:

◆ TWildcardMatcher()

template<typename TChar>
alib::strings::util::TWildcardMatcher< TChar >::TWildcardMatcher ( const TString< TChar > & pattern = NULL_STRING)
inline

Constructs a WildcardMatcher to work on a given string. Passes the optional parameters to method Compile.

Parameters
patternThe string pattern to match. Defaults to NULL_STRING to allow parameterless construction, with later invocation of Compile.

Definition at line 37 of file wildcardmatcher.inl.

Method Details:

◆ Compile()

template<typename TChar>
template void alib::strings::util::TWildcardMatcher< TChar >::Compile ( const TString< TChar > & pattern)

Resets this object to use the given pattern.

Parameters
patternThe string pattern to match.

Definition at line 29 of file wildcardmatcher.cpp.

◆ Match()

template<typename TChar>
template bool alib::strings::util::TWildcardMatcher< TChar >::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.

Parameters
haystackThe string to test.
sensitivityDenotes whether the matching is performed case-sensitive. Defaults to Case::Sensitive.
Returns
true if given haystack matches the actual pattern, false otherwise.

Definition at line 90 of file wildcardmatcher.cpp.


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