Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FX::FXRex Class Reference

FXRex is a regular expression class implementing a NFA matcher. More...

#include <FXRex.h>

List of all members.

Public Types

enum  {
  Normal = 0,
  Capture = 1,
  IgnoreCase = 2,
  Newline = 4,
  Verbatim = 8,
  Syntax = 16
}
enum  {
  Forward = 0,
  Backward = 32,
  NotBol = 64,
  NotEol = 128,
  NotEmpty = 256
}
enum  Error {
  ErrOK = 0,
  ErrEmpty = 1,
  ErrParent = 2,
  ErrBracket = 3,
  ErrBrace = 4,
  ErrRange = 5,
  ErrEscape = 6,
  ErrCount = 7,
  ErrNoAtom = 8,
  ErrRepeat = 9,
  ErrBackRef = 10,
  ErrClass = 11,
  ErrComplex = 12,
  ErrMemory = 13,
  ErrToken = 14,
  ErrBehind = 15
}

Public Member Functions

 FXRex ()
 FXRex (const FXRex &orig)
 FXRex (const FXchar *pattern, FXint mode=Normal, Error *error=NULL)
 FXRex (const FXString &pattern, FXint mode=Normal, Error *error=NULL)
FXRexoperator= (const FXRex &orig)
FXbool empty () const
FXRex::Error parse (const FXchar *pattern, FXint mode=Normal)
FXRex::Error parse (const FXString &pattern, FXint mode=Normal)
FXbool match (const FXchar *string, FXint len, FXint *beg=NULL, FXint *end=NULL, FXint mode=Forward, FXint npar=1, FXint fm=0, FXint to=2147483647) const
FXbool match (const FXString &string, FXint *beg=NULL, FXint *end=NULL, FXint mode=Forward, FXint npar=1, FXint fm=0, FXint to=2147483647) const
FXbool operator== (const FXRex &rex) const
FXbool operator!= (const FXRex &rex) const
 ~FXRex ()

Static Public Member Functions

static FXString substitute (const FXchar *string, FXint len, FXint *beg, FXint *end, const FXString &replace, FXint npar=1)
static FXString substitute (const FXString &string, FXint *beg, FXint *end, const FXString &replace, FXint npar=1)
static const FXchargetError (FXRex::Error err)

Friends

FXStreamoperator<< (FXStream &store, const FXRex &s)
FXStreamoperator>> (FXStream &store, FXRex &s)


Detailed Description

FXRex is a regular expression class implementing a NFA matcher.

It supports capturing parentheses, non-capturing parentheses, positive or negative lookahead, backreferences, case-insensitive matching, counted repetitions, lazy or greedy matches, and PERL-like matching operators. The subject string may be scanned forwards or backwards, and may contain any of 256 possible character values.

When parsing a regular expression pattern, the mode parameter is the bitwise OR of a set of flags and affects the match algorithm. Passing the flag Capture enables capturing parentheses and back references. The flag IgnoreCase enables case-insensitive matching. When the flag Newline is passed, newlines are treated like normal characters; otherwise, newline is NOT matched except when explicitly part of a character class. The flag Verbatim disables all special character interpretation.

When matching a compiled pattern, the mode parameter is the bitwise OR of a set of flags that affects how the match is performed. Passing the flag Backward causes the match to proceed backwards through the subject string. Passing the flags NotBol and/or NotEol causes the begin and end of the subject string NOT to be considered a line start or line end. The flag NotEmpty causes a match to fail if the empty string was matched.


Member Enumeration Documentation

anonymous enum

Regular expression parse flags.

Enumerator:
Normal  Normal mode.
Capture  Perform capturing parentheses.
IgnoreCase  Ignore case differences.
Newline  Match-any operators match newline too.
Verbatim  Disable interpretation of magic characters.
Syntax  Perform syntax check only.

anonymous enum

Regular expression match flags.

Enumerator:
Forward  Match scanning forward from offset.
Backward  Match scanning backward from offset.
NotBol  Start of string is NOT begin of line.
NotEol  End of string is NOT end of line.
NotEmpty  Do not match empty.

Regular expression error codes.

Enumerator:
ErrOK  No errors.
ErrEmpty  Empty pattern.
ErrParent  Unmatched parenthesis.
ErrBracket  Unmatched bracket.
ErrBrace  Unmatched brace.
ErrRange  Bad character range.
ErrEscape  Bad escape sequence.
ErrCount  Bad counted repeat.
ErrNoAtom  No atom preceding repetition.
ErrRepeat  Repeat following repeat.
ErrBackRef  Bad backward reference.
ErrClass  Bad character class.
ErrComplex  Expression too complex.
ErrMemory  Out of memory.
ErrToken  Illegal token.
ErrBehind  Bad look-behind pattern.


Constructor & Destructor Documentation

FX::FXRex::FXRex (  )  [inline]

Construct empty regular expression object.

FX::FXRex::FXRex ( const FXRex orig  ) 

Copy regular expression object.

FX::FXRex::FXRex ( const FXchar pattern,
FXint  mode = Normal,
Error error = NULL 
)

Compile expression from pattern; if error is not NULL, error code is returned.

FX::FXRex::FXRex ( const FXString pattern,
FXint  mode = Normal,
Error error = NULL 
)

Compile expression from pattern; if error is not NULL, error code is returned.

FX::FXRex::~FXRex (  ) 

Delete.


Member Function Documentation

FXRex& FX::FXRex::operator= ( const FXRex orig  ) 

Assign another regular expression to this one.

FXbool FX::FXRex::empty (  )  const [inline]

See if regular expression is empty; the regular expression will be empty when it is unable to parse a pattern due to a syntax error.

FXRex::Error FX::FXRex::parse ( const FXchar pattern,
FXint  mode = Normal 
)

Parse pattern, return error code if syntax error is found.

FXRex::Error FX::FXRex::parse ( const FXString pattern,
FXint  mode = Normal 
)

Parse pattern, return error code if syntax error is found.

FXbool FX::FXRex::match ( const FXchar string,
FXint  len,
FXint beg = NULL,
FXint end = NULL,
FXint  mode = Forward,
FXint  npar = 1,
FXint  fm = 0,
FXint  to = 2147483647 
) const

Match a subject string of length len, returning true if a match is found and false otherwise.

The entire pattern is captured in beg[0] and end[0], where beg[0] refers to the position of the first matched character and end[0] refers to the position after the last matched character. Sub expressions from capturing parenthesis i are returned in beg[i] and end[i].

FXbool FX::FXRex::match ( const FXString string,
FXint beg = NULL,
FXint end = NULL,
FXint  mode = Forward,
FXint  npar = 1,
FXint  fm = 0,
FXint  to = 2147483647 
) const

Search for match in a string.

static FXString FX::FXRex::substitute ( const FXchar string,
FXint  len,
FXint beg,
FXint end,
const FXString replace,
FXint  npar = 1 
) [static]

After performing a regular expression match with capturing parentheses, a substitution string is build from the replace string, where where "&" is replaced by the entire matched pattern, and "\1" through "\9" are replaced by captured expressions.

The original source string and its length, and the match arrays beg and end must be passed.

static FXString FX::FXRex::substitute ( const FXString string,
FXint beg,
FXint end,
const FXString replace,
FXint  npar = 1 
) [static]

Return substitution string.

static const FXchar* FX::FXRex::getError ( FXRex::Error  err  )  [inline, static]

Returns error code for given error.

FXbool FX::FXRex::operator== ( const FXRex rex  )  const

Comparison operators.

FXbool FX::FXRex::operator!= ( const FXRex rex  )  const


Friends And Related Function Documentation

FXStream& operator<< ( FXStream store,
const FXRex s 
) [friend]

Saving and loading.

FXStream& operator>> ( FXStream store,
FXRex s 
) [friend]

Copyright © 1997-2009 Jeroen van der Zijp