ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
regexmatcher.cpp
1#if ALIB_FEAT_BOOST_REGEX
2
3#if ALIB_CHARACTERS_WIDE && !ALIB_CHARACTERS_NATIVE_WCHAR
4# pragma message ( "Warning: Class RegexMatcher will not be available, because ALIB_CHARACTERS_NATIVE_WCHAR is false." )
5#else
6
7namespace alib { namespace strings { namespace util {
8
9void RegexMatcher::Compile( const String& pattern ) {
10 if( pattern.IsNull() )
11 return;
12
13 boostRegex.assign( std::basic_string<character>(pattern.Buffer(), size_t( pattern.Length() ) ),
14 boost::regex_constants::optimize );
15}
16
17bool RegexMatcher::Match( const String& haystack ) {
18 ALIB_ASSERT_ERROR( !boostRegex.empty(), "ALIB/STR", "No regular expression compiled")
19 return boost::regex_match(haystack.begin(), haystack.end(), boostRegex);
20}
21
23 ALIB_ASSERT_ERROR( !boostRegex.empty(), "ALIB/STR", "No regular expression compiled")
24 boost::match_results<String::const_iterator> what;
25 if( boost::regex_search(haystack.begin(), haystack.end(), what, boostRegex ) )
26 return { what.position(), what.length(0) };
27 return {-1,-1};
28}
29
30}}} // namespace [alib::strings::util]
31
32#endif // (!ALIB_CHARACTERS_WIDE || ALIB_CHARACTERS_NATIVE_WCHAR)
33#endif // ALIB_FEAT_BOOST_REGEX
#define ALIB_ASSERT_ERROR(cond, domain,...)
constexpr integer Length() const
Definition string.hpp:300
const_iterator end() const
Definition string.hpp:1953
constexpr const TChar * Buffer() const
Definition string.hpp:295
const_iterator begin() const
Definition string.hpp:1945
constexpr bool IsNull() const
Definition string.hpp:334
bool Match(const String &haystack)
boost::basic_regex< character, boost::regex_traits< character > > boostRegex
This is the internal regex matcher.
SRange SearchIn(const String &haystack)
void Compile(const String &pattern)
Definition alox.cpp:14
strings::TString< character > String
Type alias in namespace #"%alib".
Definition string.hpp:2165