Aegis  4.25.D505
Public Member Functions | Private Member Functions | Private Attributes
regular_expression Class Reference

#include <regula_expre.h>

Public Member Functions

virtual ~regular_expression ()
 regular_expression (const nstring &pattern, bool icase=false)
bool matches (const char *text, size_t &so, size_t &eo)
bool match (const nstring &arg, size_t offset=0)
const char * strerror () const
bool match_and_substitute (const nstring &rhs, const nstring &actual, long how_many_times, nstring &output)

Private Member Functions

void set_error (int err)
bool compile ()
 regular_expression ()
 regular_expression (const regular_expression &)
regular_expressionoperator= (const regular_expression &)

Private Attributes

nstring errstr
nstring lhs
bool icase
bool compiled
regex_t preg
regmatch_t regmatch [10]

Detailed Description

The regular_expression class is used to represent the state of a regular expression match. All of the interfacing with the regex code is taken care of by this class.

You can match the one pattern against numerous strings by making repeated calls to the match() method.

You can match against a string, and replace it with something else, by using the match_and_substitute method. It, too, may be called more than once.

Definition at line 38 of file regula_expre.h.


Constructor & Destructor Documentation

The destructor.

regular_expression::regular_expression ( const nstring pattern,
bool  icase = false 
)

The constructor.

Parameters:
patternThe pattern to be matched against.
icasetrue for case-insensitive match, the default is case sensitive
Note:
The compilation of the pattern will be deferred until it is actually used by the "match" method.

The default constructor. Do not use.

The copy constructor. Do not use.


Member Function Documentation

bool regular_expression::compile ( ) [private]

The compile method is used to compile the left and side of the regular expression match. Compilation is deferred until the regular expression is actually used.

bool regular_expression::match ( const nstring arg,
size_t  offset = 0 
)

The match method is used to match a string against the pattern given to the constructor.

Parameters:
argThe string to be matched against the pattern.
offsetThe point at which to start searching in the string; defaults to zero, meaning the start of the string.
Returns:
true if there was a match, or false if there was no match or an error occurred.
bool regular_expression::match_and_substitute ( const nstring rhs,
const nstring actual,
long  how_many_times,
nstring output 
)

The match_and_substitute method is used to match the left hand side of a regular expression and substitute the right hand side if there was a match

Parameters:
rhsThe right-hand-side pattern for substituting.
actualThe text to be matched, possibly more than once.
how_many_timesThe maximum number of times to perform the match; zero means unlimited.
outputThe result of the substitution is placed here.
Returns:
true of there were no errors, or false if there was an error.
bool regular_expression::matches ( const char *  text,
size_t &  so,
size_t &  eo 
)

The matches method is used to match a string against the pattern given to the constructor.

Parameters:
textThe string to be matched against the pattern.
soThe start offset of the match (on success)
eoThe end offset of the match (on success)
Returns:
true if there was a match, or false if there was no match or an error occurred.
regular_expression& regular_expression::operator= ( const regular_expression ) [private]

The assignment operator. Do not use.

void regular_expression::set_error ( int  err) [private]

The set_error method is used to obtain the text of the error for the last regex function call, and set the errstr instance variable accordingly.

Parameters:
errThe error code returned by the last regex call.
const char* regular_expression::strerror ( ) const

Obtain an human readable representation of the most recent error, or NULL if there has been no error.


Field Documentation

The compiled instance variable is used to remember whether or not the left hand side has been compiled yet.

Definition at line 156 of file regula_expre.h.

The errstr instance variable is used to remember the human readable text of the last error which ocurred.

Definition at line 121 of file regula_expre.h.

bool regular_expression::icase [private]

The icase instance variable is sud to remeber whether we are doing a case-sensitive match (false) or a case-IN-sensitive match (true).

Definition at line 143 of file regula_expre.h.

The lhs instance variable is used to remember the pattern on the left hand side to be matched against.

Definition at line 137 of file regula_expre.h.

The preg instance variable is an opaque storage area used by the regex functions. It is initialised by the compile() method.

Definition at line 162 of file regula_expre.h.

The regmatch instance variable is used to remember the matching postions from the last match() method call.

Definition at line 168 of file regula_expre.h.


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