#include <Regex.h>
This class makes exclusive use of the GNU regex library as provided by GLIBC. This class provides abstraction over the regex compilation process since it is performed implicitly after you add a new pattern expression.
.
.
.
String str1 = "A long time ago in a galaxy far far away...";
String str2 = "At some point in the future...";
Regex r;
r.pattern("ago");
if(r.match(str1)) cout << "Pattern " << str1 << " matches" << endl;
cout << "Pattern " << str1 << " doesn't match" << endl;
if(r.match(str2)) cout << "Pattern " << str2 << " matches" << endl;
cout << "Pattern " << str1 << " doesn't match" << endl;
.
.
.
Definition at line 48 of file Regex.h.
Public Member Functions | |
Regex () | |
Default constructor, This one wont perform pattern autocompilation and is required that the pattern gets defined and successfully compiled before any match methods are applied to it. | |
Regex (const char *pat) | |
When calling this construtor the provided pattern will be instantly compiled and the use of any match methods can be done inmediately. | |
Regex (const String &pat) | |
When calling this construtor the provided pattern will be instantly compiled and the use of any match methods can be done inmediately. | |
~Regex () | |
const char * | pattern (const char *pat=0) |
Returns of specifies the pattern to be used in future Regex::match calls. | |
void | useExtended (bool u=true) |
If called before assigning a pattern the regex compilation will add support for extended regular expressions. | |
void | ignoreCase (bool u=true) |
If called before assigning a pattern the regex compilation will will verify matches disregarding the matchable string case (so it wont matter if it is uppercase or lowercase). | |
bool | matches (const char *str) |
By using the compiled regex it attempts to check if the provided string matches the previously given pattern. | |
bool | matches (const String &str) |
By using the compiled regex it attempts to check if the provided string matches the previously given pattern. | |
virtual const char * | getClassName () |
Returns the name of the current class. | |
virtual std::string | toString () |
Static Public Member Functions | |
static bool | match (const String &pattern, const String &str, bool case_sensitive=true) |
You may use this method as a shortcut when you need to test pattern matching against a single pattern once and dont want to create a Regex object. | |
static void | debugmsg (Object *obj, const char *msg, int linenumber=__LINE__, const char *srcfile=__FILE__) |
Will print a debug message to the screen. | |
static void | debugmsgln (Object *obj, const char *msg, int linenumber=__LINE__, const char *srcfile=__FILE__) |
Protected Member Functions | |
virtual void | compile () |
Compiles the provided pattern. | |
Protected Attributes | |
int | cflags |
Holds the regex compilation flags. | |
std::string | __cls_name |
Private Attributes | |
void * | handle |
bool | compiled |
Tells wheter the pattern has already been compiled by the regex engine. | |
String * | _pattern |
Friends | |
std::ostream & | operator<< (std::ostream &stream, const Object &s) |
xvr2::Text::Regex::Regex | ( | ) |
Default constructor, This one wont perform pattern autocompilation and is required that the pattern gets defined and successfully compiled before any match methods are applied to it.
xvr2::Text::Regex::Regex | ( | const char * | pat | ) |
When calling this construtor the provided pattern will be instantly compiled and the use of any match methods can be done inmediately.
However you must verify that the pattern compilation has succeded by checking any of the exceptions that might by thrown.
pat | Is the pattern to be compiled and match against during the Regex::match method calls. |
Exception::Regex | If regex compilation fails at library level. |
xvr2::Text::Regex::Regex | ( | const String & | pat | ) |
When calling this construtor the provided pattern will be instantly compiled and the use of any match methods can be done inmediately.
However you must verify that the pattern compilation has succeded by checking any of the exceptions that might by thrown.
pat | Is the pattern to be compiled and match against during the Regex::match method calls. |
Exception::Regex | If regex compilation fails at library level. |
xvr2::Text::Regex::~Regex | ( | ) |
virtual void xvr2::Text::Regex::compile | ( | ) | [protected, virtual] |
Compiles the provided pattern.
This method will make use of the regcomp function call in order to have a regex usable structure. I for some reason the pattern object is null an appropiate exception will be thrown.
NullPointer | if the regex pattern has not been initialized yet | |
RegexException | if regex compilation or matching fails at library level. |
Reimplemented in xvr2::Text::ExtendedRegex.
const char* xvr2::Text::Regex::pattern | ( | const char * | pat = 0 |
) |
Returns of specifies the pattern to be used in future Regex::match calls.
If the pattern is provided then it will be compiled automagically, compilation will make use of previous options like useExtended() and ignoreCase().
pat | Is the regular expression pattern to be used. |
Exception::NullPointer | If the regex pattern has not been initialized yet | |
Exception::Regex | If regex compilation fails |
void xvr2::Text::Regex::useExtended | ( | bool | u = true |
) |
If called before assigning a pattern the regex compilation will add support for extended regular expressions.
u | If true then pattern compilation will use extended regular exprenssions, otherwise common posix regular expressions will be used. |
void xvr2::Text::Regex::ignoreCase | ( | bool | u = true |
) |
If called before assigning a pattern the regex compilation will will verify matches disregarding the matchable string case (so it wont matter if it is uppercase or lowercase).
u | If true then pattern compilation will ignore case, otherwise the matching algorithms will be case sensitive. |
static bool xvr2::Text::Regex::match | ( | const String & | pattern, | |
const String & | str, | |||
bool | case_sensitive = true | |||
) | [static] |
You may use this method as a shortcut when you need to test pattern matching against a single pattern once and dont want to create a Regex object.
The method internally creates a Regex object compiles the given pattern and verifies if the given string matches or not.
pattern | Is the regular expression to be used | |
str | The string to test for matches against pattern. | |
case_sensitive | Wheter pattern matching should should be case-sensitive or not. |
xvr2::NullPointer | if the regex pattern has not been initialized yet | |
xvr2::RegexException | if regex compilation or matching fails at library level. |
Reimplemented in xvr2::Text::ExtendedRegex.
bool xvr2::Text::Regex::matches | ( | const char * | str | ) |
By using the compiled regex it attempts to check if the provided string matches the previously given pattern.
str | The string o test for matches against the given pattern |
bool xvr2::Text::Regex::matches | ( | const String & | str | ) |
By using the compiled regex it attempts to check if the provided string matches the previously given pattern.
str | The string o test for matches against the given pattern |
virtual const char* xvr2::Object::getClassName | ( | ) | [virtual, inherited] |
Returns the name of the current class.
static void xvr2::Object::debugmsg | ( | Object * | obj, | |
const char * | msg, | |||
int | linenumber = __LINE__ , |
|||
const char * | srcfile = __FILE__ | |||
) | [static, inherited] |
Will print a debug message to the screen.
static void xvr2::Object::debugmsgln | ( | Object * | obj, | |
const char * | msg, | |||
int | linenumber = __LINE__ , |
|||
const char * | srcfile = __FILE__ | |||
) | [static, inherited] |
virtual std::string xvr2::Object::toString | ( | ) | [virtual, inherited] |
std::ostream& operator<< | ( | std::ostream & | stream, | |
const Object & | s | |||
) | [friend, inherited] |
void* xvr2::Text::Regex::handle [private] |
bool xvr2::Text::Regex::compiled [private] |
String* xvr2::Text::Regex::_pattern [private] |
int xvr2::Text::Regex::cflags [protected] |
std::string xvr2::Object::__cls_name [protected, inherited] |