Added new experimental captures support.

[SVN r21243]
This commit is contained in:
John Maddock
2003-12-13 12:28:48 +00:00
parent 6b95ac002e
commit bf9350aa16
28 changed files with 1593 additions and 612 deletions

View File

@ -2,23 +2,22 @@
<html>
<head>
<title>Boost.Regex: class match_results</title>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta content="HTML Tidy, see www.w3.org" name="generator">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../../../boost.css">
</head>
<LINK href="../../../boost.css" type="text/css" rel="stylesheet"></head>
<body>
<p></p>
<table id="Table1" cellspacing="1" cellpadding="1" width="100%" border="0">
<table id="Table1" cellSpacing="1" cellPadding="1" width="100%" border="0">
<tr>
<td valign="top" width="300">
<h3><a href="../../../index.htm"><img height="86" width="277" alt="C++ Boost" src="../../../c++boost.gif" border="0"></a></h3>
<td vAlign="top" width="300">
<h3><A href="../../../index.htm"><IMG height="86" alt="C++ Boost" src="../../../c++boost.gif" width="277" border="0"></A></h3>
</td>
<td width="353">
<h1 align="center">Boost.Regex</h1>
<h2 align="center">class match_results</h2>
</td>
<td width="50">
<h3><a href="index.html"><img height="45" width="43" alt="Boost.Regex Index" src="uarrow.gif" border="0"></a></h3>
<h3><A href="index.html"><IMG height="45" alt="Boost.Regex Index" src="uarrow.gif" width="43" border="0"></A></h3>
</td>
</tr>
</table>
@ -27,23 +26,23 @@
<hr>
<h3>Contents</h3>
<dl class="index">
<dt><a href="#synopsis">Synopsis</a> <dt><a href="#description">Description</a></dt>
<dt><A href="#synopsis">Synopsis</A> <dt><A href="#description">Description</A> </dt>
</dl>
<h3><a name="synopsis"></a>Synopsis</h3>
<p>#include &lt;<a href="../../../boost/regex.hpp">boost/regex.hpp</a>&gt;</p>
<p>#include &lt;<A href="../../../boost/regex.hpp">boost/regex.hpp</A>&gt;</p>
<p>Regular expressions are different from many simple pattern-matching algorithms
in that as well as finding an overall match they can also produce
sub-expression matches: each sub-expression being delimited in the pattern by a
pair of parenthesis (...). There has to be some method for reporting
sub-expression matches back to the user: this is achieved this by defining a
class <i>match_results</i> that acts as an indexed collection of sub-expression
matches, each sub-expression match being contained in an object of type <i><a href="sub_match.html">
sub_match</a></i> .</p>
matches, each sub-expression match being contained in an object of type <i><A href="sub_match.html">
sub_match</A></i> .</p>
<p>Template class match_results denotes a collection of character sequences
representing the result of a regular expression match. Objects of type
match_results are passed to the algorithms <a href="regex_match.html">regex_match</a>
and <a href="regex_search.html">regex_search</a>, and are returned by the
iterator <a href="regex_iterator.html">regex_iterator</a> .&nbsp; Storage for
match_results are passed to the algorithms <A href="regex_match.html">regex_match</A>
and <A href="regex_search.html">regex_search</A>, and are returned by the
iterator <A href="regex_iterator.html">regex_iterator</A> .&nbsp; Storage for
the collection is allocated and freed as necessary by the member functions of
class match_results.</p>
<p>The template class match_results conforms to the requirements of a Sequence, as
@ -51,8 +50,7 @@
const-qualified Sequences are supported.</p>
<p>Class template match_results is most commonly used as one of the typedefs
cmatch, wcmatch, smatch, or wsmatch:</p>
<pre>
template &lt;class BidirectionalIterator,
<pre>template &lt;class BidirectionalIterator,
class Allocator = allocator&lt;sub_match&lt;BidirectionalIterator&gt; &gt;
class match_results;
@ -78,52 +76,58 @@ public:
typedef basic_string&lt;char_type&gt; string_type;
// construct/copy/destroy:
explicit <A href="#c1">match_results</A>(const Allocator&amp; a = Allocator());
<A href="#c2">match_results</A>(const match_results&amp; m);
<A href="#c3">match_results</A>&amp; <A href="#c3">operator</A>=(const match_results&amp; m);
explicit <A href="#c1" >match_results</A>(const Allocator&amp; a = Allocator());
<A href="#c2" >match_results</A>(const match_results&amp; m);
<A href="#c3" >match_results</A>&amp; <A href="#c3" >operator</A>=(const match_results&amp; m);
~match_results();
// size:
size_type <A href="#m1">size</A>() const;
size_type <A href="#m2">max_size</A>() const;
bool <A href="#m3">empty</A>() const;
size_type <A href="#m1" >size</A>() const;
size_type <A href="#m2" >max_size</A>() const;
bool <A href="#m3" >empty</A>() const;
// element access:
difference_type <A href="#m4">length</A>(int sub = 0) const;
difference_type <A href="#m5">position</A>(unsigned int sub = 0) const;
string_type <A href="#m6">str</A>(int sub = 0) const;
const_reference <A href="#m7">operator</A>[](int n) const;
difference_type <A href="#m4" >length</A>(int sub = 0) const;
difference_type <A href="#m5" >position</A>(unsigned int sub = 0) const;
string_type <A href="#m6" >str</A>(int sub = 0) const;
const_reference <A href="#m7" >operator</A>[](int n) const;
const_reference <A href="#m8">prefix</A>() const;
const_reference <A href="#m8" >prefix</A>() const;
const_reference <A href="#m9">suffix</A>() const;
const_iterator <A href="#m10">begin</A>() const;
const_iterator <A href="#m11">end</A>() const;
const_reference <A href="#m9" >suffix</A>() const;
const_iterator <A href="#m10" >begin</A>() const;
const_iterator <A href="#m11" >end</A>() const;
// format:
template &lt;class OutputIterator&gt;
OutputIterator <A href="#m12">format</A>(OutputIterator out,
OutputIterator <A href="#m12" >format</A>(OutputIterator out,
const string_type&amp; fmt,
match_flag_type flags = format_default) const;
string_type <A href="#m13">format</A>(const string_type&amp; fmt,
string_type <A href="#m13" >format</A>(const string_type&amp; fmt,
match_flag_type flags = format_default) const;
allocator_type <A href="#m14">get_allocator</A>() const;
void <A href="#m15">swap</A>(match_results&amp; that);
allocator_type <A href="#m14" >get_allocator</A>() const;
void <A href="#m15" >swap</A>(match_results&amp; that);
#ifdef BOOST_REGEX_MATCH_EXTRA
typedef typename value_type::capture_sequence_type <A href="#m16" >capture_sequence_type</A>;
const capture_sequence_type&amp; <A href="#m17" >captures</A>(std::size_t i)const;
#endif
};
template &lt;class BidirectionalIterator, class Allocator&gt;
bool <A href="#n1">operator</A> == (const match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m1,
bool <A href="#n1" >operator</A> == (const match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m1,
const match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m2);
template &lt;class BidirectionalIterator, class Allocator&gt;
bool <A href="#n2">operator</A> != (const match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m1,
bool <A href="#n2" >operator</A> != (const match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m1,
const match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m2);
template &lt;class charT, class traits, class BidirectionalIterator, class Allocator&gt;
basic_ostream&lt;charT, traits&gt;&amp;
<A href="#n3">operator</A> &lt;&lt; (basic_ostream&lt;charT, traits&gt;&amp; os,
<A href="#n3" >operator</A> &lt;&lt; (basic_ostream&lt;charT, traits&gt;&amp; os,
const match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m);
template &lt;class BidirectionalIterator, class Allocator&gt;
void <A href="#n4">swap</A>(match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m1,
void <A href="#n4" >swap</A>(match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m1,
match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m2);
</pre>
<h3><a name="description"></a>Description</h3>
@ -139,42 +143,41 @@ match_results(const Allocator&amp; a = Allocator());
of this function are indicated in the table:</p>
<p align="center"></p>
<center>
<table id="Table2" cellspacing="1" cellpadding="7" width="624" border="1">
<table id="Table2" cellSpacing="1" cellPadding="7" width="624" border="1">
<tbody>
<tr>
<td valign="top" width="50%"><b></b>
<td vAlign="top" width="50%"><b></b>
<p><b>Element</b></p>
</td>
<td valign="top" width="50%"><b></b>
<td vAlign="top" width="50%"><b></b>
<p><b>Value</b></p>
</td>
</tr>
<tr>
<td valign="top" width="50%">
<td vAlign="top" width="50%">
<p>empty()</p>
</td>
<td valign="top" width="50%">
<td vAlign="top" width="50%">
<p>true</p>
</td>
</tr>
<tr>
<td valign="top" width="50%">
<td vAlign="top" width="50%">
<p>size()</p>
</td>
<td valign="top" width="50%">
<td vAlign="top" width="50%">
<p>0</p>
</td>
</tr>
<tr>
<td valign="top" width="50%">
<td vAlign="top" width="50%">
<p>str()</p>
</td>
<td valign="top" width="50%">
<td vAlign="top" width="50%">
<p>basic_string&lt;charT&gt;()</p>
</td>
</tr>
</tbody>
</table>
</tbody></table>
</center>
<p>&nbsp;</p>
<pre><A name=c2></A>
@ -190,82 +193,81 @@ match_results&amp; operator=(const match_results&amp; m);
indicated in the table:</p>
<p align="center"></p>
<center>
<table id="Table3" cellspacing="1" cellpadding="7" width="624" border="1">
<table id="Table3" cellSpacing="1" cellPadding="7" width="624" border="1">
<tbody>
<tr>
<td valign="top" width="50%"><b></b>
<td vAlign="top" width="50%"><b></b>
<p><b>Element</b></p>
</td>
<td valign="top" width="50%"><b></b>
<td vAlign="top" width="50%"><b></b>
<p><b>Value</b></p>
</td>
</tr>
<tr>
<td valign="top" width="50%">
<td vAlign="top" width="50%">
<p>empty()</p>
</td>
<td valign="top" width="50%">
<td vAlign="top" width="50%">
<p>m.empty().</p>
</td>
</tr>
<tr>
<td valign="top" width="50%">
<td vAlign="top" width="50%">
<p>size()</p>
</td>
<td valign="top" width="50%">
<td vAlign="top" width="50%">
<p>m.size().</p>
</td>
</tr>
<tr>
<td valign="top" width="50%">
<td vAlign="top" width="50%">
<p>str(n)</p>
</td>
<td valign="top" width="50%">
<td vAlign="top" width="50%">
<p>m.str(n) for all integers n &lt; m.size().</p>
</td>
</tr>
<tr>
<td valign="top" width="50%">
<td vAlign="top" width="50%">
<p>prefix()</p>
</td>
<td valign="top" width="50%">
<td vAlign="top" width="50%">
<p>m.prefix().</p>
</td>
</tr>
<tr>
<td valign="top" width="50%">
<td vAlign="top" width="50%">
<p>suffix()</p>
</td>
<td valign="top" width="50%">
<td vAlign="top" width="50%">
<p>m.suffix().</p>
</td>
</tr>
<tr>
<td valign="top" width="50%">
<td vAlign="top" width="50%">
<p>(*this)[n]</p>
</td>
<td valign="top" width="50%">
<td vAlign="top" width="50%">
<p>m[n] for all integers n &lt; m.size().</p>
</td>
</tr>
<tr>
<td valign="top" width="50%">
<td vAlign="top" width="50%">
<p>length(n)</p>
</td>
<td valign="top" width="50%">
<td vAlign="top" width="50%">
<p>m.length(n) for all integers n &lt; m.size().</p>
</td>
</tr>
<tr>
<td valign="top" width="50%">
<td vAlign="top" width="50%">
<p>position(n)</p>
</td>
<td valign="top" width="50%">
<td vAlign="top" width="50%">
<p>m.position(n) for all integers n &lt; m.size().</p>
</td>
</tr>
</tbody>
</table>
</tbody></table>
</center>
<h4>match_results size</h4>
<pre><A name=m1></A>
@ -342,11 +344,10 @@ const_iterator end()const;
<p><b>Effects:</b> Returns a terminating iterator that enumerates over all the
marked sub-expression matches stored in *this.</p>
<h4><A name="format"></A>match_results reformatting</h4>
<pre><A name=m12></A>
template &lt;class OutputIterator&gt;
<pre>template &lt;class OutputIterator&gt;
OutputIterator format(OutputIterator out,
const string_type&amp; fmt,
<a href="match_flag_type.html">match_flag_type</a> flags = format_default);
<A href="match_flag_type.html" >match_flag_type</A> flags = format_default);
</pre>
<b></b>
<p><b>Requires:</b> The type OutputIterator conforms to the Output Iterator
@ -356,34 +357,34 @@ OutputIterator format(OutputIterator out,
OutputIterator <i>out</i>. For each format specifier or escape sequence in <i>fmt</i>,
replace that sequence with either the character(s) it represents, or the
sequence of characters within *this to which it refers. The bitmasks specified
in <i><a href="match_flag_type.html">flags</a></i> determines what <a href="format_syntax.html">
format specifiers or escape sequences are recognized</a>, by default this is
in <i><A href="match_flag_type.html">flags</A></i> determines what <A href="format_syntax.html">
format specifiers or escape sequences are recognized</A>, by default this is
the format used by ECMA-262, ECMAScript Language Specification, Chapter 15 part
5.4.11 String.prototype.replace.</p>
<b></b>
<p><b>Returns:</b> <i>out</i>.</p>
<pre><A name=m13></A>
string_type format(const string_type&amp; fmt,
<a href="match_flag_type.html">match_flag_type</a> flags = format_default);
<A href="match_flag_type.html" >match_flag_type</A> flags = format_default);
</pre>
<b></b>
<p><b>Effects:</b> Returns a copy of the string <i>fmt</i>. For each format
specifier or escape sequence in <i>fmt</i>, replace that sequence with either
the character(s) it represents, or the sequence of characters within *this to
which it refers. The bitmasks specified in <i><a href="match_flag_type.html">flags</a></i>
determines what <a href="format_syntax.html">format specifiers or escape sequences
are recognized</a>, by default this is the format used by ECMA-262,
which it refers. The bitmasks specified in <i><A href="match_flag_type.html">flags</A></i>
determines what <A href="format_syntax.html">format specifiers or escape sequences
are recognized</A>, by default this is the format used by ECMA-262,
ECMAScript Language Specification, Chapter 15 part 5.4.11
String.prototype.replace.</p>
<pre><A name=m14></A>
allocator_type get_allocator()const;
<H4>Allocator access</H4>
<pre>allocator_type get_allocator()const;
</pre>
<b></b>
<p><b>Effects:</b> Returns a copy of the Allocator that was passed to the object's
constructor.</p>
<pre><A name=m15></A>
void swap(match_results&amp; that);
</pre>
<H4><A name="m15"></A>Swap</H4>
<PRE>void swap(match_results&amp; that);
</PRE>
<b></b>
<p><b>Effects:</b> Swaps the contents of the two sequences.</p>
<b></b>
@ -392,6 +393,36 @@ void swap(match_results&amp; that);
sequence of matched sub-expressions that were in <code>*this</code>.</p>
<b></b>
<p><b>Complexity:</b> constant time.</p>
<H4>Captures</H4>
<PRE><A name=m16></A>typedef typename value_type::capture_sequence_type capture_sequence_type;</PRE>
<P>Defines an implementation-specific type that&nbsp;satisfies the requirements of
a standard library Sequence (21.1.1 including the optional Table 68
operations),&nbsp;whose value_type is a <EM>sub_match&lt;BidirectionalIterator&gt;</EM>.&nbsp;This
type happens to be <EM>std::vector&lt;sub_match&lt;BidirectionalIterator&gt; &gt;</EM>,
but you shouldn't actually rely on that.</P>
<PRE><A name=m17></A>const capture_sequence_type&amp; <A href="#m8" >captures</A>(std::size_t i)const; </PRE>
<P><STRONG>Effects:</STRONG> returns a sequence containing all the captures
obtained for sub-expression <EM>i</EM>.</P>
<P><STRONG>Returns:</STRONG> <code>(*this)[i].captures();</code></P>
<P><STRONG>Preconditions:</STRONG> the library must be built and used with
BOOST_REGEX_MATCH_EXTRA defined, and you must pass the flag <A href="match_flag_type.html">
match_extra</A> to the regex matching functions (<A href="regex_match.html">regex_match</A>,
<A href="regex_search.html">regex_search</A>, <A href="regex_iterator.html">regex_iterator</A>
or <A href="regex_token_iterator.html">regex_token_iterator</A>) in order for
this member function to be defined and return useful information.</P>
<P><STRONG>Rationale:</STRONG> Enabling this feature has several consequences:
</P>
<UL>
<LI>
sub_match occupies more memory resulting in complex expressions running out of
memory or stack space more quickly during matching.
<LI>
The matching algorithms are less efficient at handling some features
(independent sub-expressions for example), even when match_extra is not used.
<LI>
The matching algorithms are much less efficient (i.e. slower), when match_extra
is used.&nbsp; Mostly this is down to the extra memory allocations that have to
take place.</LI></UL>
<h4>match_results non-members</h4>
<PRE><A name=n1></A>template &lt;class BidirectionalIterator, class Allocator&gt;
bool operator == (const match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m1,
@ -418,10 +449,10 @@ void swap(match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m1,
24 Oct 2003
<!--webbot bot="Timestamp" endspan i-checksum="39359" --></p>
<p><i><EFBFBD> Copyright John Maddock&nbsp;1998-
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%Y" startspan -->
2003<!--webbot bot="Timestamp" endspan i-checksum="39359" --></i></p>
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%Y" startspan --> 2003<!--webbot bot="Timestamp" endspan i-checksum="39359" --></i></p>
<P><I>Use, modification and distribution are subject to the Boost Software License,
Version 1.0. (See accompanying file <A href="../../../LICENSE_1_0.txt">LICENSE_1_0.txt</A>
or copy at <A href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</A>)</I></P>
</body>
</html>