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