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