Public Types | |
enum | { ERR_BADREPEAT = -2, ERR_BADBACKREF = -3, ERR_BADBRACE = -4, ERR_BADBRACK = -5, ERR_BADPARENTHESIS = -6, ERR_BADRANGE = -7, ERR_BADSUBREG = -8, ERR_BADCHARCLASS = -9, ERR_BADESCAPE = -10, ERR_BADPATTERN = -11, ERR_TOLARGE = -12, ERR_NOMEM = -13, ERR_GENERIC = -14 } |
Public Member Functions | |
RegExp () | |
Default constructor. | |
RegExp (const String &cExpression, bool bNoCase=false, bool bExtended=false) | |
Constructor. | |
~RegExp () | |
Destructor. | |
status_t | Compile (const String &cExpression, bool bNoCase=false, bool bExtended=false) |
Compile an regular expression. | |
int | GetSubExprCount () const |
Get the number of sub-expressions found in the previously compiled expression. | |
bool | IsValid () const |
Check if a valid expression has been compiled. | |
bool | Search (const String &cString) |
Search for the previously compiled regular expression. | |
bool | Search (const String &cString, int nStart, int nLen=-1) |
Search for the previously compiled regular expression. | |
bool | Match (const String &cString) |
Compare the regular expression to a string. | |
bool | Match (const String &cString, int nStart, int nLen=-1) |
Compare the regular expression to a string. | |
String | Expand (const String &cPattern) const |
Expand a string using substrings from the previous search. | |
int | GetStart () const |
Get the position of the first character that matched in the previous search. | |
int | GetEnd () const |
Get the position of the first character after the matched region in the previous search. | |
const String & | GetSubString (uint nIndex) const |
Get the result of a subexpression from the previous search. | |
bool | GetSubString (uint nIndex, int *pnStart, int *pnEnd) const |
Get the result of a subexpression from the previous search. | |
const std::vector< String > & | GetSubStrList () const |
Get a list of substrings from the previous search. | |
Classes | |
class | exception |
class | Private |
anonymous enum |
RegExp::RegExp | ( | ) |
RegExp::RegExp | ( | const String & | cExpression, | |
bool | bNoCase = false , |
|||
bool | bExtended = false | |||
) |
cExpression | The regular expression to compile. | |
bNoCase | Set to true if case should be ignored when doing subsequent searches. | |
bExtended | If true the POSIX Extended Regular Expression Syntax will be used. If false the POSIX Basic Regular Expression Syntax is used. |
RegExp::~RegExp | ( | ) |
status_t RegExp::Compile | ( | const String & | cExpression, | |
bool | bNoCase = false , |
|||
bool | bExtended = false | |||
) |
bExtended
argument is false (the default) the POSIX Basic Regular Expression Syntax is assumed, if it is true the the POSIX Extended Regular Expression Syntax is assumed. bNoCase
argument is false subsequent searches will be case insensitive. Error Code | Description |
ERR_BADREPEAT | An invalid repetition operator such as '*' or '?' appeared in a bad position (with no preceding subexpression to act on). |
ERR_BADBACKREF | There was an invalid backreference (\{...\}) construct in the expression. A valid backreference contain either a single numbed or two numbers in increasing order separated by a comma. |
ERR_BADBRACE | The expression had an unbalanced \{ \} construct. |
ERR_BADBRACK | The expression had an unbalanced \[ \] construct. |
ERR_BADPARENTHESIS | The expression had an unbalanced \( \) construct. |
ERR_BADRANGE | One of the endpoints in a range expression was invalid./td> |
ERR_BADSUBREG | There was an invalid number in a \digit construct. |
ERR_BADCHARCLASS | The expression referred to an invalid character class name. |
ERR_BADESCAPE | Invalid escape sequence (the expression ended with an '\'). |
ERR_BADPATTERN | There was an syntax error in the regular expression. |
ERR_TOLARGE | The expression was to large. Compiled regular expression buffer requires a pattern buffer larger than 64Kb. |
ERR_NOMEM | Ran out of memory while compiling the expression. |
ERR_GENERIC | Unspecified error. |
cExpression | The regular expression to compile. | |
bNoCase | Set to true if case should be ignored when doing subsequent searches. | |
bExtended | If true the POSIX Extended Regular Expression Syntax will be used. If false the POSIX Basic Regular Expression Syntax is used. |
int RegExp::GetSubExprCount | ( | ) | const |
bool RegExp::IsValid | ( | void | ) | const |
bool RegExp::Search | ( | const String & | cString | ) |
cString
. If the pattern was found true is returned and the start and end position of the expression within cString
is recorded. If the regular expression contain subexpression the sub-strings will be extracted and made availabel through GetSubString() and GetSubStrList(). cString | The string to search. |
bool RegExp::Search | ( | const String & | cString, | |
int | nStart, | |||
int | nLen = -1 | |||
) |
cString | The string to search. | |
nStart | Where in cString to start the search. | |
nLen | How many characters from cString to search. |
bool RegExp::Match | ( | const String & | cString | ) |
cString | The string that should be compared to the regular expression. |
bool RegExp::Match | ( | const String & | cString, | |
int | nStart, | |||
int | nLen = -1 | |||
) |
cString | The string that should be compared to the regular expression. | |
nStart | Where in cString to start the search. | |
nLen | How many characters from cString to search. |
cPattern
with the string yielded by the referenced sub-expression and return the result in a new String object. cPattern | The pattern that should be expanded. |
cPattern
with all "\%n" and "\%<nn>" constructs expanded. int RegExp::GetStart | ( | ) | const |
int RegExp::GetEnd | ( | ) | const |
const String & RegExp::GetSubString | ( | uint | nIndex | ) | const |
nIndex
. If the sub-expression was not used or if the index was out of range an empty string is returned. nIndex | A zero based index into the sub-expression list. |
bool RegExp::GetSubString | ( | uint | nIndex, | |
int * | pnStart, | |||
int * | pnEnd | |||
) | const |
nIndex
is out of range pnStart
and pnEnd
will be set to -1. nIndex | A zero based index into the sub-expression list. | |
pnStart | Pointer to an integer that will receive the index of the first character that matched the specified sub-expression. If you are not interrested in the start-position NULL can be passed. | |
pnEnd | Pointer to an integer that will receive the index of the first character after the region that matched the specified sub-expression. If you are not interrested in the end-position NULL can be passed. |
nIndex
is within range and false if not. const std::vector< String > & RegExp::GetSubStrList | ( | ) | const |