ionflux.org | Impressum

Ionflux::Tools::RegExp Class Reference
[Regular expressions]

Regular expression matching. More...

#include <RegExp.hpp>

List of all members.

Public Member Functions

 RegExp ()
 Constructor.
 RegExp (const std::string &initPattern)
 Constructor.
 RegExp (const std::string &initPattern, int initOptions)
 Constructor.
virtual ~RegExp ()
 Destructor.
virtual void setPattern (const std::string &newPattern)
 Set the pattern.
virtual std::string getPattern ()
 Get the pattern.
virtual void setOptions (int newOptions)
 Set PCRE options.
virtual int getOptions ()
 Get PCRE options.
virtual void setMaxSubpatterns (unsigned int newMaxSubpatterns)
 Set maximum number of subpatterns.
virtual unsigned int getMaxSubpatterns ()
 Get maximum number of subpatterns.
virtual bool match (const std::string &haystack, ReMatch *subPatterns=0)
 Match pattern in a string.
virtual unsigned int matchAll (const std::string &haystack, ReMatchSet *subPatterns)
 Match all patterns in a string.
virtual bool match (const std::string &needle, const std::string &haystack, ReMatch *subPatterns)
 Match pattern in a string.
virtual unsigned int matchAll (const std::string &needle, const std::string &haystack, ReMatchSet *subPatterns)
 Match pattern in a string.
virtual void replace (std::string &haystack, const std::string &replacement)
 Replace pattern in a string.
virtual void replaceSubpatterns (std::string &haystack, const std::vector< std::string > &replacement)
 Replace subpatterns in a string.
virtual void replaceAll (std::string &haystack, const std::string &replacement)
 Replace all patterns in a string.
virtual void replaceAllSubpatterns (std::string &haystack, const std::vector< std::string > &replacement)
 Replace all subpatterns in a string.
virtual void replace (const std::string &needle, std::string &haystack, const std::string &replacement)
 Replace pattern in a string.
virtual void replaceSubpatterns (const std::string &needle, std::string &haystack, const std::vector< std::string > &replacement)
 Replace subpatterns in a string.
virtual void replaceAll (const std::string &needle, std::string &haystack, const std::string &replacement)
 Replace all patterns in a string.
virtual void replaceAllSubpatterns (const std::string &needle, std::string &haystack, const std::vector< std::string > &replacement)
 Replace all subpatterns in a string.

Static Public Member Functions

static void createMatchMap (const ReMatch &match, const std::string &fields, const std::string &separator, const std::string &undefinedPrefix, std::map< std::string, std::string > &record)
 Create a map of matched subpatterns.
static void createMatchMap (const ReMatch &match, const std::vector< std::string > &fields, const std::string &undefinedPrefix, std::map< std::string, std::string > &record)
 Create a map of matched subpatterns.
static void createMatchTree (const ReMatch &match, const std::string &fields, const std::string &separator, const std::string &undefinedPrefix, Node &record)
 Create a tree of matched subpatterns.
static void createMatchTree (const ReMatch &match, const std::vector< std::string > &fields, const std::string &undefinedPrefix, Node &record)
 Create a tree of matched subpatterns.

Protected Attributes

pcre * regExp
 PCRE object.
std::string pattern
 The pattern.
unsigned int maxSubpatterns
 Maximum number of subpatterns that can be matched.
int pcreOptions
 PCRE options (see PCRE API specification).


Detailed Description

Regular expression matching.

Wrapper class for the Perl compatible regular expression API (PCRE).


Constructor & Destructor Documentation

Ionflux::Tools::RegExp::RegExp  ) 
 

Constructor.

Construct new RegExp object.

Ionflux::Tools::RegExp::RegExp const std::string &  initPattern  ) 
 

Constructor.

Construct new RegExp object.

Parameters:
initPattern The initial pattern.

Ionflux::Tools::RegExp::RegExp const std::string &  initPattern,
int  initOptions
 

Constructor.

Construct new RegExp object.

Parameters:
initPattern The initial pattern.
initOptions PCRE options.
See also:
setOptions()

Ionflux::Tools::RegExp::~RegExp  )  [virtual]
 

Destructor.

Destruct RegExp object.


Member Function Documentation

void Ionflux::Tools::RegExp::createMatchMap const ReMatch match,
const std::vector< std::string > &  fields,
const std::string &  undefinedPrefix,
std::map< std::string, std::string > &  record
[static]
 

Create a map of matched subpatterns.

Generates a map of matched subpatterns by taking keys from the fields parameter and the matched subpatterns as values. The fields parameter is a vector containing the of field names. If there are more subpatterns than field names, missing field names will be generated automatically by appending a number to the 'undefinedPrefix'.

Note:
The complete match will not be added to the map.
Parameters:
match Subpatterns for which a map should be created.
fields Vector of field names tu use as keys.
undefinedPrefix Prefix for undefined fields.
record Map to store the results in.

void Ionflux::Tools::RegExp::createMatchMap const ReMatch match,
const std::string &  fields,
const std::string &  separator,
const std::string &  undefinedPrefix,
std::map< std::string, std::string > &  record
[static]
 

Create a map of matched subpatterns.

Generates a map of matched subpatterns by taking keys from the fields parameter and the matched subpatterns as values. The fields parameter is a string consisting of field names, separated by the string 'separator'. If there are more subpatterns than field names, missing field names will be generated automatically by appending a number to the 'undefinedPrefix'.

Note:
The complete match will not be added to the map.
Parameters:
match Subpatterns for which a map should be created.
fields Field names tu use as keys.
separator Field name separator.
undefinedPrefix Prefix for undefined fields.
record Map to store the results in.

void Ionflux::Tools::RegExp::createMatchTree const ReMatch match,
const std::vector< std::string > &  fields,
const std::string &  undefinedPrefix,
Node record
[static]
 

Create a tree of matched subpatterns.

Generates a tree of matched subpatterns by taking keys from the fields parameter and the matched subpatterns as values. The fields parameter is a vector containing the of field names. If there are more subpatterns than field names, missing field names will be generated automatically by appending a number to the undefinedPrefix.

Note:
The complete match will not be added to the tree.
Parameters:
match Subpatterns for which a map should be created.
fields Vector of field names tu use as keys.
undefinedPrefix Prefix for undefined fields.
record Node to store the results in.

void Ionflux::Tools::RegExp::createMatchTree const ReMatch match,
const std::string &  fields,
const std::string &  separator,
const std::string &  undefinedPrefix,
Node record
[static]
 

Create a tree of matched subpatterns.

Generates a tree of matched subpatterns by taking keys from the fields parameter and the matched subpatterns as values. The fields parameter is a string consisting of field names, separated by the string separator. If there are more subpatterns than field names, missing field names will be generated automatically by appending a number to the undefinedPrefix.

Note:
The complete match will not be added to the tree.
Parameters:
match Subpatterns for which a map should be created.
fields Field names tu use as keys.
separator Field name separator.
undefinedPrefix Prefix for undefined fields.
record Node to store the results in.

unsigned int Ionflux::Tools::RegExp::getMaxSubpatterns  )  [virtual]
 

Get maximum number of subpatterns.

Get the maximum number of subpatterns that will be returned by a matching operation.

Returns:
Maximum number of subpatterns.

int Ionflux::Tools::RegExp::getOptions  )  [virtual]
 

Get PCRE options.

Get the current PCRE options.

Returns:
Current PCRE options.

string Ionflux::Tools::RegExp::getPattern  )  [virtual]
 

Get the pattern.

Get the current pattern.

Returns:
The current pattern.

bool Ionflux::Tools::RegExp::match const std::string &  needle,
const std::string &  haystack,
ReMatch subPatterns
[virtual]
 

Match pattern in a string.

Convenience function to match pattern needle to string haystack without any previous pattern initialization.

Parameters:
needle Pattern to search for.
haystack String in which to search for patterns.
subPatterns Where to store subpatterns.
Returns:
true if the pattern matches the haystack, false otherwise.

bool Ionflux::Tools::RegExp::match const std::string &  haystack,
ReMatch subPatterns = 0
[virtual]
 

Match pattern in a string.

Match pattern to a string. Returns true if a match is found, false otherwise. If the subPatterns argument is not null, it will be used to store matched subpatterns. The maximum number of subpatterns that will be stored can be retrieved with getMaxSubpatterns() and set with setMaxSubpatterns().

Parameters:
haystack String in which to search for patterns.
subPatterns Where to store subpatterns.
See also:
matchAll(), getMaxSubpatterns() setMaxSubpatterns()
Returns:
true if the pattern matches the haystack, false otherwise.

unsigned int Ionflux::Tools::RegExp::matchAll const std::string &  needle,
const std::string &  haystack,
ReMatchSet subPatterns
[virtual]
 

Match pattern in a string.

Convenience function to match all occurences of pattern needle in string haystack without any previous pattern initialization.

Parameters:
needle Pattern to search for.
haystack String in which to search for patterns.
subPatterns Where to store subpatterns.
See also:
match()
Returns:
Number of occurences of the pattern that have been matched.

unsigned int Ionflux::Tools::RegExp::matchAll const std::string &  haystack,
ReMatchSet subPatterns
[virtual]
 

Match all patterns in a string.

Like match(), except that all occurences of the pattern in haystack are matched. Returns the number of matches. If the subPatterns argument is not null, it will be used to store matched subpatterns.

Parameters:
haystack String in which to search for patterns.
subPatterns Where to store subpatterns.
See also:
match()
Returns:
Number of occurences of the pattern that have been matched.

void Ionflux::Tools::RegExp::replace const std::string &  needle,
std::string &  haystack,
const std::string &  replacement
[virtual]
 

Replace pattern in a string.

Convenience function to replace pattern needle in string haystack with replacement without any previous pattern initialization.

Parameters:
needle Pattern which to replace.
haystack String in which to replace patterns.
replacement Replacement string.

void Ionflux::Tools::RegExp::replace std::string &  haystack,
const std::string &  replacement
[virtual]
 

Replace pattern in a string.

Replaces pattern in string haystack with replacement.

Parameters:
haystack String in which to replace patterns.
replacement Replacement string.

void Ionflux::Tools::RegExp::replaceAll const std::string &  needle,
std::string &  haystack,
const std::string &  replacement
[virtual]
 

Replace all patterns in a string.

Convenience function to replace all occurences of pattern needle in string haystack with replacement without any previous pattern initialization.

Parameters:
needle Pattern which to replace.
haystack String in which to replace patterns.
replacement Replacement string.
See also:
replace()

void Ionflux::Tools::RegExp::replaceAll std::string &  haystack,
const std::string &  replacement
[virtual]
 

Replace all patterns in a string.

Like replace(), except that all occurences of the pattern are replaced.

Parameters:
haystack String in which to replace patterns.
replacement Replacement string.
See also:
replace()

void Ionflux::Tools::RegExp::replaceAllSubpatterns const std::string &  needle,
std::string &  haystack,
const std::vector< std::string > &  replacement
[virtual]
 

Replace all subpatterns in a string.

Convenience function to replace all occurences of subpatterns of needle in string haystack with strings from replacement without any previous pattern initialization.

Parameters:
needle Pattern which to replace.
haystack String in which to replace patterns.
replacement Replacement strings.
See also:
replaceSubPatterns()

void Ionflux::Tools::RegExp::replaceAllSubpatterns std::string &  haystack,
const std::vector< std::string > &  replacement
[virtual]
 

Replace all subpatterns in a string.

Like replaceSubpatterns(), except that all occurences of the subpatterns are replaced.

Parameters:
haystack String in which to replace patterns.
replacement Replacement strings.
See also:
replaceSubPatterns()

void Ionflux::Tools::RegExp::replaceSubpatterns const std::string &  needle,
std::string &  haystack,
const std::vector< std::string > &  replacement
[virtual]
 

Replace subpatterns in a string.

Convenience function to replace subpatterns of needle in string haystack with strings from replacement without any previous pattern initialization.

Parameters:
needle Pattern which to replace.
haystack String in which to replace patterns.
replacement Replacement strings.

void Ionflux::Tools::RegExp::replaceSubpatterns std::string &  haystack,
const std::vector< std::string > &  replacement
[virtual]
 

Replace subpatterns in a string.

Replaces subpatterns in string haystack with strings from vector replacement.

Parameters:
haystack String in which to replace patterns.
replacement Replacement strings.

void Ionflux::Tools::RegExp::setMaxSubpatterns unsigned int  newMaxSubpatterns  )  [virtual]
 

Set maximum number of subpatterns.

Sets the maximum number of subpatterns that will be returned by a matching operation.

Parameters:
newMaxSubpatterns Maximum number of subpatterns to return.

void Ionflux::Tools::RegExp::setOptions int  newOptions  )  [virtual]
 

Set PCRE options.

Sets PCRE options used for matching to the specified string.

As of PCRE 4.5, valid options are:

PCRE_ANCHORED Force pattern anchoring
PCRE_CASELESS Do caseless matching
PCRE_DOLLAR_ENDONLY $ not to match newline at end
PCRE_DOTALL . matches anything including NL
PCRE_EXTENDED Ignore whitespace and # comments
PCRE_EXTRA PCRE extra features (not much use currently)
PCRE_MULTILINE ^ and $ match newlines within data
PCRE_NO_AUTO_CAPTURE Disable numbered capturing parentheses (named ones available)
PCRE_UNGREEDY Invert greediness of quantifiers
PCRE_UTF8 Run in UTF-8 mode
PCRE_NO_UTF8_CHECK Do not check the pattern for UTF-8 validity (only relevant if PCRE_UTF8 is set)

Parameters:
newOptions PCRE options.

void Ionflux::Tools::RegExp::setPattern const std::string &  newPattern  )  [virtual]
 

Set the pattern.

Sets the pattern used for matching to the specified string.

Parameters:
newPattern The new pattern.


Member Data Documentation

unsigned int Ionflux::Tools::RegExp::maxSubpatterns [protected]
 

Maximum number of subpatterns that can be matched.

std::string Ionflux::Tools::RegExp::pattern [protected]
 

The pattern.

int Ionflux::Tools::RegExp::pcreOptions [protected]
 

PCRE options (see PCRE API specification).

pcre* Ionflux::Tools::RegExp::regExp [protected]
 

PCRE object.


The documentation for this class was generated from the following files:
Generated on Tue Mar 14 21:09:15 2006 for Ionflux Tools Class Library (iftools) by  doxygen 1.4.6