Pyro higlevel API
|
Regular expression class. More...
Classes | |
class | exception |
class | Private |
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. More... | |
RegExp (const String &cExpression, bool bNoCase=false, bool bExtended=false) | |
Constructor. More... | |
~RegExp () | |
Destructor. More... | |
status_t | Compile (const String &cExpression, bool bNoCase=false, bool bExtended=false) |
Compile an regular expression. More... | |
int | GetSubExprCount () const |
Get the number of sub-expressions found in the previously compiled expression. More... | |
bool | IsValid () const |
Check if a valid expression has been compiled. More... | |
bool | Search (const String &cString) |
Search for the previously compiled regular expression. More... | |
bool | Search (const String &cString, int nStart, int nLen=-1) |
Search for the previously compiled regular expression. More... | |
bool | Match (const String &cString) |
Compare the regular expression to a string. More... | |
bool | Match (const String &cString, int nStart, int nLen=-1) |
Compare the regular expression to a string. More... | |
String | Expand (const String &cPattern) const |
Expand a string using substrings from the previous search. More... | |
int | GetStart () const |
Get the position of the first character that matched in the previous search. More... | |
int | GetEnd () const |
Get the position of the first character after the matched region in the previous search. More... | |
const String & | GetSubString (uint nIndex) const |
Get the result of a subexpression from the previous search. More... | |
bool | GetSubString (uint nIndex, int *pnStart, int *pnEnd) const |
Get the result of a subexpression from the previous search. More... | |
const std::vector< String > & | GetSubStrList () const |
Get a list of substrings from the previous search. More... | |
anonymous enum |
RegExp::RegExp | ( | ) |
References os::RegExp::Private::m_bValid.
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. |
References Compile(), os::RegExp::Private::m_bValid, and os::RegExp::Private::m_pasMatches.
RegExp::~RegExp | ( | ) |
References os::RegExp::Private::m_bValid, os::RegExp::Private::m_pasMatches, and os::RegExp::Private::m_sRegex.
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. |
References os::String::c_str(), ERR_NOMEM, os::RegExp::Private::m_bValid, os::RegExp::Private::m_cSubStrings, os::RegExp::Private::m_pasMatches, and os::RegExp::Private::m_sRegex.
Referenced by RegExp().
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. References os::String::begin(), os::String::end(), os::RegExp::Private::m_cSubStrings, os::String::size(), and os::String::str().
int RegExp::GetEnd | ( | ) | const |
References os::RegExp::Private::m_bValid, and os::RegExp::Private::m_pasMatches.
int RegExp::GetStart | ( | ) | const |
References os::RegExp::Private::m_bValid, and os::RegExp::Private::m_pasMatches.
int RegExp::GetSubExprCount | ( | ) | const |
References os::RegExp::Private::m_bValid, and os::RegExp::Private::m_sRegex.
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. |
References os::RegExp::Private::m_cSubStrings.
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. References os::RegExp::Private::m_cSubStrings, os::RegExp::Private::m_nStartPos, and os::RegExp::Private::m_pasMatches.
const std::vector< String > & RegExp::GetSubStrList | ( | ) | const |
References os::RegExp::Private::m_cSubStrings.
bool RegExp::IsValid | ( | void | ) | const |
References os::RegExp::Private::m_bValid.
bool RegExp::Match | ( | const String & | cString | ) |
cString | The string that should be compared to the regular expression. |
References os::String::begin(), os::String::c_str(), os::RegExp::Private::m_bValid, os::RegExp::Private::m_cSubStrings, os::RegExp::Private::m_nStartPos, os::RegExp::Private::m_pasMatches, os::RegExp::Private::m_sRegex, and os::String::size().
Referenced by Match().
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. |
References os::RegExp::Private::m_nStartPos, Match(), and os::String::npos.
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. |
References os::String::begin(), os::String::c_str(), os::RegExp::Private::m_bValid, os::RegExp::Private::m_cSubStrings, os::RegExp::Private::m_nStartPos, os::RegExp::Private::m_pasMatches, and os::RegExp::Private::m_sRegex.
Referenced by 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. |
References os::RegExp::Private::m_nStartPos, os::String::npos, and Search().