Public Member Functions | List of all members
Celartem::RegularExpression Class Reference

#include <cel_regex.h>

Public Member Functions

 RegularExpression (const UChar1 *inPattern, int inOptionFlags=regex_default)
 
 RegularExpression (const String &inPattern, int inOptionFlags=regex_default)
 
 RegularExpression (const utf8s &inPattern, int inOptionFlags=regex_default)
 
void init (const UChar1 *inPattern, int inOptionFlags=regex_default)
 
bool findFirst (const String &str)
 
bool findFirst (const UChar1 *str, const UChar1 *rangePtr=NULL, const UChar1 *rangeEnd=NULL, const UChar1 *strEnd=NULL)
 
bool findNext ()
 
bool isVaild () const
 
size_t getCount () const
 
size_t getPos (size_t n=0) const
 
size_t getEndPos (size_t n=0) const
 
size_t getLength (size_t n=0) const
 
const UChar1getPtr (size_t n=0) const
 
String getString (size_t n=0) const
 

Detailed Description

This class provides the function of search using the Regular Expression. The regular expression is a common method of searching, matching and separation of strings.
For details for regular expression syntax, see Regular Expression.
The following is the sample code of using RegularExpression class.

void enumerate_URLs(const String& inText)
{
// This regular expression separates the URL into parts.
utf8s(
"(\\w+[\\w-]+\\w+):\\/\\/" // "scheme://"
"(?:([^\\:]+)(?:\\:(\\w+))?\\@)?+" // "user:pass@"
"([^/:]+)" // "hostname"
"(?::(\\d*))?" // ":111"
"([^#\\?\\s]*)" // "/foo/bar/test.txt"
"(\\S*)")); // "?foo=1&bar=2" or "#label"
if(!reUrl.findFirst(inText))
{
// There's no match in the string
return;
}
do
{
printf(
"URL : \"%s\"\n"
"Scheme : \"%s\"\n"
"Username: \"%s\"\n"
"Password: \"%s\"\n"
"Hostname: \"%s\"\n"
"Port : %s\n"
"Path : \"%s\"\n"
"Extra : \"%s\"\n",
TO_MBS(reUrl.getString(0)),
TO_MBS(reUrl.getString(1)),
TO_MBS(reUrl.getString(2)),
TO_MBS(reUrl.getString(3)),
TO_MBS(reUrl.getString(4)),
reUrl.getString(5),
TO_MBS(reUrl.getString(6)),
TO_MBS(reUrl.getString(7)));
}
while(reUrl.findnext());

Constructor & Destructor Documentation

Celartem::RegularExpression::RegularExpression ( const UChar1 inPattern,
int  inOptionFlags = regex_default 
)
inline

This method create a RegularExpression instance.

Parameters
inPatternA pattern to search.
inOptionFlagsAny combination of RegexOptionFlag enumerations to control the behavior.
Celartem::RegularExpression::RegularExpression ( const String inPattern,
int  inOptionFlags = regex_default 
)
inline

This method create a RegularExpression instance.

Parameters
inPatternA pattern to search.
inOptionFlagsAny combination of RegexOptionFlag enumerations to control the behavior.
Celartem::RegularExpression::RegularExpression ( const utf8s inPattern,
int  inOptionFlags = regex_default 
)
inline

This method create a RegularExpression instance.

Parameters
inPatternA pattern to search.
inOptionFlagsAny combination of RegexOptionFlag enumerations to control the behavior.

Member Function Documentation

bool Celartem::RegularExpression::findFirst ( const String str)
inline

This method begins a new search in the specified string.

Parameters
strThe string on which the new search starts.
Returns
true if at least one matching portion is found, otherwise false.
bool Celartem::RegularExpression::findFirst ( const UChar1 str,
const UChar1 rangePtr = NULL,
const UChar1 rangeEnd = NULL,
const UChar1 strEnd = NULL 
)
inline

This method begins a new search in the specified string.

Parameters
strA string to do pattern matching on.
rangePtrPointer to the beginning point of pattern matching.
rangeEndPointer to the ending point of pattern matching.
strEndPointer to the string end. If this parameter is explicitly specified, then str don't have to be terminated by '\0'.
Returns
true if at least one matching portion is found, otherwise false.
bool Celartem::RegularExpression::findNext ( )
inline

This method returns the next matching portion if available.

Returns
true if at least one more matching portion is found, otherwise false.
size_t Celartem::RegularExpression::getCount ( ) const
inline

This method returns the count of the portions stored in this instance.

Returns
The number of portions in the instance.
size_t Celartem::RegularExpression::getEndPos ( size_t  n = 0) const
inline

This method returns the ending position of the specified portion.

Parameters
nThe index of the portion.
Returns
The ending position.
size_t Celartem::RegularExpression::getLength ( size_t  n = 0) const
inline

This method returns the length of the specified portion.

Parameters
nThe index of the portion.
Returns
The length of the portion string.
size_t Celartem::RegularExpression::getPos ( size_t  n = 0) const
inline

This method returns the beginning position of the specified portion.

Parameters
nThe index of the portion.
Returns
The beginning position.
const UChar1* Celartem::RegularExpression::getPtr ( size_t  n = 0) const
inline

This method returns the pointer to the specified portion.

Parameters
nThe index of the portion.
Returns
Pointer to the specified portion string.
String Celartem::RegularExpression::getString ( size_t  n = 0) const
inline

This method returns the string of the specified portion.

Parameters
nThe index of the portion.
Returns
The string of the portion.
void Celartem::RegularExpression::init ( const UChar1 inPattern,
int  inOptionFlags = regex_default 
)
inline

This method re-initializes the instance to search another pattern.

Parameters
inPatternA pattern to search.
inOptionFlagsAny combination of RegexOptionFlag enumerations to control the behavior.

Referenced by RegularExpression().

bool Celartem::RegularExpression::isVaild ( ) const
inline

This method verifies whether the last match is valid or not.

Returns
true if valid, otherwise false.

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

Cuminas DjVu SDK 3.0.33103
This document is made with doxygen 1.8.5 at Sun Dec 15 2013 19:38:06.
Cuminas Logo