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, Unicode = 1, Syntax = 2, Verbatim = 4,
  Capture = 8, IgnoreCase = 16, Newline = 32, Exact = 64,
  NotEmpty = 128, NotBol = 256, NotEol = 512
}
 Regular expression flags. More...
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,
  ErrSupport = 16
}
 Regular expression error codes. More...

Public Member Functions

 FXRex ()
 Construct empty regular expression object, with the fallback program installed.
 FXRex (const FXRex &orig)
 Copy regular expression object from another.
 FXRex (const FXchar *pattern, FXint mode=Normal, Error *error=NULL)
 Compile expression from pattern; if error is not NULL, error code is returned.
 FXRex (const FXString &pattern, FXint mode=Normal, Error *error=NULL)
 Compile expression from pattern; if error is not NULL, error code is returned.
FXbool empty () const
 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.
Error parse (const FXchar *pattern, FXint mode=Normal)
 Parse pattern, return error code if syntax error is found.
Error parse (const FXString &pattern, FXint mode=Normal)
FXbool amatch (const FXchar *string, FXint len, FXint pos=0, FXint mode=Normal, FXint *beg=NULL, FXint *end=NULL, FXint npar=0) const
 Perform anchored match of subject string of length len at position pos, returning true if the pattern matches at this point.
FXbool amatch (const FXString &string, FXint pos=0, FXint mode=Normal, FXint *beg=NULL, FXint *end=NULL, FXint npar=0) const
FXint search (const FXchar *string, FXint len, FXint fm, FXint to, FXint mode=Normal, FXint *beg=NULL, FXint *end=NULL, FXint npar=0) const
 Search subject string of length len for a pattern, returning the location where the pattern is found relative from the start of the string, or -1 if there is no match.
FXint search (const FXString &string, FXint fm, FXint to, FXint mode=Normal, FXint *beg=NULL, FXint *end=NULL, FXint npar=0) const
FXRexoperator= (const FXRex &orig)
 Assign another regular expression to this one.
FXbool operator== (const FXRex &rex) const
 Comparison operators.
FXbool operator!= (const FXRex &rex) const
void clear ()
 Clear the expression object and reinstate the fallback program.
 ~FXRex ()
 Delete.

Static Public Member Functions

static FXString substitute (const FXchar *string, FXint len, FXint *beg, FXint *end, const FXchar *replace, FXint npar=1)
 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.
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 FXchar *replace, FXint npar=1)
static FXString substitute (const FXString &string, FXint *beg, FXint *end, const FXString &replace, FXint npar=1)
static const FXchar * getError (Error err)
 Returns error message text for a given error code.

Friends

FXAPI FXStreamoperator<< (FXStream &store, const FXRex &s)
 Saving and loading.
FXAPI 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 searched forwards or backwards, and may contain any of 256 possible byte 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, and allows the matcher engine to return the locations of the string matching these sub-patterns. The flag IgnoreCase enables case-insensitive matching. When the flag Newline is passed, newlines are treated like normal characters, and not line-separators. If Newline flag is not passed, character classes such as '.', '', '', [^a-z] etc. will NOT match newlines. The flag Verbatim disables all special character interpretation, making the entire pattern a literal string to be matched against a string one-to-one. When the Exact flag is passed, a match succeeds only if the entire string is matched. If the NotEmpty flag is passed, the pattern must match at least one character in order to succeed. If the flag Syntax will check the pattern for correct syntax only, and not generate a matching engine; it will just reset the engine to the empty pattern.

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 flags NotBol and/or NotEol causes the begin and end of the subject string NOT to be considered a line start or line end.

Patterns which cause inordinate amounts of recursion may cause FXRex to fail where otherwise it would succeed to match.


Member Enumeration Documentation

anonymous enum

Regular expression flags.

Enumerator:
Normal 

Flags for both parse and match mode.

Unicode 

Normal mode (default)

Syntax 

Unicode mode.

Regular expression parse flags

Verbatim 

Perform syntax check only.

Capture 

Literal pattern mode with no magic characters.

IgnoreCase 

Perform capturing parentheses.

Newline 

Ignore case differences.

Exact 

Match-any operators match newline too.

NotEmpty 

Exact match to entire string (..)

NotBol 

A successful match must not be empty.

Regular expression match flags

NotEol 

Start of string is NOT begin of line.

Regular expression error codes.

Enumerator:
ErrEmpty 

No errors.

ErrParent 

Empty pattern.

ErrBracket 

Unmatched parenthesis.

ErrBrace 

Unmatched bracket.

ErrRange 

Unmatched brace.

ErrEscape 

Bad character range.

ErrCount 

Bad escape sequence.

ErrNoAtom 

Bad counted repeat.

ErrRepeat 

No atom preceding repetition.

ErrBackRef 

Repeat following repeat.

ErrClass 

Bad backward reference.

ErrComplex 

Bad character class.

ErrMemory 

Expression too complex.

ErrToken 

Out of memory.

ErrBehind 

Illegal token.

ErrSupport 

Bad look-behind pattern.


Member Function Documentation

FXbool FX::FXRex::amatch ( const FXchar *  string,
FXint  len,
FXint  pos = 0,
FXint  mode = Normal,
FXint *  beg = NULL,
FXint *  end = NULL,
FXint  npar = 0 
) const

Perform anchored match of subject string of length len at position pos, returning true if the pattern matches at this point.

If there is a match, the pattern and subpatterns are captured in the arrays beg[] and end[] which must both be at least npar entries long.

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

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

The parse-mode flags control the compile options, and affect how the generated matcher behaves. If a parse fails, an error code is returned; in this case, the expression matcher will be set up to a fallback program.

FXint FX::FXRex::search ( const FXchar *  string,
FXint  len,
FXint  fm,
FXint  to,
FXint  mode = Normal,
FXint *  beg = NULL,
FXint *  end = NULL,
FXint  npar = 0 
) const

Search subject string of length len for a pattern, returning the location where the pattern is found relative from the start of the string, or -1 if there is no match.

In case of a successful match, the pattern and subpatterns are captured in the arrays beg[] and end[] which must be at least npar entries long. The string is searched forwards (or backwards) starting from position fm toward to, both of which must lie inside the string.

static FXString FX::FXRex::substitute ( const FXchar *  string,
FXint  len,
FXint *  beg,
FXint *  end,
const FXchar *  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. The replace string may also contain regular escape sequences to embed special characters.


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

Copyright © 1997-2016 Jeroen van der Zijp