ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
wildcardmatcher.hpp
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header-file is part of module \alib_strings of the \aliblong.
4///
5/// Copyright 2013-2026 A-Worx GmbH, Germany.
6/// Published under #"mainpage_license".
7//==================================================================================================
8ALIB_EXPORT namespace alib { namespace strings { namespace util {
9
10//==================================================================================================
11/// This utility class implements so-called <em>wildcard string matching</em>. Wildcard characters
12/// are
13/// - <c>'*'</c>: Matches zero or more characters.
14/// - <c>'?'</c>: Matches exactly one character.
15///
16/// Method #".Compile" accepts the pattern string and translates it to an internal (simple) list of
17/// "matching commands". This way, the class is optimized for performance, because after
18/// compilation, subsequent invocations of #".Match" do not need to parse the pattern string.
19///
20/// @tparam TChar The character type. Implementations for \c nchar and \c wchar are provided
21/// with type definitions #"alib::WildcardMatcherN" and
22/// #"alib::WildcardMatcherW".
23//==================================================================================================
24template<typename TChar>
26 /// The result list of commands created with #".Compile" and executed with #".Match".
27 std::vector<std::pair<int,TString<TChar>>> commands;
28
29 public:
30 /// Constructs a WildcardMatcher to work on a given string. Passes the optional parameters
31 /// to method #".Compile".
32 ///
33 /// @param pattern The string pattern to match.
34 /// Defaults to #"%NULL_STRING" to allow parameterless construction,
35 /// with later invocation of #".Compile".
36 TWildcardMatcher( const TString<TChar>& pattern= NULL_STRING ) { Compile( pattern ); }
37
38 public:
39 /// Resets this object to use the given pattern.
40 ///
41 /// @param pattern The string pattern to match.
43 void Compile( const TString<TChar>& pattern );
44
45 /// Tests if given \p{haystack} matches the actual pattern.
46 /// If #".Compile" was not invoked or an empty pattern string was given, \c true is returned.
47 ///
48 /// @param haystack The string to test.
49 /// @param sensitivity Denotes whether the matching is performed case-sensitive.
50 /// Defaults to #"%Case::Sensitive".
51 /// @return \c true if given \p{haystack} matches the actual pattern, \c false otherwise.
53 bool Match( const TString<TChar>& haystack, lang::Case sensitivity= lang::Case::Sensitive );
54
55}; // class WildcardMatcher
56
57
58extern template ALIB_DLL void TWildcardMatcher<nchar>::Compile( const TString<nchar>& );
60extern template ALIB_DLL void TWildcardMatcher<wchar>::Compile( const TString<wchar>& );
62
63}} // namespace alib[::strings::util]
64
65/// Type alias in namespace #"%alib".
67
68/// Type alias in namespace #"%alib".
70
71/// Type alias in namespace #"%alib".
73
74} // namespace [alib]
#define ALIB_DLL
#define ALIB_EXPORT
bool Match(const TString< TChar > &haystack, lang::Case sensitivity=lang::Case::Sensitive)
TWildcardMatcher(const TString< TChar > &pattern=NULL_STRING)
std::vector< std::pair< int, TString< character > > > commands
void Compile(const TString< TChar > &pattern)
Case
Denotes upper and lower case character treatment.
Definition alox.cpp:14
strings::util::TWildcardMatcher< wchar > WildcardMatcherW
Type alias in namespace #"%alib".
constexpr String NULL_STRING
A nulled string of the default character type.
Definition string.hpp:2247
strings::util::TWildcardMatcher< character > WildcardMatcher
Type alias in namespace #"%alib".
strings::util::TWildcardMatcher< nchar > WildcardMatcherN
Type alias in namespace #"%alib".