Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

PRegularExpression Class Reference

#include <pstring.h>

Inheritance diagram for PRegularExpression:

PObject List of all members.

Constructors & destructors

enum  { Extended = 1, IgnoreCase = 2, AnchorNewLine = 4 }
 Flags for compiler options. More...
enum  { NotBeginningOfLine = 1, NotEndofLine = 2 }
 Flags for execution options. More...
 PRegularExpression ()
 Create a new, empty, regular expression.
 PRegularExpression (const PString &pattern, int flags=IgnoreCase)
 PRegularExpression (const char *cpattern, int flags=IgnoreCase)
 PRegularExpression (const PRegularExpression &)
PRegularExpressionoperator= (const PRegularExpression &)
 ~PRegularExpression ()
 Release storage for the compiled regular expression.

Status functions

enum  ErrorCodes {
  NoError = 0, NoMatch, BadPattern, CollateError,
  BadClassType, BadEscape, BadSubReg, UnmatchedBracket,
  UnmatchedParen, UnmatchedBrace, BadBR, RangeError,
  OutOfMemory, BadRepitition, PrematureEnd, TooBig,
  UnmatchedRParen, NotCompiled
}
 Error codes. More...
ErrorCodes GetErrorCode () const
PString GetErrorText () const

Public Member Functions

Compile & Execute functions
BOOL Compile (const PString &pattern, int flags=IgnoreCase)
BOOL Compile (const char *cpattern, int flags=IgnoreCase)
BOOL Execute (const PString &str, PINDEX &start, int flags=0) const
BOOL Execute (const PString &str, PINDEX &start, PINDEX &len, int flags=0) const
BOOL Execute (const char *cstr, PINDEX &start, int flags=0) const
BOOL Execute (const char *cstr, PINDEX &start, PINDEX &len, int flags=0) const
BOOL Execute (const PString &str, PIntArray &starts, int flags=0) const
BOOL Execute (const PString &str, PIntArray &starts, PIntArray &ends, int flags=0) const
BOOL Execute (const char *cstr, PIntArray &starts, int flags=0) const
BOOL Execute (const char *cstr, PIntArray &starts, PIntArray &ends, int flags=0) const

Static Public Member Functions

Miscellaneous functions
static PString EscapeString (const PString &str)

Protected Attributes

PString patternSaved
int flagsSaved
void * expression
int lastError

Detailed Description

A class representing a regular expression that may be used for locating patterns in strings. The regular expression string is "compiled" into a form that is more efficient during the matching. This compiled form exists for the lifetime of the PRegularExpression instance.


Member Enumeration Documentation

anonymous enum
 

Flags for execution options.

Enumeration values:
NotBeginningOfLine  If this bit is set, then the beginning-of-line operator doesn't match the beginning of the string (presumably because it's not the beginning of a line). If not set, then the beginning-of-line operator does match the beginning of the string.
NotEndofLine  Like NotBeginningOfLine#, except for the end-of-line.

anonymous enum
 

Flags for compiler options.

Enumeration values:
Extended  Use extended regular expressions.
IgnoreCase  Ignore case in search.
AnchorNewLine  If this bit is set, then anchors do not match at newline characters in the string. If not set, then anchors do match at newlines.

enum PRegularExpression::ErrorCodes
 

Error codes.

Enumeration values:
NoError  Success.
NoMatch  Didn't find a match (for regexec).
BadPattern  Invalid pattern.
CollateError  Not implemented.
BadClassType  Invalid character class name.
BadEscape  Trailing backslash.
BadSubReg  Invalid back reference.
UnmatchedBracket  Unmatched left bracket.
UnmatchedParen  Parenthesis imbalance.
UnmatchedBrace  Unmatched #\}#.
BadBR  Invalid contents of #\}#.
RangeError  Invalid range end.
OutOfMemory  Ran out of memory.
BadRepitition  No preceding re for repetition op.
PrematureEnd  Premature end.
TooBig  Compiled pattern bigger than 2^16 bytes.
UnmatchedRParen  Unmatched ) or \); not returned from regcomp.
NotCompiled  Miscellaneous error.


Constructor & Destructor Documentation

PRegularExpression::PRegularExpression  ) 
 

Create a new, empty, regular expression.

PRegularExpression::PRegularExpression const PString pattern,
int  flags = IgnoreCase
 

Create and compile a new regular expression pattern.

Parameters:
flags  Pattern to compile Pattern match options

PRegularExpression::PRegularExpression const char *  cpattern,
int  flags = IgnoreCase
 

Create and compile a new regular expression pattern.

Parameters:
flags  Pattern to compile Pattern match options

PRegularExpression::PRegularExpression const PRegularExpression  ) 
 

Copy a regular expression

PRegularExpression::~PRegularExpression  ) 
 

Release storage for the compiled regular expression.


Member Function Documentation

BOOL PRegularExpression::Compile const char *  cpattern,
int  flags = IgnoreCase
 

Compiler pattern. The pattern is compiled into an internal format to speed subsequent execution of the pattern match algorithm.

Returns:
TRUE if successfully compiled.
Parameters:
flags  Pattern to compile Pattern match options

BOOL PRegularExpression::Compile const PString pattern,
int  flags = IgnoreCase
 

Compiler pattern.

Parameters:
flags  Pattern to compile Pattern match options

static PString PRegularExpression::EscapeString const PString str  )  [static]
 

Escape all characters in the #str# parameter that have a special meaning within a regular expression.

Returns:
String with additional escape ('\') characters.
Parameters:
str  String to add esacpes to.

BOOL PRegularExpression::Execute const char *  cstr,
PIntArray starts,
PIntArray ends,
int  flags = 0
const
 

Execute regular expression. Execute the pattern match algorithm using the previously compiled pattern.

The #starts# array is filled with as many matches as will fit into the array. If the the array size is zero then it is set to at least one for the first match found.

The #ends# array is set to teh ending position of each substring whose start is returned in the #starts# array. This will always be set to the same size as that array.

Returns:
TRUE if successfully compiled.
Parameters:
starts  Source string to search
ends  List of match locations
flags  List of match ends Pattern match options

BOOL PRegularExpression::Execute const char *  cstr,
PIntArray starts,
int  flags = 0
const
 

Execute regular expression

Parameters:
starts  Source string to search
flags  List of match locations Pattern match options

BOOL PRegularExpression::Execute const PString str,
PIntArray starts,
PIntArray ends,
int  flags = 0
const
 

Execute regular expression

Parameters:
starts  Source string to search
ends  List of match locations
flags  List of match ends Pattern match options

BOOL PRegularExpression::Execute const PString str,
PIntArray starts,
int  flags = 0
const
 

Execute regular expression

Parameters:
starts  Source string to search
flags  List of match locations Pattern match options

BOOL PRegularExpression::Execute const char *  cstr,
PINDEX &  start,
PINDEX &  len,
int  flags = 0
const
 

Execute regular expression

Parameters:
start  Source string to search
len  First match locations
flags  Length of match Pattern match options

BOOL PRegularExpression::Execute const char *  cstr,
PINDEX &  start,
int  flags = 0
const
 

Execute regular expression

Parameters:
start  Source string to search
flags  First match locations Pattern match options

BOOL PRegularExpression::Execute const PString str,
PINDEX &  start,
PINDEX &  len,
int  flags = 0
const
 

Execute regular expression

Parameters:
start  Source string to search
len  First match locations
flags  Length of match Pattern match options

BOOL PRegularExpression::Execute const PString str,
PINDEX &  start,
int  flags = 0
const
 

Execute regular expression

Parameters:
start  Source string to search
flags  First match locations Pattern match options

ErrorCodes PRegularExpression::GetErrorCode  )  const
 

Get the error code for the last Compile() or Execute() operation.

Returns:
Error code.

PString PRegularExpression::GetErrorText  )  const
 

Get the text description for the error of the last Compile() or Execute() operation.

Returns:
Error text string.

PRegularExpression& PRegularExpression::operator= const PRegularExpression  ) 
 

Assign a regular expression


Member Data Documentation

void* PRegularExpression::expression [protected]
 

int PRegularExpression::flagsSaved [protected]
 

int PRegularExpression::lastError [protected]
 

PString PRegularExpression::patternSaved [protected]
 


The documentation for this class was generated from the following file:
Generated on Mon Feb 21 20:43:15 2005 for PWLib by  doxygen 1.4.1