ALib C++ Library
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::strings::util::RegexMatcher Class Reference

Description:

This utility class wraps boost::regex library and interfaces ALib Strings with it.

The availability of the class is dependent on the compiler-symbol ALIB_FEAT_BOOST_REGEX which has to be true, and in parallel either ALIB_CHARACTERS_WIDE is false or ALIB_CHARACTERS_NATIVE_WCHAR equals true.

Method Compile accepts the pattern string and compiles it to boost::regex. Subsequent invocations of Match will then use the compiled regular expression for testing a given string.

The syntax of the regular expressions is compatible to Perl Regular Expressions .

Note
This is a very basic wrapper that supports just the bare minimum of the features available in the original boost::regex library. I.e, the expression syntax is fixed to be Perl-compatible and no string replacement features or even match positioning are available.

Definition at line 33 of file regexmatcher.inl.

Inner Type Index:

struct  SRange
 

Public Method Index:

 RegexMatcher (const String &pattern=NULL_STRING)
 
ALIB_DLL void Compile (const String &pattern)
 
ALIB_DLL bool Match (const String &haystack)
 
ALIB_DLL SRange SearchIn (const String &haystack)
 

Protected Field Index:

boost::basic_regex< character, boost::regex_traits< character > > boostRegex
 This is the internal regex matcher.
 

Field Details:

◆ boostRegex

boost::basic_regex<character, boost::regex_traits<character> > alib::strings::util::RegexMatcher::boostRegex
protected

This is the internal regex matcher.

Definition at line 37 of file regexmatcher.inl.

Constructor(s) / Destructor Details:

◆ RegexMatcher()

alib::strings::util::RegexMatcher::RegexMatcher ( const String & pattern = NULL_STRING)
inline

Constructs a RegexMatcher to work on a given string. Passes the optional parameters to method Compile.

Parameters
patternThe string pattern to match. Defaults to NULL_STRING to allow parameterless construction, with later invocation of Compile.

Definition at line 53 of file regexmatcher.inl.

Here is the call graph for this function:

Method Details:

◆ Compile()

ALIB_DLL void alib::strings::util::RegexMatcher::Compile ( const String & pattern)

Resets this object to use the given pattern.

Parameters
patternThe string pattern to match.

◆ Match()

ALIB_DLL bool alib::strings::util::RegexMatcher::Match ( const String & haystack)

Tests if the given haystack matches the actual pattern. If Compile was not invoked or an empty pattern string was given, true is returned.

Parameters
haystackThe string to test.
Returns
true if given haystack matches the actual pattern, false otherwise.

◆ SearchIn()

ALIB_DLL SRange alib::strings::util::RegexMatcher::SearchIn ( const String & haystack)

Searches for the first match of the actual pattern in the given haystack If Compile was not invoked or an empty pattern string was given, an ALib Assertion is raised.

Parameters
haystackThe string to search in..
Returns
The (first) range in haystack that matches the compiled pattern. In case the pattern was not found, {-1,-1} is returned.

The documentation for this class was generated from the following file: