SourcePro® API Reference Guide

 
List of all members | Public Member Functions

Stores Unicode regular expression match results. More...

#include <rw/i18n/RWURegexResult.h>

Public Member Functions

 RWURegexResult (const RWURegexResult &source)
 
 ~RWURegexResult ()
 
RWUConstStringIterator begin (const RWUString &str, size_t matchID=0) const
 
RWUConstStringIterator end (const RWUString &str, size_t matchID=0) const
 
size_t getLength (size_t matchID=0) const
 
size_t getStart (size_t matchID=0) const
 
 operator bool () const
 
RWURegexResultoperator= (const RWURegexResult &rhs)
 
size_t subCount () const
 
RWUConstSubString subString (const RWUString &str, size_t matchID=0) const
 

Detailed Description

RWURegexResult stores regular expression match results.

Instances of RWURegexResult are returned from the RWURegularExpression methods search() and matchAt(), and by RWURegexMatchIterator member operators operator*() and operator->(). These results can be used later to obtain details concerning the regular expression match.

This class has a conversion to bool operator, which indicates whether the search() or matchAt() operation was, in fact, a match. Iterators to the beginning and ending of the overall match, or of a subexpression match, can be obtained.

Example
#include <rw/i18n/RWURegularExpression.h>
#include <rw/i18n/RWUConversionContext.h>
#include <rw/i18n/RWUString.h>
#include <iostream>
using std::cout;
using std::endl;
int main()
{
// Indicate string literals are encoded as US-ASCII strings.
RWUConversionContext context("US-ASCII");
// Create a regular expression that searches for a bold item
// in an HTML document.
RWURegularExpression regexp("<b>([\\u0020-\\u007f]*)</b>");
// Create a string in which to search.
RWUString text("This string contains <b>bold</b> text.");
// Search the string.
RWURegexResult result = regexp.search(text);
// If a bold item was found...
if (result) {
// Show the overall match.
cout << "Overall match at offset " << int32_t(result.begin(text))
<< " with length " << result.getLength() << ": "
<< result.subString(text) << endl;
// Show the sub-expression match.
cout << "Sub-expression match at offset " << int32_t(result.begin(text, 1))
<< " with length " << result.getLength(1) << ": "
<< result.subString(text, 1) << endl;
} // if
return 0;
} // main

Program output:

Overall match at offset 21 with length 11: <b>bold</b>
Sub-expression match at offset 24 with length 4: bold
See also
RWURegularExpression

Constructor & Destructor Documentation

RWURegexResult::RWURegexResult ( const RWURegexResult source)

Copy constructor. Creates a deep copy of source.

RWURegexResult::~RWURegexResult ( )

Destructor.

Member Function Documentation

RWUConstStringIterator RWURegexResult::begin ( const RWUString str,
size_t  matchID = 0 
) const

Returns an iterator to the start of the requested match.

Returns an iterator to the match indicated by the specified match identifier matchID. The supplied string str must be the same RWUString instance used to generate self.

A match identifier of 0 requests the start of the entire match within the match string. Match identifiers greater than 0 request the starting index of matches against parenthesized subexpressions within the regular expression pattern. Match identifier 1 requests the start of the first subexpression match, 2 requests the second, and so on. Returns an iterator into the str if the specified match identifier corresponds to a match. If no match is associated with the specified match identifier then the end iterator is returned. Used in conjunction with getLength(), this method can be used to extract substrings representing regular expression matches.

RWUConstStringIterator RWURegexResult::end ( const RWUString str,
size_t  matchID = 0 
) const

Return an iterator just past the end of the requested match.

Returns the position immediately following the match indicated by the specified match identifier matchID. The supplied string str must be the same RWUString instance used to generate self.

A match identifier of 0 requests the end of the entire match within the match string. Match identifiers greater than 0 request the end position of matches against parenthesized subexpressions within the regular expression pattern. Match identifier 1 requests the start of the first subexpression match, 2 requests the second, and so on. Returns an iterator referencing the position just after the indicated match, which may be the end iterator. If no match is associated with the specified match identifier then the end iterator is returned.

size_t RWURegexResult::getLength ( size_t  matchID = 0) const

Returns the length in code units of the requested match.

size_t RWURegexResult::getStart ( size_t  matchID = 0) const

Returns the starting offset, in code units, of the requested match.

RWURegexResult::operator bool ( ) const

Returns true if the search() or matchAt() operation operation that generated self was successful.

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

Assignment operator. Creates a deep copy of rhs.

size_t RWURegexResult::subCount ( ) const

Number of sub-matches accessor. Returns the number of match IDs available for request, excluding the 0 match ID. This corresponds to the number of parenthesized sub-expressions contained in the pattern associated with the RWURegularExpression class that created self. Only match IDs that fall between 0 and subCount(), inclusive, can be used with self.

RWUConstSubString RWURegexResult::subString ( const RWUString str,
size_t  matchID = 0 
) const

Returns the const substring for the requested match.

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