xvr2::Text::Regex Class Reference

#include <Regex.h>

Inheritance diagram for xvr2::Text::Regex:

Inheritance graph
[legend]

List of all members.


Detailed Description

Use this class to handle and work with POSIX regular expressions.

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)

Constructor & Destructor Documentation

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.

Parameters:
pat Is the pattern to be compiled and match against during the Regex::match method calls.
Exceptions:
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.

Parameters:
pat Is the pattern to be compiled and match against during the Regex::match method calls.
Exceptions:
Exception::Regex If regex compilation fails at library level.

xvr2::Text::Regex::~Regex (  ) 


Member Function Documentation

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.

Exceptions:
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().

Parameters:
pat Is the regular expression pattern to be used.
Returns:
The pattern currently in use.
Exceptions:
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.

Parameters:
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).

Parameters:
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.

Parameters:
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.
Returns:
true if it str matches, false if not
Exceptions:
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.

Parameters:
str The string o test for matches against the given pattern
Returns:
true if it str matches, false if not

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.

Parameters:
str The string o test for matches against the given pattern
Returns:
true if it str matches, false if not

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]


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  stream,
const Object s 
) [friend, inherited]


Member Data Documentation

void* xvr2::Text::Regex::handle [private]

Definition at line 50 of file Regex.h.

Tells wheter the pattern has already been compiled by the regex engine.

Definition at line 53 of file Regex.h.

Definition at line 54 of file Regex.h.

int xvr2::Text::Regex::cflags [protected]

Holds the regex compilation flags.

Definition at line 57 of file Regex.h.

std::string xvr2::Object::__cls_name [protected, inherited]

Definition at line 30 of file Object.h.


The documentation for this class was generated from the following file:

Generated on Fri Jun 20 22:56:06 2008 for X-VR2 SDK by  doxygen 1.5.5