|
|
|
@ -9,6 +9,9 @@ |
|
|
|
|
@license LGPL, see file <a href="license.html">COPYING</a> |
|
|
|
|
|
|
|
|
|
$Log$ |
|
|
|
|
Revision 1.2 2004/12/16 13:09:31 marc |
|
|
|
|
possibility to evaluate and extract sub expressions |
|
|
|
|
|
|
|
|
|
Revision 1.1 2004/12/14 20:20:30 marc |
|
|
|
|
initial version |
|
|
|
|
|
|
|
|
@ -57,6 +60,9 @@ namespace mrw { |
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
|
|
/// The maximum number of sub expressions that are evaluated.
|
|
|
|
|
static const unsigned int MAX_SUB = 99; |
|
|
|
|
|
|
|
|
|
/** @brief flags that influence regular expressions
|
|
|
|
|
|
|
|
|
|
Flag @c newline treats a newline in the text to be compared as |
|
|
|
@ -82,16 +88,20 @@ namespace mrw { |
|
|
|
|
The regular expression is compiled on instanciation and can |
|
|
|
|
then be matced several times on different texts. |
|
|
|
|
|
|
|
|
|
@param pattern the regular expression pattern, thee the @c man |
|
|
|
|
@param pattern the regular expression pattern, see the @c man |
|
|
|
|
page for POSIX regular expressions (on linux: @c |
|
|
|
|
info 7 regex) |
|
|
|
|
@param flags special flags, they default to extended|nosub and |
|
|
|
|
@param hassub pass @c true if you want to evaluate sub expressions |
|
|
|
|
@param flags special flags, they default to extended and |
|
|
|
|
should consist of the Flag values combined with @c | |
|
|
|
|
flag @c nosub must not be used, because it is set |
|
|
|
|
automatically if necessary |
|
|
|
|
|
|
|
|
|
@throw std::invalid_argument if pattern compilation fails |
|
|
|
|
@throw mrw::invalid_argument if pattern compilation fails or @c nosub |
|
|
|
|
was set in @c flags |
|
|
|
|
*/ |
|
|
|
|
RegExp(const std::string& pattern, int flags = extended) |
|
|
|
|
throw(std::exception, std::bad_exception); |
|
|
|
|
RegExp(const std::string& pattern, bool hassub=false, int flags=extended) |
|
|
|
|
throw(std::exception); |
|
|
|
|
|
|
|
|
|
/** @brief cleans up expression from memory */ |
|
|
|
|
~RegExp() throw(); |
|
|
|
@ -102,11 +112,28 @@ namespace mrw { |
|
|
|
|
@return |
|
|
|
|
- true if @c text matches |
|
|
|
|
- false otherwise */ |
|
|
|
|
bool operator()(const std::string& text) const throw(); |
|
|
|
|
bool operator()(const std::string& text) throw(std::bad_exception); |
|
|
|
|
|
|
|
|
|
/** @brief get the n-th sub expression of the last matched text
|
|
|
|
|
|
|
|
|
|
If the RegExp was instanciated with @c Regexp(pattern, true), |
|
|
|
|
so that sub expressions are evaluated, then you can get the |
|
|
|
|
n-th matched sub expression. |
|
|
|
|
|
|
|
|
|
@param n the number of sub expression to get, get the n-th sub |
|
|
|
|
expression |
|
|
|
|
|
|
|
|
|
@throw mrw::invalid_argument if this subexpression is not |
|
|
|
|
available |
|
|
|
|
*/ |
|
|
|
|
std::string operator[](unsigned int n) const throw(std::exception); |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
|
|
|
|
|
regex_t _regex; |
|
|
|
|
bool _hassub; |
|
|
|
|
regmatch_t _sub[MAX_SUB]; |
|
|
|
|
std::string _text; |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|