SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches

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/RWUConversionContext.h>
#include <rw/i18n/RWURegularExpression.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;
}
return 0;
}
Specifies the default character encoding scheme for conversions between narrow character strings and ...
Definition RWUConversionContext.h:101
Stores Unicode regular expression match results.
Definition RWURegexResult.h:105
size_t getLength(size_t matchID=0) const
RWUConstSubString subString(const RWUString &str, size_t matchID=0) const
RWUConstStringIterator begin(const RWUString &str, size_t matchID=0) const
Represents a regular expression with Unicode extensions.
Definition RWURegularExpression.h:707
Stores and manipulates Unicode character sequences encoded as UTF-16 code units.
Definition RWUString.h:187

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::RWURegexResult ( const RWURegexResult & source)

Copy constructor. Creates a deep copy of source.

◆ ~RWURegexResult()

RWURegexResult::~RWURegexResult ( )

Destructor.

Member Function Documentation

◆ begin()

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.

◆ end()

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.

◆ getLength()

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

Returns the length in code units of the requested match.

◆ getStart()

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

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

◆ operator bool()

RWURegexResult::operator bool ( ) const

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

◆ operator=()

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

Assignment operator. Creates a deep copy of rhs.

◆ subCount()

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.

◆ subString()

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

Returns the const substring for the requested match.

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