Celartem::RegularExpression Class Reference

#include <cel_regex.h>

List of all members.

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.
                RegularExpression reUrl(
                    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());

Definition at line 142 of file cel_regex.h.


Constructor & Destructor Documentation

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

This method create a RegularExpression instance.

Parameters:
inPattern A pattern to search.
inOptionFlags Any combination of RegexOptionFlag enumerations to control the behavior.

Definition at line 153 of file cel_regex.h.

Celartem::RegularExpression::RegularExpression ( const String inPattern,
int  inOptionFlags = regex_default 
) [inline]

This method create a RegularExpression instance.

Parameters:
inPattern A pattern to search.
inOptionFlags Any combination of RegexOptionFlag enumerations to control the behavior.

Definition at line 168 of file cel_regex.h.

Celartem::RegularExpression::RegularExpression ( const utf8s inPattern,
int  inOptionFlags = regex_default 
) [inline]

This method create a RegularExpression instance.

Parameters:
inPattern A pattern to search.
inOptionFlags Any combination of RegexOptionFlag enumerations to control the behavior.

Definition at line 185 of file cel_regex.h.


Member Function Documentation

void Celartem::RegularExpression::init ( const UChar1 inPattern,
int  inOptionFlags = regex_default 
) [inline]

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

Parameters:
inPattern A pattern to search.
inOptionFlags Any combination of RegexOptionFlag enumerations to control the behavior.

Definition at line 200 of file cel_regex.h.

Referenced by RegularExpression().

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

This method begins a new search in the specified string.

Parameters:
str The string on which the new search starts.
Returns:
true if at least one matching portion is found, otherwise false.

Definition at line 216 of file cel_regex.h.

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:
str A string to do pattern matching on.
rangePtr Pointer to the beginning point of pattern matching.
rangeEnd Pointer to the ending point of pattern matching.
strEnd Pointer 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.

Definition at line 239 of file cel_regex.h.

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.

Definition at line 255 of file cel_regex.h.

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

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

Returns:
true if valid, otherwise false.

Definition at line 274 of file cel_regex.h.

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.

Definition at line 285 of file cel_regex.h.

size_t Celartem::RegularExpression::getPos ( size_t  n = 0  )  const [inline]

This method returns the beginning position of the specified portion.

Parameters:
n The index of the portion.
Returns:
The beginning position.

Definition at line 298 of file cel_regex.h.

size_t Celartem::RegularExpression::getEndPos ( size_t  n = 0  )  const [inline]

This method returns the ending position of the specified portion.

Parameters:
n The index of the portion.
Returns:
The ending position.

Definition at line 311 of file cel_regex.h.

size_t Celartem::RegularExpression::getLength ( size_t  n = 0  )  const [inline]

This method returns the length of the specified portion.

Parameters:
n The index of the portion.
Returns:
The length of the portion string.

Definition at line 323 of file cel_regex.h.

const UChar1* Celartem::RegularExpression::getPtr ( size_t  n = 0  )  const [inline]

This method returns the pointer to the specified portion.

Parameters:
n The index of the portion.
Returns:
Pointer to the specified portion string.

Definition at line 335 of file cel_regex.h.

String Celartem::RegularExpression::getString ( size_t  n = 0  )  const [inline]

This method returns the string of the specified portion.

Parameters:
n The index of the portion.
Returns:
The string of the portion.

Definition at line 347 of file cel_regex.h.


The documentation for this class was generated from the following file:
This document is automatically generated using doxygen 1.5.4 at Fri Jun 27 18:23:19 2008.