ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
regexmatcher.cpp
1// #################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2025 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6// #################################################################################################
7#include "alib_precompile.hpp"
8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
10#endif
11#if ALIB_C20_MODULES
12 module;
13#endif
14// ====================================== Global Fragment ======================================
16#if ALIB_FEAT_BOOST_REGEX && (!ALIB_CHARACTERS_WIDE || ALIB_CHARACTERS_NATIVE_WCHAR)
17# include <boost/regex.hpp>
18# include <string>
19#endif
20// =========================================== Module ==========================================
21#if ALIB_C20_MODULES
23#else
24# include "ALib.Strings.Search.H"
25#endif
26// ====================================== Implementation =======================================
27#if ALIB_FEAT_BOOST_REGEX && ALIB_CHARACTERS_WIDE && !ALIB_CHARACTERS_NATIVE_WCHAR
28# pragma message ( "Warning: Class RegexMatcher will not be available, because ALIB_CHARACTERS_NATIVE_WCHAR is false." )
29#endif
30
31#if ALIB_FEAT_BOOST_REGEX && (!ALIB_CHARACTERS_WIDE || ALIB_CHARACTERS_NATIVE_WCHAR)
32
33namespace alib { namespace strings { namespace util {
34
36{
37 if( boostRegex )
38 delete reinterpret_cast<boost::regex*>( boostRegex );
39}
40
41void RegexMatcher::Compile( const String& pattern )
42{
43 if( pattern.IsNull() )
44 return;
45
46 boost::basic_regex<character>* regEx;
47 if( !boostRegex )
48 boostRegex= (regEx= new boost::basic_regex<character>() );
49 else
50 regEx= reinterpret_cast<boost::basic_regex<character>*>( boostRegex );
51
52 regEx->assign( std::basic_string<character>(pattern.Buffer(), size_t( pattern.Length() ) ) );
53}
54
55bool RegexMatcher::Match( const String& haystack )
56{
57 if( !boostRegex )
58 return true;
59
60 return boost::regex_match(std::basic_string<character>(haystack.Buffer(), size_t( haystack.Length() )),
61 *reinterpret_cast<boost::basic_regex<character>*>( boostRegex ) );
62
63}
64
65}}} // namespace [alib::strings::util]
66
67#endif // ALIB_FEAT_BOOST_REGEX && (!ALIB_CHARACTERS_WIDE || ALIB_CHARACTERS_NATIVE_WCHAR)
68
ALIB_DLL ~RegexMatcher()
Destructor.
ALIB_DLL void Compile(const String &pattern)
ALIB_DLL bool Match(const String &haystack)
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2381