ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
regexmatcher.inl
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/// \emoji :copyright: 2013-2025 A-Worx GmbH, Germany.
6/// Published under \ref mainpage_license "Boost Software License".
7//==================================================================================================
8#if (ALIB_FEAT_BOOST_REGEX && (!ALIB_CHARACTERS_WIDE || ALIB_CHARACTERS_NATIVE_WCHAR) ) || DOXYGEN
9
10ALIB_EXPORT namespace alib { namespace strings { namespace util {
11
12//==================================================================================================
13/// This utility class wraps \https{boost::regex library,www.boost.org} and interfaces
14/// \alib_strings with it.
15///
16/// The availability of the class is dependent on the compiler-symbol \ref ALIB_FEAT_BOOST_REGEX
17/// which has to be \c true, and in parallel either \ref ALIB_CHARACTERS_WIDE is \c false or
18/// \ref ALIB_CHARACTERS_NATIVE_WCHAR equals \c true.
19///
20/// Method #Compile accepts the pattern string and compiles it to \b boost::regex.
21/// Subsequent invocations of #Match will then use the compiled regular expression for testing
22/// a given string.
23///
24/// The syntax of the regular expressions is compatible to
25/// \https{Perl Regular Expressions,perldoc.perl.org/perlretut.html}.
26///
27/// \note
28/// This is a very basic wrapper that supports just the <b>bare minimum of the features</b>
29/// available in the original \b boost::regex library.
30/// I.e, the expression syntax is fixed to be \e Perl-compatible and no string replacement
31/// features or even match positioning are available.
32//==================================================================================================
34{
35 protected:
36 /// This is the internal regex matcher. Yes, a nasty \c reinterpret_cast is performed in the
37 /// compilation unit. This is for avoiding the inclusion of external headers with \alib
38 /// headers at the expense of an otherwise unnecessary heap allocation.
39 void* boostRegex = nullptr;
40
41 public:
42 //==========================================================================================
43 /// Constructs a RegexMatcher to work on a given string. Passes the optional parameters
44 /// to method #Compile.
45 ///
46 /// @param pattern The string pattern to match.
47 /// Defaults to \b NULL_STRING to allow parameterless construction,
48 /// with later invocation of #Compile.
49 //==========================================================================================
50 RegexMatcher( const String& pattern= NULL_STRING )
51 {
52 Compile( pattern );
53 }
54
55 //==========================================================================================
56 /// Destructor.
57 //==========================================================================================
60
61 public:
62 //==========================================================================================
63 /// Resets this object to use the given pattern.
64 ///
65 /// @param pattern The string pattern to match.
66 //==========================================================================================
68 void Compile( const String& pattern );
69
70 //==========================================================================================
71 /// Tests if given \p{haystack} matches the actual pattern.
72 /// If #Compile was not invoked or an empty pattern string was given, \c true is returned.
73 ///
74 /// @param haystack The string to test.
75 /// @return \c true if given \p{haystack} matches the actual pattern, \c false otherwise.
76 //==========================================================================================
78 bool Match( const String& haystack );
79
80}; // class RegexMatcher
81
82}} // namespace alib[::strings::util]
83
84/// Type alias in namespace \b alib.
86
87} // namespace [alib]
88
89#endif // ALIB_FEAT_BOOST_REGEX && (!ALIB_CHARACTERS_WIDE || ALIB_CHARACTERS_NATIVE_WCHAR)
90
ALIB_DLL ~RegexMatcher()
Destructor.
ALIB_DLL void Compile(const String &pattern)
RegexMatcher(const String &pattern=NULL_STRING)
ALIB_DLL bool Match(const String &haystack)
#define ALIB_DLL
Definition alib.inl:496
#define ALIB_EXPORT
Definition alib.inl:488
constexpr String NULL_STRING
A nulled string of the default character type.
Definition string.inl:2463
strings::util::RegexMatcher RegexMatcher
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2381