1*38fd1498Szrj// class template regex -*- C++ -*-
2*38fd1498Szrj
3*38fd1498Szrj// Copyright (C) 2007-2018 Free Software Foundation, Inc.
4*38fd1498Szrj//
5*38fd1498Szrj// This file is part of the GNU ISO C++ Library.  This library is free
6*38fd1498Szrj// software; you can redistribute it and/or modify it under the
7*38fd1498Szrj// terms of the GNU General Public License as published by the
8*38fd1498Szrj// Free Software Foundation; either version 3, or (at your option)
9*38fd1498Szrj// any later version.
10*38fd1498Szrj
11*38fd1498Szrj// This library is distributed in the hope that it will be useful,
12*38fd1498Szrj// but WITHOUT ANY WARRANTY; without even the implied warranty of
13*38fd1498Szrj// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*38fd1498Szrj// GNU General Public License for more details.
15*38fd1498Szrj
16*38fd1498Szrj// Under Section 7 of GPL version 3, you are granted additional
17*38fd1498Szrj// permissions described in the GCC Runtime Library Exception, version
18*38fd1498Szrj// 3.1, as published by the Free Software Foundation.
19*38fd1498Szrj
20*38fd1498Szrj// You should have received a copy of the GNU General Public License and
21*38fd1498Szrj// a copy of the GCC Runtime Library Exception along with this program;
22*38fd1498Szrj// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23*38fd1498Szrj// <http://www.gnu.org/licenses/>.
24*38fd1498Szrj
25*38fd1498Szrj/**
26*38fd1498Szrj * @file tr1/regex
27*38fd1498Szrj * @author Stephen M. Webb  <stephen.webb@bregmasoft.ca>
28*38fd1498Szrj * This is a TR1 C++ Library header.
29*38fd1498Szrj */
30*38fd1498Szrj
31*38fd1498Szrj#ifndef _GLIBCXX_TR1_REGEX
32*38fd1498Szrj#define _GLIBCXX_TR1_REGEX 1
33*38fd1498Szrj
34*38fd1498Szrj#pragma GCC system_header
35*38fd1498Szrj
36*38fd1498Szrj#include <algorithm>
37*38fd1498Szrj#include <bitset>
38*38fd1498Szrj#include <iterator>
39*38fd1498Szrj#include <locale>
40*38fd1498Szrj#include <stdexcept>
41*38fd1498Szrj#include <string>
42*38fd1498Szrj#include <vector>
43*38fd1498Szrj#include <utility>
44*38fd1498Szrj#include <sstream>
45*38fd1498Szrj
46*38fd1498Szrjnamespace std _GLIBCXX_VISIBILITY(default)
47*38fd1498Szrj{
48*38fd1498Szrj_GLIBCXX_BEGIN_NAMESPACE_VERSION
49*38fd1498Szrj
50*38fd1498Szrjnamespace tr1
51*38fd1498Szrj{
52*38fd1498Szrj/**
53*38fd1498Szrj * @defgroup tr1_regex Regular Expressions
54*38fd1498Szrj * A facility for performing regular expression pattern matching.
55*38fd1498Szrj */
56*38fd1498Szrj //@{
57*38fd1498Szrj
58*38fd1498Szrj/** @namespace std::regex_constants
59*38fd1498Szrj *  @brief ISO C++ 0x entities sub namespace for regex.
60*38fd1498Szrj */
61*38fd1498Szrjnamespace regex_constants
62*38fd1498Szrj{
63*38fd1498Szrj  /**
64*38fd1498Szrj   * @name 5.1 Regular Expression Syntax Options
65*38fd1498Szrj   */
66*38fd1498Szrj  //@{
67*38fd1498Szrj  enum __syntax_option
68*38fd1498Szrj    {
69*38fd1498Szrj      _S_icase,
70*38fd1498Szrj      _S_nosubs,
71*38fd1498Szrj      _S_optimize,
72*38fd1498Szrj      _S_collate,
73*38fd1498Szrj      _S_ECMAScript,
74*38fd1498Szrj      _S_basic,
75*38fd1498Szrj      _S_extended,
76*38fd1498Szrj      _S_awk,
77*38fd1498Szrj      _S_grep,
78*38fd1498Szrj      _S_egrep,
79*38fd1498Szrj      _S_syntax_last
80*38fd1498Szrj    };
81*38fd1498Szrj
82*38fd1498Szrj  /**
83*38fd1498Szrj   * @brief This is a bitmask type indicating how to interpret the regex.
84*38fd1498Szrj   *
85*38fd1498Szrj   * The @c syntax_option_type is implementation defined but it is valid to
86*38fd1498Szrj   * perform bitwise operations on these values and expect the right thing to
87*38fd1498Szrj   * happen.
88*38fd1498Szrj   *
89*38fd1498Szrj   * A valid value of type syntax_option_type shall have exactly one of the
90*38fd1498Szrj   * elements @c ECMAScript, @c basic, @c extended, @c awk, @c grep, @c egrep
91*38fd1498Szrj   * %set.
92*38fd1498Szrj   */
93*38fd1498Szrj  typedef unsigned int syntax_option_type;
94*38fd1498Szrj
95*38fd1498Szrj  /**
96*38fd1498Szrj   * Specifies that the matching of regular expressions against a character
97*38fd1498Szrj   * sequence shall be performed without regard to case.
98*38fd1498Szrj   */
99*38fd1498Szrj  static const syntax_option_type icase      = 1 << _S_icase;
100*38fd1498Szrj
101*38fd1498Szrj  /**
102*38fd1498Szrj   * Specifies that when a regular expression is matched against a character
103*38fd1498Szrj   * container sequence, no sub-expression matches are to be stored in the
104*38fd1498Szrj   * supplied match_results structure.
105*38fd1498Szrj   */
106*38fd1498Szrj  static const syntax_option_type nosubs     = 1 << _S_nosubs;
107*38fd1498Szrj
108*38fd1498Szrj  /**
109*38fd1498Szrj   * Specifies that the regular expression engine should pay more attention to
110*38fd1498Szrj   * the speed with which regular expressions are matched, and less to the
111*38fd1498Szrj   * speed with which regular expression objects are constructed. Otherwise
112*38fd1498Szrj   * it has no detectable effect on the program output.
113*38fd1498Szrj   */
114*38fd1498Szrj  static const syntax_option_type optimize   = 1 << _S_optimize;
115*38fd1498Szrj
116*38fd1498Szrj  /**
117*38fd1498Szrj   * Specifies that character ranges of the form [a-b] should be locale
118*38fd1498Szrj   * sensitive.
119*38fd1498Szrj   */
120*38fd1498Szrj  static const syntax_option_type collate    = 1 << _S_collate;
121*38fd1498Szrj
122*38fd1498Szrj  /**
123*38fd1498Szrj   * Specifies that the grammar recognized by the regular expression engine is
124*38fd1498Szrj   * that used by ECMAScript in ECMA-262 [Ecma International, ECMAScript
125*38fd1498Szrj   * Language Specification, Standard Ecma-262, third edition, 1999], as
126*38fd1498Szrj   * modified in tr1 section [7.13].  This grammar is similar to that defined
127*38fd1498Szrj   * in the PERL scripting language but extended with elements found in the
128*38fd1498Szrj   * POSIX regular expression grammar.
129*38fd1498Szrj   */
130*38fd1498Szrj  static const syntax_option_type ECMAScript = 1 << _S_ECMAScript;
131*38fd1498Szrj
132*38fd1498Szrj  /**
133*38fd1498Szrj   * Specifies that the grammar recognized by the regular expression engine is
134*38fd1498Szrj   * that used by POSIX basic regular expressions in IEEE Std 1003.1-2001,
135*38fd1498Szrj   * Portable Operating System Interface (POSIX), Base Definitions and
136*38fd1498Szrj   * Headers, Section 9, Regular Expressions [IEEE, Information Technology --
137*38fd1498Szrj   * Portable Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
138*38fd1498Szrj   */
139*38fd1498Szrj  static const syntax_option_type basic      = 1 << _S_basic;
140*38fd1498Szrj
141*38fd1498Szrj  /**
142*38fd1498Szrj   * Specifies that the grammar recognized by the regular expression engine is
143*38fd1498Szrj   * that used by POSIX extended regular expressions in IEEE Std 1003.1-2001,
144*38fd1498Szrj   * Portable Operating System Interface (POSIX), Base Definitions and Headers,
145*38fd1498Szrj   * Section 9, Regular Expressions.
146*38fd1498Szrj   */
147*38fd1498Szrj  static const syntax_option_type extended   = 1 << _S_extended;
148*38fd1498Szrj
149*38fd1498Szrj  /**
150*38fd1498Szrj   * Specifies that the grammar recognized by the regular expression engine is
151*38fd1498Szrj   * that used by POSIX utility awk in IEEE Std 1003.1-2001.  This option is
152*38fd1498Szrj   * identical to syntax_option_type extended, except that C-style escape
153*38fd1498Szrj   * sequences are supported.  These sequences are:
154*38fd1498Szrj   * \\\\, \\a, \\b, \\f,
155*38fd1498Szrj   * \\n, \\r, \\t , \\v,
156*38fd1498Szrj   * \\&apos;, &apos;, and \\ddd
157*38fd1498Szrj   * (where ddd is one, two, or three octal digits).
158*38fd1498Szrj   */
159*38fd1498Szrj  static const syntax_option_type awk        = 1 << _S_awk;
160*38fd1498Szrj
161*38fd1498Szrj  /**
162*38fd1498Szrj   * Specifies that the grammar recognized by the regular expression engine is
163*38fd1498Szrj   * that used by POSIX utility grep in IEEE Std 1003.1-2001.  This option is
164*38fd1498Szrj   * identical to syntax_option_type basic, except that newlines are treated
165*38fd1498Szrj   * as whitespace.
166*38fd1498Szrj   */
167*38fd1498Szrj  static const syntax_option_type grep       = 1 << _S_grep;
168*38fd1498Szrj
169*38fd1498Szrj  /**
170*38fd1498Szrj   * Specifies that the grammar recognized by the regular expression engine is
171*38fd1498Szrj   * that used by POSIX utility grep when given the -E option in
172*38fd1498Szrj   * IEEE Std 1003.1-2001.  This option is identical to syntax_option_type
173*38fd1498Szrj   * extended, except that newlines are treated as whitespace.
174*38fd1498Szrj   */
175*38fd1498Szrj  static const syntax_option_type egrep      = 1 << _S_egrep;
176*38fd1498Szrj
177*38fd1498Szrj  //@}
178*38fd1498Szrj
179*38fd1498Szrj  /**
180*38fd1498Szrj   * @name 5.2 Matching Rules
181*38fd1498Szrj   *
182*38fd1498Szrj   * Matching a regular expression against a sequence of characters [first,
183*38fd1498Szrj   * last) proceeds according to the rules of the grammar specified for the
184*38fd1498Szrj   * regular expression object, modified according to the effects listed
185*38fd1498Szrj   * below for any bitmask elements set.
186*38fd1498Szrj   *
187*38fd1498Szrj   */
188*38fd1498Szrj  //@{
189*38fd1498Szrj
190*38fd1498Szrj  enum __match_flag
191*38fd1498Szrj    {
192*38fd1498Szrj      _S_not_bol,
193*38fd1498Szrj      _S_not_eol,
194*38fd1498Szrj      _S_not_bow,
195*38fd1498Szrj      _S_not_eow,
196*38fd1498Szrj      _S_any,
197*38fd1498Szrj      _S_not_null,
198*38fd1498Szrj      _S_continuous,
199*38fd1498Szrj      _S_prev_avail,
200*38fd1498Szrj      _S_sed,
201*38fd1498Szrj      _S_no_copy,
202*38fd1498Szrj      _S_first_only,
203*38fd1498Szrj      _S_match_flag_last
204*38fd1498Szrj    };
205*38fd1498Szrj
206*38fd1498Szrj  /**
207*38fd1498Szrj   * @brief This is a bitmask type indicating regex matching rules.
208*38fd1498Szrj   *
209*38fd1498Szrj   * The @c match_flag_type is implementation defined but it is valid to
210*38fd1498Szrj   * perform bitwise operations on these values and expect the right thing to
211*38fd1498Szrj   * happen.
212*38fd1498Szrj   */
213*38fd1498Szrj  typedef std::bitset<_S_match_flag_last> match_flag_type;
214*38fd1498Szrj
215*38fd1498Szrj  /**
216*38fd1498Szrj   * The default matching rules.
217*38fd1498Szrj   */
218*38fd1498Szrj  static const match_flag_type match_default     = 0;
219*38fd1498Szrj
220*38fd1498Szrj  /**
221*38fd1498Szrj   * The first character in the sequence [first, last) is treated as though it
222*38fd1498Szrj   * is not at the beginning of a line, so the character (^) in the regular
223*38fd1498Szrj   * expression shall not match [first, first).
224*38fd1498Szrj   */
225*38fd1498Szrj  static const match_flag_type match_not_bol     = 1 << _S_not_bol;
226*38fd1498Szrj
227*38fd1498Szrj  /**
228*38fd1498Szrj   * The last character in the sequence [first, last) is treated as though it
229*38fd1498Szrj   * is not at the end of a line, so the character ($) in the regular
230*38fd1498Szrj   * expression shall not match [last, last).
231*38fd1498Szrj   */
232*38fd1498Szrj  static const match_flag_type match_not_eol     = 1 << _S_not_eol;
233*38fd1498Szrj
234*38fd1498Szrj  /**
235*38fd1498Szrj   * The expression \\b is not matched against the sub-sequence
236*38fd1498Szrj   * [first,first).
237*38fd1498Szrj   */
238*38fd1498Szrj  static const match_flag_type match_not_bow     = 1 << _S_not_bow;
239*38fd1498Szrj
240*38fd1498Szrj  /**
241*38fd1498Szrj   * The expression \\b should not be matched against the sub-sequence
242*38fd1498Szrj   * [last,last).
243*38fd1498Szrj   */
244*38fd1498Szrj  static const match_flag_type match_not_eow     = 1 << _S_not_eow;
245*38fd1498Szrj
246*38fd1498Szrj  /**
247*38fd1498Szrj   * If more than one match is possible then any match is an acceptable
248*38fd1498Szrj   * result.
249*38fd1498Szrj   */
250*38fd1498Szrj  static const match_flag_type match_any         = 1 << _S_any;
251*38fd1498Szrj
252*38fd1498Szrj  /**
253*38fd1498Szrj   * The expression does not match an empty sequence.
254*38fd1498Szrj   */
255*38fd1498Szrj  static const match_flag_type match_not_null    = 1 << _S_not_null;
256*38fd1498Szrj
257*38fd1498Szrj  /**
258*38fd1498Szrj   * The expression only matches a sub-sequence that begins at first .
259*38fd1498Szrj   */
260*38fd1498Szrj  static const match_flag_type match_continuous  = 1 << _S_continuous;
261*38fd1498Szrj
262*38fd1498Szrj  /**
263*38fd1498Szrj   * --first is a valid iterator position.  When this flag is set then the
264*38fd1498Szrj   * flags match_not_bol and match_not_bow are ignored by the regular
265*38fd1498Szrj   * expression algorithms 7.11 and iterators 7.12.
266*38fd1498Szrj   */
267*38fd1498Szrj  static const match_flag_type match_prev_avail  = 1 << _S_prev_avail;
268*38fd1498Szrj
269*38fd1498Szrj  /**
270*38fd1498Szrj   * When a regular expression match is to be replaced by a new string, the
271*38fd1498Szrj   * new string is constructed using the rules used by the ECMAScript replace
272*38fd1498Szrj   * function in ECMA- 262 [Ecma International, ECMAScript Language
273*38fd1498Szrj   * Specification, Standard Ecma-262, third edition, 1999], part 15.5.4.11
274*38fd1498Szrj   * String.prototype.replace. In addition, during search and replace
275*38fd1498Szrj   * operations all non-overlapping occurrences of the regular expression
276*38fd1498Szrj   * are located and replaced, and sections of the input that did not match
277*38fd1498Szrj   * the expression are copied unchanged to the output string.
278*38fd1498Szrj   *
279*38fd1498Szrj   * Format strings (from ECMA-262 [15.5.4.11]):
280*38fd1498Szrj   * @li $$  The dollar-sign itself ($)
281*38fd1498Szrj   * @li $&  The matched substring.
282*38fd1498Szrj   * @li $`  The portion of @a string that precedes the matched substring.
283*38fd1498Szrj   *         This would be match_results::prefix().
284*38fd1498Szrj   * @li $'  The portion of @a string that follows the matched substring.
285*38fd1498Szrj   *         This would be match_results::suffix().
286*38fd1498Szrj   * @li $n  The nth capture, where n is in [1,9] and $n is not followed by a
287*38fd1498Szrj   *         decimal digit.  If n <= match_results::size() and the nth capture
288*38fd1498Szrj   *         is undefined, use the empty string instead.  If n >
289*38fd1498Szrj   *         match_results::size(), the result is implementation-defined.
290*38fd1498Szrj   * @li $nn The nnth capture, where nn is a two-digit decimal number on
291*38fd1498Szrj   *         [01, 99].  If nn <= match_results::size() and the nth capture is
292*38fd1498Szrj   *         undefined, use the empty string instead. If
293*38fd1498Szrj   *         nn > match_results::size(), the result is implementation-defined.
294*38fd1498Szrj   */
295*38fd1498Szrj  static const match_flag_type format_default    = 0;
296*38fd1498Szrj
297*38fd1498Szrj  /**
298*38fd1498Szrj   * When a regular expression match is to be replaced by a new string, the
299*38fd1498Szrj   * new string is constructed using the rules used by the POSIX sed utility
300*38fd1498Szrj   * in IEEE Std 1003.1- 2001 [IEEE, Information Technology -- Portable
301*38fd1498Szrj   * Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
302*38fd1498Szrj   */
303*38fd1498Szrj  static const match_flag_type format_sed        = 1 << _S_sed;
304*38fd1498Szrj
305*38fd1498Szrj  /**
306*38fd1498Szrj   * During a search and replace operation, sections of the character
307*38fd1498Szrj   * container sequence being searched that do not match the regular
308*38fd1498Szrj   * expression shall not be copied to the output string.
309*38fd1498Szrj   */
310*38fd1498Szrj  static const match_flag_type format_no_copy    = 1 << _S_no_copy;
311*38fd1498Szrj
312*38fd1498Szrj  /**
313*38fd1498Szrj   * When specified during a search and replace operation, only the first
314*38fd1498Szrj   * occurrence of the regular expression shall be replaced.
315*38fd1498Szrj   */
316*38fd1498Szrj  static const match_flag_type format_first_only = 1 << _S_first_only;
317*38fd1498Szrj
318*38fd1498Szrj  //@}
319*38fd1498Szrj
320*38fd1498Szrj  /**
321*38fd1498Szrj   * @name 5.3 Error Types
322*38fd1498Szrj   */
323*38fd1498Szrj  //@{
324*38fd1498Szrj
325*38fd1498Szrj  enum error_type
326*38fd1498Szrj    {
327*38fd1498Szrj      _S_error_collate,
328*38fd1498Szrj      _S_error_ctype,
329*38fd1498Szrj      _S_error_escape,
330*38fd1498Szrj      _S_error_backref,
331*38fd1498Szrj      _S_error_brack,
332*38fd1498Szrj      _S_error_paren,
333*38fd1498Szrj      _S_error_brace,
334*38fd1498Szrj      _S_error_badbrace,
335*38fd1498Szrj      _S_error_range,
336*38fd1498Szrj      _S_error_space,
337*38fd1498Szrj      _S_error_badrepeat,
338*38fd1498Szrj      _S_error_complexity,
339*38fd1498Szrj      _S_error_stack,
340*38fd1498Szrj      _S_error_last
341*38fd1498Szrj    };
342*38fd1498Szrj
343*38fd1498Szrj  /** The expression contained an invalid collating element name. */
344*38fd1498Szrj  static const error_type error_collate(_S_error_collate);
345*38fd1498Szrj
346*38fd1498Szrj  /** The expression contained an invalid character class name. */
347*38fd1498Szrj  static const error_type error_ctype(_S_error_ctype);
348*38fd1498Szrj
349*38fd1498Szrj  /**
350*38fd1498Szrj   * The expression contained an invalid escaped character, or a trailing
351*38fd1498Szrj   * escape.
352*38fd1498Szrj   */
353*38fd1498Szrj  static const error_type error_escape(_S_error_escape);
354*38fd1498Szrj
355*38fd1498Szrj  /** The expression contained an invalid back reference. */
356*38fd1498Szrj  static const error_type error_backref(_S_error_backref);
357*38fd1498Szrj
358*38fd1498Szrj  /** The expression contained mismatched [ and ]. */
359*38fd1498Szrj  static const error_type error_brack(_S_error_brack);
360*38fd1498Szrj
361*38fd1498Szrj  /** The expression contained mismatched ( and ). */
362*38fd1498Szrj  static const error_type error_paren(_S_error_paren);
363*38fd1498Szrj
364*38fd1498Szrj  /** The expression contained mismatched { and } */
365*38fd1498Szrj  static const error_type error_brace(_S_error_brace);
366*38fd1498Szrj
367*38fd1498Szrj  /** The expression contained an invalid range in a {} expression. */
368*38fd1498Szrj  static const error_type error_badbrace(_S_error_badbrace);
369*38fd1498Szrj
370*38fd1498Szrj  /**
371*38fd1498Szrj   * The expression contained an invalid character range,
372*38fd1498Szrj   * such as [b-a] in most encodings.
373*38fd1498Szrj   */
374*38fd1498Szrj  static const error_type error_range(_S_error_range);
375*38fd1498Szrj
376*38fd1498Szrj  /**
377*38fd1498Szrj   * There was insufficient memory to convert the expression into a
378*38fd1498Szrj   * finite state machine.
379*38fd1498Szrj   */
380*38fd1498Szrj  static const error_type error_space(_S_error_space);
381*38fd1498Szrj
382*38fd1498Szrj  /**
383*38fd1498Szrj   * One of <em>*?+{</em> was not preceded by a valid regular expression.
384*38fd1498Szrj   */
385*38fd1498Szrj  static const error_type error_badrepeat(_S_error_badrepeat);
386*38fd1498Szrj
387*38fd1498Szrj  /**
388*38fd1498Szrj   * The complexity of an attempted match against a regular expression
389*38fd1498Szrj   * exceeded a pre-set level.
390*38fd1498Szrj   */
391*38fd1498Szrj  static const error_type error_complexity(_S_error_complexity);
392*38fd1498Szrj
393*38fd1498Szrj  /**
394*38fd1498Szrj   * There was insufficient memory to determine whether the
395*38fd1498Szrj   * regular expression could match the specified character sequence.
396*38fd1498Szrj   */
397*38fd1498Szrj  static const error_type error_stack(_S_error_stack);
398*38fd1498Szrj
399*38fd1498Szrj  //@}
400*38fd1498Szrj}
401*38fd1498Szrj
402*38fd1498Szrj  // [7.8] Class regex_error
403*38fd1498Szrj  /**
404*38fd1498Szrj   *  @brief A regular expression exception class.
405*38fd1498Szrj   *  @ingroup exceptions
406*38fd1498Szrj   *
407*38fd1498Szrj   *  The regular expression library throws objects of this class on error.
408*38fd1498Szrj   */
409*38fd1498Szrj  class regex_error
410*38fd1498Szrj  : public std::runtime_error
411*38fd1498Szrj  {
412*38fd1498Szrj  public:
413*38fd1498Szrj    /**
414*38fd1498Szrj     * @brief Constructs a regex_error object.
415*38fd1498Szrj     *
416*38fd1498Szrj     * @param ecode the regex error code.
417*38fd1498Szrj     */
418*38fd1498Szrj    explicit
419*38fd1498Szrj    regex_error(regex_constants::error_type __ecode)
420*38fd1498Szrj    : std::runtime_error("regex_error"), _M_code(__ecode)
421*38fd1498Szrj    { }
422*38fd1498Szrj
423*38fd1498Szrj    /**
424*38fd1498Szrj     * @brief Gets the regex error code.
425*38fd1498Szrj     *
426*38fd1498Szrj     * @returns the regex error code.
427*38fd1498Szrj     */
428*38fd1498Szrj    regex_constants::error_type
429*38fd1498Szrj    code() const
430*38fd1498Szrj    { return _M_code; }
431*38fd1498Szrj
432*38fd1498Szrj  protected:
433*38fd1498Szrj    regex_constants::error_type _M_code;
434*38fd1498Szrj  };
435*38fd1498Szrj
436*38fd1498Szrj  // [7.7] Class regex_traits
437*38fd1498Szrj  /**
438*38fd1498Szrj   * @brief Describes aspects of a regular expression.
439*38fd1498Szrj   *
440*38fd1498Szrj   * A regular expression traits class that satisfies the requirements of tr1
441*38fd1498Szrj   * section [7.2].
442*38fd1498Szrj   *
443*38fd1498Szrj   * The class %regex is parameterized around a set of related types and
444*38fd1498Szrj   * functions used to complete the definition of its semantics.  This class
445*38fd1498Szrj   * satisfies the requirements of such a traits class.
446*38fd1498Szrj   */
447*38fd1498Szrj  template<typename _Ch_type>
448*38fd1498Szrj    struct regex_traits
449*38fd1498Szrj    {
450*38fd1498Szrj    public:
451*38fd1498Szrj      typedef _Ch_type                     char_type;
452*38fd1498Szrj      typedef std::basic_string<char_type> string_type;
453*38fd1498Szrj      typedef std::locale                  locale_type;
454*38fd1498Szrj      typedef std::ctype_base::mask        char_class_type;
455*38fd1498Szrj
456*38fd1498Szrj    public:
457*38fd1498Szrj      /**
458*38fd1498Szrj       * @brief Constructs a default traits object.
459*38fd1498Szrj       */
460*38fd1498Szrj      regex_traits()
461*38fd1498Szrj      { }
462*38fd1498Szrj
463*38fd1498Szrj      /**
464*38fd1498Szrj       * @brief Gives the length of a C-style string starting at @p __p.
465*38fd1498Szrj       *
466*38fd1498Szrj       * @param __p a pointer to the start of a character sequence.
467*38fd1498Szrj       *
468*38fd1498Szrj       * @returns the number of characters between @p *__p and the first
469*38fd1498Szrj       * default-initialized value of type @p char_type.  In other words, uses
470*38fd1498Szrj       * the C-string algorithm for determining the length of a sequence of
471*38fd1498Szrj       * characters.
472*38fd1498Szrj       */
473*38fd1498Szrj      static std::size_t
474*38fd1498Szrj      length(const char_type* __p)
475*38fd1498Szrj      { return string_type::traits_type::length(__p); }
476*38fd1498Szrj
477*38fd1498Szrj      /**
478*38fd1498Szrj       * @brief Performs the identity translation.
479*38fd1498Szrj       *
480*38fd1498Szrj       * @param c A character to the locale-specific character set.
481*38fd1498Szrj       *
482*38fd1498Szrj       * @returns c.
483*38fd1498Szrj       */
484*38fd1498Szrj      char_type
485*38fd1498Szrj      translate(char_type __c) const
486*38fd1498Szrj      { return __c; }
487*38fd1498Szrj
488*38fd1498Szrj      /**
489*38fd1498Szrj       * @brief Translates a character into a case-insensitive equivalent.
490*38fd1498Szrj       *
491*38fd1498Szrj       * @param c A character to the locale-specific character set.
492*38fd1498Szrj       *
493*38fd1498Szrj       * @returns the locale-specific lower-case equivalent of c.
494*38fd1498Szrj       * @throws std::bad_cast if the imbued locale does not support the ctype
495*38fd1498Szrj       *         facet.
496*38fd1498Szrj       */
497*38fd1498Szrj      char_type
498*38fd1498Szrj      translate_nocase(char_type __c) const
499*38fd1498Szrj      {
500*38fd1498Szrj	using std::ctype;
501*38fd1498Szrj	using std::use_facet;
502*38fd1498Szrj	return use_facet<ctype<char_type> >(_M_locale).tolower(__c);
503*38fd1498Szrj      }
504*38fd1498Szrj
505*38fd1498Szrj      /**
506*38fd1498Szrj       * @brief Gets a sort key for a character sequence.
507*38fd1498Szrj       *
508*38fd1498Szrj       * @param first beginning of the character sequence.
509*38fd1498Szrj       * @param last  one-past-the-end of the character sequence.
510*38fd1498Szrj       *
511*38fd1498Szrj       * Returns a sort key for the character sequence designated by the
512*38fd1498Szrj       * iterator range [F1, F2) such that if the character sequence [G1, G2)
513*38fd1498Szrj       * sorts before the character sequence [H1, H2) then
514*38fd1498Szrj       * v.transform(G1, G2) < v.transform(H1, H2).
515*38fd1498Szrj       *
516*38fd1498Szrj       * What this really does is provide a more efficient way to compare a
517*38fd1498Szrj       * string to multiple other strings in locales with fancy collation
518*38fd1498Szrj       * rules and equivalence classes.
519*38fd1498Szrj       *
520*38fd1498Szrj       * @returns a locale-specific sort key equivalent to the input range.
521*38fd1498Szrj       *
522*38fd1498Szrj       * @throws std::bad_cast if the current locale does not have a collate
523*38fd1498Szrj       *         facet.
524*38fd1498Szrj       */
525*38fd1498Szrj      template<typename _Fwd_iter>
526*38fd1498Szrj        string_type
527*38fd1498Szrj        transform(_Fwd_iter __first, _Fwd_iter __last) const
528*38fd1498Szrj        {
529*38fd1498Szrj	  using std::collate;
530*38fd1498Szrj	  using std::use_facet;
531*38fd1498Szrj	  const collate<_Ch_type>& __c(use_facet<
532*38fd1498Szrj				       collate<_Ch_type> >(_M_locale));
533*38fd1498Szrj	  string_type __s(__first, __last);
534*38fd1498Szrj	  return __c.transform(__s.data(), __s.data() + __s.size());
535*38fd1498Szrj	}
536*38fd1498Szrj
537*38fd1498Szrj      /**
538*38fd1498Szrj       * @brief Dunno.
539*38fd1498Szrj       *
540*38fd1498Szrj       * @param first beginning of the character sequence.
541*38fd1498Szrj       * @param last  one-past-the-end of the character sequence.
542*38fd1498Szrj       *
543*38fd1498Szrj       * Effects: if typeid(use_facet<collate<_Ch_type> >) ==
544*38fd1498Szrj       * typeid(collate_byname<_Ch_type>) and the form of the sort key
545*38fd1498Szrj       * returned by collate_byname<_Ch_type>::transform(first, last) is known
546*38fd1498Szrj       * and can be converted into a primary sort key then returns that key,
547*38fd1498Szrj       * otherwise returns an empty string. WTF??
548*38fd1498Szrj       *
549*38fd1498Szrj       * @todo Implement this function.
550*38fd1498Szrj       */
551*38fd1498Szrj      template<typename _Fwd_iter>
552*38fd1498Szrj        string_type
553*38fd1498Szrj        transform_primary(_Fwd_iter __first, _Fwd_iter __last) const;
554*38fd1498Szrj
555*38fd1498Szrj      /**
556*38fd1498Szrj       * @brief Gets a collation element by name.
557*38fd1498Szrj       *
558*38fd1498Szrj       * @param first beginning of the collation element name.
559*38fd1498Szrj       * @param last  one-past-the-end of the collation element name.
560*38fd1498Szrj       *
561*38fd1498Szrj       * @returns a sequence of one or more characters that represents the
562*38fd1498Szrj       * collating element consisting of the character sequence designated by
563*38fd1498Szrj       * the iterator range [first, last). Returns an empty string if the
564*38fd1498Szrj       * character sequence is not a valid collating element.
565*38fd1498Szrj       *
566*38fd1498Szrj       * @todo Implement this function.
567*38fd1498Szrj       */
568*38fd1498Szrj      template<typename _Fwd_iter>
569*38fd1498Szrj        string_type
570*38fd1498Szrj        lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const;
571*38fd1498Szrj
572*38fd1498Szrj      /**
573*38fd1498Szrj       * @brief Maps one or more characters to a named character
574*38fd1498Szrj       *        classification.
575*38fd1498Szrj       *
576*38fd1498Szrj       * @param first beginning of the character sequence.
577*38fd1498Szrj       * @param last  one-past-the-end of the character sequence.
578*38fd1498Szrj       *
579*38fd1498Szrj       * @returns an unspecified value that represents the character
580*38fd1498Szrj       * classification named by the character sequence designated by the
581*38fd1498Szrj       * iterator range [first, last). The value returned shall be independent
582*38fd1498Szrj       * of the case of the characters in the character sequence. If the name
583*38fd1498Szrj       * is not recognized then returns a value that compares equal to 0.
584*38fd1498Szrj       *
585*38fd1498Szrj       * At least the following names (or their wide-character equivalent) are
586*38fd1498Szrj       * supported.
587*38fd1498Szrj       * - d
588*38fd1498Szrj       * - w
589*38fd1498Szrj       * - s
590*38fd1498Szrj       * - alnum
591*38fd1498Szrj       * - alpha
592*38fd1498Szrj       * - blank
593*38fd1498Szrj       * - cntrl
594*38fd1498Szrj       * - digit
595*38fd1498Szrj       * - graph
596*38fd1498Szrj       * - lower
597*38fd1498Szrj       * - print
598*38fd1498Szrj       * - punct
599*38fd1498Szrj       * - space
600*38fd1498Szrj       * - upper
601*38fd1498Szrj       * - xdigit
602*38fd1498Szrj       *
603*38fd1498Szrj       * @todo Implement this function.
604*38fd1498Szrj       */
605*38fd1498Szrj      template<typename _Fwd_iter>
606*38fd1498Szrj        char_class_type
607*38fd1498Szrj        lookup_classname(_Fwd_iter __first, _Fwd_iter __last) const;
608*38fd1498Szrj
609*38fd1498Szrj      /**
610*38fd1498Szrj       * @brief Determines if @p c is a member of an identified class.
611*38fd1498Szrj       *
612*38fd1498Szrj       * @param c a character.
613*38fd1498Szrj       * @param f a class type (as returned from lookup_classname).
614*38fd1498Szrj       *
615*38fd1498Szrj       * @returns true if the character @p c is a member of the classification
616*38fd1498Szrj       * represented by @p f, false otherwise.
617*38fd1498Szrj       *
618*38fd1498Szrj       * @throws std::bad_cast if the current locale does not have a ctype
619*38fd1498Szrj       *         facet.
620*38fd1498Szrj       */
621*38fd1498Szrj      bool
622*38fd1498Szrj      isctype(_Ch_type __c, char_class_type __f) const;
623*38fd1498Szrj
624*38fd1498Szrj      /**
625*38fd1498Szrj       * @brief Converts a digit to an int.
626*38fd1498Szrj       *
627*38fd1498Szrj       * @param ch    a character representing a digit.
628*38fd1498Szrj       * @param radix the radix if the numeric conversion (limited to 8, 10,
629*38fd1498Szrj       *              or 16).
630*38fd1498Szrj       *
631*38fd1498Szrj       * @returns the value represented by the digit ch in base radix if the
632*38fd1498Szrj       * character ch is a valid digit in base radix; otherwise returns -1.
633*38fd1498Szrj       */
634*38fd1498Szrj      int
635*38fd1498Szrj      value(_Ch_type __ch, int __radix) const;
636*38fd1498Szrj
637*38fd1498Szrj      /**
638*38fd1498Szrj       * @brief Imbues the regex_traits object with a copy of a new locale.
639*38fd1498Szrj       *
640*38fd1498Szrj       * @param loc A locale.
641*38fd1498Szrj       *
642*38fd1498Szrj       * @returns a copy of the previous locale in use by the regex_traits
643*38fd1498Szrj       *          object.
644*38fd1498Szrj       *
645*38fd1498Szrj       * @note Calling imbue with a different locale than the one currently in
646*38fd1498Szrj       *       use invalidates all cached data held by *this.
647*38fd1498Szrj       */
648*38fd1498Szrj      locale_type
649*38fd1498Szrj      imbue(locale_type __loc)
650*38fd1498Szrj      {
651*38fd1498Szrj	std::swap(_M_locale, __loc);
652*38fd1498Szrj	return __loc;
653*38fd1498Szrj      }
654*38fd1498Szrj
655*38fd1498Szrj      /**
656*38fd1498Szrj       * @brief Gets a copy of the current locale in use by the regex_traits
657*38fd1498Szrj       * object.
658*38fd1498Szrj       */
659*38fd1498Szrj      locale_type
660*38fd1498Szrj      getloc() const
661*38fd1498Szrj      { return _M_locale; }
662*38fd1498Szrj
663*38fd1498Szrj    protected:
664*38fd1498Szrj      locale_type _M_locale;
665*38fd1498Szrj    };
666*38fd1498Szrj
667*38fd1498Szrj  template<typename _Ch_type>
668*38fd1498Szrj    bool regex_traits<_Ch_type>::
669*38fd1498Szrj    isctype(_Ch_type __c, char_class_type __f) const
670*38fd1498Szrj    {
671*38fd1498Szrj      using std::ctype;
672*38fd1498Szrj      using std::use_facet;
673*38fd1498Szrj      const ctype<_Ch_type>& __ctype(use_facet<
674*38fd1498Szrj				     ctype<_Ch_type> >(_M_locale));
675*38fd1498Szrj
676*38fd1498Szrj      if (__ctype.is(__c, __f))
677*38fd1498Szrj	return true;
678*38fd1498Szrj#if 0
679*38fd1498Szrj      // special case of underscore in [[:w:]]
680*38fd1498Szrj      if (__c == __ctype.widen('_'))
681*38fd1498Szrj	{
682*38fd1498Szrj	  const char* const __wb[] = "w";
683*38fd1498Szrj	  char_class_type __wt = this->lookup_classname(__wb,
684*38fd1498Szrj							__wb + sizeof(__wb));
685*38fd1498Szrj	  if (__f | __wt)
686*38fd1498Szrj	    return true;
687*38fd1498Szrj	}
688*38fd1498Szrj
689*38fd1498Szrj      // special case of [[:space:]] in [[:blank:]]
690*38fd1498Szrj      if (__c == __ctype.isspace(__c))
691*38fd1498Szrj	{
692*38fd1498Szrj	  const char* const __bb[] = "blank";
693*38fd1498Szrj	  char_class_type __bt = this->lookup_classname(__bb,
694*38fd1498Szrj							__bb + sizeof(__bb));
695*38fd1498Szrj	  if (__f | __bt)
696*38fd1498Szrj	    return true;
697*38fd1498Szrj	}
698*38fd1498Szrj#endif
699*38fd1498Szrj      return false;
700*38fd1498Szrj    }
701*38fd1498Szrj
702*38fd1498Szrj  template<typename _Ch_type>
703*38fd1498Szrj    int regex_traits<_Ch_type>::
704*38fd1498Szrj    value(_Ch_type __ch, int __radix) const
705*38fd1498Szrj    {
706*38fd1498Szrj      std::basic_istringstream<_Ch_type> __is(string_type(1, __ch));
707*38fd1498Szrj      int __v;
708*38fd1498Szrj      if (__radix == 8)
709*38fd1498Szrj	__is >> std::oct;
710*38fd1498Szrj      else if (__radix == 16)
711*38fd1498Szrj	__is >> std::hex;
712*38fd1498Szrj      __is >> __v;
713*38fd1498Szrj      return __is.fail() ? -1 : __v;
714*38fd1498Szrj    }
715*38fd1498Szrj
716*38fd1498Szrj  // [7.8] Class basic_regex
717*38fd1498Szrj  /**
718*38fd1498Szrj   * Objects of specializations of this class represent regular expressions
719*38fd1498Szrj   * constructed from sequences of character type @p _Ch_type.
720*38fd1498Szrj   *
721*38fd1498Szrj   * Storage for the regular expression is allocated and deallocated as
722*38fd1498Szrj   * necessary by the member functions of this class.
723*38fd1498Szrj   */
724*38fd1498Szrj  template<typename _Ch_type, typename _Rx_traits = regex_traits<_Ch_type> >
725*38fd1498Szrj    class basic_regex
726*38fd1498Szrj    {
727*38fd1498Szrj    public:
728*38fd1498Szrj      // types:
729*38fd1498Szrj      typedef _Ch_type                              value_type;
730*38fd1498Szrj      typedef regex_constants::syntax_option_type flag_type;
731*38fd1498Szrj      typedef typename _Rx_traits::locale_type  locale_type;
732*38fd1498Szrj      typedef typename _Rx_traits::string_type  string_type;
733*38fd1498Szrj
734*38fd1498Szrj      /**
735*38fd1498Szrj       * @name Constants
736*38fd1498Szrj       * tr1 [7.8.1] std [28.8.1]
737*38fd1498Szrj       */
738*38fd1498Szrj      //@{
739*38fd1498Szrj      static const regex_constants::syntax_option_type icase
740*38fd1498Szrj        = regex_constants::icase;
741*38fd1498Szrj      static const regex_constants::syntax_option_type nosubs
742*38fd1498Szrj        = regex_constants::nosubs;
743*38fd1498Szrj      static const regex_constants::syntax_option_type optimize
744*38fd1498Szrj        = regex_constants::optimize;
745*38fd1498Szrj      static const regex_constants::syntax_option_type collate
746*38fd1498Szrj        = regex_constants::collate;
747*38fd1498Szrj      static const regex_constants::syntax_option_type ECMAScript
748*38fd1498Szrj        = regex_constants::ECMAScript;
749*38fd1498Szrj      static const regex_constants::syntax_option_type basic
750*38fd1498Szrj        = regex_constants::basic;
751*38fd1498Szrj      static const regex_constants::syntax_option_type extended
752*38fd1498Szrj        = regex_constants::extended;
753*38fd1498Szrj      static const regex_constants::syntax_option_type awk
754*38fd1498Szrj        = regex_constants::awk;
755*38fd1498Szrj      static const regex_constants::syntax_option_type grep
756*38fd1498Szrj        = regex_constants::grep;
757*38fd1498Szrj      static const regex_constants::syntax_option_type egrep
758*38fd1498Szrj        = regex_constants::egrep;
759*38fd1498Szrj      //@}
760*38fd1498Szrj
761*38fd1498Szrj      // [7.8.2] construct/copy/destroy
762*38fd1498Szrj      /**
763*38fd1498Szrj       * Constructs a basic regular expression that does not match any
764*38fd1498Szrj       * character sequence.
765*38fd1498Szrj       */
766*38fd1498Szrj      basic_regex()
767*38fd1498Szrj      : _M_flags(regex_constants::ECMAScript), _M_pattern(), _M_mark_count(0)
768*38fd1498Szrj      { _M_compile(); }
769*38fd1498Szrj
770*38fd1498Szrj      /**
771*38fd1498Szrj       * @brief Constructs a basic regular expression from the sequence
772*38fd1498Szrj       * [p, p + char_traits<_Ch_type>::length(p)) interpreted according to the
773*38fd1498Szrj       * flags in @p f.
774*38fd1498Szrj       *
775*38fd1498Szrj       * @param p A pointer to the start of a C-style null-terminated string
776*38fd1498Szrj       *          containing a regular expression.
777*38fd1498Szrj       * @param f Flags indicating the syntax rules and options.
778*38fd1498Szrj       *
779*38fd1498Szrj       * @throws regex_error if @p p is not a valid regular expression.
780*38fd1498Szrj       */
781*38fd1498Szrj      explicit
782*38fd1498Szrj      basic_regex(const _Ch_type* __p,
783*38fd1498Szrj		  flag_type __f = regex_constants::ECMAScript)
784*38fd1498Szrj      : _M_flags(__f), _M_pattern(__p), _M_mark_count(0)
785*38fd1498Szrj      { _M_compile(); }
786*38fd1498Szrj
787*38fd1498Szrj      /**
788*38fd1498Szrj       * @brief Constructs a basic regular expression from the sequence
789*38fd1498Szrj       * [p, p + len) interpreted according to the flags in @p f.
790*38fd1498Szrj       *
791*38fd1498Szrj       * @param p   A pointer to the start of a string containing a regular
792*38fd1498Szrj       *            expression.
793*38fd1498Szrj       * @param len The length of the string containing the regular expression.
794*38fd1498Szrj       * @param f   Flags indicating the syntax rules and options.
795*38fd1498Szrj       *
796*38fd1498Szrj       * @throws regex_error if @p p is not a valid regular expression.
797*38fd1498Szrj       */
798*38fd1498Szrj      basic_regex(const _Ch_type* __p, std::size_t __len, flag_type __f)
799*38fd1498Szrj      : _M_flags(__f) , _M_pattern(__p, __len), _M_mark_count(0)
800*38fd1498Szrj      { _M_compile(); }
801*38fd1498Szrj
802*38fd1498Szrj      /**
803*38fd1498Szrj       * @brief Copy-constructs a basic regular expression.
804*38fd1498Szrj       *
805*38fd1498Szrj       * @param rhs A @p regex object.
806*38fd1498Szrj     */
807*38fd1498Szrj      basic_regex(const basic_regex& __rhs)
808*38fd1498Szrj      : _M_flags(__rhs._M_flags), _M_pattern(__rhs._M_pattern),
809*38fd1498Szrj	_M_mark_count(__rhs._M_mark_count)
810*38fd1498Szrj      { _M_compile(); }
811*38fd1498Szrj
812*38fd1498Szrj      /**
813*38fd1498Szrj       * @brief Constructs a basic regular expression from the string
814*38fd1498Szrj       * @p s interpreted according to the flags in @p f.
815*38fd1498Szrj       *
816*38fd1498Szrj       * @param s A string containing a regular expression.
817*38fd1498Szrj       * @param f Flags indicating the syntax rules and options.
818*38fd1498Szrj       *
819*38fd1498Szrj       * @throws regex_error if @p s is not a valid regular expression.
820*38fd1498Szrj       */
821*38fd1498Szrj      template<typename _Ch_traits, typename _Ch_alloc>
822*38fd1498Szrj        explicit
823*38fd1498Szrj        basic_regex(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
824*38fd1498Szrj		    flag_type __f = regex_constants::ECMAScript)
825*38fd1498Szrj	: _M_flags(__f), _M_pattern(__s.begin(), __s.end()), _M_mark_count(0)
826*38fd1498Szrj        { _M_compile(); }
827*38fd1498Szrj
828*38fd1498Szrj      /**
829*38fd1498Szrj       * @brief Constructs a basic regular expression from the range
830*38fd1498Szrj       * [first, last) interpreted according to the flags in @p f.
831*38fd1498Szrj       *
832*38fd1498Szrj       * @param first The start of a range containing a valid regular
833*38fd1498Szrj       *              expression.
834*38fd1498Szrj       * @param last  The end of a range containing a valid regular
835*38fd1498Szrj       *              expression.
836*38fd1498Szrj       * @param f     The format flags of the regular expression.
837*38fd1498Szrj       *
838*38fd1498Szrj       * @throws regex_error if @p [first, last) is not a valid regular
839*38fd1498Szrj       *         expression.
840*38fd1498Szrj       */
841*38fd1498Szrj      template<typename _InputIterator>
842*38fd1498Szrj        basic_regex(_InputIterator __first, _InputIterator __last,
843*38fd1498Szrj		    flag_type __f = regex_constants::ECMAScript)
844*38fd1498Szrj	: _M_flags(__f), _M_pattern(__first, __last), _M_mark_count(0)
845*38fd1498Szrj        { _M_compile(); }
846*38fd1498Szrj
847*38fd1498Szrj#ifdef _GLIBCXX_INCLUDE_AS_CXX11
848*38fd1498Szrj      /**
849*38fd1498Szrj       * @brief Constructs a basic regular expression from an initializer list.
850*38fd1498Szrj       *
851*38fd1498Szrj       * @param l  The initializer list.
852*38fd1498Szrj       * @param f  The format flags of the regular expression.
853*38fd1498Szrj       *
854*38fd1498Szrj       * @throws regex_error if @p l is not a valid regular expression.
855*38fd1498Szrj       */
856*38fd1498Szrj      basic_regex(initializer_list<_Ch_type> __l,
857*38fd1498Szrj		  flag_type __f = regex_constants::ECMAScript)
858*38fd1498Szrj	: _M_flags(__f), _M_pattern(__l.begin(), __l.end()), _M_mark_count(0)
859*38fd1498Szrj        { _M_compile(); }
860*38fd1498Szrj#endif
861*38fd1498Szrj
862*38fd1498Szrj      /**
863*38fd1498Szrj       * @brief Destroys a basic regular expression.
864*38fd1498Szrj       */
865*38fd1498Szrj      ~basic_regex()
866*38fd1498Szrj      { }
867*38fd1498Szrj
868*38fd1498Szrj      /**
869*38fd1498Szrj       * @brief Assigns one regular expression to another.
870*38fd1498Szrj       */
871*38fd1498Szrj      basic_regex&
872*38fd1498Szrj      operator=(const basic_regex& __rhs)
873*38fd1498Szrj      { return this->assign(__rhs); }
874*38fd1498Szrj
875*38fd1498Szrj      /**
876*38fd1498Szrj       * @brief Replaces a regular expression with a new one constructed from
877*38fd1498Szrj       * a C-style null-terminated string.
878*38fd1498Szrj       *
879*38fd1498Szrj       * @param A pointer to the start of a null-terminated C-style string
880*38fd1498Szrj       *        containing a regular expression.
881*38fd1498Szrj       */
882*38fd1498Szrj      basic_regex&
883*38fd1498Szrj      operator=(const _Ch_type* __p)
884*38fd1498Szrj      { return this->assign(__p, flags()); }
885*38fd1498Szrj
886*38fd1498Szrj      /**
887*38fd1498Szrj       * @brief Replaces a regular expression with a new one constructed from
888*38fd1498Szrj       * a string.
889*38fd1498Szrj       *
890*38fd1498Szrj       * @param A pointer to a string containing a regular expression.
891*38fd1498Szrj       */
892*38fd1498Szrj      template<typename _Ch_typeraits, typename _Allocator>
893*38fd1498Szrj        basic_regex&
894*38fd1498Szrj        operator=(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s)
895*38fd1498Szrj        { return this->assign(__s, flags()); }
896*38fd1498Szrj
897*38fd1498Szrj      // [7.8.3] assign
898*38fd1498Szrj      /**
899*38fd1498Szrj       * @brief the real assignment operator.
900*38fd1498Szrj       *
901*38fd1498Szrj       * @param that Another regular expression object.
902*38fd1498Szrj       */
903*38fd1498Szrj      basic_regex&
904*38fd1498Szrj      assign(const basic_regex& __that)
905*38fd1498Szrj      {
906*38fd1498Szrj	basic_regex __tmp(__that);
907*38fd1498Szrj	this->swap(__tmp);
908*38fd1498Szrj	return *this;
909*38fd1498Szrj      }
910*38fd1498Szrj
911*38fd1498Szrj      /**
912*38fd1498Szrj       * @brief Assigns a new regular expression to a regex object from a
913*38fd1498Szrj       * C-style null-terminated string containing a regular expression
914*38fd1498Szrj       * pattern.
915*38fd1498Szrj       *
916*38fd1498Szrj       * @param p     A pointer to a C-style null-terminated string containing
917*38fd1498Szrj       *              a regular expression pattern.
918*38fd1498Szrj       * @param flags Syntax option flags.
919*38fd1498Szrj       *
920*38fd1498Szrj       * @throws regex_error if p does not contain a valid regular expression
921*38fd1498Szrj       * pattern interpreted according to @p flags.  If regex_error is thrown,
922*38fd1498Szrj       * *this remains unchanged.
923*38fd1498Szrj       */
924*38fd1498Szrj      basic_regex&
925*38fd1498Szrj      assign(const _Ch_type* __p,
926*38fd1498Szrj	     flag_type __flags = regex_constants::ECMAScript)
927*38fd1498Szrj      { return this->assign(string_type(__p), __flags); }
928*38fd1498Szrj
929*38fd1498Szrj      /**
930*38fd1498Szrj       * @brief Assigns a new regular expression to a regex object from a
931*38fd1498Szrj       * C-style string containing a regular expression pattern.
932*38fd1498Szrj       *
933*38fd1498Szrj       * @param p     A pointer to a C-style string containing a
934*38fd1498Szrj       *              regular expression pattern.
935*38fd1498Szrj       * @param len   The length of the regular expression pattern string.
936*38fd1498Szrj       * @param flags Syntax option flags.
937*38fd1498Szrj       *
938*38fd1498Szrj       * @throws regex_error if p does not contain a valid regular expression
939*38fd1498Szrj       * pattern interpreted according to @p flags.  If regex_error is thrown,
940*38fd1498Szrj       * *this remains unchanged.
941*38fd1498Szrj       */
942*38fd1498Szrj      basic_regex&
943*38fd1498Szrj      assign(const _Ch_type* __p, std::size_t __len, flag_type __flags)
944*38fd1498Szrj      { return this->assign(string_type(__p, __len), __flags); }
945*38fd1498Szrj
946*38fd1498Szrj      /**
947*38fd1498Szrj       * @brief Assigns a new regular expression to a regex object from a
948*38fd1498Szrj       * string containing a regular expression pattern.
949*38fd1498Szrj       *
950*38fd1498Szrj       * @param s     A string containing a regular expression pattern.
951*38fd1498Szrj       * @param flags Syntax option flags.
952*38fd1498Szrj       *
953*38fd1498Szrj       * @throws regex_error if p does not contain a valid regular expression
954*38fd1498Szrj       * pattern interpreted according to @p flags.  If regex_error is thrown,
955*38fd1498Szrj       * *this remains unchanged.
956*38fd1498Szrj       */
957*38fd1498Szrj      template<typename _Ch_typeraits, typename _Allocator>
958*38fd1498Szrj        basic_regex&
959*38fd1498Szrj        assign(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s,
960*38fd1498Szrj	       flag_type __f = regex_constants::ECMAScript)
961*38fd1498Szrj        {
962*38fd1498Szrj	  basic_regex __tmp(__s, __f);
963*38fd1498Szrj	  this->swap(__tmp);
964*38fd1498Szrj	  return *this;
965*38fd1498Szrj	}
966*38fd1498Szrj
967*38fd1498Szrj      /**
968*38fd1498Szrj       * @brief Assigns a new regular expression to a regex object.
969*38fd1498Szrj       *
970*38fd1498Szrj       * @param first The start of a range containing a valid regular
971*38fd1498Szrj       *              expression.
972*38fd1498Szrj       * @param last  The end of a range containing a valid regular
973*38fd1498Szrj       *              expression.
974*38fd1498Szrj       * @param flags Syntax option flags.
975*38fd1498Szrj       *
976*38fd1498Szrj       * @throws regex_error if p does not contain a valid regular expression
977*38fd1498Szrj       * pattern interpreted according to @p flags.  If regex_error is thrown,
978*38fd1498Szrj       * the object remains unchanged.
979*38fd1498Szrj       */
980*38fd1498Szrj      template<typename _InputIterator>
981*38fd1498Szrj        basic_regex&
982*38fd1498Szrj        assign(_InputIterator __first, _InputIterator __last,
983*38fd1498Szrj	       flag_type __flags = regex_constants::ECMAScript)
984*38fd1498Szrj        { return this->assign(string_type(__first, __last), __flags); }
985*38fd1498Szrj
986*38fd1498Szrj#ifdef _GLIBCXX_INCLUDE_AS_CXX11
987*38fd1498Szrj      /**
988*38fd1498Szrj       * @brief Assigns a new regular expression to a regex object.
989*38fd1498Szrj       *
990*38fd1498Szrj       * @param l     An initializer list representing a regular expression.
991*38fd1498Szrj       * @param flags Syntax option flags.
992*38fd1498Szrj       *
993*38fd1498Szrj       * @throws regex_error if @p l does not contain a valid regular
994*38fd1498Szrj       * expression pattern interpreted according to @p flags.  If regex_error
995*38fd1498Szrj       * is thrown, the object remains unchanged.
996*38fd1498Szrj       */
997*38fd1498Szrj      basic_regex&
998*38fd1498Szrj      assign(initializer_list<_Ch_type> __l,
999*38fd1498Szrj	     flag_type __f = regex_constants::ECMAScript)
1000*38fd1498Szrj      { return this->assign(__l.begin(), __l.end(), __f); }
1001*38fd1498Szrj#endif
1002*38fd1498Szrj
1003*38fd1498Szrj      // [7.8.4] const operations
1004*38fd1498Szrj      /**
1005*38fd1498Szrj       * @brief Gets the number of marked subexpressions within the regular
1006*38fd1498Szrj       * expression.
1007*38fd1498Szrj       */
1008*38fd1498Szrj      unsigned int
1009*38fd1498Szrj      mark_count() const
1010*38fd1498Szrj      { return _M_mark_count; }
1011*38fd1498Szrj
1012*38fd1498Szrj      /**
1013*38fd1498Szrj       * @brief Gets the flags used to construct the regular expression
1014*38fd1498Szrj       * or in the last call to assign().
1015*38fd1498Szrj       */
1016*38fd1498Szrj      flag_type
1017*38fd1498Szrj      flags() const
1018*38fd1498Szrj      { return _M_flags; }
1019*38fd1498Szrj
1020*38fd1498Szrj      // [7.8.5] locale
1021*38fd1498Szrj      /**
1022*38fd1498Szrj       * @brief Imbues the regular expression object with the given locale.
1023*38fd1498Szrj       *
1024*38fd1498Szrj       * @param loc A locale.
1025*38fd1498Szrj       */
1026*38fd1498Szrj      locale_type
1027*38fd1498Szrj      imbue(locale_type __loc)
1028*38fd1498Szrj      { return _M_traits.imbue(__loc); }
1029*38fd1498Szrj
1030*38fd1498Szrj      /**
1031*38fd1498Szrj       * @brief Gets the locale currently imbued in the regular expression
1032*38fd1498Szrj       *        object.
1033*38fd1498Szrj       */
1034*38fd1498Szrj      locale_type
1035*38fd1498Szrj      getloc() const
1036*38fd1498Szrj      { return _M_traits.getloc(); }
1037*38fd1498Szrj
1038*38fd1498Szrj      // [7.8.6] swap
1039*38fd1498Szrj      /**
1040*38fd1498Szrj       * @brief Swaps the contents of two regular expression objects.
1041*38fd1498Szrj       *
1042*38fd1498Szrj       * @param rhs Another regular expression object.
1043*38fd1498Szrj       */
1044*38fd1498Szrj      void
1045*38fd1498Szrj      swap(basic_regex& __rhs)
1046*38fd1498Szrj      {
1047*38fd1498Szrj	std::swap(_M_flags,      __rhs._M_flags);
1048*38fd1498Szrj	std::swap(_M_pattern,    __rhs._M_pattern);
1049*38fd1498Szrj	std::swap(_M_mark_count, __rhs._M_mark_count);
1050*38fd1498Szrj	std::swap(_M_traits,     __rhs._M_traits);
1051*38fd1498Szrj      }
1052*38fd1498Szrj
1053*38fd1498Szrj    private:
1054*38fd1498Szrj      /**
1055*38fd1498Szrj       * @brief Compiles a regular expression pattern into a NFA.
1056*38fd1498Szrj       * @todo Implement this function.
1057*38fd1498Szrj       */
1058*38fd1498Szrj      void _M_compile();
1059*38fd1498Szrj
1060*38fd1498Szrj    protected:
1061*38fd1498Szrj      flag_type    _M_flags;
1062*38fd1498Szrj      string_type  _M_pattern;
1063*38fd1498Szrj      unsigned int _M_mark_count;
1064*38fd1498Szrj      _Rx_traits   _M_traits;
1065*38fd1498Szrj    };
1066*38fd1498Szrj
1067*38fd1498Szrj  /** @brief Standard regular expressions. */
1068*38fd1498Szrj  typedef basic_regex<char>    regex;
1069*38fd1498Szrj#ifdef _GLIBCXX_USE_WCHAR_T
1070*38fd1498Szrj  /** @brief Standard wide-character regular expressions. */
1071*38fd1498Szrj  typedef basic_regex<wchar_t> wregex;
1072*38fd1498Szrj#endif
1073*38fd1498Szrj
1074*38fd1498Szrj
1075*38fd1498Szrj  // [7.8.6] basic_regex swap
1076*38fd1498Szrj  /**
1077*38fd1498Szrj   * @brief Swaps the contents of two regular expression objects.
1078*38fd1498Szrj   * @param lhs First regular expression.
1079*38fd1498Szrj   * @param rhs Second regular expression.
1080*38fd1498Szrj   */
1081*38fd1498Szrj  template<typename _Ch_type, typename _Rx_traits>
1082*38fd1498Szrj    inline void
1083*38fd1498Szrj    swap(basic_regex<_Ch_type, _Rx_traits>& __lhs,
1084*38fd1498Szrj	 basic_regex<_Ch_type, _Rx_traits>& __rhs)
1085*38fd1498Szrj    { __lhs.swap(__rhs); }
1086*38fd1498Szrj
1087*38fd1498Szrj
1088*38fd1498Szrj  // [7.9] Class template sub_match
1089*38fd1498Szrj  /**
1090*38fd1498Szrj   * A sequence of characters matched by a particular marked sub-expression.
1091*38fd1498Szrj   *
1092*38fd1498Szrj   * An object of this class is essentially a pair of iterators marking a
1093*38fd1498Szrj   * matched subexpression within a regular expression pattern match. Such
1094*38fd1498Szrj   * objects can be converted to and compared with std::basic_string objects
1095*38fd1498Szrj   * of a similar base character type as the pattern matched by the regular
1096*38fd1498Szrj   * expression.
1097*38fd1498Szrj   *
1098*38fd1498Szrj   * The iterators that make up the pair are the usual half-open interval
1099*38fd1498Szrj   * referencing the actual original pattern matched.
1100*38fd1498Szrj   */
1101*38fd1498Szrj  template<typename _BiIter>
1102*38fd1498Szrj    class sub_match : public std::pair<_BiIter, _BiIter>
1103*38fd1498Szrj    {
1104*38fd1498Szrj    public:
1105*38fd1498Szrj      typedef typename iterator_traits<_BiIter>::value_type      value_type;
1106*38fd1498Szrj      typedef typename iterator_traits<_BiIter>::difference_type
1107*38fd1498Szrj                                                            difference_type;
1108*38fd1498Szrj      typedef _BiIter                                              iterator;
1109*38fd1498Szrj
1110*38fd1498Szrj    public:
1111*38fd1498Szrj      bool matched;
1112*38fd1498Szrj
1113*38fd1498Szrj      /**
1114*38fd1498Szrj       * Gets the length of the matching sequence.
1115*38fd1498Szrj       */
1116*38fd1498Szrj      difference_type
1117*38fd1498Szrj      length() const
1118*38fd1498Szrj      { return this->matched ? std::distance(this->first, this->second) : 0; }
1119*38fd1498Szrj
1120*38fd1498Szrj      /**
1121*38fd1498Szrj       * @brief Gets the matching sequence as a string.
1122*38fd1498Szrj       *
1123*38fd1498Szrj       * @returns the matching sequence as a string.
1124*38fd1498Szrj       *
1125*38fd1498Szrj       * This is the implicit conversion operator.  It is identical to the
1126*38fd1498Szrj       * str() member function except that it will want to pop up in
1127*38fd1498Szrj       * unexpected places and cause a great deal of confusion and cursing
1128*38fd1498Szrj       * from the unwary.
1129*38fd1498Szrj       */
1130*38fd1498Szrj      operator basic_string<value_type>() const
1131*38fd1498Szrj      {
1132*38fd1498Szrj	return this->matched
1133*38fd1498Szrj	  ? std::basic_string<value_type>(this->first, this->second)
1134*38fd1498Szrj	  : std::basic_string<value_type>();
1135*38fd1498Szrj      }
1136*38fd1498Szrj
1137*38fd1498Szrj      /**
1138*38fd1498Szrj       * @brief Gets the matching sequence as a string.
1139*38fd1498Szrj       *
1140*38fd1498Szrj       * @returns the matching sequence as a string.
1141*38fd1498Szrj       */
1142*38fd1498Szrj      basic_string<value_type>
1143*38fd1498Szrj      str() const
1144*38fd1498Szrj      {
1145*38fd1498Szrj	return this->matched
1146*38fd1498Szrj	  ? std::basic_string<value_type>(this->first, this->second)
1147*38fd1498Szrj	  : std::basic_string<value_type>();
1148*38fd1498Szrj      }
1149*38fd1498Szrj
1150*38fd1498Szrj      /**
1151*38fd1498Szrj       * @brief Compares this and another matched sequence.
1152*38fd1498Szrj       *
1153*38fd1498Szrj       * @param s Another matched sequence to compare to this one.
1154*38fd1498Szrj       *
1155*38fd1498Szrj       * @retval <0 this matched sequence will collate before @p s.
1156*38fd1498Szrj       * @retval =0 this matched sequence is equivalent to @p s.
1157*38fd1498Szrj       * @retval <0 this matched sequence will collate after @p s.
1158*38fd1498Szrj       */
1159*38fd1498Szrj      int
1160*38fd1498Szrj      compare(const sub_match& __s) const
1161*38fd1498Szrj      { return this->str().compare(__s.str()); }
1162*38fd1498Szrj
1163*38fd1498Szrj      /**
1164*38fd1498Szrj       * @brief Compares this sub_match to a string.
1165*38fd1498Szrj       *
1166*38fd1498Szrj       * @param s A string to compare to this sub_match.
1167*38fd1498Szrj       *
1168*38fd1498Szrj       * @retval <0 this matched sequence will collate before @p s.
1169*38fd1498Szrj       * @retval =0 this matched sequence is equivalent to @p s.
1170*38fd1498Szrj       * @retval <0 this matched sequence will collate after @p s.
1171*38fd1498Szrj       */
1172*38fd1498Szrj      int
1173*38fd1498Szrj      compare(const basic_string<value_type>& __s) const
1174*38fd1498Szrj      { return this->str().compare(__s); }
1175*38fd1498Szrj
1176*38fd1498Szrj      /**
1177*38fd1498Szrj       * @brief Compares this sub_match to a C-style string.
1178*38fd1498Szrj       *
1179*38fd1498Szrj       * @param s A C-style string to compare to this sub_match.
1180*38fd1498Szrj       *
1181*38fd1498Szrj       * @retval <0 this matched sequence will collate before @p s.
1182*38fd1498Szrj       * @retval =0 this matched sequence is equivalent to @p s.
1183*38fd1498Szrj       * @retval <0 this matched sequence will collate after @p s.
1184*38fd1498Szrj       */
1185*38fd1498Szrj      int
1186*38fd1498Szrj      compare(const value_type* __s) const
1187*38fd1498Szrj      { return this->str().compare(__s); }
1188*38fd1498Szrj    };
1189*38fd1498Szrj
1190*38fd1498Szrj
1191*38fd1498Szrj  /** @brief Standard regex submatch over a C-style null-terminated string. */
1192*38fd1498Szrj  typedef sub_match<const char*>             csub_match;
1193*38fd1498Szrj  /** @brief Standard regex submatch over a standard string. */
1194*38fd1498Szrj  typedef sub_match<string::const_iterator>  ssub_match;
1195*38fd1498Szrj#ifdef _GLIBCXX_USE_WCHAR_T
1196*38fd1498Szrj  /** @brief Regex submatch over a C-style null-terminated wide string. */
1197*38fd1498Szrj  typedef sub_match<const wchar_t*>          wcsub_match;
1198*38fd1498Szrj  /** @brief Regex submatch over a standard wide string. */
1199*38fd1498Szrj  typedef sub_match<wstring::const_iterator> wssub_match;
1200*38fd1498Szrj#endif
1201*38fd1498Szrj
1202*38fd1498Szrj  // [7.9.2] sub_match non-member operators
1203*38fd1498Szrj
1204*38fd1498Szrj  /**
1205*38fd1498Szrj   * @brief Tests the equivalence of two regular expression submatches.
1206*38fd1498Szrj   * @param lhs First regular expression submatch.
1207*38fd1498Szrj   * @param rhs Second regular expression submatch.
1208*38fd1498Szrj   * @returns true if @a lhs  is equivalent to @a rhs, false otherwise.
1209*38fd1498Szrj   */
1210*38fd1498Szrj  template<typename _BiIter>
1211*38fd1498Szrj    inline bool
1212*38fd1498Szrj    operator==(const sub_match<_BiIter>& __lhs,
1213*38fd1498Szrj	       const sub_match<_BiIter>& __rhs)
1214*38fd1498Szrj    { return __lhs.compare(__rhs) == 0; }
1215*38fd1498Szrj
1216*38fd1498Szrj  /**
1217*38fd1498Szrj   * @brief Tests the inequivalence of two regular expression submatches.
1218*38fd1498Szrj   * @param lhs First regular expression submatch.
1219*38fd1498Szrj   * @param rhs Second regular expression submatch.
1220*38fd1498Szrj   * @returns true if @a lhs  is not equivalent to @a rhs, false otherwise.
1221*38fd1498Szrj   */
1222*38fd1498Szrj  template<typename _BiIter>
1223*38fd1498Szrj    inline bool
1224*38fd1498Szrj    operator!=(const sub_match<_BiIter>& __lhs,
1225*38fd1498Szrj	       const sub_match<_BiIter>& __rhs)
1226*38fd1498Szrj    { return __lhs.compare(__rhs) != 0; }
1227*38fd1498Szrj
1228*38fd1498Szrj  /**
1229*38fd1498Szrj   * @brief Tests the ordering of two regular expression submatches.
1230*38fd1498Szrj   * @param lhs First regular expression submatch.
1231*38fd1498Szrj   * @param rhs Second regular expression submatch.
1232*38fd1498Szrj   * @returns true if @a lhs precedes @a rhs, false otherwise.
1233*38fd1498Szrj   */
1234*38fd1498Szrj  template<typename _BiIter>
1235*38fd1498Szrj    inline bool
1236*38fd1498Szrj    operator<(const sub_match<_BiIter>& __lhs,
1237*38fd1498Szrj	      const sub_match<_BiIter>& __rhs)
1238*38fd1498Szrj    { return __lhs.compare(__rhs) < 0; }
1239*38fd1498Szrj
1240*38fd1498Szrj  /**
1241*38fd1498Szrj   * @brief Tests the ordering of two regular expression submatches.
1242*38fd1498Szrj   * @param lhs First regular expression submatch.
1243*38fd1498Szrj   * @param rhs Second regular expression submatch.
1244*38fd1498Szrj   * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1245*38fd1498Szrj   */
1246*38fd1498Szrj  template<typename _BiIter>
1247*38fd1498Szrj    inline bool
1248*38fd1498Szrj    operator<=(const sub_match<_BiIter>& __lhs,
1249*38fd1498Szrj	       const sub_match<_BiIter>& __rhs)
1250*38fd1498Szrj    { return __lhs.compare(__rhs) <= 0; }
1251*38fd1498Szrj
1252*38fd1498Szrj  /**
1253*38fd1498Szrj   * @brief Tests the ordering of two regular expression submatches.
1254*38fd1498Szrj   * @param lhs First regular expression submatch.
1255*38fd1498Szrj   * @param rhs Second regular expression submatch.
1256*38fd1498Szrj   * @returns true if @a lhs does not precede @a rhs, false otherwise.
1257*38fd1498Szrj   */
1258*38fd1498Szrj  template<typename _BiIter>
1259*38fd1498Szrj    inline bool
1260*38fd1498Szrj    operator>=(const sub_match<_BiIter>& __lhs,
1261*38fd1498Szrj	       const sub_match<_BiIter>& __rhs)
1262*38fd1498Szrj    { return __lhs.compare(__rhs) >= 0; }
1263*38fd1498Szrj
1264*38fd1498Szrj  /**
1265*38fd1498Szrj   * @brief Tests the ordering of two regular expression submatches.
1266*38fd1498Szrj   * @param lhs First regular expression submatch.
1267*38fd1498Szrj   * @param rhs Second regular expression submatch.
1268*38fd1498Szrj   * @returns true if @a lhs succeeds @a rhs, false otherwise.
1269*38fd1498Szrj   */
1270*38fd1498Szrj  template<typename _BiIter>
1271*38fd1498Szrj    inline bool
1272*38fd1498Szrj    operator>(const sub_match<_BiIter>& __lhs,
1273*38fd1498Szrj	      const sub_match<_BiIter>& __rhs)
1274*38fd1498Szrj    { return __lhs.compare(__rhs) > 0; }
1275*38fd1498Szrj
1276*38fd1498Szrj  /**
1277*38fd1498Szrj   * @brief Tests the equivalence of a string and a regular expression
1278*38fd1498Szrj   *        submatch.
1279*38fd1498Szrj   * @param lhs A string.
1280*38fd1498Szrj   * @param rhs A regular expression submatch.
1281*38fd1498Szrj   * @returns true if @a lhs  is equivalent to @a rhs, false otherwise.
1282*38fd1498Szrj   */
1283*38fd1498Szrj  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1284*38fd1498Szrj    inline bool
1285*38fd1498Szrj    operator==(const basic_string<
1286*38fd1498Szrj	       typename iterator_traits<_Bi_iter>::value_type,
1287*38fd1498Szrj	       _Ch_traits, _Ch_alloc>& __lhs,
1288*38fd1498Szrj	       const sub_match<_Bi_iter>& __rhs)
1289*38fd1498Szrj    { return __lhs == __rhs.str(); }
1290*38fd1498Szrj
1291*38fd1498Szrj  /**
1292*38fd1498Szrj   * @brief Tests the inequivalence of a string and a regular expression
1293*38fd1498Szrj   *        submatch.
1294*38fd1498Szrj   * @param lhs A string.
1295*38fd1498Szrj   * @param rhs A regular expression submatch.
1296*38fd1498Szrj   * @returns true if @a lhs  is not equivalent to @a rhs, false otherwise.
1297*38fd1498Szrj   */
1298*38fd1498Szrj  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1299*38fd1498Szrj    inline bool
1300*38fd1498Szrj    operator!=(const basic_string<
1301*38fd1498Szrj	       typename iterator_traits<_Bi_iter>::value_type,
1302*38fd1498Szrj	       _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1303*38fd1498Szrj    { return __lhs != __rhs.str(); }
1304*38fd1498Szrj
1305*38fd1498Szrj  /**
1306*38fd1498Szrj   * @brief Tests the ordering of a string and a regular expression submatch.
1307*38fd1498Szrj   * @param lhs A string.
1308*38fd1498Szrj   * @param rhs A regular expression submatch.
1309*38fd1498Szrj   * @returns true if @a lhs precedes @a rhs, false otherwise.
1310*38fd1498Szrj   */
1311*38fd1498Szrj  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1312*38fd1498Szrj    inline bool
1313*38fd1498Szrj    operator<(const basic_string<
1314*38fd1498Szrj	      typename iterator_traits<_Bi_iter>::value_type,
1315*38fd1498Szrj	      _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1316*38fd1498Szrj     { return __lhs < __rhs.str(); }
1317*38fd1498Szrj
1318*38fd1498Szrj  /**
1319*38fd1498Szrj   * @brief Tests the ordering of a string and a regular expression submatch.
1320*38fd1498Szrj   * @param lhs A string.
1321*38fd1498Szrj   * @param rhs A regular expression submatch.
1322*38fd1498Szrj   * @returns true if @a lhs succeeds @a rhs, false otherwise.
1323*38fd1498Szrj   */
1324*38fd1498Szrj  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1325*38fd1498Szrj    inline bool
1326*38fd1498Szrj    operator>(const basic_string<
1327*38fd1498Szrj	      typename iterator_traits<_Bi_iter>::value_type,
1328*38fd1498Szrj	      _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1329*38fd1498Szrj    { return __lhs > __rhs.str(); }
1330*38fd1498Szrj
1331*38fd1498Szrj  /**
1332*38fd1498Szrj   * @brief Tests the ordering of a string and a regular expression submatch.
1333*38fd1498Szrj   * @param lhs A string.
1334*38fd1498Szrj   * @param rhs A regular expression submatch.
1335*38fd1498Szrj   * @returns true if @a lhs does not precede @a rhs, false otherwise.
1336*38fd1498Szrj   */
1337*38fd1498Szrj  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1338*38fd1498Szrj    inline bool
1339*38fd1498Szrj    operator>=(const basic_string<
1340*38fd1498Szrj	       typename iterator_traits<_Bi_iter>::value_type,
1341*38fd1498Szrj	       _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1342*38fd1498Szrj    { return __lhs >= __rhs.str(); }
1343*38fd1498Szrj
1344*38fd1498Szrj  /**
1345*38fd1498Szrj   * @brief Tests the ordering of a string and a regular expression submatch.
1346*38fd1498Szrj   * @param lhs A string.
1347*38fd1498Szrj   * @param rhs A regular expression submatch.
1348*38fd1498Szrj   * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1349*38fd1498Szrj   */
1350*38fd1498Szrj  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1351*38fd1498Szrj    inline bool
1352*38fd1498Szrj    operator<=(const basic_string<
1353*38fd1498Szrj	       typename iterator_traits<_Bi_iter>::value_type,
1354*38fd1498Szrj	       _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1355*38fd1498Szrj    { return __lhs <= __rhs.str(); }
1356*38fd1498Szrj
1357*38fd1498Szrj  /**
1358*38fd1498Szrj   * @brief Tests the equivalence of a regular expression submatch and a
1359*38fd1498Szrj   *        string.
1360*38fd1498Szrj   * @param lhs A regular expression submatch.
1361*38fd1498Szrj   * @param rhs A string.
1362*38fd1498Szrj   * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1363*38fd1498Szrj   */
1364*38fd1498Szrj  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1365*38fd1498Szrj    inline bool
1366*38fd1498Szrj    operator==(const sub_match<_Bi_iter>& __lhs,
1367*38fd1498Szrj	       const basic_string<
1368*38fd1498Szrj	       typename iterator_traits<_Bi_iter>::value_type,
1369*38fd1498Szrj	       _Ch_traits, _Ch_alloc>& __rhs)
1370*38fd1498Szrj    { return __lhs.str() == __rhs; }
1371*38fd1498Szrj
1372*38fd1498Szrj  /**
1373*38fd1498Szrj   * @brief Tests the inequivalence of a regular expression submatch and a
1374*38fd1498Szrj   *        string.
1375*38fd1498Szrj   * @param lhs A regular expression submatch.
1376*38fd1498Szrj   * @param rhs A string.
1377*38fd1498Szrj   * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1378*38fd1498Szrj   */
1379*38fd1498Szrj  template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1380*38fd1498Szrj    inline bool
1381*38fd1498Szrj    operator!=(const sub_match<_Bi_iter>& __lhs,
1382*38fd1498Szrj	       const basic_string<
1383*38fd1498Szrj	       typename iterator_traits<_Bi_iter>::value_type,
1384*38fd1498Szrj	       _Ch_traits, _Ch_alloc>& __rhs)
1385*38fd1498Szrj    { return __lhs.str() != __rhs; }
1386*38fd1498Szrj
1387*38fd1498Szrj  /**
1388*38fd1498Szrj   * @brief Tests the ordering of a regular expression submatch and a string.
1389*38fd1498Szrj   * @param lhs A regular expression submatch.
1390*38fd1498Szrj   * @param rhs A string.
1391*38fd1498Szrj   * @returns true if @a lhs precedes @a rhs, false otherwise.
1392*38fd1498Szrj   */
1393*38fd1498Szrj  template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1394*38fd1498Szrj    inline bool
1395*38fd1498Szrj    operator<(const sub_match<_Bi_iter>& __lhs,
1396*38fd1498Szrj	      const basic_string<
1397*38fd1498Szrj	      typename iterator_traits<_Bi_iter>::value_type,
1398*38fd1498Szrj	      _Ch_traits, _Ch_alloc>& __rhs)
1399*38fd1498Szrj    { return __lhs.str() < __rhs; }
1400*38fd1498Szrj
1401*38fd1498Szrj  /**
1402*38fd1498Szrj   * @brief Tests the ordering of a regular expression submatch and a string.
1403*38fd1498Szrj   * @param lhs A regular expression submatch.
1404*38fd1498Szrj   * @param rhs A string.
1405*38fd1498Szrj   * @returns true if @a lhs succeeds @a rhs, false otherwise.
1406*38fd1498Szrj   */
1407*38fd1498Szrj  template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1408*38fd1498Szrj    inline bool
1409*38fd1498Szrj    operator>(const sub_match<_Bi_iter>& __lhs,
1410*38fd1498Szrj	      const basic_string<
1411*38fd1498Szrj	      typename iterator_traits<_Bi_iter>::value_type,
1412*38fd1498Szrj	      _Ch_traits, _Ch_alloc>& __rhs)
1413*38fd1498Szrj    { return __lhs.str() > __rhs; }
1414*38fd1498Szrj
1415*38fd1498Szrj  /**
1416*38fd1498Szrj   * @brief Tests the ordering of a regular expression submatch and a string.
1417*38fd1498Szrj   * @param lhs A regular expression submatch.
1418*38fd1498Szrj   * @param rhs A string.
1419*38fd1498Szrj   * @returns true if @a lhs does not precede @a rhs, false otherwise.
1420*38fd1498Szrj   */
1421*38fd1498Szrj  template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1422*38fd1498Szrj    inline bool
1423*38fd1498Szrj    operator>=(const sub_match<_Bi_iter>& __lhs,
1424*38fd1498Szrj	       const basic_string<
1425*38fd1498Szrj	       typename iterator_traits<_Bi_iter>::value_type,
1426*38fd1498Szrj	       _Ch_traits, _Ch_alloc>& __rhs)
1427*38fd1498Szrj    { return __lhs.str() >= __rhs; }
1428*38fd1498Szrj
1429*38fd1498Szrj  /**
1430*38fd1498Szrj   * @brief Tests the ordering of a regular expression submatch and a string.
1431*38fd1498Szrj   * @param lhs A regular expression submatch.
1432*38fd1498Szrj   * @param rhs A string.
1433*38fd1498Szrj   * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1434*38fd1498Szrj   */
1435*38fd1498Szrj  template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1436*38fd1498Szrj    inline bool
1437*38fd1498Szrj    operator<=(const sub_match<_Bi_iter>& __lhs,
1438*38fd1498Szrj	       const basic_string<
1439*38fd1498Szrj	       typename iterator_traits<_Bi_iter>::value_type,
1440*38fd1498Szrj	       _Ch_traits, _Ch_alloc>& __rhs)
1441*38fd1498Szrj    { return __lhs.str() <= __rhs; }
1442*38fd1498Szrj
1443*38fd1498Szrj  /**
1444*38fd1498Szrj   * @brief Tests the equivalence of a C string and a regular expression
1445*38fd1498Szrj   *        submatch.
1446*38fd1498Szrj   * @param lhs A C string.
1447*38fd1498Szrj   * @param rhs A regular expression submatch.
1448*38fd1498Szrj   * @returns true if @a lhs  is equivalent to @a rhs, false otherwise.
1449*38fd1498Szrj   */
1450*38fd1498Szrj  template<typename _Bi_iter>
1451*38fd1498Szrj    inline bool
1452*38fd1498Szrj    operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1453*38fd1498Szrj	       const sub_match<_Bi_iter>& __rhs)
1454*38fd1498Szrj    { return __lhs == __rhs.str(); }
1455*38fd1498Szrj
1456*38fd1498Szrj  /**
1457*38fd1498Szrj   * @brief Tests the inequivalence of an iterator value and a regular
1458*38fd1498Szrj   *        expression submatch.
1459*38fd1498Szrj   * @param lhs A regular expression submatch.
1460*38fd1498Szrj   * @param rhs A string.
1461*38fd1498Szrj   * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1462*38fd1498Szrj   */
1463*38fd1498Szrj  template<typename _Bi_iter>
1464*38fd1498Szrj    inline bool
1465*38fd1498Szrj    operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1466*38fd1498Szrj	       const sub_match<_Bi_iter>& __rhs)
1467*38fd1498Szrj    { return __lhs != __rhs.str(); }
1468*38fd1498Szrj
1469*38fd1498Szrj  /**
1470*38fd1498Szrj   * @brief Tests the ordering of a string and a regular expression submatch.
1471*38fd1498Szrj   * @param lhs A string.
1472*38fd1498Szrj   * @param rhs A regular expression submatch.
1473*38fd1498Szrj   * @returns true if @a lhs precedes @a rhs, false otherwise.
1474*38fd1498Szrj   */
1475*38fd1498Szrj  template<typename _Bi_iter>
1476*38fd1498Szrj    inline bool
1477*38fd1498Szrj    operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1478*38fd1498Szrj	      const sub_match<_Bi_iter>& __rhs)
1479*38fd1498Szrj    { return __lhs < __rhs.str(); }
1480*38fd1498Szrj
1481*38fd1498Szrj  /**
1482*38fd1498Szrj   * @brief Tests the ordering of a string and a regular expression submatch.
1483*38fd1498Szrj   * @param lhs A string.
1484*38fd1498Szrj   * @param rhs A regular expression submatch.
1485*38fd1498Szrj   * @returns true if @a lhs succeeds @a rhs, false otherwise.
1486*38fd1498Szrj   */
1487*38fd1498Szrj  template<typename _Bi_iter>
1488*38fd1498Szrj    inline bool
1489*38fd1498Szrj    operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1490*38fd1498Szrj	      const sub_match<_Bi_iter>& __rhs)
1491*38fd1498Szrj    { return __lhs > __rhs.str(); }
1492*38fd1498Szrj
1493*38fd1498Szrj  /**
1494*38fd1498Szrj   * @brief Tests the ordering of a string and a regular expression submatch.
1495*38fd1498Szrj   * @param lhs A string.
1496*38fd1498Szrj   * @param rhs A regular expression submatch.
1497*38fd1498Szrj   * @returns true if @a lhs does not precede @a rhs, false otherwise.
1498*38fd1498Szrj   */
1499*38fd1498Szrj  template<typename _Bi_iter>
1500*38fd1498Szrj    inline bool
1501*38fd1498Szrj    operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1502*38fd1498Szrj	       const sub_match<_Bi_iter>& __rhs)
1503*38fd1498Szrj    { return __lhs >= __rhs.str(); }
1504*38fd1498Szrj
1505*38fd1498Szrj  /**
1506*38fd1498Szrj   * @brief Tests the ordering of a string and a regular expression submatch.
1507*38fd1498Szrj   * @param lhs A string.
1508*38fd1498Szrj   * @param rhs A regular expression submatch.
1509*38fd1498Szrj   * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1510*38fd1498Szrj   */
1511*38fd1498Szrj  template<typename _Bi_iter>
1512*38fd1498Szrj    inline bool
1513*38fd1498Szrj    operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1514*38fd1498Szrj	       const sub_match<_Bi_iter>& __rhs)
1515*38fd1498Szrj    { return __lhs <= __rhs.str(); }
1516*38fd1498Szrj
1517*38fd1498Szrj  /**
1518*38fd1498Szrj   * @brief Tests the equivalence of a regular expression submatch and a
1519*38fd1498Szrj   *        string.
1520*38fd1498Szrj   * @param lhs A regular expression submatch.
1521*38fd1498Szrj   * @param rhs A pointer to a string?
1522*38fd1498Szrj   * @returns true if @a lhs  is equivalent to @a rhs, false otherwise.
1523*38fd1498Szrj   */
1524*38fd1498Szrj  template<typename _Bi_iter>
1525*38fd1498Szrj    inline bool
1526*38fd1498Szrj    operator==(const sub_match<_Bi_iter>& __lhs,
1527*38fd1498Szrj	       typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1528*38fd1498Szrj    { return __lhs.str() == __rhs; }
1529*38fd1498Szrj
1530*38fd1498Szrj  /**
1531*38fd1498Szrj   * @brief Tests the inequivalence of a regular expression submatch and a
1532*38fd1498Szrj   *        string.
1533*38fd1498Szrj   * @param lhs A regular expression submatch.
1534*38fd1498Szrj   * @param rhs A pointer to a string.
1535*38fd1498Szrj   * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1536*38fd1498Szrj   */
1537*38fd1498Szrj  template<typename _Bi_iter>
1538*38fd1498Szrj    inline bool
1539*38fd1498Szrj    operator!=(const sub_match<_Bi_iter>& __lhs,
1540*38fd1498Szrj	       typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1541*38fd1498Szrj    { return __lhs.str() != __rhs; }
1542*38fd1498Szrj
1543*38fd1498Szrj  /**
1544*38fd1498Szrj   * @brief Tests the ordering of a regular expression submatch and a string.
1545*38fd1498Szrj   * @param lhs A regular expression submatch.
1546*38fd1498Szrj   * @param rhs A string.
1547*38fd1498Szrj   * @returns true if @a lhs precedes @a rhs, false otherwise.
1548*38fd1498Szrj   */
1549*38fd1498Szrj  template<typename _Bi_iter>
1550*38fd1498Szrj    inline bool
1551*38fd1498Szrj    operator<(const sub_match<_Bi_iter>& __lhs,
1552*38fd1498Szrj	      typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1553*38fd1498Szrj    { return __lhs.str() < __rhs; }
1554*38fd1498Szrj
1555*38fd1498Szrj  /**
1556*38fd1498Szrj   * @brief Tests the ordering of a regular expression submatch and a string.
1557*38fd1498Szrj   * @param lhs A regular expression submatch.
1558*38fd1498Szrj   * @param rhs A string.
1559*38fd1498Szrj   * @returns true if @a lhs succeeds @a rhs, false otherwise.
1560*38fd1498Szrj   */
1561*38fd1498Szrj  template<typename _Bi_iter>
1562*38fd1498Szrj    inline bool
1563*38fd1498Szrj    operator>(const sub_match<_Bi_iter>& __lhs,
1564*38fd1498Szrj	      typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1565*38fd1498Szrj    { return __lhs.str() > __rhs; }
1566*38fd1498Szrj
1567*38fd1498Szrj  /**
1568*38fd1498Szrj   * @brief Tests the ordering of a regular expression submatch and a string.
1569*38fd1498Szrj   * @param lhs A regular expression submatch.
1570*38fd1498Szrj   * @param rhs A string.
1571*38fd1498Szrj   * @returns true if @a lhs does not precede @a rhs, false otherwise.
1572*38fd1498Szrj   */
1573*38fd1498Szrj  template<typename _Bi_iter>
1574*38fd1498Szrj    inline bool
1575*38fd1498Szrj    operator>=(const sub_match<_Bi_iter>& __lhs,
1576*38fd1498Szrj	       typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1577*38fd1498Szrj    { return __lhs.str() >= __rhs; }
1578*38fd1498Szrj
1579*38fd1498Szrj  /**
1580*38fd1498Szrj   * @brief Tests the ordering of a regular expression submatch and a string.
1581*38fd1498Szrj   * @param lhs A regular expression submatch.
1582*38fd1498Szrj   * @param rhs A string.
1583*38fd1498Szrj   * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1584*38fd1498Szrj   */
1585*38fd1498Szrj  template<typename _Bi_iter>
1586*38fd1498Szrj    inline bool
1587*38fd1498Szrj    operator<=(const sub_match<_Bi_iter>& __lhs,
1588*38fd1498Szrj	       typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1589*38fd1498Szrj    { return __lhs.str() <= __rhs; }
1590*38fd1498Szrj
1591*38fd1498Szrj  /**
1592*38fd1498Szrj   * @brief Tests the equivalence of a string and a regular expression
1593*38fd1498Szrj   *        submatch.
1594*38fd1498Szrj   * @param lhs A string.
1595*38fd1498Szrj   * @param rhs A regular expression submatch.
1596*38fd1498Szrj   * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1597*38fd1498Szrj   */
1598*38fd1498Szrj  template<typename _Bi_iter>
1599*38fd1498Szrj    inline bool
1600*38fd1498Szrj    operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1601*38fd1498Szrj	       const sub_match<_Bi_iter>& __rhs)
1602*38fd1498Szrj    { return __lhs == __rhs.str(); }
1603*38fd1498Szrj
1604*38fd1498Szrj  /**
1605*38fd1498Szrj   * @brief Tests the inequivalence of a string and a regular expression
1606*38fd1498Szrj   *        submatch.
1607*38fd1498Szrj   * @param lhs A string.
1608*38fd1498Szrj   * @param rhs A regular expression submatch.
1609*38fd1498Szrj   * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1610*38fd1498Szrj   */
1611*38fd1498Szrj  template<typename _Bi_iter>
1612*38fd1498Szrj    inline bool
1613*38fd1498Szrj    operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1614*38fd1498Szrj	       const sub_match<_Bi_iter>& __rhs)
1615*38fd1498Szrj    { return __lhs != __rhs.str(); }
1616*38fd1498Szrj
1617*38fd1498Szrj  /**
1618*38fd1498Szrj   * @brief Tests the ordering of a string and a regular expression submatch.
1619*38fd1498Szrj   * @param lhs A string.
1620*38fd1498Szrj   * @param rhs A regular expression submatch.
1621*38fd1498Szrj   * @returns true if @a lhs precedes @a rhs, false otherwise.
1622*38fd1498Szrj   */
1623*38fd1498Szrj  template<typename _Bi_iter>
1624*38fd1498Szrj    inline bool
1625*38fd1498Szrj    operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1626*38fd1498Szrj	      const sub_match<_Bi_iter>& __rhs)
1627*38fd1498Szrj    { return __lhs < __rhs.str(); }
1628*38fd1498Szrj
1629*38fd1498Szrj  /**
1630*38fd1498Szrj   * @brief Tests the ordering of a string and a regular expression submatch.
1631*38fd1498Szrj   * @param lhs A string.
1632*38fd1498Szrj   * @param rhs A regular expression submatch.
1633*38fd1498Szrj   * @returns true if @a lhs succeeds @a rhs, false otherwise.
1634*38fd1498Szrj   */
1635*38fd1498Szrj  template<typename _Bi_iter>
1636*38fd1498Szrj    inline bool
1637*38fd1498Szrj    operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1638*38fd1498Szrj	      const sub_match<_Bi_iter>& __rhs)
1639*38fd1498Szrj    { return __lhs > __rhs.str(); }
1640*38fd1498Szrj
1641*38fd1498Szrj  /**
1642*38fd1498Szrj   * @brief Tests the ordering of a string and a regular expression submatch.
1643*38fd1498Szrj   * @param lhs A string.
1644*38fd1498Szrj   * @param rhs A regular expression submatch.
1645*38fd1498Szrj   * @returns true if @a lhs does not precede @a rhs, false otherwise.
1646*38fd1498Szrj   */
1647*38fd1498Szrj  template<typename _Bi_iter>
1648*38fd1498Szrj    inline bool
1649*38fd1498Szrj    operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1650*38fd1498Szrj	       const sub_match<_Bi_iter>& __rhs)
1651*38fd1498Szrj    { return __lhs >= __rhs.str(); }
1652*38fd1498Szrj
1653*38fd1498Szrj  /**
1654*38fd1498Szrj   * @brief Tests the ordering of a string and a regular expression submatch.
1655*38fd1498Szrj   * @param lhs A string.
1656*38fd1498Szrj   * @param rhs A regular expression submatch.
1657*38fd1498Szrj   * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1658*38fd1498Szrj   */
1659*38fd1498Szrj  template<typename _Bi_iter>
1660*38fd1498Szrj    inline bool
1661*38fd1498Szrj    operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1662*38fd1498Szrj	       const sub_match<_Bi_iter>& __rhs)
1663*38fd1498Szrj    { return __lhs <= __rhs.str(); }
1664*38fd1498Szrj
1665*38fd1498Szrj  /**
1666*38fd1498Szrj   * @brief Tests the equivalence of a regular expression submatch and a
1667*38fd1498Szrj   *        string.
1668*38fd1498Szrj   * @param lhs A regular expression submatch.
1669*38fd1498Szrj   * @param rhs A const string reference.
1670*38fd1498Szrj   * @returns true if @a lhs  is equivalent to @a rhs, false otherwise.
1671*38fd1498Szrj   */
1672*38fd1498Szrj  template<typename _Bi_iter>
1673*38fd1498Szrj    inline bool
1674*38fd1498Szrj    operator==(const sub_match<_Bi_iter>& __lhs,
1675*38fd1498Szrj	       typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1676*38fd1498Szrj    { return __lhs.str() == __rhs; }
1677*38fd1498Szrj
1678*38fd1498Szrj  /**
1679*38fd1498Szrj   * @brief Tests the inequivalence of a regular expression submatch and a
1680*38fd1498Szrj   *        string.
1681*38fd1498Szrj   * @param lhs A regular expression submatch.
1682*38fd1498Szrj   * @param rhs A const string reference.
1683*38fd1498Szrj   * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1684*38fd1498Szrj   */
1685*38fd1498Szrj  template<typename _Bi_iter>
1686*38fd1498Szrj    inline bool
1687*38fd1498Szrj    operator!=(const sub_match<_Bi_iter>& __lhs,
1688*38fd1498Szrj	       typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1689*38fd1498Szrj    { return __lhs.str() != __rhs; }
1690*38fd1498Szrj
1691*38fd1498Szrj  /**
1692*38fd1498Szrj   * @brief Tests the ordering of a regular expression submatch and a string.
1693*38fd1498Szrj   * @param lhs A regular expression submatch.
1694*38fd1498Szrj   * @param rhs A const string reference.
1695*38fd1498Szrj   * @returns true if @a lhs precedes @a rhs, false otherwise.
1696*38fd1498Szrj   */
1697*38fd1498Szrj  template<typename _Bi_iter>
1698*38fd1498Szrj    inline bool
1699*38fd1498Szrj    operator<(const sub_match<_Bi_iter>& __lhs,
1700*38fd1498Szrj	      typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1701*38fd1498Szrj    { return __lhs.str() < __rhs; }
1702*38fd1498Szrj
1703*38fd1498Szrj  /**
1704*38fd1498Szrj   * @brief Tests the ordering of a regular expression submatch and a string.
1705*38fd1498Szrj   * @param lhs A regular expression submatch.
1706*38fd1498Szrj   * @param rhs A const string reference.
1707*38fd1498Szrj   * @returns true if @a lhs succeeds @a rhs, false otherwise.
1708*38fd1498Szrj   */
1709*38fd1498Szrj  template<typename _Bi_iter>
1710*38fd1498Szrj    inline bool
1711*38fd1498Szrj    operator>(const sub_match<_Bi_iter>& __lhs,
1712*38fd1498Szrj	      typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1713*38fd1498Szrj    { return __lhs.str() > __rhs; }
1714*38fd1498Szrj
1715*38fd1498Szrj  /**
1716*38fd1498Szrj   * @brief Tests the ordering of a regular expression submatch and a string.
1717*38fd1498Szrj   * @param lhs A regular expression submatch.
1718*38fd1498Szrj   * @param rhs A const string reference.
1719*38fd1498Szrj   * @returns true if @a lhs does not precede @a rhs, false otherwise.
1720*38fd1498Szrj   */
1721*38fd1498Szrj  template<typename _Bi_iter>
1722*38fd1498Szrj    inline bool
1723*38fd1498Szrj    operator>=(const sub_match<_Bi_iter>& __lhs,
1724*38fd1498Szrj	       typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1725*38fd1498Szrj    { return __lhs.str() >= __rhs; }
1726*38fd1498Szrj
1727*38fd1498Szrj  /**
1728*38fd1498Szrj   * @brief Tests the ordering of a regular expression submatch and a string.
1729*38fd1498Szrj   * @param lhs A regular expression submatch.
1730*38fd1498Szrj   * @param rhs A const string reference.
1731*38fd1498Szrj   * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1732*38fd1498Szrj   */
1733*38fd1498Szrj  template<typename _Bi_iter>
1734*38fd1498Szrj    inline bool
1735*38fd1498Szrj    operator<=(const sub_match<_Bi_iter>& __lhs,
1736*38fd1498Szrj	       typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1737*38fd1498Szrj    { return __lhs.str() <= __rhs; }
1738*38fd1498Szrj
1739*38fd1498Szrj  /**
1740*38fd1498Szrj   * @brief Inserts a matched string into an output stream.
1741*38fd1498Szrj   *
1742*38fd1498Szrj   * @param os The output stream.
1743*38fd1498Szrj   * @param m  A submatch string.
1744*38fd1498Szrj   *
1745*38fd1498Szrj   * @returns the output stream with the submatch string inserted.
1746*38fd1498Szrj   */
1747*38fd1498Szrj  template<typename _Ch_type, typename _Ch_traits, typename _Bi_iter>
1748*38fd1498Szrj    inline
1749*38fd1498Szrj    basic_ostream<_Ch_type, _Ch_traits>&
1750*38fd1498Szrj    operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os,
1751*38fd1498Szrj	       const sub_match<_Bi_iter>& __m)
1752*38fd1498Szrj    { return __os << __m.str(); }
1753*38fd1498Szrj
1754*38fd1498Szrj  // [7.10] Class template match_results
1755*38fd1498Szrj  /**
1756*38fd1498Szrj   * @brief The results of a match or search operation.
1757*38fd1498Szrj   *
1758*38fd1498Szrj   * A collection of character sequences representing the result of a regular
1759*38fd1498Szrj   * expression match.  Storage for the collection is allocated and freed as
1760*38fd1498Szrj   * necessary by the member functions of class template match_results.
1761*38fd1498Szrj   *
1762*38fd1498Szrj   * This class satisfies the Sequence requirements, with the exception that
1763*38fd1498Szrj   * only the operations defined for a const-qualified Sequence are supported.
1764*38fd1498Szrj   *
1765*38fd1498Szrj   * The sub_match object stored at index 0 represents sub-expression 0, i.e.
1766*38fd1498Szrj   * the whole match. In this case the sub_match member matched is always true.
1767*38fd1498Szrj   * The sub_match object stored at index n denotes what matched the marked
1768*38fd1498Szrj   * sub-expression n within the matched expression. If the sub-expression n
1769*38fd1498Szrj   * participated in a regular expression match then the sub_match member
1770*38fd1498Szrj   * matched evaluates to true, and members first and second denote the range
1771*38fd1498Szrj   * of characters [first, second) which formed that match. Otherwise matched
1772*38fd1498Szrj   * is false, and members first and second point to the end of the sequence
1773*38fd1498Szrj   * that was searched.
1774*38fd1498Szrj   *
1775*38fd1498Szrj   * @nosubgrouping
1776*38fd1498Szrj   */
1777*38fd1498Szrj  template<typename _Bi_iter,
1778*38fd1498Szrj	   typename _Allocator = allocator<sub_match<_Bi_iter> > >
1779*38fd1498Szrj    class match_results
1780*38fd1498Szrj    : private std::vector<std::tr1::sub_match<_Bi_iter>, _Allocator>
1781*38fd1498Szrj    {
1782*38fd1498Szrj    private:
1783*38fd1498Szrj      typedef std::vector<std::tr1::sub_match<_Bi_iter>, _Allocator>
1784*38fd1498Szrj                                                              _Base_type;
1785*38fd1498Szrj
1786*38fd1498Szrj    public:
1787*38fd1498Szrj      /**
1788*38fd1498Szrj       * @name 10.? Public Types
1789*38fd1498Szrj       */
1790*38fd1498Szrj      //@{
1791*38fd1498Szrj      typedef sub_match<_Bi_iter>                             value_type;
1792*38fd1498Szrj      typedef typename _Allocator::const_reference            const_reference;
1793*38fd1498Szrj      typedef const_reference                                 reference;
1794*38fd1498Szrj      typedef typename _Base_type::const_iterator             const_iterator;
1795*38fd1498Szrj      typedef const_iterator                                  iterator;
1796*38fd1498Szrj      typedef typename iterator_traits<_Bi_iter>::difference_type
1797*38fd1498Szrj                                                              difference_type;
1798*38fd1498Szrj      typedef typename _Allocator::size_type                  size_type;
1799*38fd1498Szrj      typedef _Allocator                                      allocator_type;
1800*38fd1498Szrj      typedef typename iterator_traits<_Bi_iter>::value_type  char_type;
1801*38fd1498Szrj      typedef basic_string<char_type>                         string_type;
1802*38fd1498Szrj      //@}
1803*38fd1498Szrj
1804*38fd1498Szrj    public:
1805*38fd1498Szrj      /**
1806*38fd1498Szrj       * @name 10.1 Construction, Copying, and Destruction
1807*38fd1498Szrj       */
1808*38fd1498Szrj      //@{
1809*38fd1498Szrj
1810*38fd1498Szrj      /**
1811*38fd1498Szrj       * @brief Constructs a default %match_results container.
1812*38fd1498Szrj       * @post size() returns 0 and str() returns an empty string.
1813*38fd1498Szrj       */
1814*38fd1498Szrj      explicit
1815*38fd1498Szrj      match_results(const _Allocator& __a = _Allocator())
1816*38fd1498Szrj      : _Base_type(__a), _M_matched(false)
1817*38fd1498Szrj      { }
1818*38fd1498Szrj
1819*38fd1498Szrj      /**
1820*38fd1498Szrj       * @brief Copy constructs a %match_results.
1821*38fd1498Szrj       */
1822*38fd1498Szrj      match_results(const match_results& __rhs)
1823*38fd1498Szrj      : _Base_type(__rhs), _M_matched(__rhs._M_matched),
1824*38fd1498Szrj	_M_prefix(__rhs._M_prefix), _M_suffix(__rhs._M_suffix)
1825*38fd1498Szrj      { }
1826*38fd1498Szrj
1827*38fd1498Szrj      /**
1828*38fd1498Szrj       * @brief Assigns rhs to *this.
1829*38fd1498Szrj       */
1830*38fd1498Szrj      match_results&
1831*38fd1498Szrj      operator=(const match_results& __rhs)
1832*38fd1498Szrj      {
1833*38fd1498Szrj	match_results __tmp(__rhs);
1834*38fd1498Szrj	this->swap(__tmp);
1835*38fd1498Szrj	return *this;
1836*38fd1498Szrj      }
1837*38fd1498Szrj
1838*38fd1498Szrj      /**
1839*38fd1498Szrj       * @brief Destroys a %match_results object.
1840*38fd1498Szrj       */
1841*38fd1498Szrj      ~match_results()
1842*38fd1498Szrj      { }
1843*38fd1498Szrj
1844*38fd1498Szrj      //@}
1845*38fd1498Szrj
1846*38fd1498Szrj      /**
1847*38fd1498Szrj       * @name 10.2 Size
1848*38fd1498Szrj       */
1849*38fd1498Szrj      //@{
1850*38fd1498Szrj
1851*38fd1498Szrj      /**
1852*38fd1498Szrj       * @brief Gets the number of matches and submatches.
1853*38fd1498Szrj       *
1854*38fd1498Szrj       * The number of matches for a given regular expression will be either 0
1855*38fd1498Szrj       * if there was no match or mark_count() + 1 if a match was successful.
1856*38fd1498Szrj       * Some matches may be empty.
1857*38fd1498Szrj       *
1858*38fd1498Szrj       * @returns the number of matches found.
1859*38fd1498Szrj       */
1860*38fd1498Szrj      size_type
1861*38fd1498Szrj      size() const
1862*38fd1498Szrj      { return _M_matched ? _Base_type::size() + 1 : 0; }
1863*38fd1498Szrj
1864*38fd1498Szrj      //size_type
1865*38fd1498Szrj      //max_size() const;
1866*38fd1498Szrj      using _Base_type::max_size;
1867*38fd1498Szrj
1868*38fd1498Szrj      /**
1869*38fd1498Szrj       * @brief Indicates if the %match_results contains no results.
1870*38fd1498Szrj       * @retval true The %match_results object is empty.
1871*38fd1498Szrj       * @retval false The %match_results object is not empty.
1872*38fd1498Szrj       */
1873*38fd1498Szrj      bool
1874*38fd1498Szrj      empty() const
1875*38fd1498Szrj      { return size() == 0; }
1876*38fd1498Szrj
1877*38fd1498Szrj      //@}
1878*38fd1498Szrj
1879*38fd1498Szrj      /**
1880*38fd1498Szrj       * @name 10.3 Element Access
1881*38fd1498Szrj       */
1882*38fd1498Szrj      //@{
1883*38fd1498Szrj
1884*38fd1498Szrj      /**
1885*38fd1498Szrj       * @brief Gets the length of the indicated submatch.
1886*38fd1498Szrj       * @param sub indicates the submatch.
1887*38fd1498Szrj       *
1888*38fd1498Szrj       * This function returns the length of the indicated submatch, or the
1889*38fd1498Szrj       * length of the entire match if @p sub is zero (the default).
1890*38fd1498Szrj       */
1891*38fd1498Szrj      difference_type
1892*38fd1498Szrj      length(size_type __sub = 0) const
1893*38fd1498Szrj      { return _M_matched ? this->str(__sub).length() : 0; }
1894*38fd1498Szrj
1895*38fd1498Szrj      /**
1896*38fd1498Szrj       * @brief Gets the offset of the beginning of the indicated submatch.
1897*38fd1498Szrj       * @param sub indicates the submatch.
1898*38fd1498Szrj       *
1899*38fd1498Szrj       * This function returns the offset from the beginning of the target
1900*38fd1498Szrj       * sequence to the beginning of the submatch, unless the value of @p sub
1901*38fd1498Szrj       * is zero (the default), in which case this function returns the offset
1902*38fd1498Szrj       * from the beginning of the target sequence to the beginning of the
1903*38fd1498Szrj       * match.
1904*38fd1498Szrj       */
1905*38fd1498Szrj      difference_type
1906*38fd1498Szrj      position(size_type __sub = 0) const
1907*38fd1498Szrj      {
1908*38fd1498Szrj	return _M_matched ? std::distance(this->prefix().first,
1909*38fd1498Szrj					  (*this)[__sub].first) : 0;
1910*38fd1498Szrj      }
1911*38fd1498Szrj
1912*38fd1498Szrj      /**
1913*38fd1498Szrj       * @brief Gets the match or submatch converted to a string type.
1914*38fd1498Szrj       * @param sub indicates the submatch.
1915*38fd1498Szrj       *
1916*38fd1498Szrj       * This function gets the submatch (or match, if @p sub is zero) extracted
1917*38fd1498Szrj       * from the target range and converted to the associated string type.
1918*38fd1498Szrj       */
1919*38fd1498Szrj      string_type
1920*38fd1498Szrj      str(size_type __sub = 0) const
1921*38fd1498Szrj      { return _M_matched ? (*this)[__sub].str() : string_type(); }
1922*38fd1498Szrj
1923*38fd1498Szrj      /**
1924*38fd1498Szrj       * @brief Gets a %sub_match reference for the match or submatch.
1925*38fd1498Szrj       * @param sub indicates the submatch.
1926*38fd1498Szrj       *
1927*38fd1498Szrj       * This function gets a reference to the indicated submatch, or the entire
1928*38fd1498Szrj       * match if @p sub is zero.
1929*38fd1498Szrj       *
1930*38fd1498Szrj       * If @p sub >= size() then this function returns a %sub_match with a
1931*38fd1498Szrj       * special value indicating no submatch.
1932*38fd1498Szrj       */
1933*38fd1498Szrj      const_reference
1934*38fd1498Szrj      operator[](size_type __sub) const
1935*38fd1498Szrj      { return _Base_type::operator[](__sub); }
1936*38fd1498Szrj
1937*38fd1498Szrj      /**
1938*38fd1498Szrj       * @brief Gets a %sub_match representing the match prefix.
1939*38fd1498Szrj       *
1940*38fd1498Szrj       * This function gets a reference to a %sub_match object representing the
1941*38fd1498Szrj       * part of the target range between the start of the target range and the
1942*38fd1498Szrj       * start of the match.
1943*38fd1498Szrj       */
1944*38fd1498Szrj      const_reference
1945*38fd1498Szrj      prefix() const
1946*38fd1498Szrj      { return _M_prefix; }
1947*38fd1498Szrj
1948*38fd1498Szrj      /**
1949*38fd1498Szrj       * @brief Gets a %sub_match representing the match suffix.
1950*38fd1498Szrj       *
1951*38fd1498Szrj       * This function gets a reference to a %sub_match object representing the
1952*38fd1498Szrj       * part of the target range between the end of the match and the end of
1953*38fd1498Szrj       * the target range.
1954*38fd1498Szrj       */
1955*38fd1498Szrj      const_reference
1956*38fd1498Szrj      suffix() const
1957*38fd1498Szrj      { return _M_suffix; }
1958*38fd1498Szrj
1959*38fd1498Szrj      /**
1960*38fd1498Szrj       * @brief Gets an iterator to the start of the %sub_match collection.
1961*38fd1498Szrj       */
1962*38fd1498Szrj      const_iterator
1963*38fd1498Szrj      begin() const
1964*38fd1498Szrj      { return _Base_type::begin(); }
1965*38fd1498Szrj
1966*38fd1498Szrj#ifdef _GLIBCXX_INCLUDE_AS_CXX11
1967*38fd1498Szrj      /**
1968*38fd1498Szrj       * @brief Gets an iterator to the start of the %sub_match collection.
1969*38fd1498Szrj       */
1970*38fd1498Szrj      const_iterator
1971*38fd1498Szrj      cbegin() const
1972*38fd1498Szrj      { return _Base_type::begin(); }
1973*38fd1498Szrj#endif
1974*38fd1498Szrj
1975*38fd1498Szrj      /**
1976*38fd1498Szrj       * @brief Gets an iterator to one-past-the-end of the collection.
1977*38fd1498Szrj       */
1978*38fd1498Szrj      const_iterator
1979*38fd1498Szrj      end() const
1980*38fd1498Szrj      { return _Base_type::end(); }
1981*38fd1498Szrj
1982*38fd1498Szrj#ifdef _GLIBCXX_INCLUDE_AS_CXX11
1983*38fd1498Szrj      /**
1984*38fd1498Szrj       * @brief Gets an iterator to one-past-the-end of the collection.
1985*38fd1498Szrj       */
1986*38fd1498Szrj      const_iterator
1987*38fd1498Szrj      cend() const
1988*38fd1498Szrj      { return _Base_type::end(); }
1989*38fd1498Szrj#endif
1990*38fd1498Szrj
1991*38fd1498Szrj      //@}
1992*38fd1498Szrj
1993*38fd1498Szrj      /**
1994*38fd1498Szrj       * @name 10.4 Formatting
1995*38fd1498Szrj       *
1996*38fd1498Szrj       * These functions perform formatted substitution of the matched
1997*38fd1498Szrj       * character sequences into their target.  The format specifiers
1998*38fd1498Szrj       * and escape sequences accepted by these functions are
1999*38fd1498Szrj       * determined by their @p flags parameter as documented above.
2000*38fd1498Szrj       */
2001*38fd1498Szrj       //@{
2002*38fd1498Szrj
2003*38fd1498Szrj      /**
2004*38fd1498Szrj       * @todo Implement this function.
2005*38fd1498Szrj       */
2006*38fd1498Szrj      template<typename _Out_iter>
2007*38fd1498Szrj        _Out_iter
2008*38fd1498Szrj        format(_Out_iter __out, const string_type& __fmt,
2009*38fd1498Szrj	       regex_constants::match_flag_type __flags
2010*38fd1498Szrj	       = regex_constants::format_default) const;
2011*38fd1498Szrj
2012*38fd1498Szrj      /**
2013*38fd1498Szrj       * @todo Implement this function.
2014*38fd1498Szrj       */
2015*38fd1498Szrj      string_type
2016*38fd1498Szrj      format(const string_type& __fmt,
2017*38fd1498Szrj	     regex_constants::match_flag_type __flags
2018*38fd1498Szrj	     = regex_constants::format_default) const;
2019*38fd1498Szrj
2020*38fd1498Szrj      //@}
2021*38fd1498Szrj
2022*38fd1498Szrj      /**
2023*38fd1498Szrj       * @name 10.5 Allocator
2024*38fd1498Szrj       */
2025*38fd1498Szrj      //@{
2026*38fd1498Szrj
2027*38fd1498Szrj      /**
2028*38fd1498Szrj       * @brief Gets a copy of the allocator.
2029*38fd1498Szrj       */
2030*38fd1498Szrj      //allocator_type
2031*38fd1498Szrj      //get_allocator() const;
2032*38fd1498Szrj      using _Base_type::get_allocator;
2033*38fd1498Szrj
2034*38fd1498Szrj      //@}
2035*38fd1498Szrj
2036*38fd1498Szrj      /**
2037*38fd1498Szrj       * @name 10.6 Swap
2038*38fd1498Szrj       */
2039*38fd1498Szrj       //@{
2040*38fd1498Szrj
2041*38fd1498Szrj      /**
2042*38fd1498Szrj       * @brief Swaps the contents of two match_results.
2043*38fd1498Szrj       */
2044*38fd1498Szrj      void
2045*38fd1498Szrj      swap(match_results& __that)
2046*38fd1498Szrj      {
2047*38fd1498Szrj	_Base_type::swap(__that);
2048*38fd1498Szrj	std::swap(_M_matched, __that._M_matched);
2049*38fd1498Szrj	std::swap(_M_prefix,  __that._M_prefix);
2050*38fd1498Szrj	std::swap(_M_suffix,  __that._M_suffix);
2051*38fd1498Szrj      }
2052*38fd1498Szrj      //@}
2053*38fd1498Szrj
2054*38fd1498Szrj    private:
2055*38fd1498Szrj      bool       _M_matched;
2056*38fd1498Szrj      value_type _M_prefix;
2057*38fd1498Szrj      value_type _M_suffix;
2058*38fd1498Szrj    };
2059*38fd1498Szrj
2060*38fd1498Szrj  typedef match_results<const char*>             cmatch;
2061*38fd1498Szrj  typedef match_results<string::const_iterator>  smatch;
2062*38fd1498Szrj#ifdef _GLIBCXX_USE_WCHAR_T
2063*38fd1498Szrj  typedef match_results<const wchar_t*>          wcmatch;
2064*38fd1498Szrj  typedef match_results<wstring::const_iterator> wsmatch;
2065*38fd1498Szrj#endif
2066*38fd1498Szrj
2067*38fd1498Szrj  // match_results comparisons
2068*38fd1498Szrj  /**
2069*38fd1498Szrj   * @brief Compares two match_results for equality.
2070*38fd1498Szrj   * @returns true if the two objects refer to the same match,
2071*38fd1498Szrj   * false otherwise.
2072*38fd1498Szrj   * @todo Implement this function.
2073*38fd1498Szrj   */
2074*38fd1498Szrj  template<typename _Bi_iter, typename _Allocator>
2075*38fd1498Szrj    inline bool
2076*38fd1498Szrj    operator==(const match_results<_Bi_iter, _Allocator>& __m1,
2077*38fd1498Szrj	       const match_results<_Bi_iter, _Allocator>& __m2);
2078*38fd1498Szrj
2079*38fd1498Szrj  /**
2080*38fd1498Szrj   * @brief Compares two match_results for inequality.
2081*38fd1498Szrj   * @returns true if the two objects do not refer to the same match,
2082*38fd1498Szrj   * false otherwise.
2083*38fd1498Szrj   */
2084*38fd1498Szrj  template<typename _Bi_iter, class _Allocator>
2085*38fd1498Szrj    inline bool
2086*38fd1498Szrj    operator!=(const match_results<_Bi_iter, _Allocator>& __m1,
2087*38fd1498Szrj	       const match_results<_Bi_iter, _Allocator>& __m2)
2088*38fd1498Szrj    { return !(__m1 == __m2); }
2089*38fd1498Szrj
2090*38fd1498Szrj  // [7.10.6] match_results swap
2091*38fd1498Szrj  /**
2092*38fd1498Szrj   * @brief Swaps two match results.
2093*38fd1498Szrj   * @param lhs A match result.
2094*38fd1498Szrj   * @param rhs A match result.
2095*38fd1498Szrj   *
2096*38fd1498Szrj   * The contents of the two match_results objects are swapped.
2097*38fd1498Szrj   */
2098*38fd1498Szrj  template<typename _Bi_iter, typename _Allocator>
2099*38fd1498Szrj    inline void
2100*38fd1498Szrj    swap(match_results<_Bi_iter, _Allocator>& __lhs,
2101*38fd1498Szrj	 match_results<_Bi_iter, _Allocator>& __rhs)
2102*38fd1498Szrj    { __lhs.swap(__rhs); }
2103*38fd1498Szrj
2104*38fd1498Szrj  // [7.11.2] Function template regex_match
2105*38fd1498Szrj  /**
2106*38fd1498Szrj   * @name Matching, Searching, and Replacing
2107*38fd1498Szrj   */
2108*38fd1498Szrj  //@{
2109*38fd1498Szrj
2110*38fd1498Szrj  /**
2111*38fd1498Szrj   * @brief Determines if there is a match between the regular expression @p e
2112*38fd1498Szrj   * and all of the character sequence [first, last).
2113*38fd1498Szrj   *
2114*38fd1498Szrj   * @param first Beginning of the character sequence to match.
2115*38fd1498Szrj   * @param last  One-past-the-end of the character sequence to match.
2116*38fd1498Szrj   * @param m     The match results.
2117*38fd1498Szrj   * @param re    The regular expression.
2118*38fd1498Szrj   * @param flags Controls how the regular expression is matched.
2119*38fd1498Szrj   *
2120*38fd1498Szrj   * @retval true  A match exists.
2121*38fd1498Szrj   * @retval false Otherwise.
2122*38fd1498Szrj   *
2123*38fd1498Szrj   * @throws an exception of type regex_error.
2124*38fd1498Szrj   *
2125*38fd1498Szrj   * @todo Implement this function.
2126*38fd1498Szrj   */
2127*38fd1498Szrj  template<typename _Bi_iter, typename _Allocator,
2128*38fd1498Szrj	   typename _Ch_type, typename _Rx_traits>
2129*38fd1498Szrj    bool
2130*38fd1498Szrj    regex_match(_Bi_iter __first, _Bi_iter __last,
2131*38fd1498Szrj		match_results<_Bi_iter, _Allocator>& __m,
2132*38fd1498Szrj		const basic_regex<_Ch_type, _Rx_traits>& __re,
2133*38fd1498Szrj		regex_constants::match_flag_type __flags
2134*38fd1498Szrj		= regex_constants::match_default);
2135*38fd1498Szrj
2136*38fd1498Szrj  /**
2137*38fd1498Szrj   * @brief Indicates if there is a match between the regular expression @p e
2138*38fd1498Szrj   * and all of the character sequence [first, last).
2139*38fd1498Szrj   *
2140*38fd1498Szrj   * @param first Beginning of the character sequence to match.
2141*38fd1498Szrj   * @param last  One-past-the-end of the character sequence to match.
2142*38fd1498Szrj   * @param re    The regular expression.
2143*38fd1498Szrj   * @param flags Controls how the regular expression is matched.
2144*38fd1498Szrj   *
2145*38fd1498Szrj   * @retval true  A match exists.
2146*38fd1498Szrj   * @retval false Otherwise.
2147*38fd1498Szrj   *
2148*38fd1498Szrj   * @throws an exception of type regex_error.
2149*38fd1498Szrj   */
2150*38fd1498Szrj  template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
2151*38fd1498Szrj    bool
2152*38fd1498Szrj    regex_match(_Bi_iter __first, _Bi_iter __last,
2153*38fd1498Szrj		const basic_regex<_Ch_type, _Rx_traits>& __re,
2154*38fd1498Szrj		regex_constants::match_flag_type __flags
2155*38fd1498Szrj		= regex_constants::match_default)
2156*38fd1498Szrj    {
2157*38fd1498Szrj      match_results<_Bi_iter> __what;
2158*38fd1498Szrj      return regex_match(__first, __last, __what, __re, __flags);
2159*38fd1498Szrj    }
2160*38fd1498Szrj
2161*38fd1498Szrj  /**
2162*38fd1498Szrj   * @brief Determines if there is a match between the regular expression @p e
2163*38fd1498Szrj   * and a C-style null-terminated string.
2164*38fd1498Szrj   *
2165*38fd1498Szrj   * @param s  The C-style null-terminated string to match.
2166*38fd1498Szrj   * @param m  The match results.
2167*38fd1498Szrj   * @param re The regular expression.
2168*38fd1498Szrj   * @param f  Controls how the regular expression is matched.
2169*38fd1498Szrj   *
2170*38fd1498Szrj   * @retval true  A match exists.
2171*38fd1498Szrj   * @retval false Otherwise.
2172*38fd1498Szrj   *
2173*38fd1498Szrj   * @throws an exception of type regex_error.
2174*38fd1498Szrj   */
2175*38fd1498Szrj  template<typename _Ch_type, typename _Allocator, typename _Rx_traits>
2176*38fd1498Szrj    inline bool
2177*38fd1498Szrj    regex_match(const _Ch_type* __s,
2178*38fd1498Szrj		match_results<const _Ch_type*, _Allocator>& __m,
2179*38fd1498Szrj		const basic_regex<_Ch_type, _Rx_traits>& __re,
2180*38fd1498Szrj		regex_constants::match_flag_type __f
2181*38fd1498Szrj		= regex_constants::match_default)
2182*38fd1498Szrj    { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); }
2183*38fd1498Szrj
2184*38fd1498Szrj  /**
2185*38fd1498Szrj   * @brief Determines if there is a match between the regular expression @p e
2186*38fd1498Szrj   * and a string.
2187*38fd1498Szrj   *
2188*38fd1498Szrj   * @param s     The string to match.
2189*38fd1498Szrj   * @param m     The match results.
2190*38fd1498Szrj   * @param re    The regular expression.
2191*38fd1498Szrj   * @param flags Controls how the regular expression is matched.
2192*38fd1498Szrj   *
2193*38fd1498Szrj   * @retval true  A match exists.
2194*38fd1498Szrj   * @retval false Otherwise.
2195*38fd1498Szrj   *
2196*38fd1498Szrj   * @throws an exception of type regex_error.
2197*38fd1498Szrj   */
2198*38fd1498Szrj  template<typename _Ch_traits, typename _Ch_alloc,
2199*38fd1498Szrj	   typename _Allocator, typename _Ch_type, typename _Rx_traits>
2200*38fd1498Szrj    inline bool
2201*38fd1498Szrj    regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
2202*38fd1498Szrj		match_results<typename basic_string<_Ch_type,
2203*38fd1498Szrj		_Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
2204*38fd1498Szrj		const basic_regex<_Ch_type, _Rx_traits>& __re,
2205*38fd1498Szrj		regex_constants::match_flag_type __flags
2206*38fd1498Szrj		= regex_constants::match_default)
2207*38fd1498Szrj    { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }
2208*38fd1498Szrj
2209*38fd1498Szrj  /**
2210*38fd1498Szrj   * @brief Indicates if there is a match between the regular expression @p e
2211*38fd1498Szrj   * and a C-style null-terminated string.
2212*38fd1498Szrj   *
2213*38fd1498Szrj   * @param s  The C-style null-terminated string to match.
2214*38fd1498Szrj   * @param re The regular expression.
2215*38fd1498Szrj   * @param f  Controls how the regular expression is matched.
2216*38fd1498Szrj   *
2217*38fd1498Szrj   * @retval true  A match exists.
2218*38fd1498Szrj   * @retval false Otherwise.
2219*38fd1498Szrj   *
2220*38fd1498Szrj   * @throws an exception of type regex_error.
2221*38fd1498Szrj   */
2222*38fd1498Szrj  template<typename _Ch_type, class _Rx_traits>
2223*38fd1498Szrj    inline bool
2224*38fd1498Szrj    regex_match(const _Ch_type* __s,
2225*38fd1498Szrj		const basic_regex<_Ch_type, _Rx_traits>& __re,
2226*38fd1498Szrj		regex_constants::match_flag_type __f
2227*38fd1498Szrj		= regex_constants::match_default)
2228*38fd1498Szrj    { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); }
2229*38fd1498Szrj
2230*38fd1498Szrj  /**
2231*38fd1498Szrj   * @brief Indicates if there is a match between the regular expression @p e
2232*38fd1498Szrj   * and a string.
2233*38fd1498Szrj   *
2234*38fd1498Szrj   * @param s     [IN] The string to match.
2235*38fd1498Szrj   * @param re    [IN] The regular expression.
2236*38fd1498Szrj   * @param flags [IN] Controls how the regular expression is matched.
2237*38fd1498Szrj   *
2238*38fd1498Szrj   * @retval true  A match exists.
2239*38fd1498Szrj   * @retval false Otherwise.
2240*38fd1498Szrj   *
2241*38fd1498Szrj   * @throws an exception of type regex_error.
2242*38fd1498Szrj   */
2243*38fd1498Szrj  template<typename _Ch_traits, typename _Str_allocator,
2244*38fd1498Szrj	   typename _Ch_type, typename _Rx_traits>
2245*38fd1498Szrj    inline bool
2246*38fd1498Szrj    regex_match(const basic_string<_Ch_type, _Ch_traits, _Str_allocator>& __s,
2247*38fd1498Szrj		const basic_regex<_Ch_type, _Rx_traits>& __re,
2248*38fd1498Szrj		regex_constants::match_flag_type __flags
2249*38fd1498Szrj		= regex_constants::match_default)
2250*38fd1498Szrj    { return regex_match(__s.begin(), __s.end(), __re, __flags); }
2251*38fd1498Szrj
2252*38fd1498Szrj  // [7.11.3] Function template regex_search
2253*38fd1498Szrj  /**
2254*38fd1498Szrj   * Searches for a regular expression within a range.
2255*38fd1498Szrj   * @param first [IN]  The start of the string to search.
2256*38fd1498Szrj   * @param last  [IN]  One-past-the-end of the string to search.
2257*38fd1498Szrj   * @param m     [OUT] The match results.
2258*38fd1498Szrj   * @param re    [IN]  The regular expression to search for.
2259*38fd1498Szrj   * @param flags [IN]  Search policy flags.
2260*38fd1498Szrj   * @retval true  A match was found within the string.
2261*38fd1498Szrj   * @retval false No match was found within the string, the content of %m is
2262*38fd1498Szrj   *               undefined.
2263*38fd1498Szrj   *
2264*38fd1498Szrj   * @throws an exception of type regex_error.
2265*38fd1498Szrj   *
2266*38fd1498Szrj   * @todo Implement this function.
2267*38fd1498Szrj   */
2268*38fd1498Szrj  template<typename _Bi_iter, typename _Allocator,
2269*38fd1498Szrj	   typename _Ch_type, typename _Rx_traits>
2270*38fd1498Szrj    inline bool
2271*38fd1498Szrj    regex_search(_Bi_iter __first, _Bi_iter __last,
2272*38fd1498Szrj		 match_results<_Bi_iter, _Allocator>& __m,
2273*38fd1498Szrj		 const basic_regex<_Ch_type, _Rx_traits>& __re,
2274*38fd1498Szrj		 regex_constants::match_flag_type __flags
2275*38fd1498Szrj		 = regex_constants::match_default);
2276*38fd1498Szrj
2277*38fd1498Szrj  /**
2278*38fd1498Szrj   * Searches for a regular expression within a range.
2279*38fd1498Szrj   * @param first [IN]  The start of the string to search.
2280*38fd1498Szrj   * @param last  [IN]  One-past-the-end of the string to search.
2281*38fd1498Szrj   * @param re    [IN]  The regular expression to search for.
2282*38fd1498Szrj   * @param flags [IN]  Search policy flags.
2283*38fd1498Szrj   * @retval true  A match was found within the string.
2284*38fd1498Szrj   * @retval false No match was found within the string.
2285*38fd1498Szrj   * @doctodo
2286*38fd1498Szrj   *
2287*38fd1498Szrj   * @throws an exception of type regex_error.
2288*38fd1498Szrj   */
2289*38fd1498Szrj  template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
2290*38fd1498Szrj    inline bool
2291*38fd1498Szrj    regex_search(_Bi_iter __first, _Bi_iter __last,
2292*38fd1498Szrj		 const basic_regex<_Ch_type, _Rx_traits>& __re,
2293*38fd1498Szrj		 regex_constants::match_flag_type __flags
2294*38fd1498Szrj		 = regex_constants::match_default)
2295*38fd1498Szrj    {
2296*38fd1498Szrj      match_results<_Bi_iter> __what;
2297*38fd1498Szrj      return regex_search(__first, __last, __what, __re, __flags);
2298*38fd1498Szrj    }
2299*38fd1498Szrj
2300*38fd1498Szrj  /**
2301*38fd1498Szrj   * @brief Searches for a regular expression within a C-string.
2302*38fd1498Szrj   * @param s [IN]  A C-string to search for the regex.
2303*38fd1498Szrj   * @param m [OUT] The set of regex matches.
2304*38fd1498Szrj   * @param e [IN]  The regex to search for in @p s.
2305*38fd1498Szrj   * @param f [IN]  The search flags.
2306*38fd1498Szrj   * @retval true  A match was found within the string.
2307*38fd1498Szrj   * @retval false No match was found within the string, the content of %m is
2308*38fd1498Szrj   *               undefined.
2309*38fd1498Szrj   * @doctodo
2310*38fd1498Szrj   *
2311*38fd1498Szrj   * @throws an exception of type regex_error.
2312*38fd1498Szrj   */
2313*38fd1498Szrj  template<typename _Ch_type, class _Allocator, class _Rx_traits>
2314*38fd1498Szrj    inline bool
2315*38fd1498Szrj    regex_search(const _Ch_type* __s,
2316*38fd1498Szrj		 match_results<const _Ch_type*, _Allocator>& __m,
2317*38fd1498Szrj		 const basic_regex<_Ch_type, _Rx_traits>& __e,
2318*38fd1498Szrj		 regex_constants::match_flag_type __f
2319*38fd1498Szrj		 = regex_constants::match_default)
2320*38fd1498Szrj    { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
2321*38fd1498Szrj
2322*38fd1498Szrj  /**
2323*38fd1498Szrj   * @brief Searches for a regular expression within a C-string.
2324*38fd1498Szrj   * @param s [IN]  The C-string to search.
2325*38fd1498Szrj   * @param e [IN]  The regular expression to search for.
2326*38fd1498Szrj   * @param f [IN]  Search policy flags.
2327*38fd1498Szrj   * @retval true  A match was found within the string.
2328*38fd1498Szrj   * @retval false No match was found within the string.
2329*38fd1498Szrj   * @doctodo
2330*38fd1498Szrj   *
2331*38fd1498Szrj   * @throws an exception of type regex_error.
2332*38fd1498Szrj   */
2333*38fd1498Szrj  template<typename _Ch_type, typename _Rx_traits>
2334*38fd1498Szrj    inline bool
2335*38fd1498Szrj    regex_search(const _Ch_type* __s,
2336*38fd1498Szrj		 const basic_regex<_Ch_type, _Rx_traits>& __e,
2337*38fd1498Szrj		 regex_constants::match_flag_type __f
2338*38fd1498Szrj		 = regex_constants::match_default)
2339*38fd1498Szrj    { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); }
2340*38fd1498Szrj
2341*38fd1498Szrj  /**
2342*38fd1498Szrj   * @brief Searches for a regular expression within a string.
2343*38fd1498Szrj   * @param s     [IN]  The string to search.
2344*38fd1498Szrj   * @param e     [IN]  The regular expression to search for.
2345*38fd1498Szrj   * @param flags [IN]  Search policy flags.
2346*38fd1498Szrj   * @retval true  A match was found within the string.
2347*38fd1498Szrj   * @retval false No match was found within the string.
2348*38fd1498Szrj   * @doctodo
2349*38fd1498Szrj   *
2350*38fd1498Szrj   * @throws an exception of type regex_error.
2351*38fd1498Szrj   */
2352*38fd1498Szrj  template<typename _Ch_traits, typename _String_allocator,
2353*38fd1498Szrj	   typename _Ch_type, typename _Rx_traits>
2354*38fd1498Szrj    inline bool
2355*38fd1498Szrj    regex_search(const basic_string<_Ch_type, _Ch_traits,
2356*38fd1498Szrj		 _String_allocator>& __s,
2357*38fd1498Szrj		 const basic_regex<_Ch_type, _Rx_traits>& __e,
2358*38fd1498Szrj		 regex_constants::match_flag_type __flags
2359*38fd1498Szrj		 = regex_constants::match_default)
2360*38fd1498Szrj    { return regex_search(__s.begin(), __s.end(), __e, __flags); }
2361*38fd1498Szrj
2362*38fd1498Szrj  /**
2363*38fd1498Szrj   * @brief Searches for a regular expression within a string.
2364*38fd1498Szrj   * @param s [IN]  A C++ string to search for the regex.
2365*38fd1498Szrj   * @param m [OUT] The set of regex matches.
2366*38fd1498Szrj   * @param e [IN]  The regex to search for in @p s.
2367*38fd1498Szrj   * @param f [IN]  The search flags.
2368*38fd1498Szrj   * @retval true  A match was found within the string.
2369*38fd1498Szrj   * @retval false No match was found within the string, the content of %m is
2370*38fd1498Szrj   *               undefined.
2371*38fd1498Szrj   *
2372*38fd1498Szrj   * @throws an exception of type regex_error.
2373*38fd1498Szrj   */
2374*38fd1498Szrj  template<typename _Ch_traits, typename _Ch_alloc,
2375*38fd1498Szrj	   typename _Allocator, typename _Ch_type,
2376*38fd1498Szrj	   typename _Rx_traits>
2377*38fd1498Szrj    inline bool
2378*38fd1498Szrj    regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
2379*38fd1498Szrj		 match_results<typename basic_string<_Ch_type,
2380*38fd1498Szrj		 _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
2381*38fd1498Szrj		 const basic_regex<_Ch_type, _Rx_traits>& __e,
2382*38fd1498Szrj		 regex_constants::match_flag_type __f
2383*38fd1498Szrj		 = regex_constants::match_default)
2384*38fd1498Szrj    { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
2385*38fd1498Szrj
2386*38fd1498Szrj  // tr1 [7.11.4] std [28.11.4] Function template regex_replace
2387*38fd1498Szrj  /**
2388*38fd1498Szrj   * @doctodo
2389*38fd1498Szrj   * @param out
2390*38fd1498Szrj   * @param first
2391*38fd1498Szrj   * @param last
2392*38fd1498Szrj   * @param e
2393*38fd1498Szrj   * @param fmt
2394*38fd1498Szrj   * @param flags
2395*38fd1498Szrj   *
2396*38fd1498Szrj   * @returns out
2397*38fd1498Szrj   * @throws an exception of type regex_error.
2398*38fd1498Szrj   *
2399*38fd1498Szrj   * @todo Implement this function.
2400*38fd1498Szrj   */
2401*38fd1498Szrj  template<typename _Out_iter, typename _Bi_iter,
2402*38fd1498Szrj	   typename _Rx_traits, typename _Ch_type>
2403*38fd1498Szrj    inline _Out_iter
2404*38fd1498Szrj    regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
2405*38fd1498Szrj		  const basic_regex<_Ch_type, _Rx_traits>& __e,
2406*38fd1498Szrj		  const basic_string<_Ch_type>& __fmt,
2407*38fd1498Szrj		  regex_constants::match_flag_type __flags
2408*38fd1498Szrj		  = regex_constants::match_default);
2409*38fd1498Szrj
2410*38fd1498Szrj  /**
2411*38fd1498Szrj   * @doctodo
2412*38fd1498Szrj   * @param s
2413*38fd1498Szrj   * @param e
2414*38fd1498Szrj   * @param fmt
2415*38fd1498Szrj   * @param flags
2416*38fd1498Szrj   *
2417*38fd1498Szrj   * @returns a copy of string @p s with replacements.
2418*38fd1498Szrj   *
2419*38fd1498Szrj   * @throws an exception of type regex_error.
2420*38fd1498Szrj   */
2421*38fd1498Szrj  template<typename _Rx_traits, typename _Ch_type>
2422*38fd1498Szrj    inline basic_string<_Ch_type>
2423*38fd1498Szrj    regex_replace(const basic_string<_Ch_type>& __s,
2424*38fd1498Szrj		  const basic_regex<_Ch_type, _Rx_traits>& __e,
2425*38fd1498Szrj		  const basic_string<_Ch_type>& __fmt,
2426*38fd1498Szrj		  regex_constants::match_flag_type __flags
2427*38fd1498Szrj		  = regex_constants::match_default)
2428*38fd1498Szrj    {
2429*38fd1498Szrj      std::string __result;
2430*38fd1498Szrj      regex_replace(std::back_inserter(__result),
2431*38fd1498Szrj		    __s.begin(), __s.end(), __e, __fmt, __flags);
2432*38fd1498Szrj      return __result;
2433*38fd1498Szrj    }
2434*38fd1498Szrj
2435*38fd1498Szrj  //@}
2436*38fd1498Szrj
2437*38fd1498Szrj  // tr1 [7.12.1] std [28.12] Class template regex_iterator
2438*38fd1498Szrj  /**
2439*38fd1498Szrj   * An iterator adaptor that will provide repeated calls of regex_search over
2440*38fd1498Szrj   * a range until no more matches remain.
2441*38fd1498Szrj   */
2442*38fd1498Szrj  template<typename _Bi_iter,
2443*38fd1498Szrj	   typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2444*38fd1498Szrj	   typename _Rx_traits = regex_traits<_Ch_type> >
2445*38fd1498Szrj    class regex_iterator
2446*38fd1498Szrj    {
2447*38fd1498Szrj    public:
2448*38fd1498Szrj      typedef basic_regex<_Ch_type, _Rx_traits>  regex_type;
2449*38fd1498Szrj      typedef match_results<_Bi_iter>            value_type;
2450*38fd1498Szrj      typedef std::ptrdiff_t                     difference_type;
2451*38fd1498Szrj      typedef const value_type*                  pointer;
2452*38fd1498Szrj      typedef const value_type&                  reference;
2453*38fd1498Szrj      typedef std::forward_iterator_tag          iterator_category;
2454*38fd1498Szrj
2455*38fd1498Szrj    public:
2456*38fd1498Szrj      /**
2457*38fd1498Szrj       * @brief Provides a singular iterator, useful for indicating
2458*38fd1498Szrj       * one-past-the-end of a range.
2459*38fd1498Szrj       * @todo Implement this function.
2460*38fd1498Szrj       * @doctodo
2461*38fd1498Szrj       */
2462*38fd1498Szrj      regex_iterator();
2463*38fd1498Szrj
2464*38fd1498Szrj      /**
2465*38fd1498Szrj       * Constructs a %regex_iterator...
2466*38fd1498Szrj       * @param a  [IN] The start of a text range to search.
2467*38fd1498Szrj       * @param b  [IN] One-past-the-end of the text range to search.
2468*38fd1498Szrj       * @param re [IN] The regular expression to match.
2469*38fd1498Szrj       * @param m  [IN] Policy flags for match rules.
2470*38fd1498Szrj       * @todo Implement this function.
2471*38fd1498Szrj       * @doctodo
2472*38fd1498Szrj       */
2473*38fd1498Szrj      regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2474*38fd1498Szrj		     regex_constants::match_flag_type __m
2475*38fd1498Szrj		     = regex_constants::match_default);
2476*38fd1498Szrj
2477*38fd1498Szrj      /**
2478*38fd1498Szrj       * Copy constructs a %regex_iterator.
2479*38fd1498Szrj       * @todo Implement this function.
2480*38fd1498Szrj       * @doctodo
2481*38fd1498Szrj       */
2482*38fd1498Szrj      regex_iterator(const regex_iterator& __rhs);
2483*38fd1498Szrj
2484*38fd1498Szrj      /**
2485*38fd1498Szrj       * @todo Implement this function.
2486*38fd1498Szrj       * @doctodo
2487*38fd1498Szrj       */
2488*38fd1498Szrj      regex_iterator&
2489*38fd1498Szrj      operator=(const regex_iterator& __rhs);
2490*38fd1498Szrj
2491*38fd1498Szrj      /**
2492*38fd1498Szrj       * @todo Implement this function.
2493*38fd1498Szrj       * @doctodo
2494*38fd1498Szrj       */
2495*38fd1498Szrj      bool
2496*38fd1498Szrj      operator==(const regex_iterator& __rhs);
2497*38fd1498Szrj
2498*38fd1498Szrj      /**
2499*38fd1498Szrj       * @todo Implement this function.
2500*38fd1498Szrj       * @doctodo
2501*38fd1498Szrj       */
2502*38fd1498Szrj      bool
2503*38fd1498Szrj      operator!=(const regex_iterator& __rhs);
2504*38fd1498Szrj
2505*38fd1498Szrj      /**
2506*38fd1498Szrj       * @todo Implement this function.
2507*38fd1498Szrj       * @doctodo
2508*38fd1498Szrj       */
2509*38fd1498Szrj      const value_type&
2510*38fd1498Szrj      operator*();
2511*38fd1498Szrj
2512*38fd1498Szrj      /**
2513*38fd1498Szrj       * @todo Implement this function.
2514*38fd1498Szrj       * @doctodo
2515*38fd1498Szrj       */
2516*38fd1498Szrj      const value_type*
2517*38fd1498Szrj      operator->();
2518*38fd1498Szrj
2519*38fd1498Szrj      /**
2520*38fd1498Szrj       * @todo Implement this function.
2521*38fd1498Szrj       * @doctodo
2522*38fd1498Szrj       */
2523*38fd1498Szrj      regex_iterator&
2524*38fd1498Szrj      operator++();
2525*38fd1498Szrj
2526*38fd1498Szrj      /**
2527*38fd1498Szrj       * @todo Implement this function.
2528*38fd1498Szrj       * @doctodo
2529*38fd1498Szrj       */
2530*38fd1498Szrj      regex_iterator
2531*38fd1498Szrj      operator++(int);
2532*38fd1498Szrj
2533*38fd1498Szrj    private:
2534*38fd1498Szrj      // these members are shown for exposition only:
2535*38fd1498Szrj      _Bi_iter                         begin;
2536*38fd1498Szrj      _Bi_iter                         end;
2537*38fd1498Szrj      const regex_type*                pregex;
2538*38fd1498Szrj      regex_constants::match_flag_type flags;
2539*38fd1498Szrj      match_results<_Bi_iter>          match;
2540*38fd1498Szrj    };
2541*38fd1498Szrj
2542*38fd1498Szrj  typedef regex_iterator<const char*>             cregex_iterator;
2543*38fd1498Szrj  typedef regex_iterator<string::const_iterator>  sregex_iterator;
2544*38fd1498Szrj#ifdef _GLIBCXX_USE_WCHAR_T
2545*38fd1498Szrj  typedef regex_iterator<const wchar_t*>          wcregex_iterator;
2546*38fd1498Szrj  typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
2547*38fd1498Szrj#endif
2548*38fd1498Szrj
2549*38fd1498Szrj  // [7.12.2] Class template regex_token_iterator
2550*38fd1498Szrj  /**
2551*38fd1498Szrj   * Iterates over submatches in a range (or @a splits a text string).
2552*38fd1498Szrj   *
2553*38fd1498Szrj   * The purpose of this iterator is to enumerate all, or all specified,
2554*38fd1498Szrj   * matches of a regular expression within a text range.  The dereferenced
2555*38fd1498Szrj   * value of an iterator of this class is a std::tr1::sub_match object.
2556*38fd1498Szrj   */
2557*38fd1498Szrj  template<typename _Bi_iter,
2558*38fd1498Szrj	   typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2559*38fd1498Szrj	   typename _Rx_traits = regex_traits<_Ch_type> >
2560*38fd1498Szrj    class regex_token_iterator
2561*38fd1498Szrj    {
2562*38fd1498Szrj    public:
2563*38fd1498Szrj      typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
2564*38fd1498Szrj      typedef sub_match<_Bi_iter>               value_type;
2565*38fd1498Szrj      typedef std::ptrdiff_t                    difference_type;
2566*38fd1498Szrj      typedef const value_type*                 pointer;
2567*38fd1498Szrj      typedef const value_type&                 reference;
2568*38fd1498Szrj      typedef std::forward_iterator_tag         iterator_category;
2569*38fd1498Szrj
2570*38fd1498Szrj    public:
2571*38fd1498Szrj      /**
2572*38fd1498Szrj       * @brief Default constructs a %regex_token_iterator.
2573*38fd1498Szrj       * @todo Implement this function.
2574*38fd1498Szrj       *
2575*38fd1498Szrj       * A default-constructed %regex_token_iterator is a singular iterator
2576*38fd1498Szrj       * that will compare equal to the one-past-the-end value for any
2577*38fd1498Szrj       * iterator of the same type.
2578*38fd1498Szrj       */
2579*38fd1498Szrj      regex_token_iterator();
2580*38fd1498Szrj
2581*38fd1498Szrj      /**
2582*38fd1498Szrj       * Constructs a %regex_token_iterator...
2583*38fd1498Szrj       * @param a          [IN] The start of the text to search.
2584*38fd1498Szrj       * @param b          [IN] One-past-the-end of the text to search.
2585*38fd1498Szrj       * @param re         [IN] The regular expression to search for.
2586*38fd1498Szrj       * @param submatch   [IN] Which submatch to return.  There are some
2587*38fd1498Szrj       *                        special values for this parameter:
2588*38fd1498Szrj       *                        - -1 each enumerated subexpression does NOT
2589*38fd1498Szrj       *                          match the regular expression (aka field
2590*38fd1498Szrj       *                          splitting)
2591*38fd1498Szrj       *                        - 0 the entire string matching the
2592*38fd1498Szrj       *                          subexpression is returned for each match
2593*38fd1498Szrj       *                          within the text.
2594*38fd1498Szrj       *                        - >0 enumerates only the indicated
2595*38fd1498Szrj       *                          subexpression from a match within the text.
2596*38fd1498Szrj       * @param m          [IN] Policy flags for match rules.
2597*38fd1498Szrj       *
2598*38fd1498Szrj       * @todo Implement this function.
2599*38fd1498Szrj       * @doctodo
2600*38fd1498Szrj       */
2601*38fd1498Szrj      regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2602*38fd1498Szrj			   int __submatch = 0,
2603*38fd1498Szrj			   regex_constants::match_flag_type __m
2604*38fd1498Szrj			   = regex_constants::match_default);
2605*38fd1498Szrj
2606*38fd1498Szrj      /**
2607*38fd1498Szrj       * Constructs a %regex_token_iterator...
2608*38fd1498Szrj       * @param a          [IN] The start of the text to search.
2609*38fd1498Szrj       * @param b          [IN] One-past-the-end of the text to search.
2610*38fd1498Szrj       * @param re         [IN] The regular expression to search for.
2611*38fd1498Szrj       * @param submatches [IN] A list of subexpressions to return for each
2612*38fd1498Szrj       *                        regular expression match within the text.
2613*38fd1498Szrj       * @param m          [IN] Policy flags for match rules.
2614*38fd1498Szrj       *
2615*38fd1498Szrj       * @todo Implement this function.
2616*38fd1498Szrj       * @doctodo
2617*38fd1498Szrj       */
2618*38fd1498Szrj      regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2619*38fd1498Szrj			   const regex_type& __re,
2620*38fd1498Szrj			   const std::vector<int>& __submatches,
2621*38fd1498Szrj			   regex_constants::match_flag_type __m
2622*38fd1498Szrj			     = regex_constants::match_default);
2623*38fd1498Szrj
2624*38fd1498Szrj      /**
2625*38fd1498Szrj       * Constructs a %regex_token_iterator...
2626*38fd1498Szrj       * @param a          [IN] The start of the text to search.
2627*38fd1498Szrj       * @param b          [IN] One-past-the-end of the text to search.
2628*38fd1498Szrj       * @param re         [IN] The regular expression to search for.
2629*38fd1498Szrj       * @param submatches [IN] A list of subexpressions to return for each
2630*38fd1498Szrj       *                        regular expression match within the text.
2631*38fd1498Szrj       * @param m          [IN] Policy flags for match rules.
2632*38fd1498Szrj
2633*38fd1498Szrj       * @todo Implement this function.
2634*38fd1498Szrj       * @doctodo
2635*38fd1498Szrj       */
2636*38fd1498Szrj      template<std::size_t _Nm>
2637*38fd1498Szrj        regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2638*38fd1498Szrj			     const regex_type& __re,
2639*38fd1498Szrj			     const int (&__submatches)[_Nm],
2640*38fd1498Szrj			     regex_constants::match_flag_type __m
2641*38fd1498Szrj			     = regex_constants::match_default);
2642*38fd1498Szrj
2643*38fd1498Szrj      /**
2644*38fd1498Szrj       * @brief Copy constructs a %regex_token_iterator.
2645*38fd1498Szrj       * @param rhs [IN] A %regex_token_iterator to copy.
2646*38fd1498Szrj       * @todo Implement this function.
2647*38fd1498Szrj       */
2648*38fd1498Szrj      regex_token_iterator(const regex_token_iterator& __rhs);
2649*38fd1498Szrj
2650*38fd1498Szrj      /**
2651*38fd1498Szrj       * @brief Assigns a %regex_token_iterator to another.
2652*38fd1498Szrj       * @param rhs [IN] A %regex_token_iterator to copy.
2653*38fd1498Szrj       * @todo Implement this function.
2654*38fd1498Szrj       */
2655*38fd1498Szrj      regex_token_iterator&
2656*38fd1498Szrj      operator=(const regex_token_iterator& __rhs);
2657*38fd1498Szrj
2658*38fd1498Szrj      /**
2659*38fd1498Szrj       * @brief Compares a %regex_token_iterator to another for equality.
2660*38fd1498Szrj       * @todo Implement this function.
2661*38fd1498Szrj       */
2662*38fd1498Szrj      bool
2663*38fd1498Szrj      operator==(const regex_token_iterator& __rhs);
2664*38fd1498Szrj
2665*38fd1498Szrj      /**
2666*38fd1498Szrj       * @brief Compares a %regex_token_iterator to another for inequality.
2667*38fd1498Szrj       * @todo Implement this function.
2668*38fd1498Szrj       */
2669*38fd1498Szrj      bool
2670*38fd1498Szrj      operator!=(const regex_token_iterator& __rhs);
2671*38fd1498Szrj
2672*38fd1498Szrj      /**
2673*38fd1498Szrj       * @brief Dereferences a %regex_token_iterator.
2674*38fd1498Szrj       * @todo Implement this function.
2675*38fd1498Szrj       */
2676*38fd1498Szrj      const value_type&
2677*38fd1498Szrj      operator*();
2678*38fd1498Szrj
2679*38fd1498Szrj      /**
2680*38fd1498Szrj       * @brief Selects a %regex_token_iterator member.
2681*38fd1498Szrj       * @todo Implement this function.
2682*38fd1498Szrj       */
2683*38fd1498Szrj      const value_type*
2684*38fd1498Szrj      operator->();
2685*38fd1498Szrj
2686*38fd1498Szrj      /**
2687*38fd1498Szrj       * @brief Increments a %regex_token_iterator.
2688*38fd1498Szrj       * @todo Implement this function.
2689*38fd1498Szrj       */
2690*38fd1498Szrj      regex_token_iterator&
2691*38fd1498Szrj      operator++();
2692*38fd1498Szrj
2693*38fd1498Szrj      /**
2694*38fd1498Szrj       * @brief Postincrements a %regex_token_iterator.
2695*38fd1498Szrj       * @todo Implement this function.
2696*38fd1498Szrj       */
2697*38fd1498Szrj      regex_token_iterator
2698*38fd1498Szrj      operator++(int);
2699*38fd1498Szrj
2700*38fd1498Szrj    private: // data members for exposition only:
2701*38fd1498Szrj      typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> position_iterator;
2702*38fd1498Szrj
2703*38fd1498Szrj      position_iterator __position;
2704*38fd1498Szrj      const value_type* __result;
2705*38fd1498Szrj      value_type        __suffix;
2706*38fd1498Szrj      std::size_t       __n;
2707*38fd1498Szrj      std::vector<int>  __subs;
2708*38fd1498Szrj    };
2709*38fd1498Szrj
2710*38fd1498Szrj  /** @brief Token iterator for C-style NULL-terminated strings. */
2711*38fd1498Szrj  typedef regex_token_iterator<const char*>             cregex_token_iterator;
2712*38fd1498Szrj  /** @brief Token iterator for standard strings. */
2713*38fd1498Szrj  typedef regex_token_iterator<string::const_iterator>  sregex_token_iterator;
2714*38fd1498Szrj#ifdef _GLIBCXX_USE_WCHAR_T
2715*38fd1498Szrj  /** @brief Token iterator for C-style NULL-terminated wide strings. */
2716*38fd1498Szrj  typedef regex_token_iterator<const wchar_t*>          wcregex_token_iterator;
2717*38fd1498Szrj  /** @brief Token iterator for standard wide-character strings. */
2718*38fd1498Szrj  typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
2719*38fd1498Szrj#endif
2720*38fd1498Szrj
2721*38fd1498Szrj  //@}
2722*38fd1498Szrj}
2723*38fd1498Szrj
2724*38fd1498Szrj_GLIBCXX_END_NAMESPACE_VERSION
2725*38fd1498Szrj}
2726*38fd1498Szrj
2727*38fd1498Szrj#endif // _GLIBCXX_TR1_REGEX
2728