Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/regex/doc/match_results.html @ 45

Last change on this file since 45 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 22.1 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3   <head>
4      <title>Boost.Regex: class match_results</title>
5      <meta content="HTML Tidy, see www.w3.org" name="generator">
6      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
7      <LINK href="../../../boost.css" type="text/css" rel="stylesheet"></head>
8   <body>
9      <p></p>
10      <table id="Table1" cellSpacing="1" cellPadding="1" width="100%" border="0">
11         <tr>
12            <td vAlign="top" width="300">
13               <h3><A href="../../../index.htm"><IMG height="86" alt="C++ Boost" src="../../../boost.png" width="277" border="0"></A></h3>
14            </td>
15            <td width="353">
16               <h1 align="center">Boost.Regex</h1>
17               <h2 align="center">class match_results</h2>
18            </td>
19            <td width="50">
20               <h3><A href="index.html"><IMG height="45" alt="Boost.Regex Index" src="uarrow.gif" width="43" border="0"></A></h3>
21            </td>
22         </tr>
23      </table>
24      <br>
25      <br>
26      <hr>
27      <h3>Contents</h3>
28      <dl class="index">
29         <dt><A href="#synopsis">Synopsis</A> <dt><A href="#description">Description</A> </dt>
30      </dl>
31      <h3><a name="synopsis"></a>Synopsis</h3>
32      <p>#include &lt;<A href="../../../boost/regex.hpp">boost/regex.hpp</A>&gt;</p>
33      <p>Regular expressions are different from many simple pattern-matching algorithms
34         in that as well as finding an overall match they can also produce
35         sub-expression matches: each sub-expression being delimited in the pattern by a
36         pair of parenthesis (...). There has to be some method for reporting
37         sub-expression matches back to the user: this is achieved this by defining a
38         class <i>match_results</i> that acts as an indexed collection of sub-expression
39         matches, each sub-expression match being contained in an object of type <i><A href="sub_match.html">
40               sub_match</A></i> .</p>
41      <p>Template class match_results denotes a collection of character sequences
42         representing the result of a regular expression match. Objects of type
43         match_results are passed to the algorithms <A href="regex_match.html">regex_match</A>
44         and <A href="regex_search.html">regex_search</A>, and are returned by the
45         iterator <A href="regex_iterator.html">regex_iterator</A> .&nbsp; Storage for
46         the collection is allocated and freed as necessary by the member functions of
47         class match_results.</p>
48      <p>The template class match_results conforms to the requirements of a Sequence, as
49         specified in (lib.sequence.reqmts), except that only operations defined for
50         const-qualified Sequences are supported.</p>
51      <p>Class template match_results is most commonly used as one of the typedefs
52         cmatch, wcmatch, smatch, or wsmatch:</p>
53      <pre>template &lt;class BidirectionalIterator,
54          class Allocator = std::allocator&lt;sub_match&lt;BidirectionalIterator&gt; &gt;
55class match_results;
56
57typedef match_results&lt;const char*&gt; cmatch;
58typedef match_results&lt;const wchar_t*&gt; wcmatch;
59typedef match_results&lt;string::const_iterator&gt; smatch;
60typedef match_results&lt;wstring::const_iterator&gt; wsmatch;
61
62template &lt;class BidirectionalIterator,
63          class Allocator = std::allocator&lt;sub_match&lt;BidirectionalIterator&gt; &gt;
64class match_results
65{
66public:
67   typedef          sub_match&lt;BidirectionalIterator&gt;                        value_type;
68   typedef          const value_type&amp;                                       const_reference;
69   typedef          const_reference                                         reference;
70   typedef          implementation defined                                  const_iterator;
71   typedef          const_iterator                                          iterator;
72   typedef typename iterator_traits&lt;BidirectionalIterator&gt;::difference_type difference_type;
73   typedef typename Allocator::size_type                                    size_type;
74   typedef          Allocator                                               allocator_type;
75   typedef typename iterator_traits&lt;BidirectionalIterator&gt;::value_type      char_type;
76   typedef          basic_string&lt;char_type&gt;                                 string_type;
77
78   // construct/copy/destroy:
79   explicit <A href="#c1" >match_results</A>(const Allocator&amp; a = Allocator());
80   <A href="#c2" >match_results</A>(const match_results&amp; m);
81   <A href="#c3" >match_results</A>&amp; <A href="#c3" >operator</A>=(const match_results&amp; m);
82   ~match_results();
83
84   // size:
85   size_type <A href="#m1" >size</A>() const;
86   size_type <A href="#m2" >max_size</A>() const;
87   bool <A href="#m3" >empty</A>() const;
88   // element access:
89   difference_type <A href="#m4" >length</A>(int sub = 0) const;
90   difference_type <A href="#m5" >position</A>(unsigned int sub = 0) const;
91   string_type <A href="#m6" >str</A>(int sub = 0) const;
92   const_reference <A href="#m7" >operator</A>[](int n) const;
93
94   const_reference <A href="#m8" >prefix</A>() const;
95
96   const_reference <A href="#m9" >suffix</A>() const;
97   const_iterator <A href="#m10" >begin</A>() const;
98   const_iterator <A href="#m11" >end</A>() const;
99   // format:
100   template &lt;class OutputIterator&gt;
101   OutputIterator <A href="#m12" >format</A>(OutputIterator out,
102                         const string_type&amp; fmt,
103                         match_flag_type flags = format_default) const;
104   string_type <A href="#m13" >format</A>(const string_type&amp; fmt,
105                      match_flag_type flags = format_default) const;
106
107   allocator_type <A href="#m14" >get_allocator</A>() const;
108   void <A href="#m15" >swap</A>(match_results&amp; that);
109
110#ifdef BOOST_REGEX_MATCH_EXTRA
111   typedef typename value_type::capture_sequence_type <A href="#m16" >capture_sequence_type</A>;
112   const capture_sequence_type&amp; <A href="#m17" >captures</A>(std::size_t i)const;
113#endif
114
115};
116
117template &lt;class BidirectionalIterator, class Allocator&gt;
118bool <A href="#n1" >operator</A> == (const match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m1,
119                  const match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m2);
120template &lt;class BidirectionalIterator, class Allocator&gt;
121bool <A href="#n2" >operator</A> != (const match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m1,
122                  const match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m2);
123
124template &lt;class charT, class traits, class BidirectionalIterator, class Allocator&gt;
125basic_ostream&lt;charT, traits&gt;&amp;
126   <A href="#n3" >operator</A> &lt;&lt; (basic_ostream&lt;charT, traits&gt;&amp; os,
127                const match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m);
128
129template &lt;class BidirectionalIterator, class Allocator&gt;
130void <A href="#n4" >swap</A>(match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m1,
131          match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m2);
132</pre>
133      <h3><a name="description"></a>Description</h3>
134      <h4>match_results constructors</h4>
135      <p>In all <code>match_results</code> constructors, a copy of the Allocator
136         argument is used for any memory allocation performed by the constructor or
137         member functions during the lifetime of the object.</p>
138      <pre><A name=c1></A>
139match_results(const Allocator&amp; a = Allocator());
140</pre>
141      <b></b>
142      <p><b>Effects:</b> Constructs an object of class match_results. The postconditions
143         of this function are indicated in the table:</p>
144      <p align="center"></p>
145      <center>
146         <table id="Table2" cellSpacing="1" cellPadding="7" width="624" border="1">
147            <tbody>
148               <tr>
149                  <td vAlign="top" width="50%"><b></b>
150                     <p><b>Element</b></p>
151                  </td>
152                  <td vAlign="top" width="50%"><b></b>
153                     <p><b>Value</b></p>
154                  </td>
155               </tr>
156               <tr>
157                  <td vAlign="top" width="50%">
158                     <p>empty()</p>
159                  </td>
160                  <td vAlign="top" width="50%">
161                     <p>true</p>
162                  </td>
163               </tr>
164               <tr>
165                  <td vAlign="top" width="50%">
166                     <p>size()</p>
167                  </td>
168                  <td vAlign="top" width="50%">
169                     <p>0</p>
170                  </td>
171               </tr>
172               <tr>
173                  <td vAlign="top" width="50%">
174                     <p>str()</p>
175                  </td>
176                  <td vAlign="top" width="50%">
177                     <p>basic_string&lt;charT&gt;()</p>
178                  </td>
179               </tr>
180            </tbody></table>
181      </center>
182      <p>&nbsp;</p>
183      <pre><A name=c2></A>
184match_results(const match_results&amp; m);
185</pre>
186      <b></b>
187      <p><b>Effects:</b> Constructs an object of class match_results, as a copy of m.</p>
188      <pre><A name=c3></A>
189match_results&amp; operator=(const match_results&amp; m);
190</pre>
191      <b></b>
192      <p><b>Effects:</b> Assigns m to *this. The postconditions of this function are
193         indicated in the table:</p>
194      <p align="center"></p>
195      <center>
196         <table id="Table3" cellSpacing="1" cellPadding="7" width="624" border="1">
197            <tbody>
198               <tr>
199                  <td vAlign="top" width="50%"><b></b>
200                     <p><b>Element</b></p>
201                  </td>
202                  <td vAlign="top" width="50%"><b></b>
203                     <p><b>Value</b></p>
204                  </td>
205               </tr>
206               <tr>
207                  <td vAlign="top" width="50%">
208                     <p>empty()</p>
209                  </td>
210                  <td vAlign="top" width="50%">
211                     <p>m.empty().</p>
212                  </td>
213               </tr>
214               <tr>
215                  <td vAlign="top" width="50%">
216                     <p>size()</p>
217                  </td>
218                  <td vAlign="top" width="50%">
219                     <p>m.size().</p>
220                  </td>
221               </tr>
222               <tr>
223                  <td vAlign="top" width="50%">
224                     <p>str(n)</p>
225                  </td>
226                  <td vAlign="top" width="50%">
227                     <p>m.str(n) for all integers n &lt; m.size().</p>
228                  </td>
229               </tr>
230               <tr>
231                  <td vAlign="top" width="50%">
232                     <p>prefix()</p>
233                  </td>
234                  <td vAlign="top" width="50%">
235                     <p>m.prefix().</p>
236                  </td>
237               </tr>
238               <tr>
239                  <td vAlign="top" width="50%">
240                     <p>suffix()</p>
241                  </td>
242                  <td vAlign="top" width="50%">
243                     <p>m.suffix().</p>
244                  </td>
245               </tr>
246               <tr>
247                  <td vAlign="top" width="50%">
248                     <p>(*this)[n]</p>
249                  </td>
250                  <td vAlign="top" width="50%">
251                     <p>m[n] for all integers n &lt; m.size().</p>
252                  </td>
253               </tr>
254               <tr>
255                  <td vAlign="top" width="50%">
256                     <p>length(n)</p>
257                  </td>
258                  <td vAlign="top" width="50%">
259                     <p>m.length(n) for all integers n &lt; m.size().</p>
260                  </td>
261               </tr>
262               <tr>
263                  <td vAlign="top" width="50%">
264                     <p>position(n)</p>
265                  </td>
266                  <td vAlign="top" width="50%">
267                     <p>m.position(n) for all integers n &lt; m.size().</p>
268                  </td>
269               </tr>
270            </tbody></table>
271      </center>
272      <h4>match_results size</h4>
273      <pre><A name=m1></A>
274size_type size()const;
275</pre>
276      <b></b>
277      <p><b>Effects:</b> Returns the number of sub_match elements stored in *this; that
278         is the number of marked sub-expressions in the regular expression that was
279         matched plus one.</p>
280      <pre><A name=m2></A>
281size_type max_size()const;
282</pre>
283      <b></b>
284      <p><b>Effects:</b> Returns the maximum number of sub_match elements that can be
285         stored in *this.</p>
286      <pre><A name=m3></A>
287bool empty()const;
288</pre>
289      <b></b>
290      <p><b>Effects:</b> Returns <code>size() == 0</code>.</p>
291      <h4>match_results element access</h4>
292      <pre><A name=m4></A>
293difference_type length(int sub = 0)const;
294</pre>
295      <b></b>
296      <p><b>Effects:</b> Returns the length of sub-expression <EM>sub</EM>, that is to
297         say: <code>(*this)[sub].length()</code>.</p>
298      <pre><A name=m5></A>
299difference_type position(unsigned int sub = 0)const;
300</pre>
301      <b></b>
302      <p><b>Effects:</b> Returns the starting location of sub-expression <EM>sub</EM>,
303         or -1 if <EM>sub</EM> was not matched.&nbsp; Note that if this represents a <A href="partial_matches.html">
304            partial match</A> , then <code>position()</code> will return the location of
305         the partial match even though <code>(*this)[0].matched</code> is <EM>false</EM>.</p>
306      <pre><A name=m6></A>
307string_type str(int sub = 0)const;
308</pre>
309      <b></b>
310      <p><b>Effects:</b> Returns sub-expression <EM>sub</EM> as a string:&nbsp; <code>string_type((*this)[sub]).</code></p>
311      <pre><A name=m7></A>
312const_reference operator[](int n) const;
313</pre>
314      <b></b>
315      <p><b>Effects:</b> Returns a reference to the <code>sub_match</code> object
316         representing the character sequence that matched marked sub-expression <i>n</i>.
317         If <code>n == 0</code> then returns a reference to a <code>sub_match</code> object
318         representing the character sequence that matched the whole regular
319         expression.&nbsp; If <EM>n</EM> is out of range, or if <EM>n</EM> is an
320         unmatched sub-expression, then returns a sub_match object whose <EM>matched</EM>
321         member is <EM>false</EM>.</p>
322      <pre><A name=m8></A>
323const_reference prefix()const;
324</pre>
325      <b></b>
326      <p><b>Effects:</b> Returns a reference to the <code>sub_match</code> object
327         representing the character sequence from the start of the string being
328         matched/searched, to the start of the match found.</p>
329      <pre><A name=m9></A>
330const_reference suffix()const;
331</pre>
332      <b></b>
333      <p><b>Effects:</b> Returns a reference to the <code>sub_match</code> object
334         representing the character sequence from the end of the match found to the end
335         of the string being matched/searched.</p>
336      <pre><A name=m10></A>
337const_iterator begin()const;
338</pre>
339      <b></b>
340      <p><b>Effects:</b> Returns a starting iterator that enumerates over all the marked
341         sub-expression matches stored in *this.</p>
342      <pre><A name=m11></A>
343const_iterator end()const;
344</pre>
345      <b></b>
346      <p><b>Effects:</b> Returns a terminating iterator that enumerates over all the
347         marked sub-expression matches stored in *this.</p>
348      <h4><A name="format"></A>match_results reformatting</h4>
349      <pre><A name=m12></A>template &lt;class OutputIterator&gt;
350OutputIterator format(OutputIterator out,
351                      const string_type&amp; fmt,
352                      <A href="match_flag_type.html" >match_flag_type</A> flags = format_default);
353</pre>
354      <b></b>
355      <p><b>Requires:</b> The type OutputIterator conforms to the Output Iterator
356         requirements (24.1.2).</p>
357      <b></b>
358      <p><b>Effects:</b> Copies the character sequence <i>[fmt.begin(), fmt.end())</i> to
359         OutputIterator <i>out</i>. For each format specifier or escape sequence in <i>fmt</i>,
360         replace that sequence with either the character(s) it represents, or the
361         sequence of characters within *this to which it refers. The bitmasks specified
362         in <i><A href="match_flag_type.html">flags</A></i> determines what <A href="format_syntax.html">
363            format specifiers or escape sequences are recognized</A>, by default this is
364         the format used by ECMA-262, ECMAScript Language Specification, Chapter 15 part
365         5.4.11 String.prototype.replace.</p>
366      <b></b>
367      <p><b>Returns:</b> <i>out</i>.</p>
368      <pre><A name=m13></A>
369string_type format(const string_type&amp; fmt,
370                   <A href="match_flag_type.html" >match_flag_type</A> flags = format_default);
371</pre>
372      <b></b>
373      <p><b>Effects:</b> Returns a copy of the string <i>fmt</i>. For each format
374         specifier or escape sequence in <i>fmt</i>, replace that sequence with either
375         the character(s) it represents, or the sequence of characters within *this to
376         which it refers. The bitmasks specified in <i><A href="match_flag_type.html">flags</A></i>
377         determines what <A href="format_syntax.html">format specifiers or escape sequences
378            are recognized</A>, by default this is the format used by ECMA-262,
379         ECMAScript Language Specification, Chapter 15 part 5.4.11
380         String.prototype.replace.</p>
381      <H4>Allocator access</H4>
382      <pre><A name=m14>allocator_type get_allocator()const;
383</pre>
384      <b></b>
385      <p><b>Effects:</b> Returns a copy of the Allocator that was passed to the object's
386         constructor.</p>
387      <H4><A name="m15"></A>Swap</H4>
388      <PRE>void swap(match_results&amp; that);
389</PRE>
390      <b></b>
391      <p><b>Effects:</b> Swaps the contents of the two sequences.</p>
392      <b></b>
393      <p><b>Postcondition:</b> <code>*this</code> contains the sequence of matched
394         sub-expressions that were in <code>that</code>, <code>that</code> contains the
395         sequence of matched sub-expressions that were in <code>*this</code>.</p>
396      <b></b>
397      <p><b>Complexity:</b> constant time.</p>
398      <H4>Captures</H4>
399      <PRE><A name=m16></A>typedef typename value_type::capture_sequence_type capture_sequence_type;</PRE>
400      <P>Defines an implementation-specific type that&nbsp;satisfies the requirements of
401         a standard library Sequence (21.1.1 including the optional Table 68
402         operations),&nbsp;whose value_type is a <EM>sub_match&lt;BidirectionalIterator&gt;</EM>.&nbsp;This
403         type happens to be <EM>std::vector&lt;sub_match&lt;BidirectionalIterator&gt; &gt;</EM>,
404         but you shouldn't actually rely on that.</P>
405      <PRE><A name=m17></A>const capture_sequence_type&amp; <A href="#m8" >captures</A>(std::size_t i)const; </PRE>
406      <P><STRONG>Effects:</STRONG> returns a sequence containing all the captures
407         obtained for sub-expression <EM>i</EM>.</P>
408      <P><STRONG>Returns:</STRONG> <code>(*this)[i].captures();</code></P>
409      <P><STRONG>Preconditions:</STRONG> the library must be built and used with
410         BOOST_REGEX_MATCH_EXTRA defined, and you must pass the flag <A href="match_flag_type.html">
411            match_extra</A> to the regex matching functions (<A href="regex_match.html">regex_match</A>,
412         <A href="regex_search.html">regex_search</A>, <A href="regex_iterator.html">regex_iterator</A>
413         or <A href="regex_token_iterator.html">regex_token_iterator</A>) in order for
414         this member function to be defined and return useful information.</P>
415      <P><STRONG>Rationale:</STRONG> Enabling this feature has several consequences:
416      </P>
417      <UL>
418         <LI>
419         sub_match occupies more memory resulting in complex expressions running out of
420         memory or stack space more quickly during matching.
421         <LI>
422         The matching algorithms are less efficient at handling some features
423         (independent sub-expressions for example), even when match_extra is not used.
424         <LI>
425            The matching algorithms are much less efficient (i.e. slower), when match_extra
426            is used.&nbsp; Mostly this is down to the extra memory allocations that have to
427            take place.</LI></UL>
428      <h4>match_results non-members</h4>
429      <PRE><A name=n1></A>template &lt;class BidirectionalIterator, class Allocator&gt;
430bool operator == (const match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m1,
431                  const match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m2);</PRE>
432      <P><B>Effects:</B> Compares the two sequences for equality.</P>
433      <PRE><A name=n2></A>template &lt;class BidirectionalIterator, class Allocator&gt;
434bool operator != (const match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m1,
435                  const match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m2);</PRE>
436      <P><B>Effects:</B> Compares the two sequences for inequality.</P>
437      <PRE><A name=n3></A>template &lt;class charT, class traits, class BidirectionalIterator, class Allocator&gt;
438basic_ostream&lt;charT, traits&gt;&amp;
439   operator &lt;&lt; (basic_ostream&lt;charT, traits&gt;&amp; os,
440                const match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m);</PRE>
441      <P><B>Effects:</B> Writes the contents of <EM>m</EM> to the stream <EM>os</EM> as
442         if by calling <code>os &lt;&lt; m.str();</code> Returns <EM>os</EM>..</P>
443      <PRE><A name=n4></A>template &lt;class BidirectionalIterator, class Allocator&gt;
444void swap(match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m1,
445          match_results&lt;BidirectionalIterator, Allocator&gt;&amp; m2);</PRE>
446      <P><B>Effects:</B> Swaps the contents of the two sequences.</P>
447      <p></p>
448      <hr>
449      <p>Revised
450         <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan --> 
451         24 Oct 2003
452         <!--webbot bot="Timestamp" endspan i-checksum="39359" --></p>
453      <p><i>© Copyright John Maddock&nbsp;1998-
454            <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%Y" startspan -->  2003<!--webbot bot="Timestamp" endspan i-checksum="39359" --></i></p>
455      <P><I>Use, modification and distribution are subject to the Boost Software License,
456            Version 1.0. (See accompanying file <A href="../../../LICENSE_1_0.txt">LICENSE_1_0.txt</A>
457            or copy at <A href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</A>)</I></P>
458   </body>
459</html>
Note: See TracBrowser for help on using the repository browser.