ALib C++ Library
Library Version: 2402 R1
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 !defined(ALIB_DOX)
10#if !defined (HPP_ALIB_STRINGS_UTIL_REGEXMATCHER)
12#endif
13#endif // !defined(ALIB_DOX)
14
15#if ALIB_FEAT_BOOST_REGEX && ALIB_CHARACTERS_WIDE && !ALIB_CHARACTERS_NATIVE_WCHAR
16# pragma message ( "Warning: Class RegexMatcher will not be available, because ALIB_CHARACTERS_NATIVE_WCHAR is false." )
17#endif
18
19
20#if ALIB_FEAT_BOOST_REGEX && (!ALIB_CHARACTERS_WIDE || ALIB_CHARACTERS_NATIVE_WCHAR)
21
22#if !defined(ALIB_DOX)
23#include <boost/regex.hpp>
24
25#if !defined (_GLIBCXX_STRING) && !defined(_STRING_)
26# include <string>
27#endif
28#endif // !defined(ALIB_DOX)
29
30namespace alib { namespace strings { namespace util {
31
32
33
35{
36 if( boostRegex )
37 delete reinterpret_cast<boost::regex*>( boostRegex );
38}
39
40void RegexMatcher::Compile( const String& pattern )
41{
42 if( pattern.IsNull() )
43 return;
44
45 boost::basic_regex<character>* regEx;
46 if( !boostRegex )
47 boostRegex= (regEx= new boost::basic_regex<character>() );
48 else
49 regEx= reinterpret_cast<boost::basic_regex<character>*>( boostRegex );
50
51 regEx->assign( std::basic_string<character>(pattern.Buffer(), static_cast<size_t>( pattern.Length() ) ) );
52}
53
54bool RegexMatcher::Match( const String& haystack )
55{
56 if( !boostRegex )
57 return true;
58
59 return boost::regex_match(std::basic_string<character>(haystack.Buffer(), static_cast<size_t>( haystack.Length() )),
60 *reinterpret_cast<boost::basic_regex<character>*>( boostRegex ) );
61
62}
63
64}}} // namespace [alib::strings::util]
65
66#endif // ALIB_FEAT_BOOST_REGEX && (!ALIB_CHARACTERS_WIDE || ALIB_CHARACTERS_NATIVE_WCHAR)
constexpr bool IsNull() const
Definition string.hpp:395
constexpr integer Length() const
Definition string.hpp:357
constexpr const TChar * Buffer() const
Definition string.hpp:350
ALIB_API void Compile(const String &pattern)
ALIB_API bool Match(const String &haystack)
Definition alib.cpp:57