Matcher Class Reference

List of all members.

Public Member Functions

 ~Matcher ()
 Cleans up the dynamic memory used by this matcher.
std::string replaceWithGroups (const std::string &str)
unsigned long getFlags () const
std::string getText () const
bool matches ()
bool findFirstMatch ()
bool findNextMatch ()
std::vector< std::string > findAll ()
void reset ()
std::string getString () const
void setString (const std::string &newStr)
int getStartingIndex (const int groupNum=0) const
int getEndingIndex (const int groupNum=0) const
std::string getGroup (const int groupNum=0) const
std::vector< std::string > getGroups (const bool includeGroupZero=0) const
int getGroupNum ()

Static Public Attributes

static const int MATCH_ENTIRE_STRING = 0x01
 Used internally by match to signify we want the entire string matched.

Protected Member Functions

void clearGroups ()
 Called by reset to clear the group arrays.

Protected Attributes

Patternpat
 The pattern we use to match.
std::string str
 The string in which we are matching.
int start
 The starting point of our match.
int * starts
 An array of the starting positions for each group.
int * ends
 An array of the ending positions for each group.
int * groups
 An array of private data used by NFANodes during matching.
int * groupIndeces
 An array of private data used by NFANodes during matching.
int * groupPos
 An array of private data used by NFANodes during matching.
int lm
 The ending index of the last match.
int gc
 The number of capturing groups we have.
int ncgc
 The number of non-capturing groups we havew.
int matchedSomething
 Whether or not we have matched something (used only by findFirstMatch and findNextMatch).
unsigned long flags
 The flags with which we were made.

Friends

class NFANode
class NFAStartNode
class NFAEndNode
class NFAGroupHeadNode
class NFAGroupLoopNode
class NFAGroupLoopPrologueNode
class NFAGroupTailNode
class NFALookBehindNode
class NFAStartOfLineNode
class NFAEndOfLineNode
class NFAEndOfMatchNode
class NFAReferenceNode
class Pattern

Detailed Description

A matcher is a non thread-safe object used to scan strings using a given Pattern object. Using a Matcher is the preferred method for scanning strings. Matchers are not thread-safe. Matchers require very little dynamic memory, hence one is encouraged to create several instances of a matcher when necessary as opposed to sharing a single instance of a matcher.

Author:
Jeffery Stuart
Since:
March 2003, Stable Since November 2004
Version:
0.02a Mutable object used on instances of a Pattern class


Member Function Documentation

std::string Matcher::replaceWithGroups ( const std::string &  str  ) 

Replaces the contents of str with the appropriate captured text. str should have at least one back reference, otherwise this function does nothing.

Parameters:
str The string in which to replace text
Returns:
A string with all backreferences appropriately replaced

unsigned long Matcher::getFlags (  )  const

The flags currently being used by the matcher.

Returns:
Zero

std::string Matcher::getText (  )  const

The text being searched by the matcher.

Returns:
the text being searched by the matcher.

bool Matcher::matches (  ) 

Scans the string from start to finish for a match. The entire string must match for this function to return success. Group variables are appropriately set and can be queried after this function returns.

Returns:
Success if and only if the entire string matches the pattern

bool Matcher::findFirstMatch (  ) 

Scans the string for the first substring matching the pattern. The entire string does not necessarily have to match for this function to return success. Group variables are appropriately set and can be queried after this function returns.

Returns:
Success if any substring matches the specified pattern

bool Matcher::findNextMatch (  ) 

Scans the string for the next substring matching the pattern. If no calls have been made to findFirstMatch of findNextMatch since the last call to reset, matches, or setString, then this function's behavior results to that of findFirstMatch.

Returns:
Success if another substring can be found that matches the pattern

std::vector< std::string > Matcher::findAll (  ) 

Returns a vector of every substring in order which matches the given pattern.

Returns:
Every substring in order which matches the given pattern

void Matcher::reset (  ) 

Resets the internal state of the matcher

std::string Matcher::getString (  )  const [inline]

Same as getText. Left n for backwards compatibilty with old source code

Returns:
Returns the string that is currently being used for matching

void Matcher::setString ( const std::string &  newStr  )  [inline]

Sets the string to scan

Parameters:
newStr The string to scan for subsequent matches

int Matcher::getStartingIndex ( const int  groupNum = 0  )  const

Returns the starting index of the specified group.

Parameters:
groupNum The group to query
Returns:
The starting index of the group if it was matched, -1 for an invalid group or if the group was not matched

int Matcher::getEndingIndex ( const int  groupNum = 0  )  const

Returns the ending index of the specified group.

Parameters:
groupNum The group to query
Returns:
The ending index of the group if it was matched, -1 for an invalid group or if the group was not matched

std::string Matcher::getGroup ( const int  groupNum = 0  )  const

Returns the specified group. An empty string ("") does not necessarily mean the group was not matched. A group such as (a*b?) could be matched by a zero length. If an empty string is returned, getStartingIndex can be called to determine if the group was actually matched.

Parameters:
groupNum The group to query
Returns:
The text of the group

std::vector< std::string > Matcher::getGroups ( const bool  includeGroupZero = 0  )  const

Returns every capture group in a vector

Parameters:
includeGroupZero Whether or not include capture group zero
Returns:
Every capture group

int Matcher::getGroupNum (  )  [inline]

Number of captured groups

Returns:
number of captured groups.


The documentation for this class was generated from the following files:
Generated on Fri Apr 27 13:12:36 2007 for Highlight Code Converter by  doxygen 1.5.2