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 2, 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 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
31 * @file tr1_impl/regex
32 * @brief The common implementation file for tr1 and std regular expressions.
34 * This is an internal header file, included by other library headers.
35 * You should not attempt to use it directly.
40 _GLIBCXX_BEGIN_NAMESPACE_TR1
43 * @addtogroup tr1_regex Regular Expressions
44 * A facility for performing regular expression pattern matching.
48 namespace regex_constants
51 * @name 5.1 Regular Expression Syntax Options
70 * @brief This is a bitmask type indicating how to interpret the regex.
72 * The @c syntax_option_type is implementation defined but it is valid to
73 * perform bitwise operations on these values and expect the right thing to
76 * A valid value of type syntax_option_type shall have exactly one of the
77 * elements @c ECMAScript, @c basic, @c extended, @c awk, @c grep, @c egrep
80 typedef unsigned int syntax_option_type;
83 * Specifies that the matching of regular expressions against a character
84 * sequence shall be performed without regard to case.
86 static const syntax_option_type icase = 1 << _S_icase;
89 * Specifies that when a regular expression is matched against a character
90 * container sequence, no sub-expression matches are to be stored in the
91 * supplied match_results structure.
93 static const syntax_option_type nosubs = 1 << _S_nosubs;
96 * Specifies that the regular expression engine should pay more attention to
97 * the speed with which regular expressions are matched, and less to the
98 * speed with which regular expression objects are constructed. Otherwise
99 * it has no detectable effect on the program output.
101 static const syntax_option_type optimize = 1 << _S_optimize;
104 * Specifies that character ranges of the form [a-b] should be locale
107 static const syntax_option_type collate = 1 << _S_collate;
110 * Specifies that the grammar recognized by the regular expression engine is
111 * that used by ECMAScript in ECMA-262 [Ecma International, ECMAScript
112 * Language Specification, Standard Ecma-262, third edition, 1999], as
113 * modified in tr1 section [7.13]. This grammar is similar to that defined
114 * in the PERL scripting language but extended with elements found in the
115 * POSIX regular expression grammar.
117 static const syntax_option_type ECMAScript = 1 << _S_ECMAScript;
120 * Specifies that the grammar recognized by the regular expression engine is
121 * that used by POSIX basic regular expressions in IEEE Std 1003.1-2001,
122 * Portable Operating System Interface (POSIX), Base Definitions and
123 * Headers, Section 9, Regular Expressions [IEEE, Information Technology --
124 * Portable Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
126 static const syntax_option_type basic = 1 << _S_basic;
129 * Specifies that the grammar recognized by the regular expression engine is
130 * that used by POSIX extended regular expressions in IEEE Std 1003.1-2001,
131 * Portable Operating System Interface (POSIX), Base Definitions and Headers,
132 * Section 9, Regular Expressions.
134 static const syntax_option_type extended = 1 << _S_extended;
137 * Specifies that the grammar recognized by the regular expression engine is
138 * that used by POSIX utility awk in IEEE Std 1003.1-2001. This option is
139 * identical to syntax_option_type extended, except that C-style escape
140 * sequences are supported. These sequences are, explicitly, "\\", "\a",
141 * "\b", "\f", "\n", "\r", "\t" , "\v", "\"", "'",
142 * and "\ddd" (where ddd is one, two, or three octal digits).
144 static const syntax_option_type awk = 1 << _S_awk;
147 * Specifies that the grammar recognized by the regular expression engine is
148 * that used by POSIX utility grep in IEEE Std 1003.1-2001. This option is
149 * identical to syntax_option_type basic, except that newlines are treated
152 static const syntax_option_type grep = 1 << _S_grep;
155 * Specifies that the grammar recognized by the regular expression engine is
156 * that used by POSIX utility grep when given the -E option in
157 * IEEE Std 1003.1-2001. This option is identical to syntax_option_type
158 * extended, except that newlines are treated as whitespace.
160 static const syntax_option_type egrep = 1 << _S_egrep;
165 * @name 5.2 Matching Rules
167 * Matching a regular expression against a sequence of characters [first,
168 * last) proceeds according to the rules of the grammar specified for the
169 * regular expression object, modified according to the effects listed
170 * below for any bitmask elements set.
192 * @brief This is a bitmask type indicating regex matching rules.
194 * The @c match_flag_type is implementation defined but it is valid to
195 * perform bitwise operations on these values and expect the right thing to
198 typedef std::bitset<_S_match_flag_last> match_flag_type;
201 * The default matching rules.
203 static const match_flag_type match_default = 0;
206 * The first character in the sequence [first, last) is treated as though it
207 * is not at the beginning of a line, so the character "^" in the regular
208 * expression shall not match [first, first).
210 static const match_flag_type match_not_bol = 1 << _S_not_bol;
213 * The last character in the sequence [first, last) is treated as though it
214 * is not at the end of a line, so the character "$" in the regular
215 * expression shall not match [last, last).
217 static const match_flag_type match_not_eol = 1 << _S_not_eol;
220 * The expression "\b" is not matched against the sub-sequence
223 static const match_flag_type match_not_bow = 1 << _S_not_bow;
226 * The expression "\b" should not be matched against the sub-sequence
229 static const match_flag_type match_not_eow = 1 << _S_not_eow;
232 * If more than one match is possible then any match is an acceptable
235 static const match_flag_type match_any = 1 << _S_any;
238 * The expression does not match an empty sequence.
240 static const match_flag_type match_not_null = 1 << _S_not_null;
243 * The expression only matches a sub-sequence that begins at first .
245 static const match_flag_type match_continuous = 1 << _S_continuous;
248 * --first is a valid iterator position. When this flag is set then the
249 * flags match_not_bol and match_not_bow are ignored by the regular
250 * expression algorithms 7.11 and iterators 7.12.
252 static const match_flag_type match_prev_avail = 1 << _S_prev_avail;
255 * When a regular expression match is to be replaced by a new string, the
256 * new string is constructed using the rules used by the ECMAScript replace
257 * function in ECMA- 262 [Ecma International, ECMAScript Language
258 * Specification, Standard Ecma-262, third edition, 1999], part 15.5.4.11
259 * String.prototype.replace. In addition, during search and replace
260 * operations all non-overlapping occurrences of the regular expression
261 * are located and replaced, and sections of the input that did not match
262 * the expression are copied unchanged to the output string.
264 * Format strings (from ECMA-262 [15.5.4.11]):
265 * @li $$ The dollar-sign itself ($)
266 * @li $& The matched substring.
267 * @li $` The portion of <em>string</em> that precedes the matched substring.
268 * This would be match_results::prefix().
269 * @li $' The portion of <em>string</em> that follows the matched substring.
270 * This would be match_results::suffix().
271 * @li $n The nth capture, where n is in [1,9] and $n is not followed by a
272 * decimal digit. If n <= match_results::size() and the nth capture
273 * is undefined, use the empty string instead. If n >
274 * match_results::size(), the result is implementation-defined.
275 * @li $nn The nnth capture, where nn is a two-digit decimal number on
276 * [01, 99]. If nn <= match_results::size() and the nth capture is
277 * undefined, use the empty string instead. If
278 * nn > match_results::size(), the result is implementation-defined.
280 static const match_flag_type format_default = 0;
283 * When a regular expression match is to be replaced by a new string, the
284 * new string is constructed using the rules used by the POSIX sed utility
285 * in IEEE Std 1003.1- 2001 [IEEE, Information Technology -- Portable
286 * Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
288 static const match_flag_type format_sed = 1 << _S_sed;
291 * During a search and replace operation, sections of the character
292 * container sequence being searched that do not match the regular
293 * expression shall not be copied to the output string.
295 static const match_flag_type format_no_copy = 1 << _S_no_copy;
298 * When specified during a search and replace operation, only the first
299 * occurrence of the regular expression shall be replaced.
301 static const match_flag_type format_first_only = 1 << _S_first_only;
306 * @name 5.3 Error Types
328 /** The expression contained an invalid collating element name. */
329 static const error_type error_collate(_S_error_collate);
331 /** The expression contained an invalid character class name. */
332 static const error_type error_ctype(_S_error_ctype);
335 * The expression contained an invalid escaped character, or a trailing
338 static const error_type error_escape(_S_error_escape);
340 /** The expression contained an invalid back reference. */
341 static const error_type error_backref(_S_error_backref);
343 /** The expression contained mismatched [ and ]. */
344 static const error_type error_brack(_S_error_brack);
346 /** The expression contained mismatched ( and ). */
347 static const error_type error_paren(_S_error_paren);
349 /** The expression contained mismatched { and } */
350 static const error_type error_brace(_S_error_brace);
352 /** The expression contained an invalid range in a {} expression. */
353 static const error_type error_badbrace(_S_error_badbrace);
356 * The expression contained an invalid character range,
357 * such as [b-a] in most encodings.
359 static const error_type error_range(_S_error_range);
362 * There was insufficient memory to convert the expression into a
363 * finite state machine.
365 static const error_type error_space(_S_error_space);
368 * One of "*?+{" was not preceded by a valid regular expression.
370 static const error_type error_badrepeat(_S_error_badrepeat);
373 * The complexity of an attempted match against a regular expression
374 * exceeded a pre-set level.
376 static const error_type error_complexity(_S_error_complexity);
379 * There was insufficient memory to determine whether the
380 * regular expression could match the specified character sequence.
382 static const error_type error_stack(_S_error_stack);
388 // [7.8] Class regex_error
390 * @brief A regular expression exception class.
392 * The regular expression library throws objects of this class on error.
395 : public std::runtime_error
399 * @brief Constructs a regex_error object.
401 * @param ecode the regex error code.
404 regex_error(regex_constants::error_type __ecode)
405 : std::runtime_error("regex_error"), _M_code(__ecode)
409 * @brief Gets the regex error code.
411 * @returns the regex error code.
413 regex_constants::error_type
418 regex_constants::error_type _M_code;
421 // [7.7] Class regex_traits
423 * @brief Describes aspects of a regular expression.
425 * A regular expression traits class that satisfies the requirements of tr1
428 * The class %regex is parameterized around a set of related types and
429 * functions used to complete the definition of its semantics. This class
430 * satisfies the requirements of such a traits class.
432 template<typename _Ch_type>
436 typedef _Ch_type char_type;
437 typedef std::basic_string<char_type> string_type;
438 typedef std::locale locale_type;
439 typedef std::ctype_base::mask char_class_type;
443 * @brief Constructs a default traits object.
449 * @brief Gives the length of a C-style string starting at @p __p.
451 * @param __p a pointer to the start of a character sequence.
453 * @returns the number of characters between @p *__p and the first
454 * default-initialized value of type @p char_type. In other words, uses
455 * the C-string algorithm for determining the length of a sequence of
459 length(const char_type* __p)
460 { return string_type::traits_type::length(__p); }
463 * @brief Performs the identity translation.
465 * @param c A character to the locale-specific character set.
470 translate(char_type __c) const
474 * @brief Translates a character into a case-insensitive equivalent.
476 * @param c A character to the locale-specific character set.
478 * @returns the locale-specific lower-case equivalent of c.
479 * @throws std::bad_cast if the imbued locale does not support the ctype
483 translate_nocase(char_type __c) const
486 using std::use_facet;
487 return use_facet<ctype<char_type> >(_M_locale).tolower(__c);
491 * @brief Gets a sort key for a character sequence.
493 * @param first beginning of the character sequence.
494 * @param last one-past-the-end of the character sequence.
496 * Returns a sort key for the character sequence designated by the
497 * iterator range [F1, F2) such that if the character sequence [G1, G2)
498 * sorts before the character sequence [H1, H2) then
499 * v.transform(G1, G2) < v.transform(H1, H2).
501 * What this really does is provide a more efficient way to compare a
502 * string to multiple other strings in locales with fancy collation
503 * rules and equivalence classes.
505 * @returns a locale-specific sort key equivalent to the input range.
507 * @throws std::bad_cast if the current locale does not have a collate
510 template<typename _Fwd_iter>
512 transform(_Fwd_iter __first, _Fwd_iter __last) const
515 using std::use_facet;
516 const collate<_Ch_type>& __c(use_facet<
517 collate<_Ch_type> >(_M_locale));
518 string_type __s(__first, __last);
519 return __c.transform(__s.data(), __s.data() + __s.size());
525 * @param first beginning of the character sequence.
526 * @param last one-past-the-end of the character sequence.
528 * Effects: if typeid(use_facet<collate<_Ch_type> >) ==
529 * typeid(collate_byname<_Ch_type>) and the form of the sort key
530 * returned by collate_byname<_Ch_type>::transform(first, last) is known
531 * and can be converted into a primary sort key then returns that key,
532 * otherwise returns an empty string. WTF??
534 * @todo Implement this function.
536 template<typename _Fwd_iter>
538 transform_primary(_Fwd_iter __first, _Fwd_iter __last) const;
541 * @brief Gets a collation element by name.
543 * @param first beginning of the collation element name.
544 * @param last one-past-the-end of the collation element name.
546 * @returns a sequence of one or more characters that represents the
547 * collating element consisting of the character sequence designated by
548 * the iterator range [first, last). Returns an empty string if the
549 * character sequence is not a valid collating element.
551 * @todo Implement this function.
553 template<typename _Fwd_iter>
555 lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const;
558 * @brief Maps one or more characters to a named character
561 * @param first beginning of the character sequence.
562 * @param last one-past-the-end of the character sequence.
564 * @returns an unspecified value that represents the character
565 * classification named by the character sequence designated by the
566 * iterator range [first, last). The value returned shall be independent
567 * of the case of the characters in the character sequence. If the name
568 * is not recognized then returns a value that compares equal to 0.
570 * At least the following names (or their wide-character equivalent) are
588 * @todo Implement this function.
590 template<typename _Fwd_iter>
592 lookup_classname(_Fwd_iter __first, _Fwd_iter __last) const;
595 * @brief Determines if @p c is a member of an identified class.
597 * @param c a character.
598 * @param f a class type (as returned from lookup_classname).
600 * @returns true if the character @p c is a member of the classification
601 * represented by @p f, false otherwise.
603 * @throws std::bad_cast if the current locale does not have a ctype
607 isctype(_Ch_type __c, char_class_type __f) const;
610 * @brief Converts a digit to an int.
612 * @param ch a character representing a digit.
613 * @param radix the radix if the numeric conversion (limited to 8, 10,
616 * @returns the value represented by the digit ch in base radix if the
617 * character ch is a valid digit in base radix; otherwise returns -1.
620 value(_Ch_type __ch, int __radix) const;
623 * @brief Imbues the regex_traits object with a copy of a new locale.
625 * @param loc A locale.
627 * @returns a copy of the previous locale in use by the regex_traits
630 * @note Calling imbue with a different locale than the one currently in
631 * use invalidates all cached data held by *this.
634 imbue(locale_type __loc)
636 std::swap(_M_locale, __loc);
641 * @brief Gets a copy of the current locale in use by the regex_traits
646 { return _M_locale; }
649 locale_type _M_locale;
652 template<typename _Ch_type>
653 bool regex_traits<_Ch_type>::
654 isctype(_Ch_type __c, char_class_type __f) const
657 using std::use_facet;
658 const ctype<_Ch_type>& __ctype(use_facet<
659 ctype<_Ch_type> >(_M_locale));
661 if (__ctype.is(__c, __f))
664 // special case of underscore in [[:w:]]
665 if (__c == __ctype.widen('_'))
667 const char* const __wb[] = "w";
668 char_class_type __wt = this->lookup_classname(__wb,
669 __wb + sizeof(__wb));
674 // special case of [[:space:]] in [[:blank:]]
675 if (__c == __ctype.isspace(__c))
677 const char* const __bb[] = "blank";
678 char_class_type __bt = this->lookup_classname(__bb,
679 __bb + sizeof(__bb));
687 template<typename _Ch_type>
688 int regex_traits<_Ch_type>::
689 value(_Ch_type __ch, int __radix) const
691 std::basic_istringstream<_Ch_type> __is(string_type(1, __ch));
695 else if (__radix == 16)
701 // [7.8] Class basic_regex
703 * Objects of specializations of this class represent regular expressions
704 * constructed from sequences of character type @p _Ch_type.
706 * Storage for the regular expression is allocated and deallocated as
707 * necessary by the member functions of this class.
709 template<typename _Ch_type, typename _Rx_traits = regex_traits<_Ch_type> >
714 typedef _Ch_type value_type;
715 typedef regex_constants::syntax_option_type flag_type;
716 typedef typename _Rx_traits::locale_type locale_type;
717 typedef typename _Rx_traits::string_type string_type;
721 * tr1 [7.8.1] std [28.8.1]
724 static const regex_constants::syntax_option_type icase
725 = regex_constants::icase;
726 static const regex_constants::syntax_option_type nosubs
727 = regex_constants::nosubs;
728 static const regex_constants::syntax_option_type optimize
729 = regex_constants::optimize;
730 static const regex_constants::syntax_option_type collate
731 = regex_constants::collate;
732 static const regex_constants::syntax_option_type ECMAScript
733 = regex_constants::ECMAScript;
734 static const regex_constants::syntax_option_type basic
735 = regex_constants::basic;
736 static const regex_constants::syntax_option_type extended
737 = regex_constants::extended;
738 static const regex_constants::syntax_option_type awk
739 = regex_constants::awk;
740 static const regex_constants::syntax_option_type grep
741 = regex_constants::grep;
742 static const regex_constants::syntax_option_type egrep
743 = regex_constants::egrep;
746 // [7.8.2] construct/copy/destroy
748 * Constructs a basic regular expression that does not match any
749 * character sequence.
752 : _M_flags(regex_constants::ECMAScript), _M_pattern(), _M_mark_count(0)
756 * @brief Constructs a basic regular expression from the sequence
757 * [p, p + char_traits<_Ch_type>::length(p)) interpreted according to the
760 * @param p A pointer to the start of a C-style null-terminated string
761 * containing a regular expression.
762 * @param f Flags indicating the syntax rules and options.
764 * @throws regex_error if @p p is not a valid regular expression.
767 basic_regex(const _Ch_type* __p,
768 flag_type __f = regex_constants::ECMAScript)
769 : _M_flags(__f), _M_pattern(__p), _M_mark_count(0)
773 * @brief Constructs a basic regular expression from the sequence
774 * [p, p + len) interpreted according to the flags in @p f.
776 * @param p A pointer to the start of a string containing a regular
778 * @param len The length of the string containing the regular expression.
779 * @param f Flags indicating the syntax rules and options.
781 * @throws regex_error if @p p is not a valid regular expression.
783 basic_regex(const _Ch_type* __p, std::size_t __len, flag_type __f)
784 : _M_flags(__f) , _M_pattern(__p, __len), _M_mark_count(0)
788 * @brief Copy-constructs a basic regular expression.
790 * @param rhs A @p regex object.
792 basic_regex(const basic_regex& __rhs)
793 : _M_flags(__rhs._M_flags), _M_pattern(__rhs._M_pattern),
794 _M_mark_count(__rhs._M_mark_count)
798 * @brief Constructs a basic regular expression from the string
799 * @p interpreted according to the flags in @p f.
801 * @param p A string containing a regular expression.
802 * @param f Flags indicating the syntax rules and options.
804 * @throws regex_error if @p p is not a valid regular expression.
806 template<typename _Ch_traits, typename _Ch_alloc>
808 basic_regex(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
809 flag_type __f = regex_constants::ECMAScript)
810 : _M_flags(__f), _M_pattern(__s), _M_mark_count(0)
814 * @brief Constructs a basic regular expression from the range
815 * [first, last) interpreted according to the flags in @p f.
817 * @param first The start of a range containing a valid regular
819 * @param last The end of a range containing a valid regular
821 * @param f The format flags of the regular expression.
823 * @throws regex_error if @p [first, last) is not a valid regular
826 template<typename _InputIterator>
827 basic_regex(_InputIterator __first, _InputIterator __last,
828 flag_type __f = regex_constants::ECMAScript)
829 : _M_flags(__f), _M_pattern(__first, __last), _M_mark_count(0)
832 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
834 * @brief Constructs a basic regular expression from an initializer list.
836 * @param l The initializer list.
837 * @param f The format flags of the regular expression.
839 * @throws regex_error if @p l is not a valid regular expression.
841 basic_regex(initializer_list<_Ch_type> __l,
842 flag_type __f = regex_constants::ECMAScript)
843 : _M_flags(__f), _M_pattern(__l.begin(), __l.end()), _M_mark_count(0)
848 * @brief Destroys a basic regular expression.
854 * @brief Assigns one regular expression to another.
857 operator=(const basic_regex& __rhs)
858 { return this->assign(__rhs); }
861 * @brief Replaces a regular expression with a new one constructed from
862 * a C-style null-terminated string.
864 * @param A pointer to the start of a null-terminated C-style string
865 * containing a regular expression.
868 operator=(const _Ch_type* __p)
869 { return this->assign(__p, flags()); }
872 * @brief Replaces a regular expression with a new one constructed from
875 * @param A pointer to a string containing a regular expression.
877 template<typename _Ch_typeraits, typename _Allocator>
879 operator=(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s)
880 { return this->assign(__s, flags()); }
884 * @brief the real assignment operator.
886 * @param that Another regular expression object.
889 assign(const basic_regex& __that)
891 basic_regex __tmp(__that);
897 * @brief Assigns a new regular expression to a regex object from a
898 * C-style null-terminated string containing a regular expression
901 * @param p A pointer to a C-style null-terminated string containing
902 * a regular expression pattern.
903 * @param flags Syntax option flags.
905 * @throws regex_error if p does not contain a valid regular expression
906 * pattern interpreted according to @p flags. If regex_error is thrown,
907 * *this remains unchanged.
910 assign(const _Ch_type* __p,
911 flag_type __flags = regex_constants::ECMAScript)
912 { return this->assign(string_type(__p), __flags); }
915 * @brief Assigns a new regular expression to a regex object from a
916 * C-style string containing a regular expression pattern.
918 * @param p A pointer to a C-style string containing a
919 * regular expression pattern.
920 * @param len The length of the regular expression pattern string.
921 * @param flags Syntax option flags.
923 * @throws regex_error if p does not contain a valid regular expression
924 * pattern interpreted according to @p flags. If regex_error is thrown,
925 * *this remains unchanged.
928 assign(const _Ch_type* __p, std::size_t __len, flag_type __flags)
929 { return this->assign(string_type(__p, __len), __flags); }
932 * @brief Assigns a new regular expression to a regex object from a
933 * string containing a regular expression pattern.
935 * @param s A string containing a regular expression pattern.
936 * @param flags Syntax option flags.
938 * @throws regex_error if p does not contain a valid regular expression
939 * pattern interpreted according to @p flags. If regex_error is thrown,
940 * *this remains unchanged.
942 template<typename _Ch_typeraits, typename _Allocator>
944 assign(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s,
945 flag_type __f = regex_constants::ECMAScript)
947 basic_regex __tmp(__s, __f);
953 * @brief Assigns a new regular expression to a regex object.
955 * @param first The start of a range containing a valid regular
957 * @param last The end of a range containing a valid regular
959 * @param flags Syntax option flags.
961 * @throws regex_error if p does not contain a valid regular expression
962 * pattern interpreted according to @p flags. If regex_error is thrown,
963 * the object remains unchanged.
965 template<typename _InputIterator>
967 assign(_InputIterator __first, _InputIterator __last,
968 flag_type __flags = regex_constants::ECMAScript)
969 { return this->assign(string_type(__first, __last), __flags); }
971 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
973 * @brief Assigns a new regular expression to a regex object.
975 * @param l An initializer list representing a regular expression.
976 * @param flags Syntax option flags.
978 * @throws regex_error if @p l does not contain a valid regular
979 * expression pattern interpreted according to @p flags. If regex_error
980 * is thrown, the object remains unchanged.
983 assign(initializer_list<_Ch_type> __l,
984 flag_type __f = regex_constants::ECMAScript)
985 { return this->assign(__l.begin(), __l.end(), __f); }
988 // [7.8.4] const operations
990 * @brief Gets the number of marked subexpressions within the regular
995 { return _M_mark_count; }
998 * @brief Gets the flags used to construct the regular expression
999 * or in the last call to assign().
1003 { return _M_flags; }
1007 * @brief Imbues the regular expression object with the given locale.
1009 * @param loc A locale.
1012 imbue(locale_type __loc)
1013 { return _M_traits.imbue(__loc); }
1016 * @brief Gets the locale currently imbued in the regular expression
1021 { return _M_traits.getloc(); }
1025 * @brief Swaps the contents of two regular expression objects.
1027 * @param rhs Another regular expression object.
1030 swap(basic_regex& __rhs)
1032 std::swap(_M_flags, __rhs._M_flags);
1033 std::swap(_M_pattern, __rhs._M_pattern);
1034 std::swap(_M_mark_count, __rhs._M_mark_count);
1035 std::swap(_M_traits, __rhs._M_traits);
1040 * @brief Compiles a regular expression pattern into a NFA.
1041 * @todo Implement this function.
1047 string_type _M_pattern;
1048 unsigned int _M_mark_count;
1049 _Rx_traits _M_traits;
1052 /** @brief Standard regular expressions. */
1053 typedef basic_regex<char> regex;
1054 #ifdef _GLIBCXX_USE_WCHAR_T
1055 /** @brief Standard wide-character regular expressions. */
1056 typedef basic_regex<wchar_t> wregex;
1060 // [7.8.6] basic_regex swap
1062 * @brief Swaps the contents of two regular expression objects.
1063 * @param lhs First regular expression.
1064 * @param rhs Second regular expression.
1066 template<typename _Ch_type, typename _Rx_traits>
1068 swap(basic_regex<_Ch_type, _Rx_traits>& __lhs,
1069 basic_regex<_Ch_type, _Rx_traits>& __rhs)
1070 { __lhs.swap(__rhs); }
1073 // [7.9] Class template sub_match
1075 * A sequence of characters matched by a particular marked sub-expression.
1077 * An object of this class is essentially a pair of iterators marking a
1078 * matched subexpression within a regular expression pattern match. Such
1079 * objects can be converted to and compared with std::basic_string objects
1080 * of a similar base character type as the pattern matched by the regular
1083 * The iterators that make up the pair are the usual half-open interval
1084 * referencing the actual original pattern matched.
1086 template<typename _BiIter>
1087 class sub_match : public std::pair<_BiIter, _BiIter>
1090 typedef typename iterator_traits<_BiIter>::value_type value_type;
1091 typedef typename iterator_traits<_BiIter>::difference_type
1093 typedef _BiIter iterator;
1099 * Gets the length of the matching sequence.
1103 { return this->matched ? std::distance(this->first, this->second) : 0; }
1106 * @brief Gets the matching sequence as a string.
1108 * @returns the matching sequence as a string.
1110 * This is the implicit conversion operator. It is identical to the
1111 * str() member function except that it will want to pop up in
1112 * unexpected places and cause a great deal of confusion and cursing
1115 operator basic_string<value_type>() const
1117 return this->matched
1118 ? std::basic_string<value_type>(this->first, this->second)
1119 : std::basic_string<value_type>();
1123 * @brief Gets the matching sequence as a string.
1125 * @returns the matching sequence as a string.
1127 basic_string<value_type>
1130 return this->matched
1131 ? std::basic_string<value_type>(this->first, this->second)
1132 : std::basic_string<value_type>();
1136 * @brief Compares this and another matched sequence.
1138 * @param s Another matched sequence to compare to this one.
1140 * @retval <0 this matched sequence will collate before @p s.
1141 * @retval =0 this matched sequence is equivalent to @p s.
1142 * @retval <0 this matched sequence will collate after @p s.
1145 compare(const sub_match& __s) const
1146 { return this->str().compare(__s.str()); }
1149 * @brief Compares this sub_match to a string.
1151 * @param s A string to compare to this sub_match.
1153 * @retval <0 this matched sequence will collate before @p s.
1154 * @retval =0 this matched sequence is equivalent to @p s.
1155 * @retval <0 this matched sequence will collate after @p s.
1158 compare(const basic_string<value_type>& __s) const
1159 { return this->str().compare(__s); }
1162 * @brief Compares this sub_match to a C-style string.
1164 * @param s A C-style string to compare to this sub_match.
1166 * @retval <0 this matched sequence will collate before @p s.
1167 * @retval =0 this matched sequence is equivalent to @p s.
1168 * @retval <0 this matched sequence will collate after @p s.
1171 compare(const value_type* __s) const
1172 { return this->str().compare(__s); }
1176 /** @brief Standard regex submatch over a C-style null-terminated string. */
1177 typedef sub_match<const char*> csub_match;
1178 /** @brief Standard regex submatch over a standard string. */
1179 typedef sub_match<string::const_iterator> ssub_match;
1180 #ifdef _GLIBCXX_USE_WCHAR_T
1181 /** @brief Regex submatch over a C-style null-terminated wide string. */
1182 typedef sub_match<const wchar_t*> wcsub_match;
1183 /** @brief Regex submatch over a standard wide string. */
1184 typedef sub_match<wstring::const_iterator> wssub_match;
1187 // [7.9.2] sub_match non-member operators
1190 * @brief Tests the equivalence of two regular expression submatches.
1191 * @param lhs First regular expression submatch.
1192 * @param rhs Second regular expression submatch.
1193 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1195 template<typename _BiIter>
1197 operator==(const sub_match<_BiIter>& __lhs,
1198 const sub_match<_BiIter>& __rhs)
1199 { return __lhs.compare(__rhs) == 0; }
1202 * @brief Tests the inequivalence of two regular expression submatches.
1203 * @param lhs First regular expression submatch.
1204 * @param rhs Second regular expression submatch.
1205 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1207 template<typename _BiIter>
1209 operator!=(const sub_match<_BiIter>& __lhs,
1210 const sub_match<_BiIter>& __rhs)
1211 { return __lhs.compare(__rhs) != 0; }
1214 * @brief Tests the ordering of two regular expression submatches.
1215 * @param lhs First regular expression submatch.
1216 * @param rhs Second regular expression submatch.
1217 * @returns true if @a lhs precedes @a rhs, false otherwise.
1219 template<typename _BiIter>
1221 operator<(const sub_match<_BiIter>& __lhs,
1222 const sub_match<_BiIter>& __rhs)
1223 { return __lhs.compare(__rhs) < 0; }
1226 * @brief Tests the ordering of two regular expression submatches.
1227 * @param lhs First regular expression submatch.
1228 * @param rhs Second regular expression submatch.
1229 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1231 template<typename _BiIter>
1233 operator<=(const sub_match<_BiIter>& __lhs,
1234 const sub_match<_BiIter>& __rhs)
1235 { return __lhs.compare(__rhs) <= 0; }
1238 * @brief Tests the ordering of two regular expression submatches.
1239 * @param lhs First regular expression submatch.
1240 * @param rhs Second regular expression submatch.
1241 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1243 template<typename _BiIter>
1245 operator>=(const sub_match<_BiIter>& __lhs,
1246 const sub_match<_BiIter>& __rhs)
1247 { return __lhs.compare(__rhs) >= 0; }
1250 * @brief Tests the ordering of two regular expression submatches.
1251 * @param lhs First regular expression submatch.
1252 * @param rhs Second regular expression submatch.
1253 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1255 template<typename _BiIter>
1257 operator>(const sub_match<_BiIter>& __lhs,
1258 const sub_match<_BiIter>& __rhs)
1259 { return __lhs.compare(__rhs) > 0; }
1262 * @brief Tests the equivalence of a string and a regular expression
1264 * @param lhs A string.
1265 * @param rhs A regular expression submatch.
1266 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1268 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1270 operator==(const basic_string<
1271 typename iterator_traits<_Bi_iter>::value_type,
1272 _Ch_traits, _Ch_alloc>& __lhs,
1273 const sub_match<_Bi_iter>& __rhs)
1274 { return __lhs == __rhs.str(); }
1277 * @brief Tests the inequivalence of a string and a regular expression
1279 * @param lhs A string.
1280 * @param rhs A regular expression submatch.
1281 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1283 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1285 operator!=(const basic_string<
1286 typename iterator_traits<_Bi_iter>::value_type,
1287 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1288 { return __lhs != __rhs.str(); }
1291 * @brief Tests the ordering of a string and a regular expression submatch.
1292 * @param lhs A string.
1293 * @param rhs A regular expression submatch.
1294 * @returns true if @a lhs precedes @a rhs, false otherwise.
1296 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1298 operator<(const basic_string<
1299 typename iterator_traits<_Bi_iter>::value_type,
1300 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1301 { return __lhs < __rhs.str(); }
1304 * @brief Tests the ordering of a string and a regular expression submatch.
1305 * @param lhs A string.
1306 * @param rhs A regular expression submatch.
1307 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1309 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1311 operator>(const basic_string<
1312 typename iterator_traits<_Bi_iter>::value_type,
1313 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1314 { return __lhs > __rhs.str(); }
1317 * @brief Tests the ordering of a string and a regular expression submatch.
1318 * @param lhs A string.
1319 * @param rhs A regular expression submatch.
1320 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1322 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1324 operator>=(const basic_string<
1325 typename iterator_traits<_Bi_iter>::value_type,
1326 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1327 { return __lhs >= __rhs.str(); }
1330 * @brief Tests the ordering of a string and a regular expression submatch.
1331 * @param lhs A string.
1332 * @param rhs A regular expression submatch.
1333 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1335 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1337 operator<=(const basic_string<
1338 typename iterator_traits<_Bi_iter>::value_type,
1339 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1340 { return __lhs <= __rhs.str(); }
1343 * @brief Tests the equivalence of a regular expression submatch and a
1345 * @param lhs A regular expression submatch.
1346 * @param rhs A string.
1347 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1349 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1351 operator==(const sub_match<_Bi_iter>& __lhs,
1353 typename iterator_traits<_Bi_iter>::value_type,
1354 _Ch_traits, _Ch_alloc>& __rhs)
1355 { return __lhs.str() == __rhs; }
1358 * @brief Tests the inequivalence of a regular expression submatch and a
1360 * @param lhs A regular expression submatch.
1361 * @param rhs A string.
1362 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1364 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1366 operator!=(const sub_match<_Bi_iter>& __lhs,
1368 typename iterator_traits<_Bi_iter>::value_type,
1369 _Ch_traits, _Ch_alloc>& __rhs)
1370 { return __lhs.str() != __rhs; }
1373 * @brief Tests the ordering of a regular expression submatch and a string.
1374 * @param lhs A regular expression submatch.
1375 * @param rhs A string.
1376 * @returns true if @a lhs precedes @a rhs, false otherwise.
1378 template<typename _Bi_iter, class _Ch_traits, class _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 succeeds @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 does not precede @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 succeed @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 equivalence of a C string and a regular expression
1431 * @param lhs A C string.
1432 * @param rhs A regular expression submatch.
1433 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1435 template<typename _Bi_iter>
1437 operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1438 const sub_match<_Bi_iter>& __rhs)
1439 { return __lhs == __rhs.str(); }
1442 * @brief Tests the inequivalence of an iterator value and a regular
1443 * expression submatch.
1444 * @param lhs A regular expression submatch.
1445 * @param rhs A string.
1446 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1448 template<typename _Bi_iter>
1450 operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1451 const sub_match<_Bi_iter>& __rhs)
1452 { return __lhs != __rhs.str(); }
1455 * @brief Tests the ordering of a string and a regular expression submatch.
1456 * @param lhs A string.
1457 * @param rhs A regular expression submatch.
1458 * @returns true if @a lhs precedes @a rhs, false otherwise.
1460 template<typename _Bi_iter>
1462 operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1463 const sub_match<_Bi_iter>& __rhs)
1464 { return __lhs < __rhs.str(); }
1467 * @brief Tests the ordering of a string and a regular expression submatch.
1468 * @param lhs A string.
1469 * @param rhs A regular expression submatch.
1470 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1472 template<typename _Bi_iter>
1474 operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1475 const sub_match<_Bi_iter>& __rhs)
1476 { return __lhs > __rhs.str(); }
1479 * @brief Tests the ordering of a string and a regular expression submatch.
1480 * @param lhs A string.
1481 * @param rhs A regular expression submatch.
1482 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1484 template<typename _Bi_iter>
1486 operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1487 const sub_match<_Bi_iter>& __rhs)
1488 { return __lhs >= __rhs.str(); }
1491 * @brief Tests the ordering of a string and a regular expression submatch.
1492 * @param lhs A string.
1493 * @param rhs A regular expression submatch.
1494 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1496 template<typename _Bi_iter>
1498 operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1499 const sub_match<_Bi_iter>& __rhs)
1500 { return __lhs <= __rhs.str(); }
1503 * @brief Tests the equivalence of a regular expression submatch and a
1505 * @param lhs A regular expression submatch.
1506 * @param rhs A pointer to a string?
1507 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1509 template<typename _Bi_iter>
1511 operator==(const sub_match<_Bi_iter>& __lhs,
1512 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1513 { return __lhs.str() == __rhs; }
1516 * @brief Tests the inequivalence of a regular expression submatch and a
1518 * @param lhs A regular expression submatch.
1519 * @param rhs A pointer to a string.
1520 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1522 template<typename _Bi_iter>
1524 operator!=(const sub_match<_Bi_iter>& __lhs,
1525 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1526 { return __lhs.str() != __rhs; }
1529 * @brief Tests the ordering of a regular expression submatch and a string.
1530 * @param lhs A regular expression submatch.
1531 * @param rhs A string.
1532 * @returns true if @a lhs precedes @a rhs, false otherwise.
1534 template<typename _Bi_iter>
1536 operator<(const sub_match<_Bi_iter>& __lhs,
1537 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1538 { return __lhs.str() < __rhs; }
1541 * @brief Tests the ordering of a regular expression submatch and a string.
1542 * @param lhs A regular expression submatch.
1543 * @param rhs A string.
1544 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1546 template<typename _Bi_iter>
1548 operator>(const sub_match<_Bi_iter>& __lhs,
1549 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1550 { return __lhs.str() > __rhs; }
1553 * @brief Tests the ordering of a regular expression submatch and a string.
1554 * @param lhs A regular expression submatch.
1555 * @param rhs A string.
1556 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1558 template<typename _Bi_iter>
1560 operator>=(const sub_match<_Bi_iter>& __lhs,
1561 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1562 { return __lhs.str() >= __rhs; }
1565 * @brief Tests the ordering of a regular expression submatch and a string.
1566 * @param lhs A regular expression submatch.
1567 * @param rhs A string.
1568 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1570 template<typename _Bi_iter>
1572 operator<=(const sub_match<_Bi_iter>& __lhs,
1573 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1574 { return __lhs.str() <= __rhs; }
1577 * @brief Tests the equivalence of a string and a regular expression
1579 * @param lhs A string.
1580 * @param rhs A regular expression submatch.
1581 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1583 template<typename _Bi_iter>
1585 operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1586 const sub_match<_Bi_iter>& __rhs)
1587 { return __lhs == __rhs.str(); }
1590 * @brief Tests the inequivalence of a string and a regular expression
1592 * @param lhs A string.
1593 * @param rhs A regular expression submatch.
1594 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1596 template<typename _Bi_iter>
1598 operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1599 const sub_match<_Bi_iter>& __rhs)
1600 { return __lhs != __rhs.str(); }
1603 * @brief Tests the ordering of a string and a regular expression submatch.
1604 * @param lhs A string.
1605 * @param rhs A regular expression submatch.
1606 * @returns true if @a lhs precedes @a rhs, false otherwise.
1608 template<typename _Bi_iter>
1610 operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1611 const sub_match<_Bi_iter>& __rhs)
1612 { return __lhs < __rhs.str(); }
1615 * @brief Tests the ordering of a string and a regular expression submatch.
1616 * @param lhs A string.
1617 * @param rhs A regular expression submatch.
1618 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1620 template<typename _Bi_iter>
1622 operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1623 const sub_match<_Bi_iter>& __rhs)
1624 { return __lhs > __rhs.str(); }
1627 * @brief Tests the ordering of a string and a regular expression submatch.
1628 * @param lhs A string.
1629 * @param rhs A regular expression submatch.
1630 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1632 template<typename _Bi_iter>
1634 operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1635 const sub_match<_Bi_iter>& __rhs)
1636 { return __lhs >= __rhs.str(); }
1639 * @brief Tests the ordering of a string and a regular expression submatch.
1640 * @param lhs A string.
1641 * @param rhs A regular expression submatch.
1642 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1644 template<typename _Bi_iter>
1646 operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1647 const sub_match<_Bi_iter>& __rhs)
1648 { return __lhs <= __rhs.str(); }
1651 * @brief Tests the equivalence of a regular expression submatch and a
1653 * @param lhs A regular expression submatch.
1654 * @param rhs A const string reference.
1655 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1657 template<typename _Bi_iter>
1659 operator==(const sub_match<_Bi_iter>& __lhs,
1660 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1661 { return __lhs.str() == __rhs; }
1664 * @brief Tests the inequivalence of a regular expression submatch and a
1666 * @param lhs A regular expression submatch.
1667 * @param rhs A const string reference.
1668 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1670 template<typename _Bi_iter>
1672 operator!=(const sub_match<_Bi_iter>& __lhs,
1673 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1674 { return __lhs.str() != __rhs; }
1677 * @brief Tests the ordering of a regular expression submatch and a string.
1678 * @param lhs A regular expression submatch.
1679 * @param rhs A const string reference.
1680 * @returns true if @a lhs precedes @a rhs, false otherwise.
1682 template<typename _Bi_iter>
1684 operator<(const sub_match<_Bi_iter>& __lhs,
1685 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1686 { return __lhs.str() < __rhs; }
1689 * @brief Tests the ordering of a regular expression submatch and a string.
1690 * @param lhs A regular expression submatch.
1691 * @param rhs A const string reference.
1692 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1694 template<typename _Bi_iter>
1696 operator>(const sub_match<_Bi_iter>& __lhs,
1697 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1698 { return __lhs.str() > __rhs; }
1701 * @brief Tests the ordering of a regular expression submatch and a string.
1702 * @param lhs A regular expression submatch.
1703 * @param rhs A const string reference.
1704 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1706 template<typename _Bi_iter>
1708 operator>=(const sub_match<_Bi_iter>& __lhs,
1709 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1710 { return __lhs.str() >= __rhs; }
1713 * @brief Tests the ordering of a regular expression submatch and a string.
1714 * @param lhs A regular expression submatch.
1715 * @param rhs A const string reference.
1716 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1718 template<typename _Bi_iter>
1720 operator<=(const sub_match<_Bi_iter>& __lhs,
1721 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1722 { return __lhs.str() <= __rhs; }
1725 * @brief Inserts a matched string into an output stream.
1727 * @param os The output stream.
1728 * @param m A submatch string.
1730 * @returns the output stream with the submatch string inserted.
1732 template<typename _Ch_type, typename _Ch_traits, typename _Bi_iter>
1734 basic_ostream<_Ch_type, _Ch_traits>&
1735 operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os,
1736 const sub_match<_Bi_iter>& __m)
1737 { return __os << __m.str(); }
1739 // [7.10] Class template match_results
1741 * @brief The results of a match or search operation.
1743 * A collection of character sequences representing the result of a regular
1744 * expression match. Storage for the collection is allocated and freed as
1745 * necessary by the member functions of class template match_results.
1747 * This class satisfies the Sequence requirements, with the exception that
1748 * only the operations defined for a const-qualified Sequence are supported.
1750 * The sub_match object stored at index 0 represents sub-expression 0, i.e.
1751 * the whole match. In this case the sub_match member matched is always true.
1752 * The sub_match object stored at index n denotes what matched the marked
1753 * sub-expression n within the matched expression. If the sub-expression n
1754 * participated in a regular expression match then the sub_match member
1755 * matched evaluates to true, and members first and second denote the range
1756 * of characters [first, second) which formed that match. Otherwise matched
1757 * is false, and members first and second point to the end of the sequence
1758 * that was searched.
1762 template<typename _Bi_iter,
1763 typename _Allocator = allocator<sub_match<_Bi_iter> > >
1765 : private std::vector<std::_GLIBCXX_TR1 sub_match<_Bi_iter>, _Allocator>
1768 typedef std::vector<std::_GLIBCXX_TR1 sub_match<_Bi_iter>, _Allocator>
1773 * @name 10.? Public Types
1776 typedef sub_match<_Bi_iter> value_type;
1777 typedef typename _Allocator::const_reference const_reference;
1778 typedef const_reference reference;
1779 typedef typename _Base_type::const_iterator const_iterator;
1780 typedef const_iterator iterator;
1781 typedef typename iterator_traits<_Bi_iter>::difference_type
1783 typedef typename _Allocator::size_type size_type;
1784 typedef _Allocator allocator_type;
1785 typedef typename iterator_traits<_Bi_iter>::value_type char_type;
1786 typedef basic_string<char_type> string_type;
1791 * @name 10.1 Construction, Copying, and Destruction
1796 * @brief Constructs a default %match_results container.
1797 * @post size() returns 0 and str() returns an empty string.
1800 match_results(const _Allocator& __a = _Allocator())
1801 : _Base_type(__a), _M_matched(false)
1805 * @brief Copy constructs a %match_results.
1807 match_results(const match_results& __rhs)
1808 : _Base_type(__rhs), _M_matched(__rhs._M_matched),
1809 _M_prefix(__rhs._M_prefix), _M_suffix(__rhs._M_suffix)
1813 * @brief Assigns rhs to *this.
1816 operator=(const match_results& __rhs)
1818 match_results __tmp(__rhs);
1824 * @brief Destroys a %match_results object.
1837 * @brief Gets the number of matches and submatches.
1839 * The number of matches for a given regular expression will be either 0
1840 * if there was no match or mark_count() + 1 if a match was successful.
1841 * Some matches may be empty.
1843 * @returns the number of matches found.
1847 { return _M_matched ? _Base_type::size() + 1 : 0; }
1851 using _Base_type::max_size;
1854 * @brief Indicates if the %match_results contains no results.
1855 * @retval true The %match_results object is empty.
1856 * @retval false The %match_results object is not empty.
1860 { return size() == 0; }
1865 * @name 10.3 Element Access
1870 * @brief Gets the length of the indicated submatch.
1871 * @param sub indicates the submatch.
1873 * This function returns the length of the indicated submatch, or the
1874 * length of the entire match if @p sub is zero (the default).
1877 length(size_type __sub = 0) const
1878 { return _M_matched ? this->str(__sub).length() : 0; }
1881 * @brief Gets the offset of the beginning of the indicated submatch.
1882 * @param sub indicates the submatch.
1884 * This function returns the offset from the beginning of the target
1885 * sequence to the beginning of the submatch, unless the value of @p sub
1886 * is zero (the default), in which case this function returns the offset
1887 * from the beginning of the target sequence to the beginning of the
1891 position(size_type __sub = 0) const
1893 return _M_matched ? std::distance(this->prefix().first,
1894 (*this)[__sub].first) : 0;
1898 * @brief Gets the match or submatch converted to a string type.
1899 * @param sub indicates the submatch.
1901 * This function gets the submatch (or match, if @p sub is zero) extracted
1902 * from the target range and converted to the associated string type.
1905 str(size_type __sub = 0) const
1906 { return _M_matched ? (*this)[__sub].str() : string_type(); }
1909 * @brief Gets a %sub_match reference for the match or submatch.
1910 * @param sub indicates the submatch.
1912 * This function gets a reference to the indicated submatch, or the entire
1913 * match if @p sub is zero.
1915 * If @p sub >= size() then this function returns a %sub_match with a
1916 * special value indicating no submatch.
1919 operator[](size_type __sub) const
1920 { return _Base_type::operator[](__sub); }
1923 * @brief Gets a %sub_match representing the match prefix.
1925 * This function gets a reference to a %sub_match object representing the
1926 * part of the target range between the start of the target range and the
1927 * start of the match.
1931 { return _M_prefix; }
1934 * @brief Gets a %sub_match representing the match suffix.
1936 * This function gets a reference to a %sub_match object representing the
1937 * part of the target range between the end of the match and the end of
1942 { return _M_suffix; }
1945 * @brief Gets an iterator to the start of the %sub_match collection.
1949 { return _Base_type::begin(); }
1951 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
1953 * @brief Gets an iterator to the start of the %sub_match collection.
1957 { return _Base_type::begin(); }
1961 * @brief Gets an iterator to one-past-the-end of the collection.
1965 { return _Base_type::end(); }
1967 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
1969 * @brief Gets an iterator to one-past-the-end of the collection.
1973 { return _Base_type::end(); }
1979 * @name 10.4 Formatting
1981 * These functions perform formatted substitution of the matched character
1982 * sequences into their target. The format specifiers and escape sequences
1983 * accepted by these functions are determined by their @p flags parameter
1984 * as documented above.
1989 * @todo Implement this function.
1991 template<typename _Out_iter>
1993 format(_Out_iter __out, const string_type& __fmt,
1994 regex_constants::match_flag_type __flags
1995 = regex_constants::format_default) const;
1998 * @todo Implement this function.
2001 format(const string_type& __fmt,
2002 regex_constants::match_flag_type __flags
2003 = regex_constants::format_default) const;
2008 * @name 10.5 Allocator
2013 * @brief Gets a copy of the allocator.
2016 //get_allocator() const;
2017 using _Base_type::get_allocator;
2027 * @brief Swaps the contents of two match_results.
2030 swap(match_results& __that)
2032 _Base_type::swap(__that);
2033 std::swap(_M_matched, __that._M_matched);
2034 std::swap(_M_prefix, __that._M_prefix);
2035 std::swap(_M_suffix, __that._M_suffix);
2041 value_type _M_prefix;
2042 value_type _M_suffix;
2045 typedef match_results<const char*> cmatch;
2046 typedef match_results<string::const_iterator> smatch;
2047 #ifdef _GLIBCXX_USE_WCHAR_T
2048 typedef match_results<const wchar_t*> wcmatch;
2049 typedef match_results<wstring::const_iterator> wsmatch;
2052 // match_results comparisons
2054 * @brief Compares two match_results for equality.
2055 * @returns true if the two objects refer to the same match,
2057 * @todo Implement this function.
2059 template<typename _Bi_iter, typename _Allocator>
2061 operator==(const match_results<_Bi_iter, _Allocator>& __m1,
2062 const match_results<_Bi_iter, _Allocator>& __m2);
2065 * @brief Compares two match_results for inequality.
2066 * @returns true if the two objects do not refer to the same match,
2069 template<typename _Bi_iter, class _Allocator>
2071 operator!=(const match_results<_Bi_iter, _Allocator>& __m1,
2072 const match_results<_Bi_iter, _Allocator>& __m2)
2073 { return !(__m1 == __m2); }
2075 // [7.10.6] match_results swap
2077 * @brief Swaps two match results.
2078 * @param lhs A match result.
2079 * @param rhs A match result.
2081 * The contents of the two match_results objects are swapped.
2083 template<typename _Bi_iter, typename _Allocator>
2085 swap(match_results<_Bi_iter, _Allocator>& __lhs,
2086 match_results<_Bi_iter, _Allocator>& __rhs)
2087 { __lhs.swap(__rhs); }
2089 // [7.11.2] Function template regex_match
2091 * @name Matching, Searching, and Replacing
2096 * @brief Determines if there is a match between the regular expression @p e
2097 * and all of the character sequence [first, last).
2099 * @param first Beginning of the character sequence to match.
2100 * @param last One-past-the-end of the character sequence to match.
2101 * @param m The match results.
2102 * @param re The regular expression.
2103 * @param flags Controls how the regular expression is matched.
2105 * @retval true A match exists.
2106 * @retval false Otherwise.
2108 * @throws an exception of type regex_error.
2110 * @todo Implement this function.
2112 template<typename _Bi_iter, typename _Allocator,
2113 typename _Ch_type, typename _Rx_traits>
2115 regex_match(_Bi_iter __first, _Bi_iter __last,
2116 match_results<_Bi_iter, _Allocator>& __m,
2117 const basic_regex<_Ch_type, _Rx_traits>& __re,
2118 regex_constants::match_flag_type __flags
2119 = regex_constants::match_default);
2122 * @brief Indicates if there is a match between the regular expression @p e
2123 * and all of the character sequence [first, last).
2125 * @param first Beginning of the character sequence to match.
2126 * @param last One-past-the-end of the character sequence to match.
2127 * @param re The regular expression.
2128 * @param flags Controls how the regular expression is matched.
2130 * @retval true A match exists.
2131 * @retval false Otherwise.
2133 * @throws an exception of type regex_error.
2135 template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
2137 regex_match(_Bi_iter __first, _Bi_iter __last,
2138 const basic_regex<_Ch_type, _Rx_traits>& __re,
2139 regex_constants::match_flag_type __flags
2140 = regex_constants::match_default)
2142 match_results<_Bi_iter> __what;
2143 return regex_match(__first, __last, __what, __re, __flags);
2147 * @brief Determines if there is a match between the regular expression @p e
2148 * and a C-style null-terminated string.
2150 * @param s The C-style null-terminated string to match.
2151 * @param m The match results.
2152 * @param re The regular expression.
2153 * @param f Controls how the regular expression is matched.
2155 * @retval true A match exists.
2156 * @retval false Otherwise.
2158 * @throws an exception of type regex_error.
2160 template<typename _Ch_type, typename _Allocator, typename _Rx_traits>
2162 regex_match(const _Ch_type* __s,
2163 match_results<const _Ch_type*, _Allocator>& __m,
2164 const basic_regex<_Ch_type, _Rx_traits>& __re,
2165 regex_constants::match_flag_type __f
2166 = regex_constants::match_default)
2167 { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); }
2170 * @brief Determines if there is a match between the regular expression @p e
2173 * @param s The string to match.
2174 * @param m The match results.
2175 * @param re The regular expression.
2176 * @param flags Controls how the regular expression is matched.
2178 * @retval true A match exists.
2179 * @retval false Otherwise.
2181 * @throws an exception of type regex_error.
2183 template<typename _Ch_traits, typename _Ch_alloc,
2184 typename _Allocator, typename _Ch_type, typename _Rx_traits>
2186 regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
2187 match_results<typename basic_string<_Ch_type,
2188 _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
2189 const basic_regex<_Ch_type, _Rx_traits>& __re,
2190 regex_constants::match_flag_type __flags
2191 = regex_constants::match_default)
2192 { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }
2195 * @brief Indicates if there is a match between the regular expression @p e
2196 * and a C-style null-terminated string.
2198 * @param s The C-style null-terminated string to match.
2199 * @param re The regular expression.
2200 * @param f Controls how the regular expression is matched.
2202 * @retval true A match exists.
2203 * @retval false Otherwise.
2205 * @throws an exception of type regex_error.
2207 template<typename _Ch_type, class _Rx_traits>
2209 regex_match(const _Ch_type* __s,
2210 const basic_regex<_Ch_type, _Rx_traits>& __re,
2211 regex_constants::match_flag_type __f
2212 = regex_constants::match_default)
2213 { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); }
2216 * @brief Indicates if there is a match between the regular expression @p e
2219 * @param s [IN] The string to match.
2220 * @param re [IN] The regular expression.
2221 * @param flags [IN] Controls how the regular expression is matched.
2223 * @retval true A match exists.
2224 * @retval false Otherwise.
2226 * @throws an exception of type regex_error.
2228 template<typename _Ch_traits, typename _Str_allocator,
2229 typename _Ch_type, typename _Rx_traits>
2231 regex_match(const basic_string<_Ch_type, _Ch_traits, _Str_allocator>& __s,
2232 const basic_regex<_Ch_type, _Rx_traits>& __re,
2233 regex_constants::match_flag_type __flags
2234 = regex_constants::match_default)
2235 { return regex_match(__s.begin(), __s.end(), __re, __flags); }
2237 // [7.11.3] Function template regex_search
2239 * Searches for a regular expression within a range.
2240 * @param first [IN] The start of the string to search.
2241 * @param last [IN] One-past-the-end of the string to search.
2242 * @param m [OUT] The match results.
2243 * @param re [IN] The regular expression to search for.
2244 * @param flags [IN] Search policy flags.
2245 * @retval true A match was found within the string.
2246 * @retval false No match was found within the string, the content of %m is
2249 * @throws an exception of type regex_error.
2251 * @todo Implement this function.
2253 template<typename _Bi_iter, typename _Allocator,
2254 typename _Ch_type, typename _Rx_traits>
2256 regex_search(_Bi_iter __first, _Bi_iter __last,
2257 match_results<_Bi_iter, _Allocator>& __m,
2258 const basic_regex<_Ch_type, _Rx_traits>& __re,
2259 regex_constants::match_flag_type __flags
2260 = regex_constants::match_default);
2263 * Searches for a regular expression within a range.
2264 * @param first [IN] The start of the string to search.
2265 * @param last [IN] One-past-the-end of the string to search.
2266 * @param re [IN] The regular expression to search for.
2267 * @param flags [IN] Search policy flags.
2268 * @retval true A match was found within the string.
2269 * @retval false No match was found within the string.
2272 * @throws an exception of type regex_error.
2274 template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
2276 regex_search(_Bi_iter __first, _Bi_iter __last,
2277 const basic_regex<_Ch_type, _Rx_traits>& __re,
2278 regex_constants::match_flag_type __flags
2279 = regex_constants::match_default)
2281 match_results<_Bi_iter> __what;
2282 return regex_search(__first, __last, __what, __re, __flags);
2286 * @brief Searches for a regular expression within a C-string.
2287 * @param s [IN] A C-string to search for the regex.
2288 * @param m [OUT] The set of regex matches.
2289 * @param e [IN] The regex to search for in @p s.
2290 * @param f [IN] The search flags.
2291 * @retval true A match was found within the string.
2292 * @retval false No match was found within the string, the content of %m is
2296 * @throws an exception of type regex_error.
2298 template<typename _Ch_type, class _Allocator, class _Rx_traits>
2300 regex_search(const _Ch_type* __s,
2301 match_results<const _Ch_type*, _Allocator>& __m,
2302 const basic_regex<_Ch_type, _Rx_traits>& __e,
2303 regex_constants::match_flag_type __f
2304 = regex_constants::match_default)
2305 { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
2308 * @brief Searches for a regular expression within a C-string.
2309 * @param s [IN] The C-string to search.
2310 * @param e [IN] The regular expression to search for.
2311 * @param f [IN] Search policy flags.
2312 * @retval true A match was found within the string.
2313 * @retval false No match was found within the string.
2316 * @throws an exception of type regex_error.
2318 template<typename _Ch_type, typename _Rx_traits>
2320 regex_search(const _Ch_type* __s,
2321 const basic_regex<_Ch_type, _Rx_traits>& __e,
2322 regex_constants::match_flag_type __f
2323 = regex_constants::match_default)
2324 { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); }
2327 * @brief Searches for a regular expression within a string.
2328 * @param s [IN] The string to search.
2329 * @param e [IN] The regular expression to search for.
2330 * @param flags [IN] Search policy flags.
2331 * @retval true A match was found within the string.
2332 * @retval false No match was found within the string.
2335 * @throws an exception of type regex_error.
2337 template<typename _Ch_traits, typename _String_allocator,
2338 typename _Ch_type, typename _Rx_traits>
2340 regex_search(const basic_string<_Ch_type, _Ch_traits,
2341 _String_allocator>& __s,
2342 const basic_regex<_Ch_type, _Rx_traits>& __e,
2343 regex_constants::match_flag_type __flags
2344 = regex_constants::match_default)
2345 { return regex_search(__s.begin(), __s.end(), __e, __flags); }
2348 * @brief Searches for a regular expression within a string.
2349 * @param s [IN] A C++ string to search for the regex.
2350 * @param m [OUT] The set of regex matches.
2351 * @param e [IN] The regex to search for in @p s.
2352 * @param f [IN] The search flags.
2353 * @retval true A match was found within the string.
2354 * @retval false No match was found within the string, the content of %m is
2357 * @throws an exception of type regex_error.
2359 template<typename _Ch_traits, typename _Ch_alloc,
2360 typename _Allocator, typename _Ch_type,
2361 typename _Rx_traits>
2363 regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
2364 match_results<typename basic_string<_Ch_type,
2365 _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
2366 const basic_regex<_Ch_type, _Rx_traits>& __e,
2367 regex_constants::match_flag_type __f
2368 = regex_constants::match_default)
2369 { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
2371 // tr1 [7.11.4] std [28.11.4] Function template regex_replace
2382 * @throws an exception of type regex_error.
2384 * @todo Implement this function.
2386 template<typename _Out_iter, typename _Bi_iter,
2387 typename _Rx_traits, typename _Ch_type>
2389 regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
2390 const basic_regex<_Ch_type, _Rx_traits>& __e,
2391 const basic_string<_Ch_type>& __fmt,
2392 regex_constants::match_flag_type __flags
2393 = regex_constants::match_default);
2402 * @returns a copy of string @p s with replacements.
2404 * @throws an exception of type regex_error.
2406 template<typename _Rx_traits, typename _Ch_type>
2407 inline basic_string<_Ch_type>
2408 regex_replace(const basic_string<_Ch_type>& __s,
2409 const basic_regex<_Ch_type, _Rx_traits>& __e,
2410 const basic_string<_Ch_type>& __fmt,
2411 regex_constants::match_flag_type __flags
2412 = regex_constants::match_default)
2414 std::string __result;
2415 regex_replace(std::back_inserter(__result),
2416 __s.begin(), __s.end(), __e, __fmt, __flags);
2422 // tr1 [7.12.1] std [28.12] Class template regex_iterator
2424 * An iterator adaptor that will provide repeated calls of regex_search over
2425 * a range until no more matches remain.
2427 template<typename _Bi_iter,
2428 typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2429 typename _Rx_traits = regex_traits<_Ch_type> >
2430 class regex_iterator
2433 typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
2434 typedef match_results<_Bi_iter> value_type;
2435 typedef std::ptrdiff_t difference_type;
2436 typedef const value_type* pointer;
2437 typedef const value_type& reference;
2438 typedef std::forward_iterator_tag iterator_category;
2442 * @brief Provides a singular iterator, useful for indicating
2443 * one-past-the-end of a range.
2444 * @todo Implement this function.
2450 * Constructs a %regex_iterator...
2451 * @param a [IN] The start of a text range to search.
2452 * @param b [IN] One-past-the-end of the text range to search.
2453 * @param re [IN] The regular expression to match.
2454 * @param m [IN] Policy flags for match rules.
2455 * @todo Implement this function.
2458 regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2459 regex_constants::match_flag_type __m
2460 = regex_constants::match_default);
2463 * Copy constructs a %regex_iterator.
2464 * @todo Implement this function.
2467 regex_iterator(const regex_iterator& __rhs);
2470 * @todo Implement this function.
2474 operator=(const regex_iterator& __rhs);
2477 * @todo Implement this function.
2481 operator==(const regex_iterator& __rhs);
2484 * @todo Implement this function.
2488 operator!=(const regex_iterator& __rhs);
2491 * @todo Implement this function.
2498 * @todo Implement this function.
2505 * @todo Implement this function.
2512 * @todo Implement this function.
2519 // these members are shown for exposition only:
2522 const regex_type* pregex;
2523 regex_constants::match_flag_type flags;
2524 match_results<_Bi_iter> match;
2527 typedef regex_iterator<const char*> cregex_iterator;
2528 typedef regex_iterator<string::const_iterator> sregex_iterator;
2529 #ifdef _GLIBCXX_USE_WCHAR_T
2530 typedef regex_iterator<const wchar_t*> wcregex_iterator;
2531 typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
2534 // [7.12.2] Class template regex_token_iterator
2536 * Iterates over submatches in a range (or "splits" a text string).
2538 * The purpose of this iterator is to enumerate all, or all specified,
2539 * matches of a regular expression within a text range. The dereferenced
2540 * value of an iterator of this class is a std::tr1::sub_match object.
2542 template<typename _Bi_iter,
2543 typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2544 typename _Rx_traits = regex_traits<_Ch_type> >
2545 class regex_token_iterator
2548 typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
2549 typedef sub_match<_Bi_iter> value_type;
2550 typedef std::ptrdiff_t difference_type;
2551 typedef const value_type* pointer;
2552 typedef const value_type& reference;
2553 typedef std::forward_iterator_tag iterator_category;
2557 * @brief Default constructs a %regex_token_iterator.
2558 * @todo Implement this function.
2560 * A default-constructed %regex_token_iterator is a singular iterator
2561 * that will compare equal to the one-past-the-end value for any
2562 * iterator of the same type.
2564 regex_token_iterator();
2567 * Constructs a %regex_token_iterator...
2568 * @param a [IN] The start of the text to search.
2569 * @param b [IN] One-past-the-end of the text to search.
2570 * @param re [IN] The regular expression to search for.
2571 * @param submatch [IN] Which submatch to return. There are some
2572 * special values for this parameter:
2573 * - -1 each enumerated subexpression does NOT
2574 * match the regular expression (aka field
2576 * - 0 the entire string matching the
2577 * subexpression is returned for each match
2579 * - >0 enumerates only the indicated
2580 * subexpression from a match within the text.
2581 * @param m [IN] Policy flags for match rules.
2583 * @todo Implement this function.
2586 regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2588 regex_constants::match_flag_type __m
2589 = regex_constants::match_default);
2592 * Constructs a %regex_token_iterator...
2593 * @param a [IN] The start of the text to search.
2594 * @param b [IN] One-past-the-end of the text to search.
2595 * @param re [IN] The regular expression to search for.
2596 * @param submatches [IN] A list of subexpressions to return for each
2597 * regular expression match within the text.
2598 * @param m [IN] Policy flags for match rules.
2600 * @todo Implement this function.
2603 regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2604 const regex_type& __re,
2605 const std::vector<int>& __submatches,
2606 regex_constants::match_flag_type __m
2607 = regex_constants::match_default);
2610 * Constructs a %regex_token_iterator...
2611 * @param a [IN] The start of the text to search.
2612 * @param b [IN] One-past-the-end of the text to search.
2613 * @param re [IN] The regular expression to search for.
2614 * @param submatches [IN] A list of subexpressions to return for each
2615 * regular expression match within the text.
2616 * @param m [IN] Policy flags for match rules.
2618 * @todo Implement this function.
2621 template<std::size_t _Nm>
2622 regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2623 const regex_type& __re,
2624 const int (&__submatches)[_Nm],
2625 regex_constants::match_flag_type __m
2626 = regex_constants::match_default);
2629 * @brief Copy constructs a %regex_token_iterator.
2630 * @param rhs [IN] A %regex_token_iterator to copy.
2631 * @todo Implement this function.
2633 regex_token_iterator(const regex_token_iterator& __rhs);
2636 * @brief Assigns a %regex_token_iterator to another.
2637 * @param rhs [IN] A %regex_token_iterator to copy.
2638 * @todo Implement this function.
2640 regex_token_iterator&
2641 operator=(const regex_token_iterator& __rhs);
2644 * @brief Compares a %regex_token_iterator to another for equality.
2645 * @todo Implement this function.
2648 operator==(const regex_token_iterator& __rhs);
2651 * @brief Compares a %regex_token_iterator to another for inequality.
2652 * @todo Implement this function.
2655 operator!=(const regex_token_iterator& __rhs);
2658 * @brief Dereferences a %regex_token_iterator.
2659 * @todo Implement this function.
2665 * @brief Selects a %regex_token_iterator member.
2666 * @todo Implement this function.
2672 * @brief Increments a %regex_token_iterator.
2673 * @todo Implement this function.
2675 regex_token_iterator&
2679 * @brief Postincrements a %regex_token_iterator.
2680 * @todo Implement this function.
2682 regex_token_iterator
2685 private: // data members for exposition only:
2686 typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> position_iterator;
2688 position_iterator __position;
2689 const value_type* __result;
2690 value_type __suffix;
2692 std::vector<int> __subs;
2695 /** @brief Token iterator for C-style NULL-terminated strings. */
2696 typedef regex_token_iterator<const char*> cregex_token_iterator;
2697 /** @brief Token iterator for standard strings. */
2698 typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
2699 #ifdef _GLIBCXX_USE_WCHAR_T
2700 /** @brief Token iterator for C-style NULL-terminated wide strings. */
2701 typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
2702 /** @brief Token iterator for standard wide-character strings. */
2703 typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
2706 //@} // group tr1_regex
2708 _GLIBCXX_END_NAMESPACE_TR1