ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
No Matches
TWildcardMatcher< TChar > Class Template Reference


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 alib::WildcardMatcherN and alib::WildcardMatcherW.

Definition at line 37 of file wildcardmatcher.hpp.

#include <wildcardmatcher.hpp>

Collaboration diagram for TWildcardMatcher< TChar >:

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)

Field Details:

◆ commands

template<typename TChar >
std::vector<std::pair<int,TString<TChar> > > commands

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

Definition at line 40 of file wildcardmatcher.hpp.

Constructor(s) / Destructor Details::

◆ TWildcardMatcher()

template<typename TChar >
TWildcardMatcher ( const TString< TChar > & pattern = NullString())

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

patternThe string pattern to match. Defaults to NullString() to allow parameterless construction, with later invocation of Compile.

Definition at line 51 of file wildcardmatcher.hpp.

Here is the call graph for this function:

Method Details:

◆ Compile()

template<typename TChar >
template ALIB_API void Compile ( const TString< TChar > & pattern)

Resets this object to use the given pattern.

patternThe string pattern to match.

Definition at line 25 of file wildcardmatcher.cpp.

Here is the call graph for this function:

◆ Match()

template<typename TChar >
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.

haystackThe string to test.
sensitivityDenotes 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.

Here is the call graph for this function:

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