ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
regexmatcher.cpp
1// #################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2024 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6// #################################################################################################
8
9#if !DOXYGEN
11#endif // !DOXYGEN
12
13#if ALIB_FEAT_BOOST_REGEX && ALIB_CHARACTERS_WIDE && !ALIB_CHARACTERS_NATIVE_WCHAR
14# pragma message ( "Warning: Class RegexMatcher will not be available, because ALIB_CHARACTERS_NATIVE_WCHAR is false." )
15#endif
16
17#if ALIB_FEAT_BOOST_REGEX && (!ALIB_CHARACTERS_WIDE || ALIB_CHARACTERS_NATIVE_WCHAR)
18
19#if !DOXYGEN
20# include <boost/regex.hpp>
21# include <string>
22#endif // !DOXYGEN
23
24namespace alib { namespace strings { namespace util {
25
26
27
29{
30 if( boostRegex )
31 delete reinterpret_cast<boost::regex*>( boostRegex );
32}
33
34void RegexMatcher::Compile( const String& pattern )
35{
36 if( pattern.IsNull() )
37 return;
38
39 boost::basic_regex<character>* regEx;
40 if( !boostRegex )
41 boostRegex= (regEx= new boost::basic_regex<character>() );
42 else
43 regEx= reinterpret_cast<boost::basic_regex<character>*>( boostRegex );
44
45 regEx->assign( std::basic_string<character>(pattern.Buffer(), size_t( pattern.Length() ) ) );
46}
47
48bool RegexMatcher::Match( const String& haystack )
49{
50 if( !boostRegex )
51 return true;
52
53 return boost::regex_match(std::basic_string<character>(haystack.Buffer(), size_t( haystack.Length() )),
54 *reinterpret_cast<boost::basic_regex<character>*>( boostRegex ) );
55
56}
57
58}}} // namespace [alib::strings::util]
59
60#endif // ALIB_FEAT_BOOST_REGEX && (!ALIB_CHARACTERS_WIDE || ALIB_CHARACTERS_NATIVE_WCHAR)
61
constexpr bool IsNull() const
Definition string.hpp:364
constexpr integer Length() const
Definition string.hpp:326
constexpr const TChar * Buffer() const
Definition string.hpp:319
ALIB_API ~RegexMatcher()
Destructor.
ALIB_API void Compile(const String &pattern)
ALIB_API bool Match(const String &haystack)
Definition alib.cpp:69