1 // class template regex -*- C++ -*-
3 // Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
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)
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.
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.
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/>.
27 * @author Stephen M. Webb <stephen.webb@bregmasoft.ca>
28 * This is a TR1 C++ Library header.
31 #ifndef _GLIBCXX_TR1_REGEX
32 #define _GLIBCXX_TR1_REGEX 1
34 #pragma GCC system_header
51 * @defgroup tr1_regex Regular Expressions
52 * A facility for performing regular expression pattern matching.
56 /** @namespace std::regex_constants
57 * @brief ISO C++ 0x entities sub namespace for regex.
59 namespace regex_constants
62 * @name 5.1 Regular Expression Syntax Options
81 * @brief This is a bitmask type indicating how to interpret the regex.
83 * The @c syntax_option_type is implementation defined but it is valid to
84 * perform bitwise operations on these values and expect the right thing to
87 * A valid value of type syntax_option_type shall have exactly one of the
88 * elements @c ECMAScript, @c basic, @c extended, @c awk, @c grep, @c egrep
91 typedef unsigned int syntax_option_type;
94 * Specifies that the matching of regular expressions against a character
95 * sequence shall be performed without regard to case.
97 static const syntax_option_type icase = 1 << _S_icase;
100 * Specifies that when a regular expression is matched against a character
101 * container sequence, no sub-expression matches are to be stored in the
102 * supplied match_results structure.
104 static const syntax_option_type nosubs = 1 << _S_nosubs;
107 * Specifies that the regular expression engine should pay more attention to
108 * the speed with which regular expressions are matched, and less to the
109 * speed with which regular expression objects are constructed. Otherwise
110 * it has no detectable effect on the program output.
112 static const syntax_option_type optimize = 1 << _S_optimize;
115 * Specifies that character ranges of the form [a-b] should be locale
118 static const syntax_option_type collate = 1 << _S_collate;
121 * Specifies that the grammar recognized by the regular expression engine is
122 * that used by ECMAScript in ECMA-262 [Ecma International, ECMAScript
123 * Language Specification, Standard Ecma-262, third edition, 1999], as
124 * modified in tr1 section [7.13]. This grammar is similar to that defined
125 * in the PERL scripting language but extended with elements found in the
126 * POSIX regular expression grammar.
128 static const syntax_option_type ECMAScript = 1 << _S_ECMAScript;
131 * Specifies that the grammar recognized by the regular expression engine is
132 * that used by POSIX basic regular expressions in IEEE Std 1003.1-2001,
133 * Portable Operating System Interface (POSIX), Base Definitions and
134 * Headers, Section 9, Regular Expressions [IEEE, Information Technology --
135 * Portable Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
137 static const syntax_option_type basic = 1 << _S_basic;
140 * Specifies that the grammar recognized by the regular expression engine is
141 * that used by POSIX extended regular expressions in IEEE Std 1003.1-2001,
142 * Portable Operating System Interface (POSIX), Base Definitions and Headers,
143 * Section 9, Regular Expressions.
145 static const syntax_option_type extended = 1 << _S_extended;
148 * Specifies that the grammar recognized by the regular expression engine is
149 * that used by POSIX utility awk in IEEE Std 1003.1-2001. This option is
150 * identical to syntax_option_type extended, except that C-style escape
151 * sequences are supported. These sequences are:
152 * \\\\, \\a, \\b, \\f,
153 * \\n, \\r, \\t , \\v,
154 * \\', ', and \\ddd
155 * (where ddd is one, two, or three octal digits).
157 static const syntax_option_type awk = 1 << _S_awk;
160 * Specifies that the grammar recognized by the regular expression engine is
161 * that used by POSIX utility grep in IEEE Std 1003.1-2001. This option is
162 * identical to syntax_option_type basic, except that newlines are treated
165 static const syntax_option_type grep = 1 << _S_grep;
168 * Specifies that the grammar recognized by the regular expression engine is
169 * that used by POSIX utility grep when given the -E option in
170 * IEEE Std 1003.1-2001. This option is identical to syntax_option_type
171 * extended, except that newlines are treated as whitespace.
173 static const syntax_option_type egrep = 1 << _S_egrep;
178 * @name 5.2 Matching Rules
180 * Matching a regular expression against a sequence of characters [first,
181 * last) proceeds according to the rules of the grammar specified for the
182 * regular expression object, modified according to the effects listed
183 * below for any bitmask elements set.
205 * @brief This is a bitmask type indicating regex matching rules.
207 * The @c match_flag_type is implementation defined but it is valid to
208 * perform bitwise operations on these values and expect the right thing to
211 typedef std::bitset<_S_match_flag_last> match_flag_type;
214 * The default matching rules.
216 static const match_flag_type match_default = 0;
219 * The first character in the sequence [first, last) is treated as though it
220 * is not at the beginning of a line, so the character (^) in the regular
221 * expression shall not match [first, first).
223 static const match_flag_type match_not_bol = 1 << _S_not_bol;
226 * The last character in the sequence [first, last) is treated as though it
227 * is not at the end of a line, so the character ($) in the regular
228 * expression shall not match [last, last).
230 static const match_flag_type match_not_eol = 1 << _S_not_eol;
233 * The expression \\b is not matched against the sub-sequence
236 static const match_flag_type match_not_bow = 1 << _S_not_bow;
239 * The expression \\b should not be matched against the sub-sequence
242 static const match_flag_type match_not_eow = 1 << _S_not_eow;
245 * If more than one match is possible then any match is an acceptable
248 static const match_flag_type match_any = 1 << _S_any;
251 * The expression does not match an empty sequence.
253 static const match_flag_type match_not_null = 1 << _S_not_null;
256 * The expression only matches a sub-sequence that begins at first .
258 static const match_flag_type match_continuous = 1 << _S_continuous;
261 * --first is a valid iterator position. When this flag is set then the
262 * flags match_not_bol and match_not_bow are ignored by the regular
263 * expression algorithms 7.11 and iterators 7.12.
265 static const match_flag_type match_prev_avail = 1 << _S_prev_avail;
268 * When a regular expression match is to be replaced by a new string, the
269 * new string is constructed using the rules used by the ECMAScript replace
270 * function in ECMA- 262 [Ecma International, ECMAScript Language
271 * Specification, Standard Ecma-262, third edition, 1999], part 15.5.4.11
272 * String.prototype.replace. In addition, during search and replace
273 * operations all non-overlapping occurrences of the regular expression
274 * are located and replaced, and sections of the input that did not match
275 * the expression are copied unchanged to the output string.
277 * Format strings (from ECMA-262 [15.5.4.11]):
278 * @li $$ The dollar-sign itself ($)
279 * @li $& The matched substring.
280 * @li $` The portion of @a string that precedes the matched substring.
281 * This would be match_results::prefix().
282 * @li $' The portion of @a string that follows the matched substring.
283 * This would be match_results::suffix().
284 * @li $n The nth capture, where n is in [1,9] and $n is not followed by a
285 * decimal digit. If n <= match_results::size() and the nth capture
286 * is undefined, use the empty string instead. If n >
287 * match_results::size(), the result is implementation-defined.
288 * @li $nn The nnth capture, where nn is a two-digit decimal number on
289 * [01, 99]. If nn <= match_results::size() and the nth capture is
290 * undefined, use the empty string instead. If
291 * nn > match_results::size(), the result is implementation-defined.
293 static const match_flag_type format_default = 0;
296 * When a regular expression match is to be replaced by a new string, the
297 * new string is constructed using the rules used by the POSIX sed utility
298 * in IEEE Std 1003.1- 2001 [IEEE, Information Technology -- Portable
299 * Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
301 static const match_flag_type format_sed = 1 << _S_sed;
304 * During a search and replace operation, sections of the character
305 * container sequence being searched that do not match the regular
306 * expression shall not be copied to the output string.
308 static const match_flag_type format_no_copy = 1 << _S_no_copy;
311 * When specified during a search and replace operation, only the first
312 * occurrence of the regular expression shall be replaced.
314 static const match_flag_type format_first_only = 1 << _S_first_only;
319 * @name 5.3 Error Types
341 /** The expression contained an invalid collating element name. */
342 static const error_type error_collate(_S_error_collate);
344 /** The expression contained an invalid character class name. */
345 static const error_type error_ctype(_S_error_ctype);
348 * The expression contained an invalid escaped character, or a trailing
351 static const error_type error_escape(_S_error_escape);
353 /** The expression contained an invalid back reference. */
354 static const error_type error_backref(_S_error_backref);
356 /** The expression contained mismatched [ and ]. */
357 static const error_type error_brack(_S_error_brack);
359 /** The expression contained mismatched ( and ). */
360 static const error_type error_paren(_S_error_paren);
362 /** The expression contained mismatched { and } */
363 static const error_type error_brace(_S_error_brace);
365 /** The expression contained an invalid range in a {} expression. */
366 static const error_type error_badbrace(_S_error_badbrace);
369 * The expression contained an invalid character range,
370 * such as [b-a] in most encodings.
372 static const error_type error_range(_S_error_range);
375 * There was insufficient memory to convert the expression into a
376 * finite state machine.
378 static const error_type error_space(_S_error_space);
381 * One of <em>*?+{</em> was not preceded by a valid regular expression.
383 static const error_type error_badrepeat(_S_error_badrepeat);
386 * The complexity of an attempted match against a regular expression
387 * exceeded a pre-set level.
389 static const error_type error_complexity(_S_error_complexity);
392 * There was insufficient memory to determine whether the
393 * regular expression could match the specified character sequence.
395 static const error_type error_stack(_S_error_stack);
401 // [7.8] Class regex_error
403 * @brief A regular expression exception class.
404 * @ingroup exceptions
406 * The regular expression library throws objects of this class on error.
409 : public std::runtime_error
413 * @brief Constructs a regex_error object.
415 * @param ecode the regex error code.
418 regex_error(regex_constants::error_type __ecode)
419 : std::runtime_error("regex_error"), _M_code(__ecode)
423 * @brief Gets the regex error code.
425 * @returns the regex error code.
427 regex_constants::error_type
432 regex_constants::error_type _M_code;
435 // [7.7] Class regex_traits
437 * @brief Describes aspects of a regular expression.
439 * A regular expression traits class that satisfies the requirements of tr1
442 * The class %regex is parameterized around a set of related types and
443 * functions used to complete the definition of its semantics. This class
444 * satisfies the requirements of such a traits class.
446 template<typename _Ch_type>
450 typedef _Ch_type char_type;
451 typedef std::basic_string<char_type> string_type;
452 typedef std::locale locale_type;
453 typedef std::ctype_base::mask char_class_type;
457 * @brief Constructs a default traits object.
463 * @brief Gives the length of a C-style string starting at @p __p.
465 * @param __p a pointer to the start of a character sequence.
467 * @returns the number of characters between @p *__p and the first
468 * default-initialized value of type @p char_type. In other words, uses
469 * the C-string algorithm for determining the length of a sequence of
473 length(const char_type* __p)
474 { return string_type::traits_type::length(__p); }
477 * @brief Performs the identity translation.
479 * @param c A character to the locale-specific character set.
484 translate(char_type __c) const
488 * @brief Translates a character into a case-insensitive equivalent.
490 * @param c A character to the locale-specific character set.
492 * @returns the locale-specific lower-case equivalent of c.
493 * @throws std::bad_cast if the imbued locale does not support the ctype
497 translate_nocase(char_type __c) const
500 using std::use_facet;
501 return use_facet<ctype<char_type> >(_M_locale).tolower(__c);
505 * @brief Gets a sort key for a character sequence.
507 * @param first beginning of the character sequence.
508 * @param last one-past-the-end of the character sequence.
510 * Returns a sort key for the character sequence designated by the
511 * iterator range [F1, F2) such that if the character sequence [G1, G2)
512 * sorts before the character sequence [H1, H2) then
513 * v.transform(G1, G2) < v.transform(H1, H2).
515 * What this really does is provide a more efficient way to compare a
516 * string to multiple other strings in locales with fancy collation
517 * rules and equivalence classes.
519 * @returns a locale-specific sort key equivalent to the input range.
521 * @throws std::bad_cast if the current locale does not have a collate
524 template<typename _Fwd_iter>
526 transform(_Fwd_iter __first, _Fwd_iter __last) const
529 using std::use_facet;
530 const collate<_Ch_type>& __c(use_facet<
531 collate<_Ch_type> >(_M_locale));
532 string_type __s(__first, __last);
533 return __c.transform(__s.data(), __s.data() + __s.size());
539 * @param first beginning of the character sequence.
540 * @param last one-past-the-end of the character sequence.
542 * Effects: if typeid(use_facet<collate<_Ch_type> >) ==
543 * typeid(collate_byname<_Ch_type>) and the form of the sort key
544 * returned by collate_byname<_Ch_type>::transform(first, last) is known
545 * and can be converted into a primary sort key then returns that key,
546 * otherwise returns an empty string. WTF??
548 * @todo Implement this function.
550 template<typename _Fwd_iter>
552 transform_primary(_Fwd_iter __first, _Fwd_iter __last) const;
555 * @brief Gets a collation element by name.
557 * @param first beginning of the collation element name.
558 * @param last one-past-the-end of the collation element name.
560 * @returns a sequence of one or more characters that represents the
561 * collating element consisting of the character sequence designated by
562 * the iterator range [first, last). Returns an empty string if the
563 * character sequence is not a valid collating element.
565 * @todo Implement this function.
567 template<typename _Fwd_iter>
569 lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const;
572 * @brief Maps one or more characters to a named character
575 * @param first beginning of the character sequence.
576 * @param last one-past-the-end of the character sequence.
578 * @returns an unspecified value that represents the character
579 * classification named by the character sequence designated by the
580 * iterator range [first, last). The value returned shall be independent
581 * of the case of the characters in the character sequence. If the name
582 * is not recognized then returns a value that compares equal to 0.
584 * At least the following names (or their wide-character equivalent) are
602 * @todo Implement this function.
604 template<typename _Fwd_iter>
606 lookup_classname(_Fwd_iter __first, _Fwd_iter __last) const;
609 * @brief Determines if @p c is a member of an identified class.
611 * @param c a character.
612 * @param f a class type (as returned from lookup_classname).
614 * @returns true if the character @p c is a member of the classification
615 * represented by @p f, false otherwise.
617 * @throws std::bad_cast if the current locale does not have a ctype
621 isctype(_Ch_type __c, char_class_type __f) const;
624 * @brief Converts a digit to an int.
626 * @param ch a character representing a digit.
627 * @param radix the radix if the numeric conversion (limited to 8, 10,
630 * @returns the value represented by the digit ch in base radix if the
631 * character ch is a valid digit in base radix; otherwise returns -1.
634 value(_Ch_type __ch, int __radix) const;
637 * @brief Imbues the regex_traits object with a copy of a new locale.
639 * @param loc A locale.
641 * @returns a copy of the previous locale in use by the regex_traits
644 * @note Calling imbue with a different locale than the one currently in
645 * use invalidates all cached data held by *this.
648 imbue(locale_type __loc)
650 std::swap(_M_locale, __loc);
655 * @brief Gets a copy of the current locale in use by the regex_traits
660 { return _M_locale; }
663 locale_type _M_locale;
666 template<typename _Ch_type>
667 bool regex_traits<_Ch_type>::
668 isctype(_Ch_type __c, char_class_type __f) const
671 using std::use_facet;
672 const ctype<_Ch_type>& __ctype(use_facet<
673 ctype<_Ch_type> >(_M_locale));
675 if (__ctype.is(__c, __f))
678 // special case of underscore in [[:w:]]
679 if (__c == __ctype.widen('_'))
681 const char* const __wb[] = "w";
682 char_class_type __wt = this->lookup_classname(__wb,
683 __wb + sizeof(__wb));
688 // special case of [[:space:]] in [[:blank:]]
689 if (__c == __ctype.isspace(__c))
691 const char* const __bb[] = "blank";
692 char_class_type __bt = this->lookup_classname(__bb,
693 __bb + sizeof(__bb));
701 template<typename _Ch_type>
702 int regex_traits<_Ch_type>::
703 value(_Ch_type __ch, int __radix) const
705 std::basic_istringstream<_Ch_type> __is(string_type(1, __ch));
709 else if (__radix == 16)
712 return __is.fail() ? -1 : __v;
715 // [7.8] Class basic_regex
717 * Objects of specializations of this class represent regular expressions
718 * constructed from sequences of character type @p _Ch_type.
720 * Storage for the regular expression is allocated and deallocated as
721 * necessary by the member functions of this class.
723 template<typename _Ch_type, typename _Rx_traits = regex_traits<_Ch_type> >
728 typedef _Ch_type value_type;
729 typedef regex_constants::syntax_option_type flag_type;
730 typedef typename _Rx_traits::locale_type locale_type;
731 typedef typename _Rx_traits::string_type string_type;
735 * tr1 [7.8.1] std [28.8.1]
738 static const regex_constants::syntax_option_type icase
739 = regex_constants::icase;
740 static const regex_constants::syntax_option_type nosubs
741 = regex_constants::nosubs;
742 static const regex_constants::syntax_option_type optimize
743 = regex_constants::optimize;
744 static const regex_constants::syntax_option_type collate
745 = regex_constants::collate;
746 static const regex_constants::syntax_option_type ECMAScript
747 = regex_constants::ECMAScript;
748 static const regex_constants::syntax_option_type basic
749 = regex_constants::basic;
750 static const regex_constants::syntax_option_type extended
751 = regex_constants::extended;
752 static const regex_constants::syntax_option_type awk
753 = regex_constants::awk;
754 static const regex_constants::syntax_option_type grep
755 = regex_constants::grep;
756 static const regex_constants::syntax_option_type egrep
757 = regex_constants::egrep;
760 // [7.8.2] construct/copy/destroy
762 * Constructs a basic regular expression that does not match any
763 * character sequence.
766 : _M_flags(regex_constants::ECMAScript), _M_pattern(), _M_mark_count(0)
770 * @brief Constructs a basic regular expression from the sequence
771 * [p, p + char_traits<_Ch_type>::length(p)) interpreted according to the
774 * @param p A pointer to the start of a C-style null-terminated string
775 * containing a regular expression.
776 * @param f Flags indicating the syntax rules and options.
778 * @throws regex_error if @p p is not a valid regular expression.
781 basic_regex(const _Ch_type* __p,
782 flag_type __f = regex_constants::ECMAScript)
783 : _M_flags(__f), _M_pattern(__p), _M_mark_count(0)
787 * @brief Constructs a basic regular expression from the sequence
788 * [p, p + len) interpreted according to the flags in @p f.
790 * @param p A pointer to the start of a string containing a regular
792 * @param len The length of the string containing the regular expression.
793 * @param f Flags indicating the syntax rules and options.
795 * @throws regex_error if @p p is not a valid regular expression.
797 basic_regex(const _Ch_type* __p, std::size_t __len, flag_type __f)
798 : _M_flags(__f) , _M_pattern(__p, __len), _M_mark_count(0)
802 * @brief Copy-constructs a basic regular expression.
804 * @param rhs A @p regex object.
806 basic_regex(const basic_regex& __rhs)
807 : _M_flags(__rhs._M_flags), _M_pattern(__rhs._M_pattern),
808 _M_mark_count(__rhs._M_mark_count)
812 * @brief Constructs a basic regular expression from the string
813 * @p s interpreted according to the flags in @p f.
815 * @param s A string containing a regular expression.
816 * @param f Flags indicating the syntax rules and options.
818 * @throws regex_error if @p s is not a valid regular expression.
820 template<typename _Ch_traits, typename _Ch_alloc>
822 basic_regex(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
823 flag_type __f = regex_constants::ECMAScript)
824 : _M_flags(__f), _M_pattern(__s.begin(), __s.end()), _M_mark_count(0)
828 * @brief Constructs a basic regular expression from the range
829 * [first, last) interpreted according to the flags in @p f.
831 * @param first The start of a range containing a valid regular
833 * @param last The end of a range containing a valid regular
835 * @param f The format flags of the regular expression.
837 * @throws regex_error if @p [first, last) is not a valid regular
840 template<typename _InputIterator>
841 basic_regex(_InputIterator __first, _InputIterator __last,
842 flag_type __f = regex_constants::ECMAScript)
843 : _M_flags(__f), _M_pattern(__first, __last), _M_mark_count(0)
846 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
848 * @brief Constructs a basic regular expression from an initializer list.
850 * @param l The initializer list.
851 * @param f The format flags of the regular expression.
853 * @throws regex_error if @p l is not a valid regular expression.
855 basic_regex(initializer_list<_Ch_type> __l,
856 flag_type __f = regex_constants::ECMAScript)
857 : _M_flags(__f), _M_pattern(__l.begin(), __l.end()), _M_mark_count(0)
862 * @brief Destroys a basic regular expression.
868 * @brief Assigns one regular expression to another.
871 operator=(const basic_regex& __rhs)
872 { return this->assign(__rhs); }
875 * @brief Replaces a regular expression with a new one constructed from
876 * a C-style null-terminated string.
878 * @param A pointer to the start of a null-terminated C-style string
879 * containing a regular expression.
882 operator=(const _Ch_type* __p)
883 { return this->assign(__p, flags()); }
886 * @brief Replaces a regular expression with a new one constructed from
889 * @param A pointer to a string containing a regular expression.
891 template<typename _Ch_typeraits, typename _Allocator>
893 operator=(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s)
894 { return this->assign(__s, flags()); }
898 * @brief the real assignment operator.
900 * @param that Another regular expression object.
903 assign(const basic_regex& __that)
905 basic_regex __tmp(__that);
911 * @brief Assigns a new regular expression to a regex object from a
912 * C-style null-terminated string containing a regular expression
915 * @param p A pointer to a C-style null-terminated string containing
916 * a regular expression pattern.
917 * @param flags Syntax option flags.
919 * @throws regex_error if p does not contain a valid regular expression
920 * pattern interpreted according to @p flags. If regex_error is thrown,
921 * *this remains unchanged.
924 assign(const _Ch_type* __p,
925 flag_type __flags = regex_constants::ECMAScript)
926 { return this->assign(string_type(__p), __flags); }
929 * @brief Assigns a new regular expression to a regex object from a
930 * C-style string containing a regular expression pattern.
932 * @param p A pointer to a C-style string containing a
933 * regular expression pattern.
934 * @param len The length of the regular expression pattern string.
935 * @param flags Syntax option flags.
937 * @throws regex_error if p does not contain a valid regular expression
938 * pattern interpreted according to @p flags. If regex_error is thrown,
939 * *this remains unchanged.
942 assign(const _Ch_type* __p, std::size_t __len, flag_type __flags)
943 { return this->assign(string_type(__p, __len), __flags); }
946 * @brief Assigns a new regular expression to a regex object from a
947 * string containing a regular expression pattern.
949 * @param s A string containing a regular expression pattern.
950 * @param flags Syntax option flags.
952 * @throws regex_error if p does not contain a valid regular expression
953 * pattern interpreted according to @p flags. If regex_error is thrown,
954 * *this remains unchanged.
956 template<typename _Ch_typeraits, typename _Allocator>
958 assign(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s,
959 flag_type __f = regex_constants::ECMAScript)
961 basic_regex __tmp(__s, __f);
967 * @brief Assigns a new regular expression to a regex object.
969 * @param first The start of a range containing a valid regular
971 * @param last The end of a range containing a valid regular
973 * @param flags Syntax option flags.
975 * @throws regex_error if p does not contain a valid regular expression
976 * pattern interpreted according to @p flags. If regex_error is thrown,
977 * the object remains unchanged.
979 template<typename _InputIterator>
981 assign(_InputIterator __first, _InputIterator __last,
982 flag_type __flags = regex_constants::ECMAScript)
983 { return this->assign(string_type(__first, __last), __flags); }
985 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
987 * @brief Assigns a new regular expression to a regex object.
989 * @param l An initializer list representing a regular expression.
990 * @param flags Syntax option flags.
992 * @throws regex_error if @p l does not contain a valid regular
993 * expression pattern interpreted according to @p flags. If regex_error
994 * is thrown, the object remains unchanged.
997 assign(initializer_list<_Ch_type> __l,
998 flag_type __f = regex_constants::ECMAScript)
999 { return this->assign(__l.begin(), __l.end(), __f); }
1002 // [7.8.4] const operations
1004 * @brief Gets the number of marked subexpressions within the regular
1009 { return _M_mark_count; }
1012 * @brief Gets the flags used to construct the regular expression
1013 * or in the last call to assign().
1017 { return _M_flags; }
1021 * @brief Imbues the regular expression object with the given locale.
1023 * @param loc A locale.
1026 imbue(locale_type __loc)
1027 { return _M_traits.imbue(__loc); }
1030 * @brief Gets the locale currently imbued in the regular expression
1035 { return _M_traits.getloc(); }
1039 * @brief Swaps the contents of two regular expression objects.
1041 * @param rhs Another regular expression object.
1044 swap(basic_regex& __rhs)
1046 std::swap(_M_flags, __rhs._M_flags);
1047 std::swap(_M_pattern, __rhs._M_pattern);
1048 std::swap(_M_mark_count, __rhs._M_mark_count);
1049 std::swap(_M_traits, __rhs._M_traits);
1054 * @brief Compiles a regular expression pattern into a NFA.
1055 * @todo Implement this function.
1061 string_type _M_pattern;
1062 unsigned int _M_mark_count;
1063 _Rx_traits _M_traits;
1066 /** @brief Standard regular expressions. */
1067 typedef basic_regex<char> regex;
1068 #ifdef _GLIBCXX_USE_WCHAR_T
1069 /** @brief Standard wide-character regular expressions. */
1070 typedef basic_regex<wchar_t> wregex;
1074 // [7.8.6] basic_regex swap
1076 * @brief Swaps the contents of two regular expression objects.
1077 * @param lhs First regular expression.
1078 * @param rhs Second regular expression.
1080 template<typename _Ch_type, typename _Rx_traits>
1082 swap(basic_regex<_Ch_type, _Rx_traits>& __lhs,
1083 basic_regex<_Ch_type, _Rx_traits>& __rhs)
1084 { __lhs.swap(__rhs); }
1087 // [7.9] Class template sub_match
1089 * A sequence of characters matched by a particular marked sub-expression.
1091 * An object of this class is essentially a pair of iterators marking a
1092 * matched subexpression within a regular expression pattern match. Such
1093 * objects can be converted to and compared with std::basic_string objects
1094 * of a similar base character type as the pattern matched by the regular
1097 * The iterators that make up the pair are the usual half-open interval
1098 * referencing the actual original pattern matched.
1100 template<typename _BiIter>
1101 class sub_match : public std::pair<_BiIter, _BiIter>
1104 typedef typename iterator_traits<_BiIter>::value_type value_type;
1105 typedef typename iterator_traits<_BiIter>::difference_type
1107 typedef _BiIter iterator;
1113 * Gets the length of the matching sequence.
1117 { return this->matched ? std::distance(this->first, this->second) : 0; }
1120 * @brief Gets the matching sequence as a string.
1122 * @returns the matching sequence as a string.
1124 * This is the implicit conversion operator. It is identical to the
1125 * str() member function except that it will want to pop up in
1126 * unexpected places and cause a great deal of confusion and cursing
1129 operator basic_string<value_type>() const
1131 return this->matched
1132 ? std::basic_string<value_type>(this->first, this->second)
1133 : std::basic_string<value_type>();
1137 * @brief Gets the matching sequence as a string.
1139 * @returns the matching sequence as a string.
1141 basic_string<value_type>
1144 return this->matched
1145 ? std::basic_string<value_type>(this->first, this->second)
1146 : std::basic_string<value_type>();
1150 * @brief Compares this and another matched sequence.
1152 * @param s Another matched sequence to compare to this one.
1154 * @retval <0 this matched sequence will collate before @p s.
1155 * @retval =0 this matched sequence is equivalent to @p s.
1156 * @retval <0 this matched sequence will collate after @p s.
1159 compare(const sub_match& __s) const
1160 { return this->str().compare(__s.str()); }
1163 * @brief Compares this sub_match to a string.
1165 * @param s A string to compare to this sub_match.
1167 * @retval <0 this matched sequence will collate before @p s.
1168 * @retval =0 this matched sequence is equivalent to @p s.
1169 * @retval <0 this matched sequence will collate after @p s.
1172 compare(const basic_string<value_type>& __s) const
1173 { return this->str().compare(__s); }
1176 * @brief Compares this sub_match to a C-style string.
1178 * @param s A C-style string to compare to this sub_match.
1180 * @retval <0 this matched sequence will collate before @p s.
1181 * @retval =0 this matched sequence is equivalent to @p s.
1182 * @retval <0 this matched sequence will collate after @p s.
1185 compare(const value_type* __s) const
1186 { return this->str().compare(__s); }
1190 /** @brief Standard regex submatch over a C-style null-terminated string. */
1191 typedef sub_match<const char*> csub_match;
1192 /** @brief Standard regex submatch over a standard string. */
1193 typedef sub_match<string::const_iterator> ssub_match;
1194 #ifdef _GLIBCXX_USE_WCHAR_T
1195 /** @brief Regex submatch over a C-style null-terminated wide string. */
1196 typedef sub_match<const wchar_t*> wcsub_match;
1197 /** @brief Regex submatch over a standard wide string. */
1198 typedef sub_match<wstring::const_iterator> wssub_match;
1201 // [7.9.2] sub_match non-member operators
1204 * @brief Tests the equivalence of two regular expression submatches.
1205 * @param lhs First regular expression submatch.
1206 * @param rhs Second regular expression submatch.
1207 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1209 template<typename _BiIter>
1211 operator==(const sub_match<_BiIter>& __lhs,
1212 const sub_match<_BiIter>& __rhs)
1213 { return __lhs.compare(__rhs) == 0; }
1216 * @brief Tests the inequivalence of two regular expression submatches.
1217 * @param lhs First regular expression submatch.
1218 * @param rhs Second regular expression submatch.
1219 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1221 template<typename _BiIter>
1223 operator!=(const sub_match<_BiIter>& __lhs,
1224 const sub_match<_BiIter>& __rhs)
1225 { return __lhs.compare(__rhs) != 0; }
1228 * @brief Tests the ordering of two regular expression submatches.
1229 * @param lhs First regular expression submatch.
1230 * @param rhs Second regular expression submatch.
1231 * @returns true if @a lhs precedes @a rhs, false otherwise.
1233 template<typename _BiIter>
1235 operator<(const sub_match<_BiIter>& __lhs,
1236 const sub_match<_BiIter>& __rhs)
1237 { return __lhs.compare(__rhs) < 0; }
1240 * @brief Tests the ordering of two regular expression submatches.
1241 * @param lhs First regular expression submatch.
1242 * @param rhs Second regular expression submatch.
1243 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1245 template<typename _BiIter>
1247 operator<=(const sub_match<_BiIter>& __lhs,
1248 const sub_match<_BiIter>& __rhs)
1249 { return __lhs.compare(__rhs) <= 0; }
1252 * @brief Tests the ordering of two regular expression submatches.
1253 * @param lhs First regular expression submatch.
1254 * @param rhs Second regular expression submatch.
1255 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1257 template<typename _BiIter>
1259 operator>=(const sub_match<_BiIter>& __lhs,
1260 const sub_match<_BiIter>& __rhs)
1261 { return __lhs.compare(__rhs) >= 0; }
1264 * @brief Tests the ordering of two regular expression submatches.
1265 * @param lhs First regular expression submatch.
1266 * @param rhs Second regular expression submatch.
1267 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1269 template<typename _BiIter>
1271 operator>(const sub_match<_BiIter>& __lhs,
1272 const sub_match<_BiIter>& __rhs)
1273 { return __lhs.compare(__rhs) > 0; }
1276 * @brief Tests the equivalence of a string and a regular expression
1278 * @param lhs A string.
1279 * @param rhs A regular expression submatch.
1280 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1282 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1284 operator==(const basic_string<
1285 typename iterator_traits<_Bi_iter>::value_type,
1286 _Ch_traits, _Ch_alloc>& __lhs,
1287 const sub_match<_Bi_iter>& __rhs)
1288 { return __lhs == __rhs.str(); }
1291 * @brief Tests the inequivalence of a string and a regular expression
1293 * @param lhs A string.
1294 * @param rhs A regular expression submatch.
1295 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1297 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1299 operator!=(const basic_string<
1300 typename iterator_traits<_Bi_iter>::value_type,
1301 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1302 { return __lhs != __rhs.str(); }
1305 * @brief Tests the ordering of a string and a regular expression submatch.
1306 * @param lhs A string.
1307 * @param rhs A regular expression submatch.
1308 * @returns true if @a lhs precedes @a rhs, false otherwise.
1310 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1312 operator<(const basic_string<
1313 typename iterator_traits<_Bi_iter>::value_type,
1314 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1315 { return __lhs < __rhs.str(); }
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 succeeds @a rhs, false otherwise.
1323 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1325 operator>(const basic_string<
1326 typename iterator_traits<_Bi_iter>::value_type,
1327 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1328 { return __lhs > __rhs.str(); }
1331 * @brief Tests the ordering of a string and a regular expression submatch.
1332 * @param lhs A string.
1333 * @param rhs A regular expression submatch.
1334 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1336 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1338 operator>=(const basic_string<
1339 typename iterator_traits<_Bi_iter>::value_type,
1340 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1341 { return __lhs >= __rhs.str(); }
1344 * @brief Tests the ordering of a string and a regular expression submatch.
1345 * @param lhs A string.
1346 * @param rhs A regular expression submatch.
1347 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1349 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1351 operator<=(const basic_string<
1352 typename iterator_traits<_Bi_iter>::value_type,
1353 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1354 { return __lhs <= __rhs.str(); }
1357 * @brief Tests the equivalence of a regular expression submatch and a
1359 * @param lhs A regular expression submatch.
1360 * @param rhs A string.
1361 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1363 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1365 operator==(const sub_match<_Bi_iter>& __lhs,
1367 typename iterator_traits<_Bi_iter>::value_type,
1368 _Ch_traits, _Ch_alloc>& __rhs)
1369 { return __lhs.str() == __rhs; }
1372 * @brief Tests the inequivalence of a regular expression submatch and a
1374 * @param lhs A regular expression submatch.
1375 * @param rhs A string.
1376 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1378 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1380 operator!=(const sub_match<_Bi_iter>& __lhs,
1382 typename iterator_traits<_Bi_iter>::value_type,
1383 _Ch_traits, _Ch_alloc>& __rhs)
1384 { return __lhs.str() != __rhs; }
1387 * @brief Tests the ordering of a regular expression submatch and a string.
1388 * @param lhs A regular expression submatch.
1389 * @param rhs A string.
1390 * @returns true if @a lhs precedes @a rhs, false otherwise.
1392 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1394 operator<(const sub_match<_Bi_iter>& __lhs,
1396 typename iterator_traits<_Bi_iter>::value_type,
1397 _Ch_traits, _Ch_alloc>& __rhs)
1398 { return __lhs.str() < __rhs; }
1401 * @brief Tests the ordering of a regular expression submatch and a string.
1402 * @param lhs A regular expression submatch.
1403 * @param rhs A string.
1404 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1406 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1408 operator>(const sub_match<_Bi_iter>& __lhs,
1410 typename iterator_traits<_Bi_iter>::value_type,
1411 _Ch_traits, _Ch_alloc>& __rhs)
1412 { return __lhs.str() > __rhs; }
1415 * @brief Tests the ordering of a regular expression submatch and a string.
1416 * @param lhs A regular expression submatch.
1417 * @param rhs A string.
1418 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1420 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1422 operator>=(const sub_match<_Bi_iter>& __lhs,
1424 typename iterator_traits<_Bi_iter>::value_type,
1425 _Ch_traits, _Ch_alloc>& __rhs)
1426 { return __lhs.str() >= __rhs; }
1429 * @brief Tests the ordering of a regular expression submatch and a string.
1430 * @param lhs A regular expression submatch.
1431 * @param rhs A string.
1432 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1434 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1436 operator<=(const sub_match<_Bi_iter>& __lhs,
1438 typename iterator_traits<_Bi_iter>::value_type,
1439 _Ch_traits, _Ch_alloc>& __rhs)
1440 { return __lhs.str() <= __rhs; }
1443 * @brief Tests the equivalence of a C string and a regular expression
1445 * @param lhs A C string.
1446 * @param rhs A regular expression submatch.
1447 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1449 template<typename _Bi_iter>
1451 operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1452 const sub_match<_Bi_iter>& __rhs)
1453 { return __lhs == __rhs.str(); }
1456 * @brief Tests the inequivalence of an iterator value and a regular
1457 * expression submatch.
1458 * @param lhs A regular expression submatch.
1459 * @param rhs A string.
1460 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1462 template<typename _Bi_iter>
1464 operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1465 const sub_match<_Bi_iter>& __rhs)
1466 { return __lhs != __rhs.str(); }
1469 * @brief Tests the ordering of a string and a regular expression submatch.
1470 * @param lhs A string.
1471 * @param rhs A regular expression submatch.
1472 * @returns true if @a lhs precedes @a rhs, false otherwise.
1474 template<typename _Bi_iter>
1476 operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1477 const sub_match<_Bi_iter>& __rhs)
1478 { return __lhs < __rhs.str(); }
1481 * @brief Tests the ordering of a string and a regular expression submatch.
1482 * @param lhs A string.
1483 * @param rhs A regular expression submatch.
1484 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1486 template<typename _Bi_iter>
1488 operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1489 const sub_match<_Bi_iter>& __rhs)
1490 { return __lhs > __rhs.str(); }
1493 * @brief Tests the ordering of a string and a regular expression submatch.
1494 * @param lhs A string.
1495 * @param rhs A regular expression submatch.
1496 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1498 template<typename _Bi_iter>
1500 operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1501 const sub_match<_Bi_iter>& __rhs)
1502 { return __lhs >= __rhs.str(); }
1505 * @brief Tests the ordering of a string and a regular expression submatch.
1506 * @param lhs A string.
1507 * @param rhs A regular expression submatch.
1508 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1510 template<typename _Bi_iter>
1512 operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1513 const sub_match<_Bi_iter>& __rhs)
1514 { return __lhs <= __rhs.str(); }
1517 * @brief Tests the equivalence of a regular expression submatch and a
1519 * @param lhs A regular expression submatch.
1520 * @param rhs A pointer to a string?
1521 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1523 template<typename _Bi_iter>
1525 operator==(const sub_match<_Bi_iter>& __lhs,
1526 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1527 { return __lhs.str() == __rhs; }
1530 * @brief Tests the inequivalence of a regular expression submatch and a
1532 * @param lhs A regular expression submatch.
1533 * @param rhs A pointer to a string.
1534 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1536 template<typename _Bi_iter>
1538 operator!=(const sub_match<_Bi_iter>& __lhs,
1539 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1540 { return __lhs.str() != __rhs; }
1543 * @brief Tests the ordering of a regular expression submatch and a string.
1544 * @param lhs A regular expression submatch.
1545 * @param rhs A string.
1546 * @returns true if @a lhs precedes @a rhs, false otherwise.
1548 template<typename _Bi_iter>
1550 operator<(const sub_match<_Bi_iter>& __lhs,
1551 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1552 { return __lhs.str() < __rhs; }
1555 * @brief Tests the ordering of a regular expression submatch and a string.
1556 * @param lhs A regular expression submatch.
1557 * @param rhs A string.
1558 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1560 template<typename _Bi_iter>
1562 operator>(const sub_match<_Bi_iter>& __lhs,
1563 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1564 { return __lhs.str() > __rhs; }
1567 * @brief Tests the ordering of a regular expression submatch and a string.
1568 * @param lhs A regular expression submatch.
1569 * @param rhs A string.
1570 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1572 template<typename _Bi_iter>
1574 operator>=(const sub_match<_Bi_iter>& __lhs,
1575 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1576 { return __lhs.str() >= __rhs; }
1579 * @brief Tests the ordering of a regular expression submatch and a string.
1580 * @param lhs A regular expression submatch.
1581 * @param rhs A string.
1582 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1584 template<typename _Bi_iter>
1586 operator<=(const sub_match<_Bi_iter>& __lhs,
1587 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1588 { return __lhs.str() <= __rhs; }
1591 * @brief Tests the equivalence of a string and a regular expression
1593 * @param lhs A string.
1594 * @param rhs A regular expression submatch.
1595 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1597 template<typename _Bi_iter>
1599 operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1600 const sub_match<_Bi_iter>& __rhs)
1601 { return __lhs == __rhs.str(); }
1604 * @brief Tests the inequivalence of a string and a regular expression
1606 * @param lhs A string.
1607 * @param rhs A regular expression submatch.
1608 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1610 template<typename _Bi_iter>
1612 operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1613 const sub_match<_Bi_iter>& __rhs)
1614 { return __lhs != __rhs.str(); }
1617 * @brief Tests the ordering of a string and a regular expression submatch.
1618 * @param lhs A string.
1619 * @param rhs A regular expression submatch.
1620 * @returns true if @a lhs precedes @a rhs, false otherwise.
1622 template<typename _Bi_iter>
1624 operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1625 const sub_match<_Bi_iter>& __rhs)
1626 { return __lhs < __rhs.str(); }
1629 * @brief Tests the ordering of a string and a regular expression submatch.
1630 * @param lhs A string.
1631 * @param rhs A regular expression submatch.
1632 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1634 template<typename _Bi_iter>
1636 operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1637 const sub_match<_Bi_iter>& __rhs)
1638 { return __lhs > __rhs.str(); }
1641 * @brief Tests the ordering of a string and a regular expression submatch.
1642 * @param lhs A string.
1643 * @param rhs A regular expression submatch.
1644 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1646 template<typename _Bi_iter>
1648 operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1649 const sub_match<_Bi_iter>& __rhs)
1650 { return __lhs >= __rhs.str(); }
1653 * @brief Tests the ordering of a string and a regular expression submatch.
1654 * @param lhs A string.
1655 * @param rhs A regular expression submatch.
1656 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1658 template<typename _Bi_iter>
1660 operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1661 const sub_match<_Bi_iter>& __rhs)
1662 { return __lhs <= __rhs.str(); }
1665 * @brief Tests the equivalence of a regular expression submatch and a
1667 * @param lhs A regular expression submatch.
1668 * @param rhs A const string reference.
1669 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1671 template<typename _Bi_iter>
1673 operator==(const sub_match<_Bi_iter>& __lhs,
1674 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1675 { return __lhs.str() == __rhs; }
1678 * @brief Tests the inequivalence of a regular expression submatch and a
1680 * @param lhs A regular expression submatch.
1681 * @param rhs A const string reference.
1682 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1684 template<typename _Bi_iter>
1686 operator!=(const sub_match<_Bi_iter>& __lhs,
1687 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1688 { return __lhs.str() != __rhs; }
1691 * @brief Tests the ordering of a regular expression submatch and a string.
1692 * @param lhs A regular expression submatch.
1693 * @param rhs A const string reference.
1694 * @returns true if @a lhs precedes @a rhs, false otherwise.
1696 template<typename _Bi_iter>
1698 operator<(const sub_match<_Bi_iter>& __lhs,
1699 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1700 { return __lhs.str() < __rhs; }
1703 * @brief Tests the ordering of a regular expression submatch and a string.
1704 * @param lhs A regular expression submatch.
1705 * @param rhs A const string reference.
1706 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1708 template<typename _Bi_iter>
1710 operator>(const sub_match<_Bi_iter>& __lhs,
1711 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1712 { return __lhs.str() > __rhs; }
1715 * @brief Tests the ordering of a regular expression submatch and a string.
1716 * @param lhs A regular expression submatch.
1717 * @param rhs A const string reference.
1718 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1720 template<typename _Bi_iter>
1722 operator>=(const sub_match<_Bi_iter>& __lhs,
1723 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1724 { return __lhs.str() >= __rhs; }
1727 * @brief Tests the ordering of a regular expression submatch and a string.
1728 * @param lhs A regular expression submatch.
1729 * @param rhs A const string reference.
1730 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1732 template<typename _Bi_iter>
1734 operator<=(const sub_match<_Bi_iter>& __lhs,
1735 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1736 { return __lhs.str() <= __rhs; }
1739 * @brief Inserts a matched string into an output stream.
1741 * @param os The output stream.
1742 * @param m A submatch string.
1744 * @returns the output stream with the submatch string inserted.
1746 template<typename _Ch_type, typename _Ch_traits, typename _Bi_iter>
1748 basic_ostream<_Ch_type, _Ch_traits>&
1749 operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os,
1750 const sub_match<_Bi_iter>& __m)
1751 { return __os << __m.str(); }
1753 // [7.10] Class template match_results
1755 * @brief The results of a match or search operation.
1757 * A collection of character sequences representing the result of a regular
1758 * expression match. Storage for the collection is allocated and freed as
1759 * necessary by the member functions of class template match_results.
1761 * This class satisfies the Sequence requirements, with the exception that
1762 * only the operations defined for a const-qualified Sequence are supported.
1764 * The sub_match object stored at index 0 represents sub-expression 0, i.e.
1765 * the whole match. In this case the sub_match member matched is always true.
1766 * The sub_match object stored at index n denotes what matched the marked
1767 * sub-expression n within the matched expression. If the sub-expression n
1768 * participated in a regular expression match then the sub_match member
1769 * matched evaluates to true, and members first and second denote the range
1770 * of characters [first, second) which formed that match. Otherwise matched
1771 * is false, and members first and second point to the end of the sequence
1772 * that was searched.
1776 template<typename _Bi_iter,
1777 typename _Allocator = allocator<sub_match<_Bi_iter> > >
1779 : private std::vector<std::tr1::sub_match<_Bi_iter>, _Allocator>
1782 typedef std::vector<std::tr1::sub_match<_Bi_iter>, _Allocator>
1787 * @name 10.? Public Types
1790 typedef sub_match<_Bi_iter> value_type;
1791 typedef typename _Allocator::const_reference const_reference;
1792 typedef const_reference reference;
1793 typedef typename _Base_type::const_iterator const_iterator;
1794 typedef const_iterator iterator;
1795 typedef typename iterator_traits<_Bi_iter>::difference_type
1797 typedef typename _Allocator::size_type size_type;
1798 typedef _Allocator allocator_type;
1799 typedef typename iterator_traits<_Bi_iter>::value_type char_type;
1800 typedef basic_string<char_type> string_type;
1805 * @name 10.1 Construction, Copying, and Destruction
1810 * @brief Constructs a default %match_results container.
1811 * @post size() returns 0 and str() returns an empty string.
1814 match_results(const _Allocator& __a = _Allocator())
1815 : _Base_type(__a), _M_matched(false)
1819 * @brief Copy constructs a %match_results.
1821 match_results(const match_results& __rhs)
1822 : _Base_type(__rhs), _M_matched(__rhs._M_matched),
1823 _M_prefix(__rhs._M_prefix), _M_suffix(__rhs._M_suffix)
1827 * @brief Assigns rhs to *this.
1830 operator=(const match_results& __rhs)
1832 match_results __tmp(__rhs);
1838 * @brief Destroys a %match_results object.
1851 * @brief Gets the number of matches and submatches.
1853 * The number of matches for a given regular expression will be either 0
1854 * if there was no match or mark_count() + 1 if a match was successful.
1855 * Some matches may be empty.
1857 * @returns the number of matches found.
1861 { return _M_matched ? _Base_type::size() + 1 : 0; }
1865 using _Base_type::max_size;
1868 * @brief Indicates if the %match_results contains no results.
1869 * @retval true The %match_results object is empty.
1870 * @retval false The %match_results object is not empty.
1874 { return size() == 0; }
1879 * @name 10.3 Element Access
1884 * @brief Gets the length of the indicated submatch.
1885 * @param sub indicates the submatch.
1887 * This function returns the length of the indicated submatch, or the
1888 * length of the entire match if @p sub is zero (the default).
1891 length(size_type __sub = 0) const
1892 { return _M_matched ? this->str(__sub).length() : 0; }
1895 * @brief Gets the offset of the beginning of the indicated submatch.
1896 * @param sub indicates the submatch.
1898 * This function returns the offset from the beginning of the target
1899 * sequence to the beginning of the submatch, unless the value of @p sub
1900 * is zero (the default), in which case this function returns the offset
1901 * from the beginning of the target sequence to the beginning of the
1905 position(size_type __sub = 0) const
1907 return _M_matched ? std::distance(this->prefix().first,
1908 (*this)[__sub].first) : 0;
1912 * @brief Gets the match or submatch converted to a string type.
1913 * @param sub indicates the submatch.
1915 * This function gets the submatch (or match, if @p sub is zero) extracted
1916 * from the target range and converted to the associated string type.
1919 str(size_type __sub = 0) const
1920 { return _M_matched ? (*this)[__sub].str() : string_type(); }
1923 * @brief Gets a %sub_match reference for the match or submatch.
1924 * @param sub indicates the submatch.
1926 * This function gets a reference to the indicated submatch, or the entire
1927 * match if @p sub is zero.
1929 * If @p sub >= size() then this function returns a %sub_match with a
1930 * special value indicating no submatch.
1933 operator[](size_type __sub) const
1934 { return _Base_type::operator[](__sub); }
1937 * @brief Gets a %sub_match representing the match prefix.
1939 * This function gets a reference to a %sub_match object representing the
1940 * part of the target range between the start of the target range and the
1941 * start of the match.
1945 { return _M_prefix; }
1948 * @brief Gets a %sub_match representing the match suffix.
1950 * This function gets a reference to a %sub_match object representing the
1951 * part of the target range between the end of the match and the end of
1956 { return _M_suffix; }
1959 * @brief Gets an iterator to the start of the %sub_match collection.
1963 { return _Base_type::begin(); }
1965 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
1967 * @brief Gets an iterator to the start of the %sub_match collection.
1971 { return _Base_type::begin(); }
1975 * @brief Gets an iterator to one-past-the-end of the collection.
1979 { return _Base_type::end(); }
1981 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
1983 * @brief Gets an iterator to one-past-the-end of the collection.
1987 { return _Base_type::end(); }
1993 * @name 10.4 Formatting
1995 * These functions perform formatted substitution of the matched character
1996 * sequences into their target. The format specifiers and escape sequences
1997 * accepted by these functions are determined by their @p flags parameter
1998 * as documented above.
2003 * @todo Implement this function.
2005 template<typename _Out_iter>
2007 format(_Out_iter __out, const string_type& __fmt,
2008 regex_constants::match_flag_type __flags
2009 = regex_constants::format_default) const;
2012 * @todo Implement this function.
2015 format(const string_type& __fmt,
2016 regex_constants::match_flag_type __flags
2017 = regex_constants::format_default) const;
2022 * @name 10.5 Allocator
2027 * @brief Gets a copy of the allocator.
2030 //get_allocator() const;
2031 using _Base_type::get_allocator;
2041 * @brief Swaps the contents of two match_results.
2044 swap(match_results& __that)
2046 _Base_type::swap(__that);
2047 std::swap(_M_matched, __that._M_matched);
2048 std::swap(_M_prefix, __that._M_prefix);
2049 std::swap(_M_suffix, __that._M_suffix);
2055 value_type _M_prefix;
2056 value_type _M_suffix;
2059 typedef match_results<const char*> cmatch;
2060 typedef match_results<string::const_iterator> smatch;
2061 #ifdef _GLIBCXX_USE_WCHAR_T
2062 typedef match_results<const wchar_t*> wcmatch;
2063 typedef match_results<wstring::const_iterator> wsmatch;
2066 // match_results comparisons
2068 * @brief Compares two match_results for equality.
2069 * @returns true if the two objects refer to the same match,
2071 * @todo Implement this function.
2073 template<typename _Bi_iter, typename _Allocator>
2075 operator==(const match_results<_Bi_iter, _Allocator>& __m1,
2076 const match_results<_Bi_iter, _Allocator>& __m2);
2079 * @brief Compares two match_results for inequality.
2080 * @returns true if the two objects do not refer to the same match,
2083 template<typename _Bi_iter, class _Allocator>
2085 operator!=(const match_results<_Bi_iter, _Allocator>& __m1,
2086 const match_results<_Bi_iter, _Allocator>& __m2)
2087 { return !(__m1 == __m2); }
2089 // [7.10.6] match_results swap
2091 * @brief Swaps two match results.
2092 * @param lhs A match result.
2093 * @param rhs A match result.
2095 * The contents of the two match_results objects are swapped.
2097 template<typename _Bi_iter, typename _Allocator>
2099 swap(match_results<_Bi_iter, _Allocator>& __lhs,
2100 match_results<_Bi_iter, _Allocator>& __rhs)
2101 { __lhs.swap(__rhs); }
2103 // [7.11.2] Function template regex_match
2105 * @name Matching, Searching, and Replacing
2110 * @brief Determines if there is a match between the regular expression @p e
2111 * and all of the character sequence [first, last).
2113 * @param first Beginning of the character sequence to match.
2114 * @param last One-past-the-end of the character sequence to match.
2115 * @param m The match results.
2116 * @param re The regular expression.
2117 * @param flags Controls how the regular expression is matched.
2119 * @retval true A match exists.
2120 * @retval false Otherwise.
2122 * @throws an exception of type regex_error.
2124 * @todo Implement this function.
2126 template<typename _Bi_iter, typename _Allocator,
2127 typename _Ch_type, typename _Rx_traits>
2129 regex_match(_Bi_iter __first, _Bi_iter __last,
2130 match_results<_Bi_iter, _Allocator>& __m,
2131 const basic_regex<_Ch_type, _Rx_traits>& __re,
2132 regex_constants::match_flag_type __flags
2133 = regex_constants::match_default);
2136 * @brief Indicates if there is a match between the regular expression @p e
2137 * and all of the character sequence [first, last).
2139 * @param first Beginning of the character sequence to match.
2140 * @param last One-past-the-end of the character sequence to match.
2141 * @param re The regular expression.
2142 * @param flags Controls how the regular expression is matched.
2144 * @retval true A match exists.
2145 * @retval false Otherwise.
2147 * @throws an exception of type regex_error.
2149 template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
2151 regex_match(_Bi_iter __first, _Bi_iter __last,
2152 const basic_regex<_Ch_type, _Rx_traits>& __re,
2153 regex_constants::match_flag_type __flags
2154 = regex_constants::match_default)
2156 match_results<_Bi_iter> __what;
2157 return regex_match(__first, __last, __what, __re, __flags);
2161 * @brief Determines if there is a match between the regular expression @p e
2162 * and a C-style null-terminated string.
2164 * @param s The C-style null-terminated string to match.
2165 * @param m The match results.
2166 * @param re The regular expression.
2167 * @param f Controls how the regular expression is matched.
2169 * @retval true A match exists.
2170 * @retval false Otherwise.
2172 * @throws an exception of type regex_error.
2174 template<typename _Ch_type, typename _Allocator, typename _Rx_traits>
2176 regex_match(const _Ch_type* __s,
2177 match_results<const _Ch_type*, _Allocator>& __m,
2178 const basic_regex<_Ch_type, _Rx_traits>& __re,
2179 regex_constants::match_flag_type __f
2180 = regex_constants::match_default)
2181 { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); }
2184 * @brief Determines if there is a match between the regular expression @p e
2187 * @param s The string to match.
2188 * @param m The match results.
2189 * @param re The regular expression.
2190 * @param flags Controls how the regular expression is matched.
2192 * @retval true A match exists.
2193 * @retval false Otherwise.
2195 * @throws an exception of type regex_error.
2197 template<typename _Ch_traits, typename _Ch_alloc,
2198 typename _Allocator, typename _Ch_type, typename _Rx_traits>
2200 regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
2201 match_results<typename basic_string<_Ch_type,
2202 _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
2203 const basic_regex<_Ch_type, _Rx_traits>& __re,
2204 regex_constants::match_flag_type __flags
2205 = regex_constants::match_default)
2206 { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }
2209 * @brief Indicates if there is a match between the regular expression @p e
2210 * and a C-style null-terminated string.
2212 * @param s The C-style null-terminated string to match.
2213 * @param re The regular expression.
2214 * @param f Controls how the regular expression is matched.
2216 * @retval true A match exists.
2217 * @retval false Otherwise.
2219 * @throws an exception of type regex_error.
2221 template<typename _Ch_type, class _Rx_traits>
2223 regex_match(const _Ch_type* __s,
2224 const basic_regex<_Ch_type, _Rx_traits>& __re,
2225 regex_constants::match_flag_type __f
2226 = regex_constants::match_default)
2227 { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); }
2230 * @brief Indicates if there is a match between the regular expression @p e
2233 * @param s [IN] The string to match.
2234 * @param re [IN] The regular expression.
2235 * @param flags [IN] Controls how the regular expression is matched.
2237 * @retval true A match exists.
2238 * @retval false Otherwise.
2240 * @throws an exception of type regex_error.
2242 template<typename _Ch_traits, typename _Str_allocator,
2243 typename _Ch_type, typename _Rx_traits>
2245 regex_match(const basic_string<_Ch_type, _Ch_traits, _Str_allocator>& __s,
2246 const basic_regex<_Ch_type, _Rx_traits>& __re,
2247 regex_constants::match_flag_type __flags
2248 = regex_constants::match_default)
2249 { return regex_match(__s.begin(), __s.end(), __re, __flags); }
2251 // [7.11.3] Function template regex_search
2253 * Searches for a regular expression within a range.
2254 * @param first [IN] The start of the string to search.
2255 * @param last [IN] One-past-the-end of the string to search.
2256 * @param m [OUT] The match results.
2257 * @param re [IN] The regular expression to search for.
2258 * @param flags [IN] Search policy flags.
2259 * @retval true A match was found within the string.
2260 * @retval false No match was found within the string, the content of %m is
2263 * @throws an exception of type regex_error.
2265 * @todo Implement this function.
2267 template<typename _Bi_iter, typename _Allocator,
2268 typename _Ch_type, typename _Rx_traits>
2270 regex_search(_Bi_iter __first, _Bi_iter __last,
2271 match_results<_Bi_iter, _Allocator>& __m,
2272 const basic_regex<_Ch_type, _Rx_traits>& __re,
2273 regex_constants::match_flag_type __flags
2274 = regex_constants::match_default);
2277 * Searches for a regular expression within a range.
2278 * @param first [IN] The start of the string to search.
2279 * @param last [IN] One-past-the-end of the string to search.
2280 * @param re [IN] The regular expression to search for.
2281 * @param flags [IN] Search policy flags.
2282 * @retval true A match was found within the string.
2283 * @retval false No match was found within the string.
2286 * @throws an exception of type regex_error.
2288 template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
2290 regex_search(_Bi_iter __first, _Bi_iter __last,
2291 const basic_regex<_Ch_type, _Rx_traits>& __re,
2292 regex_constants::match_flag_type __flags
2293 = regex_constants::match_default)
2295 match_results<_Bi_iter> __what;
2296 return regex_search(__first, __last, __what, __re, __flags);
2300 * @brief Searches for a regular expression within a C-string.
2301 * @param s [IN] A C-string to search for the regex.
2302 * @param m [OUT] The set of regex matches.
2303 * @param e [IN] The regex to search for in @p s.
2304 * @param f [IN] The search flags.
2305 * @retval true A match was found within the string.
2306 * @retval false No match was found within the string, the content of %m is
2310 * @throws an exception of type regex_error.
2312 template<typename _Ch_type, class _Allocator, class _Rx_traits>
2314 regex_search(const _Ch_type* __s,
2315 match_results<const _Ch_type*, _Allocator>& __m,
2316 const basic_regex<_Ch_type, _Rx_traits>& __e,
2317 regex_constants::match_flag_type __f
2318 = regex_constants::match_default)
2319 { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
2322 * @brief Searches for a regular expression within a C-string.
2323 * @param s [IN] The C-string to search.
2324 * @param e [IN] The regular expression to search for.
2325 * @param f [IN] Search policy flags.
2326 * @retval true A match was found within the string.
2327 * @retval false No match was found within the string.
2330 * @throws an exception of type regex_error.
2332 template<typename _Ch_type, typename _Rx_traits>
2334 regex_search(const _Ch_type* __s,
2335 const basic_regex<_Ch_type, _Rx_traits>& __e,
2336 regex_constants::match_flag_type __f
2337 = regex_constants::match_default)
2338 { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); }
2341 * @brief Searches for a regular expression within a string.
2342 * @param s [IN] The string to search.
2343 * @param e [IN] The regular expression to search for.
2344 * @param flags [IN] Search policy flags.
2345 * @retval true A match was found within the string.
2346 * @retval false No match was found within the string.
2349 * @throws an exception of type regex_error.
2351 template<typename _Ch_traits, typename _String_allocator,
2352 typename _Ch_type, typename _Rx_traits>
2354 regex_search(const basic_string<_Ch_type, _Ch_traits,
2355 _String_allocator>& __s,
2356 const basic_regex<_Ch_type, _Rx_traits>& __e,
2357 regex_constants::match_flag_type __flags
2358 = regex_constants::match_default)
2359 { return regex_search(__s.begin(), __s.end(), __e, __flags); }
2362 * @brief Searches for a regular expression within a string.
2363 * @param s [IN] A C++ string to search for the regex.
2364 * @param m [OUT] The set of regex matches.
2365 * @param e [IN] The regex to search for in @p s.
2366 * @param f [IN] The search flags.
2367 * @retval true A match was found within the string.
2368 * @retval false No match was found within the string, the content of %m is
2371 * @throws an exception of type regex_error.
2373 template<typename _Ch_traits, typename _Ch_alloc,
2374 typename _Allocator, typename _Ch_type,
2375 typename _Rx_traits>
2377 regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
2378 match_results<typename basic_string<_Ch_type,
2379 _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
2380 const basic_regex<_Ch_type, _Rx_traits>& __e,
2381 regex_constants::match_flag_type __f
2382 = regex_constants::match_default)
2383 { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
2385 // tr1 [7.11.4] std [28.11.4] Function template regex_replace
2396 * @throws an exception of type regex_error.
2398 * @todo Implement this function.
2400 template<typename _Out_iter, typename _Bi_iter,
2401 typename _Rx_traits, typename _Ch_type>
2403 regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
2404 const basic_regex<_Ch_type, _Rx_traits>& __e,
2405 const basic_string<_Ch_type>& __fmt,
2406 regex_constants::match_flag_type __flags
2407 = regex_constants::match_default);
2416 * @returns a copy of string @p s with replacements.
2418 * @throws an exception of type regex_error.
2420 template<typename _Rx_traits, typename _Ch_type>
2421 inline basic_string<_Ch_type>
2422 regex_replace(const basic_string<_Ch_type>& __s,
2423 const basic_regex<_Ch_type, _Rx_traits>& __e,
2424 const basic_string<_Ch_type>& __fmt,
2425 regex_constants::match_flag_type __flags
2426 = regex_constants::match_default)
2428 std::string __result;
2429 regex_replace(std::back_inserter(__result),
2430 __s.begin(), __s.end(), __e, __fmt, __flags);
2436 // tr1 [7.12.1] std [28.12] Class template regex_iterator
2438 * An iterator adaptor that will provide repeated calls of regex_search over
2439 * a range until no more matches remain.
2441 template<typename _Bi_iter,
2442 typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2443 typename _Rx_traits = regex_traits<_Ch_type> >
2444 class regex_iterator
2447 typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
2448 typedef match_results<_Bi_iter> value_type;
2449 typedef std::ptrdiff_t difference_type;
2450 typedef const value_type* pointer;
2451 typedef const value_type& reference;
2452 typedef std::forward_iterator_tag iterator_category;
2456 * @brief Provides a singular iterator, useful for indicating
2457 * one-past-the-end of a range.
2458 * @todo Implement this function.
2464 * Constructs a %regex_iterator...
2465 * @param a [IN] The start of a text range to search.
2466 * @param b [IN] One-past-the-end of the text range to search.
2467 * @param re [IN] The regular expression to match.
2468 * @param m [IN] Policy flags for match rules.
2469 * @todo Implement this function.
2472 regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2473 regex_constants::match_flag_type __m
2474 = regex_constants::match_default);
2477 * Copy constructs a %regex_iterator.
2478 * @todo Implement this function.
2481 regex_iterator(const regex_iterator& __rhs);
2484 * @todo Implement this function.
2488 operator=(const regex_iterator& __rhs);
2491 * @todo Implement this function.
2495 operator==(const regex_iterator& __rhs);
2498 * @todo Implement this function.
2502 operator!=(const regex_iterator& __rhs);
2505 * @todo Implement this function.
2512 * @todo Implement this function.
2519 * @todo Implement this function.
2526 * @todo Implement this function.
2533 // these members are shown for exposition only:
2536 const regex_type* pregex;
2537 regex_constants::match_flag_type flags;
2538 match_results<_Bi_iter> match;
2541 typedef regex_iterator<const char*> cregex_iterator;
2542 typedef regex_iterator<string::const_iterator> sregex_iterator;
2543 #ifdef _GLIBCXX_USE_WCHAR_T
2544 typedef regex_iterator<const wchar_t*> wcregex_iterator;
2545 typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
2548 // [7.12.2] Class template regex_token_iterator
2550 * Iterates over submatches in a range (or @a splits a text string).
2552 * The purpose of this iterator is to enumerate all, or all specified,
2553 * matches of a regular expression within a text range. The dereferenced
2554 * value of an iterator of this class is a std::tr1::sub_match object.
2556 template<typename _Bi_iter,
2557 typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2558 typename _Rx_traits = regex_traits<_Ch_type> >
2559 class regex_token_iterator
2562 typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
2563 typedef sub_match<_Bi_iter> value_type;
2564 typedef std::ptrdiff_t difference_type;
2565 typedef const value_type* pointer;
2566 typedef const value_type& reference;
2567 typedef std::forward_iterator_tag iterator_category;
2571 * @brief Default constructs a %regex_token_iterator.
2572 * @todo Implement this function.
2574 * A default-constructed %regex_token_iterator is a singular iterator
2575 * that will compare equal to the one-past-the-end value for any
2576 * iterator of the same type.
2578 regex_token_iterator();
2581 * Constructs a %regex_token_iterator...
2582 * @param a [IN] The start of the text to search.
2583 * @param b [IN] One-past-the-end of the text to search.
2584 * @param re [IN] The regular expression to search for.
2585 * @param submatch [IN] Which submatch to return. There are some
2586 * special values for this parameter:
2587 * - -1 each enumerated subexpression does NOT
2588 * match the regular expression (aka field
2590 * - 0 the entire string matching the
2591 * subexpression is returned for each match
2593 * - >0 enumerates only the indicated
2594 * subexpression from a match within the text.
2595 * @param m [IN] Policy flags for match rules.
2597 * @todo Implement this function.
2600 regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2602 regex_constants::match_flag_type __m
2603 = regex_constants::match_default);
2606 * Constructs a %regex_token_iterator...
2607 * @param a [IN] The start of the text to search.
2608 * @param b [IN] One-past-the-end of the text to search.
2609 * @param re [IN] The regular expression to search for.
2610 * @param submatches [IN] A list of subexpressions to return for each
2611 * regular expression match within the text.
2612 * @param m [IN] Policy flags for match rules.
2614 * @todo Implement this function.
2617 regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2618 const regex_type& __re,
2619 const std::vector<int>& __submatches,
2620 regex_constants::match_flag_type __m
2621 = regex_constants::match_default);
2624 * Constructs a %regex_token_iterator...
2625 * @param a [IN] The start of the text to search.
2626 * @param b [IN] One-past-the-end of the text to search.
2627 * @param re [IN] The regular expression to search for.
2628 * @param submatches [IN] A list of subexpressions to return for each
2629 * regular expression match within the text.
2630 * @param m [IN] Policy flags for match rules.
2632 * @todo Implement this function.
2635 template<std::size_t _Nm>
2636 regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2637 const regex_type& __re,
2638 const int (&__submatches)[_Nm],
2639 regex_constants::match_flag_type __m
2640 = regex_constants::match_default);
2643 * @brief Copy constructs a %regex_token_iterator.
2644 * @param rhs [IN] A %regex_token_iterator to copy.
2645 * @todo Implement this function.
2647 regex_token_iterator(const regex_token_iterator& __rhs);
2650 * @brief Assigns a %regex_token_iterator to another.
2651 * @param rhs [IN] A %regex_token_iterator to copy.
2652 * @todo Implement this function.
2654 regex_token_iterator&
2655 operator=(const regex_token_iterator& __rhs);
2658 * @brief Compares a %regex_token_iterator to another for equality.
2659 * @todo Implement this function.
2662 operator==(const regex_token_iterator& __rhs);
2665 * @brief Compares a %regex_token_iterator to another for inequality.
2666 * @todo Implement this function.
2669 operator!=(const regex_token_iterator& __rhs);
2672 * @brief Dereferences a %regex_token_iterator.
2673 * @todo Implement this function.
2679 * @brief Selects a %regex_token_iterator member.
2680 * @todo Implement this function.
2686 * @brief Increments a %regex_token_iterator.
2687 * @todo Implement this function.
2689 regex_token_iterator&
2693 * @brief Postincrements a %regex_token_iterator.
2694 * @todo Implement this function.
2696 regex_token_iterator
2699 private: // data members for exposition only:
2700 typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> position_iterator;
2702 position_iterator __position;
2703 const value_type* __result;
2704 value_type __suffix;
2706 std::vector<int> __subs;
2709 /** @brief Token iterator for C-style NULL-terminated strings. */
2710 typedef regex_token_iterator<const char*> cregex_token_iterator;
2711 /** @brief Token iterator for standard strings. */
2712 typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
2713 #ifdef _GLIBCXX_USE_WCHAR_T
2714 /** @brief Token iterator for C-style NULL-terminated wide strings. */
2715 typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
2716 /** @brief Token iterator for standard wide-character strings. */
2717 typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
2724 #endif // _GLIBCXX_TR1_REGEX