![]() |
appkit
1.5.1
RoadNarrows Robotics Application Kit
|
Regular Express Class. More...
#include <RegEx.h>
Classes | |
| struct | ReMatch |
| Regular expression match structure. More... | |
Public Types | |
| typedef std::vector< ReMatch > | ReMatchVec |
| vector of matches | |
Public Member Functions | |
| RegEx (int nFlags=ReFlagDefaults) | |
| Default constructor. More... | |
| RegEx (const std::string &strRegEx, int nFlags=ReFlagDefaults) | |
| String initialization constructor. More... | |
| RegEx (const char *sRegEx, int nFlags=ReFlagDefaults) | |
| Null-terminated char* initialization constructor. More... | |
| RegEx (const RegEx &src) | |
| Copy constructor. More... | |
| virtual | ~RegEx () |
| Default destructor. | |
| RegEx & | operator= (const RegEx &rhs) |
| Assignment copy operator. More... | |
| RegEx & | operator= (const std::string &rhs) |
| Assignment operator. More... | |
| RegEx & | operator= (const char *rhs) |
| Assignment operator. More... | |
| bool | match (const char *sInput, const int nFlags=ReFlagDefaults) |
| Match the input char* against the regular expression. More... | |
| bool | match (const char *sInput, const int nFlags=ReFlagDefaults) const |
| size_t | match (const std::string &strInput, ReMatchVec &matches, const size_t uMaxSubMatches=ReMaxSubMatchesDft, const int nFlags=ReFlagDefaults) |
| Find all substrings in the input that match the regular expression. More... | |
| size_t | match (const std::string &strInput, ReMatchVec &matches, const size_t uMaxSubMatches=ReMaxSubMatchesDft, const int nFlags=ReFlagDefaults) const |
| size_t | match (const char *sInput, ReMatchVec &matches, const size_t uMaxSubMatches=ReMaxSubMatchesDft, const int nFlags=ReFlagDefaults) |
| Find all substrings in input that match the regular expression. More... | |
| size_t | match (const char *sInput, ReMatchVec &matches, const size_t uMaxSubMatches=ReMaxSubMatchesDft, const int nFlags=ReFlagDefaults) const |
| const std::string & | getRegEx () const |
| Get the pre-compiled regular expression. More... | |
| bool | isValid () const |
| Test if in a valid state (i.e. compiled). More... | |
| int | getFlags () const |
| Get compile behavior flags. More... | |
| void | setFlags (int nFlags) |
| Set new compile behavior flags. More... | |
| int | getReturnCode () const |
| Get the extened return code from the last RegEx operation. More... | |
| const std::string & | getErrorStr () const |
| Get the last RegExs operation error string. More... | |
| bool | match (const std::string &strInput, const int nFlags=ReFlagDefaults) |
| Match the input string against the regular expression. More... | |
| bool | match (const std::string &strInput, const int nFlags=ReFlagDefaults) const |
Static Public Attributes | |
| static const int | ReOk = REG_NOERROR |
| Special return and error codes. More... | |
| static const int | ReENoExpr = -1000 |
| no pre-compiled express | |
| static const int | ReENotComp = -1001 |
| not compiled | |
| static const int | ReFlagDefaults = 0 |
| Regular expression compile and matching behavior flags. More... | |
| static const int | ReFlagICase = REG_ICASE |
| ignore case when matching | |
| static const int | ReFlagNewLine = REG_NEWLINE |
force bol/eol matching | |
| static const int | ReFlagNotBoL = REG_NOTBOL |
| input not begin of line | |
| static const int | ReFlagNotEoL = REG_NOTEOL |
| input not end of line | |
| static const char * | ReInvalid = "inre" |
| Concerning, in reality, in regards to invalid regular expressions. | |
| static const size_t | ReMaxSubMatchesDft = 32 |
Protected Member Functions | |
| bool | compile () |
| Compile the regular expression string. More... | |
| void | groomFlags (const int nFlags) |
| Groom compile behavior flags, disabling any unsupported flags. More... | |
| void | setError (const int nCode) |
| Set the error code and associated error string. More... | |
| void | freeReMem () |
| Free compiled regular expression memory. | |
Protected Attributes | |
| std::string | m_strRegEx |
| pre-compiled regular expression string | |
| int | m_nFlags |
| compile and matching flags | |
| bool | m_bIsValid |
| expression [not] successfully compiled | |
| regex_t | m_regex |
| compiled reqular expression | |
| int | m_nReCode |
| compiled regular expression return code | |
| std::string | m_strReError |
| compiled regualar expresson error string | |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const RegEx &re) |
| Insert object into output stream. More... | |
| std::istream & | operator>> (std::istream &is, RegEx &re) |
| Extract from input stream to object. More... | |
Regular Express Class.
Regular expression are evaluated using the POSIX Extended Regular Expression syntax.
| RegEx::RegEx | ( | int | nFlags = ReFlagDefaults | ) |
Default constructor.
No regular expression compile will be attempted.
| nFlags | Bitwise-or of compile behavior flags. |
Definition at line 81 of file RegEx.cxx.
| rnr::RegEx::RegEx | ( | const std::string & | strRegEx, |
| int | nFlags = ReFlagDefaults |
||
| ) |
String initialization constructor.
Regular expression compile will be attempted.
| strRegEx | Pre-compile regular expression string. |
| nFlags | Bitwise-or of compile behavior flags. |
| RegEx::RegEx | ( | const char * | sRegEx, |
| int | nFlags = ReFlagDefaults |
||
| ) |
Null-terminated char* initialization constructor.
If not NULL or empty, regular expression compile will be attempted.
| sRegEx | Null-terminated pre-compile regular expression string. |
| nFlags | Bitwise-or of compile behavior flags. |
Definition at line 99 of file RegEx.cxx.
| RegEx::RegEx | ( | const RegEx & | src | ) |
Copy constructor.
Regular expression compile will be attempted.
| src | Source object. |
Definition at line 116 of file RegEx.cxx.
References m_nFlags, and m_strRegEx.
|
protected |
Compile the regular expression string.
Definition at line 373 of file RegEx.cxx.
|
inline |
Get the last RegExs operation error string.
Definition at line 401 of file RegEx.h.
References m_strReError, operator<<, and operator>>.
Referenced by rnr::cmd::CommandLine::parseVarRegExpr(), utPr(), and utRun().
|
inline |
Get compile behavior flags.
Definition at line 364 of file RegEx.h.
References m_nFlags, and setFlags().
Referenced by utPr().
|
inline |
Get the pre-compiled regular expression.
Definition at line 342 of file RegEx.h.
References m_strRegEx.
Referenced by freeReMem(), rnr::cmd::CmdArgDef::getRegEx(), rnr::cmd::CommandLine::parseVarRegExpr(), and utPr().
|
inline |
Get the extened return code from the last RegEx operation.
| Return Code | Description |
|---|---|
| ReOk (REG_NOERROR) | No error |
| REG_NOMATCH | Input does no match regular expression |
| REG_BAD*, REG_E* | The regex C interface standard compile errors |
| ReENoExpr | No regular expression extended error |
| ReENotComp | Not compiled extended error |
Definition at line 391 of file RegEx.h.
References m_nReCode.
Referenced by utPr().
|
protected |
Groom compile behavior flags, disabling any unsupported flags.
| nFlags | Bitwise-or of compile behavior flags. |
Definition at line 409 of file RegEx.cxx.
|
inline |
Test if in a valid state (i.e. compiled).
If valid, match operation may be applied.
Definition at line 354 of file RegEx.h.
References m_bIsValid.
Referenced by freeReMem(), rnr::cmd::CommandLine::parseVarRegExpr(), and utPr().
| bool rnr::RegEx::match | ( | const std::string & | strInput, |
| const int | nFlags = ReFlagDefaults |
||
| ) |
Match the input string against the regular expression.
The entire input must match the regular expression.
| [in] | strInput | Input string to match. |
Referenced by utConstRe(), and utRun().
| bool RegEx::match | ( | const char * | sInput, |
| const int | nFlags = ReFlagDefaults |
||
| ) |
Match the input char* against the regular expression.
The entire input must match the regular expression.
| [in] | sInput | Null-terminated input char* to match. |
Definition at line 222 of file RegEx.cxx.
References rnr::RegEx::ReMatch::m_strMatch, rnr::RegEx::ReMatch::m_uEnd, and rnr::RegEx::ReMatch::m_uStart.
| size_t rnr::RegEx::match | ( | const std::string & | strInput, |
| ReMatchVec & | matches, | ||
| const size_t | uMaxSubMatches = ReMaxSubMatchesDft, |
||
| const int | nFlags = ReFlagDefaults |
||
| ) |
Find all substrings in the input that match the regular expression.
As an example, the following C++ code snippet:
Produces the output:
Notes:
| [in] | strInput | Input string. |
| [in,out] | Vector | of matches. |
| uMaxSubMatches | Maximum number of submatches per match. | |
| nFlags | Bitwise-or of matching behavior flags. |
| size_t RegEx::match | ( | const char * | sInput, |
| ReMatchVec & | matches, | ||
| const size_t | uMaxSubMatches = ReMaxSubMatchesDft, |
||
| const int | nFlags = ReFlagDefaults |
||
| ) |
Find all substrings in input that match the regular expression.
| [in] | sInput | Null-terminated input char*. |
| [in,out] | Vector | of matches. |
| uMaxSubMatches | Maximum number of submatches per match. | |
| nFlags | Bitwise-or of matching behavior flags. |
Definition at line 358 of file RegEx.cxx.
Assignment copy operator.
Regular expression compile will be attempted.
| rhs | Regular expression class object. |
Definition at line 131 of file RegEx.cxx.
References m_nFlags, and m_strRegEx.
| RegEx& rnr::RegEx::operator= | ( | const std::string & | rhs | ) |
Assignment operator.
Regular expression compile will be attempted.
| rhs | String regular expression. |
| RegEx & RegEx::operator= | ( | const char * | rhs | ) |
Assignment operator.
If not NULL or empty, regular expression compile will be attempted.
| rhs | Null-terminated string expression object. |
Definition at line 155 of file RegEx.cxx.
|
protected |
Set the error code and associated error string.
| nCode | Extended return code. |
Definition at line 415 of file RegEx.cxx.
| void RegEx::setFlags | ( | int | nFlags | ) |
Set new compile behavior flags.
| nFlags | Bitwise-or of compile behavior flags. |
Definition at line 397 of file RegEx.cxx.
Referenced by getFlags(), and rnr::cmd::CommandLine::parseVarRegExpr().
|
friend |
Insert object into output stream.
Output: re"REGEX" string where REGEX is the regular expression pattern.
| os | Output stream. |
| re | Object to insert. |
Referenced by getErrorStr().
|
friend |
Extract from input stream to object.
Input: re"REGEX" string where REGEX is the regular expression pattern.
| is | Input stream. |
| re | Object to extract into. |
Referenced by getErrorStr().
|
static |
|
static |
|
static |