1 // class template regex -*- C++ -*-
3 // Copyright (C) 2007, 2008, 2009 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/>.
26 * @file tr1_impl/regex
27 * @brief The common implementation file for tr1 and std regular expressions.
29 * This is an internal header file, included by other library headers.
30 * You should not attempt to use it directly.
35 _GLIBCXX_BEGIN_NAMESPACE_TR1
38 * @defgroup tr1_regex Regular Expressions
39 * A facility for performing regular expression pattern matching.
43 /** @namespace std::regex_constants
44 * @brief ISO C++ 0x entities sub namespace for regex.
46 namespace regex_constants
49 * @name 5.1 Regular Expression Syntax Options
68 * @brief This is a bitmask type indicating how to interpret the regex.
70 * The @c syntax_option_type is implementation defined but it is valid to
71 * perform bitwise operations on these values and expect the right thing to
74 * A valid value of type syntax_option_type shall have exactly one of the
75 * elements @c ECMAScript, @c basic, @c extended, @c awk, @c grep, @c egrep
78 typedef unsigned int syntax_option_type;
81 * Specifies that the matching of regular expressions against a character
82 * sequence shall be performed without regard to case.
84 static const syntax_option_type icase = 1 << _S_icase;
87 * Specifies that when a regular expression is matched against a character
88 * container sequence, no sub-expression matches are to be stored in the
89 * supplied match_results structure.
91 static const syntax_option_type nosubs = 1 << _S_nosubs;
94 * Specifies that the regular expression engine should pay more attention to
95 * the speed with which regular expressions are matched, and less to the
96 * speed with which regular expression objects are constructed. Otherwise
97 * it has no detectable effect on the program output.
99 static const syntax_option_type optimize = 1 << _S_optimize;
102 * Specifies that character ranges of the form [a-b] should be locale
105 static const syntax_option_type collate = 1 << _S_collate;
108 * Specifies that the grammar recognized by the regular expression engine is
109 * that used by ECMAScript in ECMA-262 [Ecma International, ECMAScript
110 * Language Specification, Standard Ecma-262, third edition, 1999], as
111 * modified in tr1 section [7.13]. This grammar is similar to that defined
112 * in the PERL scripting language but extended with elements found in the
113 * POSIX regular expression grammar.
115 static const syntax_option_type ECMAScript = 1 << _S_ECMAScript;
118 * Specifies that the grammar recognized by the regular expression engine is
119 * that used by POSIX basic regular expressions in IEEE Std 1003.1-2001,
120 * Portable Operating System Interface (POSIX), Base Definitions and
121 * Headers, Section 9, Regular Expressions [IEEE, Information Technology --
122 * Portable Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
124 static const syntax_option_type basic = 1 << _S_basic;
127 * Specifies that the grammar recognized by the regular expression engine is
128 * that used by POSIX extended regular expressions in IEEE Std 1003.1-2001,
129 * Portable Operating System Interface (POSIX), Base Definitions and Headers,
130 * Section 9, Regular Expressions.
132 static const syntax_option_type extended = 1 << _S_extended;
135 * Specifies that the grammar recognized by the regular expression engine is
136 * that used by POSIX utility awk in IEEE Std 1003.1-2001. This option is
137 * identical to syntax_option_type extended, except that C-style escape
138 * sequences are supported. These sequences are, explicitly, "\\", "\a",
139 * "\b", "\f", "\n", "\r", "\t" , "\v", "\"", "'",
140 * and "\ddd" (where ddd is one, two, or three octal digits).
142 static const syntax_option_type awk = 1 << _S_awk;
145 * Specifies that the grammar recognized by the regular expression engine is
146 * that used by POSIX utility grep in IEEE Std 1003.1-2001. This option is
147 * identical to syntax_option_type basic, except that newlines are treated
150 static const syntax_option_type grep = 1 << _S_grep;
153 * Specifies that the grammar recognized by the regular expression engine is
154 * that used by POSIX utility grep when given the -E option in
155 * IEEE Std 1003.1-2001. This option is identical to syntax_option_type
156 * extended, except that newlines are treated as whitespace.
158 static const syntax_option_type egrep = 1 << _S_egrep;
163 * @name 5.2 Matching Rules
165 * Matching a regular expression against a sequence of characters [first,
166 * last) proceeds according to the rules of the grammar specified for the
167 * regular expression object, modified according to the effects listed
168 * below for any bitmask elements set.
190 * @brief This is a bitmask type indicating regex matching rules.
192 * The @c match_flag_type is implementation defined but it is valid to
193 * perform bitwise operations on these values and expect the right thing to
196 typedef std::bitset<_S_match_flag_last> match_flag_type;
199 * The default matching rules.
201 static const match_flag_type match_default = 0;
204 * The first character in the sequence [first, last) is treated as though it
205 * is not at the beginning of a line, so the character "^" in the regular
206 * expression shall not match [first, first).
208 static const match_flag_type match_not_bol = 1 << _S_not_bol;
211 * The last character in the sequence [first, last) is treated as though it
212 * is not at the end of a line, so the character "$" in the regular
213 * expression shall not match [last, last).
215 static const match_flag_type match_not_eol = 1 << _S_not_eol;
218 * The expression "\b" is not matched against the sub-sequence
221 static const match_flag_type match_not_bow = 1 << _S_not_bow;
224 * The expression "\b" should not be matched against the sub-sequence
227 static const match_flag_type match_not_eow = 1 << _S_not_eow;
230 * If more than one match is possible then any match is an acceptable
233 static const match_flag_type match_any = 1 << _S_any;
236 * The expression does not match an empty sequence.
238 static const match_flag_type match_not_null = 1 << _S_not_null;
241 * The expression only matches a sub-sequence that begins at first .
243 static const match_flag_type match_continuous = 1 << _S_continuous;
246 * --first is a valid iterator position. When this flag is set then the
247 * flags match_not_bol and match_not_bow are ignored by the regular
248 * expression algorithms 7.11 and iterators 7.12.
250 static const match_flag_type match_prev_avail = 1 << _S_prev_avail;
253 * When a regular expression match is to be replaced by a new string, the
254 * new string is constructed using the rules used by the ECMAScript replace
255 * function in ECMA- 262 [Ecma International, ECMAScript Language
256 * Specification, Standard Ecma-262, third edition, 1999], part 15.5.4.11
257 * String.prototype.replace. In addition, during search and replace
258 * operations all non-overlapping occurrences of the regular expression
259 * are located and replaced, and sections of the input that did not match
260 * the expression are copied unchanged to the output string.
262 * Format strings (from ECMA-262 [15.5.4.11]):
263 * @li $$ The dollar-sign itself ($)
264 * @li $& The matched substring.
265 * @li $` The portion of <em>string</em> that precedes the matched substring.
266 * This would be match_results::prefix().
267 * @li $' The portion of <em>string</em> that follows the matched substring.
268 * This would be match_results::suffix().
269 * @li $n The nth capture, where n is in [1,9] and $n is not followed by a
270 * decimal digit. If n <= match_results::size() and the nth capture
271 * is undefined, use the empty string instead. If n >
272 * match_results::size(), the result is implementation-defined.
273 * @li $nn The nnth capture, where nn is a two-digit decimal number on
274 * [01, 99]. If nn <= match_results::size() and the nth capture is
275 * undefined, use the empty string instead. If
276 * nn > match_results::size(), the result is implementation-defined.
278 static const match_flag_type format_default = 0;
281 * When a regular expression match is to be replaced by a new string, the
282 * new string is constructed using the rules used by the POSIX sed utility
283 * in IEEE Std 1003.1- 2001 [IEEE, Information Technology -- Portable
284 * Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
286 static const match_flag_type format_sed = 1 << _S_sed;
289 * During a search and replace operation, sections of the character
290 * container sequence being searched that do not match the regular
291 * expression shall not be copied to the output string.
293 static const match_flag_type format_no_copy = 1 << _S_no_copy;
296 * When specified during a search and replace operation, only the first
297 * occurrence of the regular expression shall be replaced.
299 static const match_flag_type format_first_only = 1 << _S_first_only;
304 * @name 5.3 Error Types
326 /** The expression contained an invalid collating element name. */
327 static const error_type error_collate(_S_error_collate);
329 /** The expression contained an invalid character class name. */
330 static const error_type error_ctype(_S_error_ctype);
333 * The expression contained an invalid escaped character, or a trailing
336 static const error_type error_escape(_S_error_escape);
338 /** The expression contained an invalid back reference. */
339 static const error_type error_backref(_S_error_backref);
341 /** The expression contained mismatched [ and ]. */
342 static const error_type error_brack(_S_error_brack);
344 /** The expression contained mismatched ( and ). */
345 static const error_type error_paren(_S_error_paren);
347 /** The expression contained mismatched { and } */
348 static const error_type error_brace(_S_error_brace);
350 /** The expression contained an invalid range in a {} expression. */
351 static const error_type error_badbrace(_S_error_badbrace);
354 * The expression contained an invalid character range,
355 * such as [b-a] in most encodings.
357 static const error_type error_range(_S_error_range);
360 * There was insufficient memory to convert the expression into a
361 * finite state machine.
363 static const error_type error_space(_S_error_space);
366 * One of "*?+{" was not preceded by a valid regular expression.
368 static const error_type error_badrepeat(_S_error_badrepeat);
371 * The complexity of an attempted match against a regular expression
372 * exceeded a pre-set level.
374 static const error_type error_complexity(_S_error_complexity);
377 * There was insufficient memory to determine whether the
378 * regular expression could match the specified character sequence.
380 static const error_type error_stack(_S_error_stack);
386 // [7.8] Class regex_error
388 * @brief A regular expression exception class.
389 * @ingroup exceptions
391 * The regular expression library throws objects of this class on error.
394 : public std::runtime_error
398 * @brief Constructs a regex_error object.
400 * @param ecode the regex error code.
403 regex_error(regex_constants::error_type __ecode)
404 : std::runtime_error("regex_error"), _M_code(__ecode)
408 * @brief Gets the regex error code.
410 * @returns the regex error code.
412 regex_constants::error_type
417 regex_constants::error_type _M_code;
420 // [7.7] Class regex_traits
422 * @brief Describes aspects of a regular expression.
424 * A regular expression traits class that satisfies the requirements of tr1
427 * The class %regex is parameterized around a set of related types and
428 * functions used to complete the definition of its semantics. This class
429 * satisfies the requirements of such a traits class.
431 template<typename _Ch_type>
435 typedef _Ch_type char_type;
436 typedef std::basic_string<char_type> string_type;
437 typedef std::locale locale_type;
438 typedef std::ctype_base::mask char_class_type;
442 * @brief Constructs a default traits object.
448 * @brief Gives the length of a C-style string starting at @p __p.
450 * @param __p a pointer to the start of a character sequence.
452 * @returns the number of characters between @p *__p and the first
453 * default-initialized value of type @p char_type. In other words, uses
454 * the C-string algorithm for determining the length of a sequence of
458 length(const char_type* __p)
459 { return string_type::traits_type::length(__p); }
462 * @brief Performs the identity translation.
464 * @param c A character to the locale-specific character set.
469 translate(char_type __c) const
473 * @brief Translates a character into a case-insensitive equivalent.
475 * @param c A character to the locale-specific character set.
477 * @returns the locale-specific lower-case equivalent of c.
478 * @throws std::bad_cast if the imbued locale does not support the ctype
482 translate_nocase(char_type __c) const
485 using std::use_facet;
486 return use_facet<ctype<char_type> >(_M_locale).tolower(__c);
490 * @brief Gets a sort key for a character sequence.
492 * @param first beginning of the character sequence.
493 * @param last one-past-the-end of the character sequence.
495 * Returns a sort key for the character sequence designated by the
496 * iterator range [F1, F2) such that if the character sequence [G1, G2)
497 * sorts before the character sequence [H1, H2) then
498 * v.transform(G1, G2) < v.transform(H1, H2).
500 * What this really does is provide a more efficient way to compare a
501 * string to multiple other strings in locales with fancy collation
502 * rules and equivalence classes.
504 * @returns a locale-specific sort key equivalent to the input range.
506 * @throws std::bad_cast if the current locale does not have a collate
509 template<typename _Fwd_iter>
511 transform(_Fwd_iter __first, _Fwd_iter __last) const
514 using std::use_facet;
515 const collate<_Ch_type>& __c(use_facet<
516 collate<_Ch_type> >(_M_locale));
517 string_type __s(__first, __last);
518 return __c.transform(__s.data(), __s.data() + __s.size());
524 * @param first beginning of the character sequence.
525 * @param last one-past-the-end of the character sequence.
527 * Effects: if typeid(use_facet<collate<_Ch_type> >) ==
528 * typeid(collate_byname<_Ch_type>) and the form of the sort key
529 * returned by collate_byname<_Ch_type>::transform(first, last) is known
530 * and can be converted into a primary sort key then returns that key,
531 * otherwise returns an empty string. WTF??
533 * @todo Implement this function.
535 template<typename _Fwd_iter>
537 transform_primary(_Fwd_iter __first, _Fwd_iter __last) const;
540 * @brief Gets a collation element by name.
542 * @param first beginning of the collation element name.
543 * @param last one-past-the-end of the collation element name.
545 * @returns a sequence of one or more characters that represents the
546 * collating element consisting of the character sequence designated by
547 * the iterator range [first, last). Returns an empty string if the
548 * character sequence is not a valid collating element.
550 * @todo Implement this function.
552 template<typename _Fwd_iter>
554 lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const;
557 * @brief Maps one or more characters to a named character
560 * @param first beginning of the character sequence.
561 * @param last one-past-the-end of the character sequence.
563 * @returns an unspecified value that represents the character
564 * classification named by the character sequence designated by the
565 * iterator range [first, last). The value returned shall be independent
566 * of the case of the characters in the character sequence. If the name
567 * is not recognized then returns a value that compares equal to 0.
569 * At least the following names (or their wide-character equivalent) are
587 * @todo Implement this function.
589 template<typename _Fwd_iter>
591 lookup_classname(_Fwd_iter __first, _Fwd_iter __last) const;
594 * @brief Determines if @p c is a member of an identified class.
596 * @param c a character.
597 * @param f a class type (as returned from lookup_classname).
599 * @returns true if the character @p c is a member of the classification
600 * represented by @p f, false otherwise.
602 * @throws std::bad_cast if the current locale does not have a ctype
606 isctype(_Ch_type __c, char_class_type __f) const;
609 * @brief Converts a digit to an int.
611 * @param ch a character representing a digit.
612 * @param radix the radix if the numeric conversion (limited to 8, 10,
615 * @returns the value represented by the digit ch in base radix if the
616 * character ch is a valid digit in base radix; otherwise returns -1.
619 value(_Ch_type __ch, int __radix) const;
622 * @brief Imbues the regex_traits object with a copy of a new locale.
624 * @param loc A locale.
626 * @returns a copy of the previous locale in use by the regex_traits
629 * @note Calling imbue with a different locale than the one currently in
630 * use invalidates all cached data held by *this.
633 imbue(locale_type __loc)
635 std::swap(_M_locale, __loc);
640 * @brief Gets a copy of the current locale in use by the regex_traits
645 { return _M_locale; }
648 locale_type _M_locale;
651 template<typename _Ch_type>
652 bool regex_traits<_Ch_type>::
653 isctype(_Ch_type __c, char_class_type __f) const
656 using std::use_facet;
657 const ctype<_Ch_type>& __ctype(use_facet<
658 ctype<_Ch_type> >(_M_locale));
660 if (__ctype.is(__c, __f))
663 // special case of underscore in [[:w:]]
664 if (__c == __ctype.widen('_'))
666 const char* const __wb[] = "w";
667 char_class_type __wt = this->lookup_classname(__wb,
668 __wb + sizeof(__wb));
673 // special case of [[:space:]] in [[:blank:]]
674 if (__c == __ctype.isspace(__c))
676 const char* const __bb[] = "blank";
677 char_class_type __bt = this->lookup_classname(__bb,
678 __bb + sizeof(__bb));
686 template<typename _Ch_type>
687 int regex_traits<_Ch_type>::
688 value(_Ch_type __ch, int __radix) const
690 std::basic_istringstream<_Ch_type> __is(string_type(1, __ch));
694 else if (__radix == 16)
697 return __is.fail() ? -1 : __v;
700 // [7.8] Class basic_regex
702 * Objects of specializations of this class represent regular expressions
703 * constructed from sequences of character type @p _Ch_type.
705 * Storage for the regular expression is allocated and deallocated as
706 * necessary by the member functions of this class.
708 template<typename _Ch_type, typename _Rx_traits = regex_traits<_Ch_type> >
713 typedef _Ch_type value_type;
714 typedef regex_constants::syntax_option_type flag_type;
715 typedef typename _Rx_traits::locale_type locale_type;
716 typedef typename _Rx_traits::string_type string_type;
720 * tr1 [7.8.1] std [28.8.1]
723 static const regex_constants::syntax_option_type icase
724 = regex_constants::icase;
725 static const regex_constants::syntax_option_type nosubs
726 = regex_constants::nosubs;
727 static const regex_constants::syntax_option_type optimize
728 = regex_constants::optimize;
729 static const regex_constants::syntax_option_type collate
730 = regex_constants::collate;
731 static const regex_constants::syntax_option_type ECMAScript
732 = regex_constants::ECMAScript;
733 static const regex_constants::syntax_option_type basic
734 = regex_constants::basic;
735 static const regex_constants::syntax_option_type extended
736 = regex_constants::extended;
737 static const regex_constants::syntax_option_type awk
738 = regex_constants::awk;
739 static const regex_constants::syntax_option_type grep
740 = regex_constants::grep;
741 static const regex_constants::syntax_option_type egrep
742 = regex_constants::egrep;
745 // [7.8.2] construct/copy/destroy
747 * Constructs a basic regular expression that does not match any
748 * character sequence.
751 : _M_flags(regex_constants::ECMAScript), _M_pattern(), _M_mark_count(0)
755 * @brief Constructs a basic regular expression from the sequence
756 * [p, p + char_traits<_Ch_type>::length(p)) interpreted according to the
759 * @param p A pointer to the start of a C-style null-terminated string
760 * containing a regular expression.
761 * @param f Flags indicating the syntax rules and options.
763 * @throws regex_error if @p p is not a valid regular expression.
766 basic_regex(const _Ch_type* __p,
767 flag_type __f = regex_constants::ECMAScript)
768 : _M_flags(__f), _M_pattern(__p), _M_mark_count(0)
772 * @brief Constructs a basic regular expression from the sequence
773 * [p, p + len) interpreted according to the flags in @p f.
775 * @param p A pointer to the start of a string containing a regular
777 * @param len The length of the string containing the regular expression.
778 * @param f Flags indicating the syntax rules and options.
780 * @throws regex_error if @p p is not a valid regular expression.
782 basic_regex(const _Ch_type* __p, std::size_t __len, flag_type __f)
783 : _M_flags(__f) , _M_pattern(__p, __len), _M_mark_count(0)
787 * @brief Copy-constructs a basic regular expression.
789 * @param rhs A @p regex object.
791 basic_regex(const basic_regex& __rhs)
792 : _M_flags(__rhs._M_flags), _M_pattern(__rhs._M_pattern),
793 _M_mark_count(__rhs._M_mark_count)
797 * @brief Constructs a basic regular expression from the string
798 * @p s interpreted according to the flags in @p f.
800 * @param s A string containing a regular expression.
801 * @param f Flags indicating the syntax rules and options.
803 * @throws regex_error if @p s is not a valid regular expression.
805 template<typename _Ch_traits, typename _Ch_alloc>
807 basic_regex(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
808 flag_type __f = regex_constants::ECMAScript)
809 : _M_flags(__f), _M_pattern(__s.begin(), __s.end()), _M_mark_count(0)
813 * @brief Constructs a basic regular expression from the range
814 * [first, last) interpreted according to the flags in @p f.
816 * @param first The start of a range containing a valid regular
818 * @param last The end of a range containing a valid regular
820 * @param f The format flags of the regular expression.
822 * @throws regex_error if @p [first, last) is not a valid regular
825 template<typename _InputIterator>
826 basic_regex(_InputIterator __first, _InputIterator __last,
827 flag_type __f = regex_constants::ECMAScript)
828 : _M_flags(__f), _M_pattern(__first, __last), _M_mark_count(0)
831 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
833 * @brief Constructs a basic regular expression from an initializer list.
835 * @param l The initializer list.
836 * @param f The format flags of the regular expression.
838 * @throws regex_error if @p l is not a valid regular expression.
840 basic_regex(initializer_list<_Ch_type> __l,
841 flag_type __f = regex_constants::ECMAScript)
842 : _M_flags(__f), _M_pattern(__l.begin(), __l.end()), _M_mark_count(0)
847 * @brief Destroys a basic regular expression.
853 * @brief Assigns one regular expression to another.
856 operator=(const basic_regex& __rhs)
857 { return this->assign(__rhs); }
860 * @brief Replaces a regular expression with a new one constructed from
861 * a C-style null-terminated string.
863 * @param A pointer to the start of a null-terminated C-style string
864 * containing a regular expression.
867 operator=(const _Ch_type* __p)
868 { return this->assign(__p, flags()); }
871 * @brief Replaces a regular expression with a new one constructed from
874 * @param A pointer to a string containing a regular expression.
876 template<typename _Ch_typeraits, typename _Allocator>
878 operator=(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s)
879 { return this->assign(__s, flags()); }
883 * @brief the real assignment operator.
885 * @param that Another regular expression object.
888 assign(const basic_regex& __that)
890 basic_regex __tmp(__that);
896 * @brief Assigns a new regular expression to a regex object from a
897 * C-style null-terminated string containing a regular expression
900 * @param p A pointer to a C-style null-terminated string containing
901 * a regular expression pattern.
902 * @param flags Syntax option flags.
904 * @throws regex_error if p does not contain a valid regular expression
905 * pattern interpreted according to @p flags. If regex_error is thrown,
906 * *this remains unchanged.
909 assign(const _Ch_type* __p,
910 flag_type __flags = regex_constants::ECMAScript)
911 { return this->assign(string_type(__p), __flags); }
914 * @brief Assigns a new regular expression to a regex object from a
915 * C-style string containing a regular expression pattern.
917 * @param p A pointer to a C-style string containing a
918 * regular expression pattern.
919 * @param len The length of the regular expression pattern string.
920 * @param flags Syntax option flags.
922 * @throws regex_error if p does not contain a valid regular expression
923 * pattern interpreted according to @p flags. If regex_error is thrown,
924 * *this remains unchanged.
927 assign(const _Ch_type* __p, std::size_t __len, flag_type __flags)
928 { return this->assign(string_type(__p, __len), __flags); }
931 * @brief Assigns a new regular expression to a regex object from a
932 * string containing a regular expression pattern.
934 * @param s A string containing a regular expression pattern.
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.
941 template<typename _Ch_typeraits, typename _Allocator>
943 assign(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s,
944 flag_type __f = regex_constants::ECMAScript)
946 basic_regex __tmp(__s, __f);
952 * @brief Assigns a new regular expression to a regex object.
954 * @param first The start of a range containing a valid regular
956 * @param last The end of a range containing a valid regular
958 * @param flags Syntax option flags.
960 * @throws regex_error if p does not contain a valid regular expression
961 * pattern interpreted according to @p flags. If regex_error is thrown,
962 * the object remains unchanged.
964 template<typename _InputIterator>
966 assign(_InputIterator __first, _InputIterator __last,
967 flag_type __flags = regex_constants::ECMAScript)
968 { return this->assign(string_type(__first, __last), __flags); }
970 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
972 * @brief Assigns a new regular expression to a regex object.
974 * @param l An initializer list representing a regular expression.
975 * @param flags Syntax option flags.
977 * @throws regex_error if @p l does not contain a valid regular
978 * expression pattern interpreted according to @p flags. If regex_error
979 * is thrown, the object remains unchanged.
982 assign(initializer_list<_Ch_type> __l,
983 flag_type __f = regex_constants::ECMAScript)
984 { return this->assign(__l.begin(), __l.end(), __f); }
987 // [7.8.4] const operations
989 * @brief Gets the number of marked subexpressions within the regular
994 { return _M_mark_count; }
997 * @brief Gets the flags used to construct the regular expression
998 * or in the last call to assign().
1002 { return _M_flags; }
1006 * @brief Imbues the regular expression object with the given locale.
1008 * @param loc A locale.
1011 imbue(locale_type __loc)
1012 { return _M_traits.imbue(__loc); }
1015 * @brief Gets the locale currently imbued in the regular expression
1020 { return _M_traits.getloc(); }
1024 * @brief Swaps the contents of two regular expression objects.
1026 * @param rhs Another regular expression object.
1029 swap(basic_regex& __rhs)
1031 std::swap(_M_flags, __rhs._M_flags);
1032 std::swap(_M_pattern, __rhs._M_pattern);
1033 std::swap(_M_mark_count, __rhs._M_mark_count);
1034 std::swap(_M_traits, __rhs._M_traits);
1039 * @brief Compiles a regular expression pattern into a NFA.
1040 * @todo Implement this function.
1046 string_type _M_pattern;
1047 unsigned int _M_mark_count;
1048 _Rx_traits _M_traits;
1051 /** @brief Standard regular expressions. */
1052 typedef basic_regex<char> regex;
1053 #ifdef _GLIBCXX_USE_WCHAR_T
1054 /** @brief Standard wide-character regular expressions. */
1055 typedef basic_regex<wchar_t> wregex;
1059 // [7.8.6] basic_regex swap
1061 * @brief Swaps the contents of two regular expression objects.
1062 * @param lhs First regular expression.
1063 * @param rhs Second regular expression.
1065 template<typename _Ch_type, typename _Rx_traits>
1067 swap(basic_regex<_Ch_type, _Rx_traits>& __lhs,
1068 basic_regex<_Ch_type, _Rx_traits>& __rhs)
1069 { __lhs.swap(__rhs); }
1072 // [7.9] Class template sub_match
1074 * A sequence of characters matched by a particular marked sub-expression.
1076 * An object of this class is essentially a pair of iterators marking a
1077 * matched subexpression within a regular expression pattern match. Such
1078 * objects can be converted to and compared with std::basic_string objects
1079 * of a similar base character type as the pattern matched by the regular
1082 * The iterators that make up the pair are the usual half-open interval
1083 * referencing the actual original pattern matched.
1085 template<typename _BiIter>
1086 class sub_match : public std::pair<_BiIter, _BiIter>
1089 typedef typename iterator_traits<_BiIter>::value_type value_type;
1090 typedef typename iterator_traits<_BiIter>::difference_type
1092 typedef _BiIter iterator;
1098 * Gets the length of the matching sequence.
1102 { return this->matched ? std::distance(this->first, this->second) : 0; }
1105 * @brief Gets the matching sequence as a string.
1107 * @returns the matching sequence as a string.
1109 * This is the implicit conversion operator. It is identical to the
1110 * str() member function except that it will want to pop up in
1111 * unexpected places and cause a great deal of confusion and cursing
1114 operator basic_string<value_type>() const
1116 return this->matched
1117 ? std::basic_string<value_type>(this->first, this->second)
1118 : std::basic_string<value_type>();
1122 * @brief Gets the matching sequence as a string.
1124 * @returns the matching sequence as a string.
1126 basic_string<value_type>
1129 return this->matched
1130 ? std::basic_string<value_type>(this->first, this->second)
1131 : std::basic_string<value_type>();
1135 * @brief Compares this and another matched sequence.
1137 * @param s Another matched sequence to compare to this one.
1139 * @retval <0 this matched sequence will collate before @p s.
1140 * @retval =0 this matched sequence is equivalent to @p s.
1141 * @retval <0 this matched sequence will collate after @p s.
1144 compare(const sub_match& __s) const
1145 { return this->str().compare(__s.str()); }
1148 * @brief Compares this sub_match to a string.
1150 * @param s A string to compare to this sub_match.
1152 * @retval <0 this matched sequence will collate before @p s.
1153 * @retval =0 this matched sequence is equivalent to @p s.
1154 * @retval <0 this matched sequence will collate after @p s.
1157 compare(const basic_string<value_type>& __s) const
1158 { return this->str().compare(__s); }
1161 * @brief Compares this sub_match to a C-style string.
1163 * @param s A C-style string to compare to this sub_match.
1165 * @retval <0 this matched sequence will collate before @p s.
1166 * @retval =0 this matched sequence is equivalent to @p s.
1167 * @retval <0 this matched sequence will collate after @p s.
1170 compare(const value_type* __s) const
1171 { return this->str().compare(__s); }
1175 /** @brief Standard regex submatch over a C-style null-terminated string. */
1176 typedef sub_match<const char*> csub_match;
1177 /** @brief Standard regex submatch over a standard string. */
1178 typedef sub_match<string::const_iterator> ssub_match;
1179 #ifdef _GLIBCXX_USE_WCHAR_T
1180 /** @brief Regex submatch over a C-style null-terminated wide string. */
1181 typedef sub_match<const wchar_t*> wcsub_match;
1182 /** @brief Regex submatch over a standard wide string. */
1183 typedef sub_match<wstring::const_iterator> wssub_match;
1186 // [7.9.2] sub_match non-member operators
1189 * @brief Tests the equivalence of two regular expression submatches.
1190 * @param lhs First regular expression submatch.
1191 * @param rhs Second regular expression submatch.
1192 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1194 template<typename _BiIter>
1196 operator==(const sub_match<_BiIter>& __lhs,
1197 const sub_match<_BiIter>& __rhs)
1198 { return __lhs.compare(__rhs) == 0; }
1201 * @brief Tests the inequivalence of two regular expression submatches.
1202 * @param lhs First regular expression submatch.
1203 * @param rhs Second regular expression submatch.
1204 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1206 template<typename _BiIter>
1208 operator!=(const sub_match<_BiIter>& __lhs,
1209 const sub_match<_BiIter>& __rhs)
1210 { return __lhs.compare(__rhs) != 0; }
1213 * @brief Tests the ordering of two regular expression submatches.
1214 * @param lhs First regular expression submatch.
1215 * @param rhs Second regular expression submatch.
1216 * @returns true if @a lhs precedes @a rhs, false otherwise.
1218 template<typename _BiIter>
1220 operator<(const sub_match<_BiIter>& __lhs,
1221 const sub_match<_BiIter>& __rhs)
1222 { return __lhs.compare(__rhs) < 0; }
1225 * @brief Tests the ordering of two regular expression submatches.
1226 * @param lhs First regular expression submatch.
1227 * @param rhs Second regular expression submatch.
1228 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1230 template<typename _BiIter>
1232 operator<=(const sub_match<_BiIter>& __lhs,
1233 const sub_match<_BiIter>& __rhs)
1234 { return __lhs.compare(__rhs) <= 0; }
1237 * @brief Tests the ordering of two regular expression submatches.
1238 * @param lhs First regular expression submatch.
1239 * @param rhs Second regular expression submatch.
1240 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1242 template<typename _BiIter>
1244 operator>=(const sub_match<_BiIter>& __lhs,
1245 const sub_match<_BiIter>& __rhs)
1246 { return __lhs.compare(__rhs) >= 0; }
1249 * @brief Tests the ordering of two regular expression submatches.
1250 * @param lhs First regular expression submatch.
1251 * @param rhs Second regular expression submatch.
1252 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1254 template<typename _BiIter>
1256 operator>(const sub_match<_BiIter>& __lhs,
1257 const sub_match<_BiIter>& __rhs)
1258 { return __lhs.compare(__rhs) > 0; }
1261 * @brief Tests the equivalence of a string and a regular expression
1263 * @param lhs A string.
1264 * @param rhs A regular expression submatch.
1265 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1267 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1269 operator==(const basic_string<
1270 typename iterator_traits<_Bi_iter>::value_type,
1271 _Ch_traits, _Ch_alloc>& __lhs,
1272 const sub_match<_Bi_iter>& __rhs)
1273 { return __lhs == __rhs.str(); }
1276 * @brief Tests the inequivalence 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 not 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, const sub_match<_Bi_iter>& __rhs)
1287 { return __lhs != __rhs.str(); }
1290 * @brief Tests the ordering of a string and a regular expression submatch.
1291 * @param lhs A string.
1292 * @param rhs A regular expression submatch.
1293 * @returns true if @a lhs precedes @a rhs, false otherwise.
1295 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1297 operator<(const basic_string<
1298 typename iterator_traits<_Bi_iter>::value_type,
1299 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1300 { return __lhs < __rhs.str(); }
1303 * @brief Tests the ordering of a string and a regular expression submatch.
1304 * @param lhs A string.
1305 * @param rhs A regular expression submatch.
1306 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1308 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1310 operator>(const basic_string<
1311 typename iterator_traits<_Bi_iter>::value_type,
1312 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1313 { return __lhs > __rhs.str(); }
1316 * @brief Tests the ordering of a string and a regular expression submatch.
1317 * @param lhs A string.
1318 * @param rhs A regular expression submatch.
1319 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1321 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1323 operator>=(const basic_string<
1324 typename iterator_traits<_Bi_iter>::value_type,
1325 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1326 { return __lhs >= __rhs.str(); }
1329 * @brief Tests the ordering of a string and a regular expression submatch.
1330 * @param lhs A string.
1331 * @param rhs A regular expression submatch.
1332 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1334 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1336 operator<=(const basic_string<
1337 typename iterator_traits<_Bi_iter>::value_type,
1338 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1339 { return __lhs <= __rhs.str(); }
1342 * @brief Tests the equivalence of a regular expression submatch and a
1344 * @param lhs A regular expression submatch.
1345 * @param rhs A string.
1346 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1348 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1350 operator==(const sub_match<_Bi_iter>& __lhs,
1352 typename iterator_traits<_Bi_iter>::value_type,
1353 _Ch_traits, _Ch_alloc>& __rhs)
1354 { return __lhs.str() == __rhs; }
1357 * @brief Tests the inequivalence 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 not 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 ordering of a regular expression submatch and a string.
1373 * @param lhs A regular expression submatch.
1374 * @param rhs A string.
1375 * @returns true if @a lhs precedes @a rhs, false otherwise.
1377 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1379 operator<(const sub_match<_Bi_iter>& __lhs,
1381 typename iterator_traits<_Bi_iter>::value_type,
1382 _Ch_traits, _Ch_alloc>& __rhs)
1383 { return __lhs.str() < __rhs; }
1386 * @brief Tests the ordering of a regular expression submatch and a string.
1387 * @param lhs A regular expression submatch.
1388 * @param rhs A string.
1389 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1391 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1393 operator>(const sub_match<_Bi_iter>& __lhs,
1395 typename iterator_traits<_Bi_iter>::value_type,
1396 _Ch_traits, _Ch_alloc>& __rhs)
1397 { return __lhs.str() > __rhs; }
1400 * @brief Tests the ordering of a regular expression submatch and a string.
1401 * @param lhs A regular expression submatch.
1402 * @param rhs A string.
1403 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1405 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1407 operator>=(const sub_match<_Bi_iter>& __lhs,
1409 typename iterator_traits<_Bi_iter>::value_type,
1410 _Ch_traits, _Ch_alloc>& __rhs)
1411 { return __lhs.str() >= __rhs; }
1414 * @brief Tests the ordering of a regular expression submatch and a string.
1415 * @param lhs A regular expression submatch.
1416 * @param rhs A string.
1417 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1419 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1421 operator<=(const sub_match<_Bi_iter>& __lhs,
1423 typename iterator_traits<_Bi_iter>::value_type,
1424 _Ch_traits, _Ch_alloc>& __rhs)
1425 { return __lhs.str() <= __rhs; }
1428 * @brief Tests the equivalence of a C string and a regular expression
1430 * @param lhs A C string.
1431 * @param rhs A regular expression submatch.
1432 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1434 template<typename _Bi_iter>
1436 operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1437 const sub_match<_Bi_iter>& __rhs)
1438 { return __lhs == __rhs.str(); }
1441 * @brief Tests the inequivalence of an iterator value and a regular
1442 * expression submatch.
1443 * @param lhs A regular expression submatch.
1444 * @param rhs A string.
1445 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1447 template<typename _Bi_iter>
1449 operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1450 const sub_match<_Bi_iter>& __rhs)
1451 { return __lhs != __rhs.str(); }
1454 * @brief Tests the ordering of a string and a regular expression submatch.
1455 * @param lhs A string.
1456 * @param rhs A regular expression submatch.
1457 * @returns true if @a lhs precedes @a rhs, false otherwise.
1459 template<typename _Bi_iter>
1461 operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1462 const sub_match<_Bi_iter>& __rhs)
1463 { return __lhs < __rhs.str(); }
1466 * @brief Tests the ordering of a string and a regular expression submatch.
1467 * @param lhs A string.
1468 * @param rhs A regular expression submatch.
1469 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1471 template<typename _Bi_iter>
1473 operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1474 const sub_match<_Bi_iter>& __rhs)
1475 { return __lhs > __rhs.str(); }
1478 * @brief Tests the ordering of a string and a regular expression submatch.
1479 * @param lhs A string.
1480 * @param rhs A regular expression submatch.
1481 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1483 template<typename _Bi_iter>
1485 operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1486 const sub_match<_Bi_iter>& __rhs)
1487 { return __lhs >= __rhs.str(); }
1490 * @brief Tests the ordering of a string and a regular expression submatch.
1491 * @param lhs A string.
1492 * @param rhs A regular expression submatch.
1493 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1495 template<typename _Bi_iter>
1497 operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1498 const sub_match<_Bi_iter>& __rhs)
1499 { return __lhs <= __rhs.str(); }
1502 * @brief Tests the equivalence of a regular expression submatch and a
1504 * @param lhs A regular expression submatch.
1505 * @param rhs A pointer to a string?
1506 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1508 template<typename _Bi_iter>
1510 operator==(const sub_match<_Bi_iter>& __lhs,
1511 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1512 { return __lhs.str() == __rhs; }
1515 * @brief Tests the inequivalence of a regular expression submatch and a
1517 * @param lhs A regular expression submatch.
1518 * @param rhs A pointer to a string.
1519 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1521 template<typename _Bi_iter>
1523 operator!=(const sub_match<_Bi_iter>& __lhs,
1524 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1525 { return __lhs.str() != __rhs; }
1528 * @brief Tests the ordering of a regular expression submatch and a string.
1529 * @param lhs A regular expression submatch.
1530 * @param rhs A string.
1531 * @returns true if @a lhs precedes @a rhs, false otherwise.
1533 template<typename _Bi_iter>
1535 operator<(const sub_match<_Bi_iter>& __lhs,
1536 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1537 { return __lhs.str() < __rhs; }
1540 * @brief Tests the ordering of a regular expression submatch and a string.
1541 * @param lhs A regular expression submatch.
1542 * @param rhs A string.
1543 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1545 template<typename _Bi_iter>
1547 operator>(const sub_match<_Bi_iter>& __lhs,
1548 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1549 { return __lhs.str() > __rhs; }
1552 * @brief Tests the ordering of a regular expression submatch and a string.
1553 * @param lhs A regular expression submatch.
1554 * @param rhs A string.
1555 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1557 template<typename _Bi_iter>
1559 operator>=(const sub_match<_Bi_iter>& __lhs,
1560 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1561 { return __lhs.str() >= __rhs; }
1564 * @brief Tests the ordering of a regular expression submatch and a string.
1565 * @param lhs A regular expression submatch.
1566 * @param rhs A string.
1567 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1569 template<typename _Bi_iter>
1571 operator<=(const sub_match<_Bi_iter>& __lhs,
1572 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1573 { return __lhs.str() <= __rhs; }
1576 * @brief Tests the equivalence of a string and a regular expression
1578 * @param lhs A string.
1579 * @param rhs A regular expression submatch.
1580 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1582 template<typename _Bi_iter>
1584 operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1585 const sub_match<_Bi_iter>& __rhs)
1586 { return __lhs == __rhs.str(); }
1589 * @brief Tests the inequivalence of a string and a regular expression
1591 * @param lhs A string.
1592 * @param rhs A regular expression submatch.
1593 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1595 template<typename _Bi_iter>
1597 operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1598 const sub_match<_Bi_iter>& __rhs)
1599 { return __lhs != __rhs.str(); }
1602 * @brief Tests the ordering of a string and a regular expression submatch.
1603 * @param lhs A string.
1604 * @param rhs A regular expression submatch.
1605 * @returns true if @a lhs precedes @a rhs, false otherwise.
1607 template<typename _Bi_iter>
1609 operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1610 const sub_match<_Bi_iter>& __rhs)
1611 { return __lhs < __rhs.str(); }
1614 * @brief Tests the ordering of a string and a regular expression submatch.
1615 * @param lhs A string.
1616 * @param rhs A regular expression submatch.
1617 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1619 template<typename _Bi_iter>
1621 operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1622 const sub_match<_Bi_iter>& __rhs)
1623 { return __lhs > __rhs.str(); }
1626 * @brief Tests the ordering of a string and a regular expression submatch.
1627 * @param lhs A string.
1628 * @param rhs A regular expression submatch.
1629 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1631 template<typename _Bi_iter>
1633 operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1634 const sub_match<_Bi_iter>& __rhs)
1635 { return __lhs >= __rhs.str(); }
1638 * @brief Tests the ordering of a string and a regular expression submatch.
1639 * @param lhs A string.
1640 * @param rhs A regular expression submatch.
1641 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1643 template<typename _Bi_iter>
1645 operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1646 const sub_match<_Bi_iter>& __rhs)
1647 { return __lhs <= __rhs.str(); }
1650 * @brief Tests the equivalence of a regular expression submatch and a
1652 * @param lhs A regular expression submatch.
1653 * @param rhs A const string reference.
1654 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1656 template<typename _Bi_iter>
1658 operator==(const sub_match<_Bi_iter>& __lhs,
1659 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1660 { return __lhs.str() == __rhs; }
1663 * @brief Tests the inequivalence of a regular expression submatch and a
1665 * @param lhs A regular expression submatch.
1666 * @param rhs A const string reference.
1667 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1669 template<typename _Bi_iter>
1671 operator!=(const sub_match<_Bi_iter>& __lhs,
1672 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1673 { return __lhs.str() != __rhs; }
1676 * @brief Tests the ordering of a regular expression submatch and a string.
1677 * @param lhs A regular expression submatch.
1678 * @param rhs A const string reference.
1679 * @returns true if @a lhs precedes @a rhs, false otherwise.
1681 template<typename _Bi_iter>
1683 operator<(const sub_match<_Bi_iter>& __lhs,
1684 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1685 { return __lhs.str() < __rhs; }
1688 * @brief Tests the ordering of a regular expression submatch and a string.
1689 * @param lhs A regular expression submatch.
1690 * @param rhs A const string reference.
1691 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1693 template<typename _Bi_iter>
1695 operator>(const sub_match<_Bi_iter>& __lhs,
1696 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1697 { return __lhs.str() > __rhs; }
1700 * @brief Tests the ordering of a regular expression submatch and a string.
1701 * @param lhs A regular expression submatch.
1702 * @param rhs A const string reference.
1703 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1705 template<typename _Bi_iter>
1707 operator>=(const sub_match<_Bi_iter>& __lhs,
1708 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1709 { return __lhs.str() >= __rhs; }
1712 * @brief Tests the ordering of a regular expression submatch and a string.
1713 * @param lhs A regular expression submatch.
1714 * @param rhs A const string reference.
1715 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1717 template<typename _Bi_iter>
1719 operator<=(const sub_match<_Bi_iter>& __lhs,
1720 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1721 { return __lhs.str() <= __rhs; }
1724 * @brief Inserts a matched string into an output stream.
1726 * @param os The output stream.
1727 * @param m A submatch string.
1729 * @returns the output stream with the submatch string inserted.
1731 template<typename _Ch_type, typename _Ch_traits, typename _Bi_iter>
1733 basic_ostream<_Ch_type, _Ch_traits>&
1734 operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os,
1735 const sub_match<_Bi_iter>& __m)
1736 { return __os << __m.str(); }
1738 // [7.10] Class template match_results
1740 * @brief The results of a match or search operation.
1742 * A collection of character sequences representing the result of a regular
1743 * expression match. Storage for the collection is allocated and freed as
1744 * necessary by the member functions of class template match_results.
1746 * This class satisfies the Sequence requirements, with the exception that
1747 * only the operations defined for a const-qualified Sequence are supported.
1749 * The sub_match object stored at index 0 represents sub-expression 0, i.e.
1750 * the whole match. In this case the sub_match member matched is always true.
1751 * The sub_match object stored at index n denotes what matched the marked
1752 * sub-expression n within the matched expression. If the sub-expression n
1753 * participated in a regular expression match then the sub_match member
1754 * matched evaluates to true, and members first and second denote the range
1755 * of characters [first, second) which formed that match. Otherwise matched
1756 * is false, and members first and second point to the end of the sequence
1757 * that was searched.
1761 template<typename _Bi_iter,
1762 typename _Allocator = allocator<sub_match<_Bi_iter> > >
1764 : private std::vector<std::_GLIBCXX_TR1 sub_match<_Bi_iter>, _Allocator>
1767 typedef std::vector<std::_GLIBCXX_TR1 sub_match<_Bi_iter>, _Allocator>
1772 * @name 10.? Public Types
1775 typedef sub_match<_Bi_iter> value_type;
1776 typedef typename _Allocator::const_reference const_reference;
1777 typedef const_reference reference;
1778 typedef typename _Base_type::const_iterator const_iterator;
1779 typedef const_iterator iterator;
1780 typedef typename iterator_traits<_Bi_iter>::difference_type
1782 typedef typename _Allocator::size_type size_type;
1783 typedef _Allocator allocator_type;
1784 typedef typename iterator_traits<_Bi_iter>::value_type char_type;
1785 typedef basic_string<char_type> string_type;
1790 * @name 10.1 Construction, Copying, and Destruction
1795 * @brief Constructs a default %match_results container.
1796 * @post size() returns 0 and str() returns an empty string.
1799 match_results(const _Allocator& __a = _Allocator())
1800 : _Base_type(__a), _M_matched(false)
1804 * @brief Copy constructs a %match_results.
1806 match_results(const match_results& __rhs)
1807 : _Base_type(__rhs), _M_matched(__rhs._M_matched),
1808 _M_prefix(__rhs._M_prefix), _M_suffix(__rhs._M_suffix)
1812 * @brief Assigns rhs to *this.
1815 operator=(const match_results& __rhs)
1817 match_results __tmp(__rhs);
1823 * @brief Destroys a %match_results object.
1836 * @brief Gets the number of matches and submatches.
1838 * The number of matches for a given regular expression will be either 0
1839 * if there was no match or mark_count() + 1 if a match was successful.
1840 * Some matches may be empty.
1842 * @returns the number of matches found.
1846 { return _M_matched ? _Base_type::size() + 1 : 0; }
1850 using _Base_type::max_size;
1853 * @brief Indicates if the %match_results contains no results.
1854 * @retval true The %match_results object is empty.
1855 * @retval false The %match_results object is not empty.
1859 { return size() == 0; }
1864 * @name 10.3 Element Access
1869 * @brief Gets the length of the indicated submatch.
1870 * @param sub indicates the submatch.
1872 * This function returns the length of the indicated submatch, or the
1873 * length of the entire match if @p sub is zero (the default).
1876 length(size_type __sub = 0) const
1877 { return _M_matched ? this->str(__sub).length() : 0; }
1880 * @brief Gets the offset of the beginning of the indicated submatch.
1881 * @param sub indicates the submatch.
1883 * This function returns the offset from the beginning of the target
1884 * sequence to the beginning of the submatch, unless the value of @p sub
1885 * is zero (the default), in which case this function returns the offset
1886 * from the beginning of the target sequence to the beginning of the
1890 position(size_type __sub = 0) const
1892 return _M_matched ? std::distance(this->prefix().first,
1893 (*this)[__sub].first) : 0;
1897 * @brief Gets the match or submatch converted to a string type.
1898 * @param sub indicates the submatch.
1900 * This function gets the submatch (or match, if @p sub is zero) extracted
1901 * from the target range and converted to the associated string type.
1904 str(size_type __sub = 0) const
1905 { return _M_matched ? (*this)[__sub].str() : string_type(); }
1908 * @brief Gets a %sub_match reference for the match or submatch.
1909 * @param sub indicates the submatch.
1911 * This function gets a reference to the indicated submatch, or the entire
1912 * match if @p sub is zero.
1914 * If @p sub >= size() then this function returns a %sub_match with a
1915 * special value indicating no submatch.
1918 operator[](size_type __sub) const
1919 { return _Base_type::operator[](__sub); }
1922 * @brief Gets a %sub_match representing the match prefix.
1924 * This function gets a reference to a %sub_match object representing the
1925 * part of the target range between the start of the target range and the
1926 * start of the match.
1930 { return _M_prefix; }
1933 * @brief Gets a %sub_match representing the match suffix.
1935 * This function gets a reference to a %sub_match object representing the
1936 * part of the target range between the end of the match and the end of
1941 { return _M_suffix; }
1944 * @brief Gets an iterator to the start of the %sub_match collection.
1948 { return _Base_type::begin(); }
1950 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
1952 * @brief Gets an iterator to the start of the %sub_match collection.
1956 { return _Base_type::begin(); }
1960 * @brief Gets an iterator to one-past-the-end of the collection.
1964 { return _Base_type::end(); }
1966 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
1968 * @brief Gets an iterator to one-past-the-end of the collection.
1972 { return _Base_type::end(); }
1978 * @name 10.4 Formatting
1980 * These functions perform formatted substitution of the matched character
1981 * sequences into their target. The format specifiers and escape sequences
1982 * accepted by these functions are determined by their @p flags parameter
1983 * as documented above.
1988 * @todo Implement this function.
1990 template<typename _Out_iter>
1992 format(_Out_iter __out, const string_type& __fmt,
1993 regex_constants::match_flag_type __flags
1994 = regex_constants::format_default) const;
1997 * @todo Implement this function.
2000 format(const string_type& __fmt,
2001 regex_constants::match_flag_type __flags
2002 = regex_constants::format_default) const;
2007 * @name 10.5 Allocator
2012 * @brief Gets a copy of the allocator.
2015 //get_allocator() const;
2016 using _Base_type::get_allocator;
2026 * @brief Swaps the contents of two match_results.
2029 swap(match_results& __that)
2031 _Base_type::swap(__that);
2032 std::swap(_M_matched, __that._M_matched);
2033 std::swap(_M_prefix, __that._M_prefix);
2034 std::swap(_M_suffix, __that._M_suffix);
2040 value_type _M_prefix;
2041 value_type _M_suffix;
2044 typedef match_results<const char*> cmatch;
2045 typedef match_results<string::const_iterator> smatch;
2046 #ifdef _GLIBCXX_USE_WCHAR_T
2047 typedef match_results<const wchar_t*> wcmatch;
2048 typedef match_results<wstring::const_iterator> wsmatch;
2051 // match_results comparisons
2053 * @brief Compares two match_results for equality.
2054 * @returns true if the two objects refer to the same match,
2056 * @todo Implement this function.
2058 template<typename _Bi_iter, typename _Allocator>
2060 operator==(const match_results<_Bi_iter, _Allocator>& __m1,
2061 const match_results<_Bi_iter, _Allocator>& __m2);
2064 * @brief Compares two match_results for inequality.
2065 * @returns true if the two objects do not refer to the same match,
2068 template<typename _Bi_iter, class _Allocator>
2070 operator!=(const match_results<_Bi_iter, _Allocator>& __m1,
2071 const match_results<_Bi_iter, _Allocator>& __m2)
2072 { return !(__m1 == __m2); }
2074 // [7.10.6] match_results swap
2076 * @brief Swaps two match results.
2077 * @param lhs A match result.
2078 * @param rhs A match result.
2080 * The contents of the two match_results objects are swapped.
2082 template<typename _Bi_iter, typename _Allocator>
2084 swap(match_results<_Bi_iter, _Allocator>& __lhs,
2085 match_results<_Bi_iter, _Allocator>& __rhs)
2086 { __lhs.swap(__rhs); }
2088 // [7.11.2] Function template regex_match
2090 * @name Matching, Searching, and Replacing
2095 * @brief Determines if there is a match between the regular expression @p e
2096 * and all of the character sequence [first, last).
2098 * @param first Beginning of the character sequence to match.
2099 * @param last One-past-the-end of the character sequence to match.
2100 * @param m The match results.
2101 * @param re The regular expression.
2102 * @param flags Controls how the regular expression is matched.
2104 * @retval true A match exists.
2105 * @retval false Otherwise.
2107 * @throws an exception of type regex_error.
2109 * @todo Implement this function.
2111 template<typename _Bi_iter, typename _Allocator,
2112 typename _Ch_type, typename _Rx_traits>
2114 regex_match(_Bi_iter __first, _Bi_iter __last,
2115 match_results<_Bi_iter, _Allocator>& __m,
2116 const basic_regex<_Ch_type, _Rx_traits>& __re,
2117 regex_constants::match_flag_type __flags
2118 = regex_constants::match_default);
2121 * @brief Indicates if there is a match between the regular expression @p e
2122 * and all of the character sequence [first, last).
2124 * @param first Beginning of the character sequence to match.
2125 * @param last One-past-the-end of the character sequence to match.
2126 * @param re The regular expression.
2127 * @param flags Controls how the regular expression is matched.
2129 * @retval true A match exists.
2130 * @retval false Otherwise.
2132 * @throws an exception of type regex_error.
2134 template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
2136 regex_match(_Bi_iter __first, _Bi_iter __last,
2137 const basic_regex<_Ch_type, _Rx_traits>& __re,
2138 regex_constants::match_flag_type __flags
2139 = regex_constants::match_default)
2141 match_results<_Bi_iter> __what;
2142 return regex_match(__first, __last, __what, __re, __flags);
2146 * @brief Determines if there is a match between the regular expression @p e
2147 * and a C-style null-terminated string.
2149 * @param s The C-style null-terminated string to match.
2150 * @param m The match results.
2151 * @param re The regular expression.
2152 * @param f Controls how the regular expression is matched.
2154 * @retval true A match exists.
2155 * @retval false Otherwise.
2157 * @throws an exception of type regex_error.
2159 template<typename _Ch_type, typename _Allocator, typename _Rx_traits>
2161 regex_match(const _Ch_type* __s,
2162 match_results<const _Ch_type*, _Allocator>& __m,
2163 const basic_regex<_Ch_type, _Rx_traits>& __re,
2164 regex_constants::match_flag_type __f
2165 = regex_constants::match_default)
2166 { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); }
2169 * @brief Determines if there is a match between the regular expression @p e
2172 * @param s The string to match.
2173 * @param m The match results.
2174 * @param re The regular expression.
2175 * @param flags Controls how the regular expression is matched.
2177 * @retval true A match exists.
2178 * @retval false Otherwise.
2180 * @throws an exception of type regex_error.
2182 template<typename _Ch_traits, typename _Ch_alloc,
2183 typename _Allocator, typename _Ch_type, typename _Rx_traits>
2185 regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
2186 match_results<typename basic_string<_Ch_type,
2187 _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
2188 const basic_regex<_Ch_type, _Rx_traits>& __re,
2189 regex_constants::match_flag_type __flags
2190 = regex_constants::match_default)
2191 { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }
2194 * @brief Indicates if there is a match between the regular expression @p e
2195 * and a C-style null-terminated string.
2197 * @param s The C-style null-terminated string to match.
2198 * @param re The regular expression.
2199 * @param f Controls how the regular expression is matched.
2201 * @retval true A match exists.
2202 * @retval false Otherwise.
2204 * @throws an exception of type regex_error.
2206 template<typename _Ch_type, class _Rx_traits>
2208 regex_match(const _Ch_type* __s,
2209 const basic_regex<_Ch_type, _Rx_traits>& __re,
2210 regex_constants::match_flag_type __f
2211 = regex_constants::match_default)
2212 { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); }
2215 * @brief Indicates if there is a match between the regular expression @p e
2218 * @param s [IN] The string to match.
2219 * @param re [IN] The regular expression.
2220 * @param flags [IN] Controls how the regular expression is matched.
2222 * @retval true A match exists.
2223 * @retval false Otherwise.
2225 * @throws an exception of type regex_error.
2227 template<typename _Ch_traits, typename _Str_allocator,
2228 typename _Ch_type, typename _Rx_traits>
2230 regex_match(const basic_string<_Ch_type, _Ch_traits, _Str_allocator>& __s,
2231 const basic_regex<_Ch_type, _Rx_traits>& __re,
2232 regex_constants::match_flag_type __flags
2233 = regex_constants::match_default)
2234 { return regex_match(__s.begin(), __s.end(), __re, __flags); }
2236 // [7.11.3] Function template regex_search
2238 * Searches for a regular expression within a range.
2239 * @param first [IN] The start of the string to search.
2240 * @param last [IN] One-past-the-end of the string to search.
2241 * @param m [OUT] The match results.
2242 * @param re [IN] The regular expression to search for.
2243 * @param flags [IN] Search policy flags.
2244 * @retval true A match was found within the string.
2245 * @retval false No match was found within the string, the content of %m is
2248 * @throws an exception of type regex_error.
2250 * @todo Implement this function.
2252 template<typename _Bi_iter, typename _Allocator,
2253 typename _Ch_type, typename _Rx_traits>
2255 regex_search(_Bi_iter __first, _Bi_iter __last,
2256 match_results<_Bi_iter, _Allocator>& __m,
2257 const basic_regex<_Ch_type, _Rx_traits>& __re,
2258 regex_constants::match_flag_type __flags
2259 = regex_constants::match_default);
2262 * Searches for a regular expression within a range.
2263 * @param first [IN] The start of the string to search.
2264 * @param last [IN] One-past-the-end of the string to search.
2265 * @param re [IN] The regular expression to search for.
2266 * @param flags [IN] Search policy flags.
2267 * @retval true A match was found within the string.
2268 * @retval false No match was found within the string.
2271 * @throws an exception of type regex_error.
2273 template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
2275 regex_search(_Bi_iter __first, _Bi_iter __last,
2276 const basic_regex<_Ch_type, _Rx_traits>& __re,
2277 regex_constants::match_flag_type __flags
2278 = regex_constants::match_default)
2280 match_results<_Bi_iter> __what;
2281 return regex_search(__first, __last, __what, __re, __flags);
2285 * @brief Searches for a regular expression within a C-string.
2286 * @param s [IN] A C-string to search for the regex.
2287 * @param m [OUT] The set of regex matches.
2288 * @param e [IN] The regex to search for in @p s.
2289 * @param f [IN] The search flags.
2290 * @retval true A match was found within the string.
2291 * @retval false No match was found within the string, the content of %m is
2295 * @throws an exception of type regex_error.
2297 template<typename _Ch_type, class _Allocator, class _Rx_traits>
2299 regex_search(const _Ch_type* __s,
2300 match_results<const _Ch_type*, _Allocator>& __m,
2301 const basic_regex<_Ch_type, _Rx_traits>& __e,
2302 regex_constants::match_flag_type __f
2303 = regex_constants::match_default)
2304 { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
2307 * @brief Searches for a regular expression within a C-string.
2308 * @param s [IN] The C-string to search.
2309 * @param e [IN] The regular expression to search for.
2310 * @param f [IN] Search policy flags.
2311 * @retval true A match was found within the string.
2312 * @retval false No match was found within the string.
2315 * @throws an exception of type regex_error.
2317 template<typename _Ch_type, typename _Rx_traits>
2319 regex_search(const _Ch_type* __s,
2320 const basic_regex<_Ch_type, _Rx_traits>& __e,
2321 regex_constants::match_flag_type __f
2322 = regex_constants::match_default)
2323 { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); }
2326 * @brief Searches for a regular expression within a string.
2327 * @param s [IN] The string to search.
2328 * @param e [IN] The regular expression to search for.
2329 * @param flags [IN] Search policy flags.
2330 * @retval true A match was found within the string.
2331 * @retval false No match was found within the string.
2334 * @throws an exception of type regex_error.
2336 template<typename _Ch_traits, typename _String_allocator,
2337 typename _Ch_type, typename _Rx_traits>
2339 regex_search(const basic_string<_Ch_type, _Ch_traits,
2340 _String_allocator>& __s,
2341 const basic_regex<_Ch_type, _Rx_traits>& __e,
2342 regex_constants::match_flag_type __flags
2343 = regex_constants::match_default)
2344 { return regex_search(__s.begin(), __s.end(), __e, __flags); }
2347 * @brief Searches for a regular expression within a string.
2348 * @param s [IN] A C++ string to search for the regex.
2349 * @param m [OUT] The set of regex matches.
2350 * @param e [IN] The regex to search for in @p s.
2351 * @param f [IN] The search flags.
2352 * @retval true A match was found within the string.
2353 * @retval false No match was found within the string, the content of %m is
2356 * @throws an exception of type regex_error.
2358 template<typename _Ch_traits, typename _Ch_alloc,
2359 typename _Allocator, typename _Ch_type,
2360 typename _Rx_traits>
2362 regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
2363 match_results<typename basic_string<_Ch_type,
2364 _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
2365 const basic_regex<_Ch_type, _Rx_traits>& __e,
2366 regex_constants::match_flag_type __f
2367 = regex_constants::match_default)
2368 { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
2370 // tr1 [7.11.4] std [28.11.4] Function template regex_replace
2381 * @throws an exception of type regex_error.
2383 * @todo Implement this function.
2385 template<typename _Out_iter, typename _Bi_iter,
2386 typename _Rx_traits, typename _Ch_type>
2388 regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
2389 const basic_regex<_Ch_type, _Rx_traits>& __e,
2390 const basic_string<_Ch_type>& __fmt,
2391 regex_constants::match_flag_type __flags
2392 = regex_constants::match_default);
2401 * @returns a copy of string @p s with replacements.
2403 * @throws an exception of type regex_error.
2405 template<typename _Rx_traits, typename _Ch_type>
2406 inline basic_string<_Ch_type>
2407 regex_replace(const basic_string<_Ch_type>& __s,
2408 const basic_regex<_Ch_type, _Rx_traits>& __e,
2409 const basic_string<_Ch_type>& __fmt,
2410 regex_constants::match_flag_type __flags
2411 = regex_constants::match_default)
2413 std::string __result;
2414 regex_replace(std::back_inserter(__result),
2415 __s.begin(), __s.end(), __e, __fmt, __flags);
2421 // tr1 [7.12.1] std [28.12] Class template regex_iterator
2423 * An iterator adaptor that will provide repeated calls of regex_search over
2424 * a range until no more matches remain.
2426 template<typename _Bi_iter,
2427 typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2428 typename _Rx_traits = regex_traits<_Ch_type> >
2429 class regex_iterator
2432 typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
2433 typedef match_results<_Bi_iter> value_type;
2434 typedef std::ptrdiff_t difference_type;
2435 typedef const value_type* pointer;
2436 typedef const value_type& reference;
2437 typedef std::forward_iterator_tag iterator_category;
2441 * @brief Provides a singular iterator, useful for indicating
2442 * one-past-the-end of a range.
2443 * @todo Implement this function.
2449 * Constructs a %regex_iterator...
2450 * @param a [IN] The start of a text range to search.
2451 * @param b [IN] One-past-the-end of the text range to search.
2452 * @param re [IN] The regular expression to match.
2453 * @param m [IN] Policy flags for match rules.
2454 * @todo Implement this function.
2457 regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2458 regex_constants::match_flag_type __m
2459 = regex_constants::match_default);
2462 * Copy constructs a %regex_iterator.
2463 * @todo Implement this function.
2466 regex_iterator(const regex_iterator& __rhs);
2469 * @todo Implement this function.
2473 operator=(const regex_iterator& __rhs);
2476 * @todo Implement this function.
2480 operator==(const regex_iterator& __rhs);
2483 * @todo Implement this function.
2487 operator!=(const regex_iterator& __rhs);
2490 * @todo Implement this function.
2497 * @todo Implement this function.
2504 * @todo Implement this function.
2511 * @todo Implement this function.
2518 // these members are shown for exposition only:
2521 const regex_type* pregex;
2522 regex_constants::match_flag_type flags;
2523 match_results<_Bi_iter> match;
2526 typedef regex_iterator<const char*> cregex_iterator;
2527 typedef regex_iterator<string::const_iterator> sregex_iterator;
2528 #ifdef _GLIBCXX_USE_WCHAR_T
2529 typedef regex_iterator<const wchar_t*> wcregex_iterator;
2530 typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
2533 // [7.12.2] Class template regex_token_iterator
2535 * Iterates over submatches in a range (or "splits" a text string).
2537 * The purpose of this iterator is to enumerate all, or all specified,
2538 * matches of a regular expression within a text range. The dereferenced
2539 * value of an iterator of this class is a std::tr1::sub_match object.
2541 template<typename _Bi_iter,
2542 typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2543 typename _Rx_traits = regex_traits<_Ch_type> >
2544 class regex_token_iterator
2547 typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
2548 typedef sub_match<_Bi_iter> value_type;
2549 typedef std::ptrdiff_t difference_type;
2550 typedef const value_type* pointer;
2551 typedef const value_type& reference;
2552 typedef std::forward_iterator_tag iterator_category;
2556 * @brief Default constructs a %regex_token_iterator.
2557 * @todo Implement this function.
2559 * A default-constructed %regex_token_iterator is a singular iterator
2560 * that will compare equal to the one-past-the-end value for any
2561 * iterator of the same type.
2563 regex_token_iterator();
2566 * Constructs a %regex_token_iterator...
2567 * @param a [IN] The start of the text to search.
2568 * @param b [IN] One-past-the-end of the text to search.
2569 * @param re [IN] The regular expression to search for.
2570 * @param submatch [IN] Which submatch to return. There are some
2571 * special values for this parameter:
2572 * - -1 each enumerated subexpression does NOT
2573 * match the regular expression (aka field
2575 * - 0 the entire string matching the
2576 * subexpression is returned for each match
2578 * - >0 enumerates only the indicated
2579 * subexpression from a match within the text.
2580 * @param m [IN] Policy flags for match rules.
2582 * @todo Implement this function.
2585 regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2587 regex_constants::match_flag_type __m
2588 = regex_constants::match_default);
2591 * Constructs a %regex_token_iterator...
2592 * @param a [IN] The start of the text to search.
2593 * @param b [IN] One-past-the-end of the text to search.
2594 * @param re [IN] The regular expression to search for.
2595 * @param submatches [IN] A list of subexpressions to return for each
2596 * regular expression match within the text.
2597 * @param m [IN] Policy flags for match rules.
2599 * @todo Implement this function.
2602 regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2603 const regex_type& __re,
2604 const std::vector<int>& __submatches,
2605 regex_constants::match_flag_type __m
2606 = regex_constants::match_default);
2609 * Constructs a %regex_token_iterator...
2610 * @param a [IN] The start of the text to search.
2611 * @param b [IN] One-past-the-end of the text to search.
2612 * @param re [IN] The regular expression to search for.
2613 * @param submatches [IN] A list of subexpressions to return for each
2614 * regular expression match within the text.
2615 * @param m [IN] Policy flags for match rules.
2617 * @todo Implement this function.
2620 template<std::size_t _Nm>
2621 regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2622 const regex_type& __re,
2623 const int (&__submatches)[_Nm],
2624 regex_constants::match_flag_type __m
2625 = regex_constants::match_default);
2628 * @brief Copy constructs a %regex_token_iterator.
2629 * @param rhs [IN] A %regex_token_iterator to copy.
2630 * @todo Implement this function.
2632 regex_token_iterator(const regex_token_iterator& __rhs);
2635 * @brief Assigns a %regex_token_iterator to another.
2636 * @param rhs [IN] A %regex_token_iterator to copy.
2637 * @todo Implement this function.
2639 regex_token_iterator&
2640 operator=(const regex_token_iterator& __rhs);
2643 * @brief Compares a %regex_token_iterator to another for equality.
2644 * @todo Implement this function.
2647 operator==(const regex_token_iterator& __rhs);
2650 * @brief Compares a %regex_token_iterator to another for inequality.
2651 * @todo Implement this function.
2654 operator!=(const regex_token_iterator& __rhs);
2657 * @brief Dereferences a %regex_token_iterator.
2658 * @todo Implement this function.
2664 * @brief Selects a %regex_token_iterator member.
2665 * @todo Implement this function.
2671 * @brief Increments a %regex_token_iterator.
2672 * @todo Implement this function.
2674 regex_token_iterator&
2678 * @brief Postincrements a %regex_token_iterator.
2679 * @todo Implement this function.
2681 regex_token_iterator
2684 private: // data members for exposition only:
2685 typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> position_iterator;
2687 position_iterator __position;
2688 const value_type* __result;
2689 value_type __suffix;
2691 std::vector<int> __subs;
2694 /** @brief Token iterator for C-style NULL-terminated strings. */
2695 typedef regex_token_iterator<const char*> cregex_token_iterator;
2696 /** @brief Token iterator for standard strings. */
2697 typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
2698 #ifdef _GLIBCXX_USE_WCHAR_T
2699 /** @brief Token iterator for C-style NULL-terminated wide strings. */
2700 typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
2701 /** @brief Token iterator for standard wide-character strings. */
2702 typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
2707 _GLIBCXX_END_NAMESPACE_TR1