SourcePro® API Reference Guide

 
List of all members | Public Types | Public Member Functions
RWURegexMatchIterator Class Reference

Iterates over matches found for a Unicode regular expression pattern. More...

#include <rw/i18n/RWURegexMatchIterator.h>

Public Types

typedef std::forward_iterator_tag iterator_category
 
typedef value_typepointer
 
typedef value_typereference
 
typedef RWURegexResult value_type
 

Public Member Functions

 RWURegexMatchIterator ()
 
 RWURegexMatchIterator (const RWURegexMatchIterator &source)
 
 RWURegexMatchIterator (RWURegularExpression &regex, const RWUString &str)
 
 RWURegexMatchIterator (RWURegularExpression &regex, const RWUString &str, const RWUConstStringIterator &start)
 
 RWURegexMatchIterator (RWURegularExpression &regex, const RWUString &str, const RWUConstStringIterator &start, const RWUConstStringIterator &end, bool overlap=false)
 
 ~RWURegexMatchIterator ()
 
bool operator!= (const RWURegexMatchIterator &rhs) const
 
RWURegexResult operator* () const
 
RWURegexMatchIteratoroperator++ ()
 
RWURegexMatchIterator operator++ (int)
 
const RWURegexResultoperator-> () const
 
RWURegexMatchIteratoroperator= (const RWURegexMatchIterator &rhs)
 
bool operator== (const RWURegexMatchIterator &rhs) const
 

Detailed Description

RWURegexMatchIterator provides a convenient interface for finding all successive matches of a particular regular expression pattern in a string. RWURegexMatchIterator is a forward iterator, allowing forward searches over the specified string using pre-increment and post-increment operators

By default, only non-overlapping matches are reported, but this behavior can be changed in the constructor.

Note
As with many iterators, changing the item being iterated over invalidates the iterator. If the regular expression pattern or search string used by an RWURegexMatchIterator is changed, then the iterator is invalidated.
Example
#include <rw/i18n/RWURegularExpression.h>
#include <rw/i18n/RWURegexMatchIterator.h>
#include <iostream>
using std::cout;
using std::endl;
int main()
{
RWUString str("aaabaacadeaaaafgaaa");
// Search for all occurrences of the pattern in the string
for (RWURegexMatchIterator i(r, str); i != RWURegexMatchIterator(); ++i)
{
// Show the overall match information
cout << "Match at position: " << i->getStart()
<< ", with length: " << i->getLength() << endl;
} // for
return 0;
} // main

Program output:

Match at position: 0, with length: 3
Match at position: 4, with length: 2
Match at position: 7, with length: 1
Match at position: 10, with length: 4
Match at position: 16, with length: 3
See also
RWURegularExpression, RWURegexResult

Member Typedef Documentation

typedef std::forward_iterator_tag RWURegexMatchIterator::iterator_category

Tags this class as a C++ Standard Library-compatible forward iterator.

Declares an alias for the value pointer type.

Declares an alias for the value reference type.

Declares an alias for the value type returned by operator*().

Constructor & Destructor Documentation

RWURegexMatchIterator::RWURegexMatchIterator ( )

Default constructor. Creates an invalid iterator, which can be used to test for the end-of-iteration condition.

RWURegexMatchIterator::RWURegexMatchIterator ( const RWURegexMatchIterator source)

Copy constructor.

RWURegexMatchIterator::RWURegexMatchIterator ( RWURegularExpression regex,
const RWUString str 
)

Creates a match iterator from regular expression object regex and search string str. The entire search string is considered for a match. Only non-overlapping matches are reported.

RWURegexMatchIterator::RWURegexMatchIterator ( RWURegularExpression regex,
const RWUString str,
const RWUConstStringIterator start 
)

Creates a match iterator from regular expression object regex, search string str, and starting position start. The string is searched from the specified starting position to the end of the string. Only non-overlapping matches are reported.

RWURegexMatchIterator::RWURegexMatchIterator ( RWURegularExpression regex,
const RWUString str,
const RWUConstStringIterator start,
const RWUConstStringIterator end,
bool  overlap = false 
)

Creates a match iterator from regular expression object regex, search string str, starting position start, ending position end, and an overlap flag indicating whether or not to report overlapping matches. The string is searched from the specified starting position to the specified ending position. By default, only non-overlapping matches are reported.

RWURegexMatchIterator::~RWURegexMatchIterator ( )

Destructor.

Member Function Documentation

bool RWURegexMatchIterator::operator!= ( const RWURegexMatchIterator rhs) const

Compares two iterators for inequality. Returns true if self and rhs reference different regular expression pattern or search strings, or the position in the search string is different; otherwise, false.

RWURegexResult RWURegexMatchIterator::operator* ( ) const

Dereference operator. Returns an RWURegexResult instance describing the current match.

RWURegexMatchIterator& RWURegexMatchIterator::operator++ ( )

Prefix increment operator. Advances self to the next occurrence of a match of the regular expression pattern in the search string, and returns a reference to self.

RWURegexMatchIterator RWURegexMatchIterator::operator++ ( int  )

Postfix increment operator. Advances self to the next occurrence of a match of the regular expression pattern in the search string, and returns a copy of the previous value of self.

const RWURegexResult* RWURegexMatchIterator::operator-> ( ) const

Returns a pointer to an RWURegexResult instance describing the current match. This pointer is valid only for the lifetime of the RWURegexMatchIterator instance from which it is obtained. The contents will change with any call to the prefix or postfix increment operators.

RWURegexMatchIterator& RWURegexMatchIterator::operator= ( const RWURegexMatchIterator rhs)

Assignment operator. Assigns self the value of the rhs iterator. Makes a deep copy of all data, except self references the same regular expression and search string as rhs.

bool RWURegexMatchIterator::operator== ( const RWURegexMatchIterator rhs) const

Compares two iterators for equality. Returns true if self and rhs reference the same regular expression pattern and search strings, and the position in the search string is the same; otherwise, false.

Copyright © 2023 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.