Keyple C++  0.9.0
Keyple, an Open Source SDK for Ticketing
Public Member Functions | List of all members
keyple::common::Matcher Class Reference

#include <Matcher.h>

Public Member Functions

 Matcher (const Pattern *parent, const std::string &text)
 
bool match (const int from, const int anchor) const
 
bool matches ()
 
std::string replaceAll (const std::string &replacement) const
 
bool find ()
 
bool find (const int start)
 
const std::string group (const int group) const
 
const std::string group () const
 
bool search (const int from)
 
int getTextLength () const
 
Matcherreset ()
 

Constructor & Destructor Documentation

◆ Matcher()

keyple::common::Matcher::Matcher ( const Pattern parent,
const std::string &  text 
)

All matchers have the state used by Pattern during a match.

Member Function Documentation

◆ find() [1/2]

bool keyple::common::Matcher::find ( )

Attempts to find the next subsequence of the input sequence that matches the pattern.

This method starts at the beginning of this matcher's region, o, if a previous invocation of the method was successful and the matcher has not since been reset, at the first character not matched by the previous match.

If the match succeeds then more information can be obtained viw the start, end, group methods.

Returns
true if, and only if, a subsequence of the input sequences matches this matcher's patern.

◆ find() [2/2]

bool keyple::common::Matcher::find ( const int  start)

Resets this matcher and then attempts to find the next subsequence of the input sequence that matches the pattern, starting at the specified index.

If the match succeeds then more information can be obtained viw the start, end, group methods, and subsequent invocations of the find() method will start at the first character not matched by this match.

Returns
true if, and only if, a subsequence of the input sequences matches this matcher's patern.
Exceptions
IndexOutOfBoundExceptionif start is less than zero of if start is greated than the length of the input sequence.

◆ getTextLength()

int keyple::common::Matcher::getTextLength ( ) const

Returns the end index of the text.

Returns
the index after the last charaecter in the text

◆ group() [1/2]

const std::string keyple::common::Matcher::group ( ) const

Returns the text that matched the whole regular expression.

Returns
the text
Exceptions
IllegalStateExceptionif no successful match has been made

◆ group() [2/2]

const std::string keyple::common::Matcher::group ( const int  group) const

Returns the text that matched a given group of the regular expression. Explicit capturing groups in the pattern are numbered left to right in order of their opening parenthesis, starting at 1. The special group 0 represents the entire match (as if the entier pattern is surrounded by an implicit capturing group).

For example, "a((b)c)" matching "abc" would give the following groups: 0 "abc" 1 "bc" 2 "b"

An optional capturing group that failed to match as part of an overall sucessful match (for example "a(b)?c" matching "ac") returns null. A capturing group that matched the empty string (for example, "a(b?)c" matching "ac") returns the empty string.

Exceptions
IllegalStateExceptionif no successful match has been made

◆ match()

bool keyple::common::Matcher::match ( const int  from,
const int  anchor 
) const

Initiates a search for an anchored match to a Pattern within the given bounds. The groups are filled with default values and the match of the root of the state machine is called. The state machine will hold the state of the match as it proceeds in this matcher.

◆ matches()

bool keyple::common::Matcher::matches ( )

Attempts to match the entire region against the pattern.

If the match succeeds then more information can be obtained via the start, end, and group methods.

Returns
true if, and only if, the entire region sequence matches this matcher's pattern

◆ replaceAll()

std::string keyple::common::Matcher::replaceAll ( const std::string &  replacement) const

Replaces every subsequence of the input sequence that matches the pattern with the given replacement string.

This method first resets this matcher. It then scans the input sequence looking for matches of the pattern. Characters that are not part of any match are appended directly to the result string; each match is replaced in the result by the replacement string. The replacement string may contain references to captured subsequences as in the appendReplacement() method.

Note that backslashes (\) and dollar signs ($) in the replacement string may cause the results to be different than if it were being treated as a literal replacement string. Dollar signs may be treated as references to captured subsequences as described above, and backslashes are used to escape literal characters in the replacement string.

Given the regular expression a*b, the input "aabfooaabfooabfoob", and the replacement string "-", an invocation of this method on a matcher for that expression would yield the string "-foo-foo-foo-".

Invoking this method changes this matcher's state. If the matcher is to be used in further matching operations then it should first be reset.

Parameters
replacementThe replacement string
Returns
The string constructed by replacing each matching subsequence by the replacement string, substituting captured subsequences as needed

◆ reset()

Matcher * keyple::common::Matcher::reset ( )

Resets this matcher.

Resetting a matcher discards all of its explicit states information and sets its append position to zero. The matcher's region is set to the default region, which is its entire character sequence. The anchoring and transparency of this matcher's region boundaries are unaffected.

◆ search()

bool keyple::common::Matcher::search ( const int  from)

Initiates a search to find a Pattern within the given bounds. The groups are filled with defaults values and the match of the root of the state machine is called. The state machine will hold the state of the match as it proceeds in this matcher.

Matcher.from is not set here, because it is the 'hard' boundary of the start of the search which anchors will set to. The from param is the 'soft' boundary of the start of the search, meaning that the regex tries to match at that index but won't match there. Subsequent calls to the search methods start at a new 'soft' boundary which is the end of the previous match.


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