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