1 // class template regex -*- C++ -*-
3 // Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
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:
139 * \\\\, \\a, \\b, \\f,
140 * \\n, \\r, \\t , \\v,
141 * \\', ', and \\ddd
142 * (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 @a string that precedes the matched substring.
268 * This would be match_results::prefix().
269 * @li $' The portion of @a string 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 <em>*?+{</em> 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.
391 * @ingroup exceptions
393 * The regular expression library throws objects of this class on error.
396 : public std::runtime_error
400 * @brief Constructs a regex_error object.
402 * @param ecode the regex error code.
405 regex_error(regex_constants::error_type __ecode)
406 : std::runtime_error("regex_error"), _M_code(__ecode)
410 * @brief Gets the regex error code.
412 * @returns the regex error code.
414 regex_constants::error_type
419 regex_constants::error_type _M_code;
422 // [7.7] Class regex_traits
424 * @brief Describes aspects of a regular expression.
426 * A regular expression traits class that satisfies the requirements of tr1
429 * The class %regex is parameterized around a set of related types and
430 * functions used to complete the definition of its semantics. This class
431 * satisfies the requirements of such a traits class.
433 template<typename _Ch_type>
437 typedef _Ch_type char_type;
438 typedef std::basic_string<char_type> string_type;
439 typedef std::locale locale_type;
440 typedef std::ctype_base::mask char_class_type;
444 * @brief Constructs a default traits object.
450 * @brief Gives the length of a C-style string starting at @p __p.
452 * @param __p a pointer to the start of a character sequence.
454 * @returns the number of characters between @p *__p and the first
455 * default-initialized value of type @p char_type. In other words, uses
456 * the C-string algorithm for determining the length of a sequence of
460 length(const char_type* __p)
461 { return string_type::traits_type::length(__p); }
464 * @brief Performs the identity translation.
466 * @param c A character to the locale-specific character set.
471 translate(char_type __c) const
475 * @brief Translates a character into a case-insensitive equivalent.
477 * @param c A character to the locale-specific character set.
479 * @returns the locale-specific lower-case equivalent of c.
480 * @throws std::bad_cast if the imbued locale does not support the ctype
484 translate_nocase(char_type __c) const
487 using std::use_facet;
488 return use_facet<ctype<char_type> >(_M_locale).tolower(__c);
492 * @brief Gets a sort key for a character sequence.
494 * @param first beginning of the character sequence.
495 * @param last one-past-the-end of the character sequence.
497 * Returns a sort key for the character sequence designated by the
498 * iterator range [F1, F2) such that if the character sequence [G1, G2)
499 * sorts before the character sequence [H1, H2) then
500 * v.transform(G1, G2) < v.transform(H1, H2).
502 * What this really does is provide a more efficient way to compare a
503 * string to multiple other strings in locales with fancy collation
504 * rules and equivalence classes.
506 * @returns a locale-specific sort key equivalent to the input range.
508 * @throws std::bad_cast if the current locale does not have a collate
511 template<typename _Fwd_iter>
513 transform(_Fwd_iter __first, _Fwd_iter __last) const
516 using std::use_facet;
517 const collate<_Ch_type>& __c(use_facet<
518 collate<_Ch_type> >(_M_locale));
519 string_type __s(__first, __last);
520 return __c.transform(__s.data(), __s.data() + __s.size());
526 * @param first beginning of the character sequence.
527 * @param last one-past-the-end of the character sequence.
529 * Effects: if typeid(use_facet<collate<_Ch_type> >) ==
530 * typeid(collate_byname<_Ch_type>) and the form of the sort key
531 * returned by collate_byname<_Ch_type>::transform(first, last) is known
532 * and can be converted into a primary sort key then returns that key,
533 * otherwise returns an empty string. WTF??
535 * @todo Implement this function.
537 template<typename _Fwd_iter>
539 transform_primary(_Fwd_iter __first, _Fwd_iter __last) const;
542 * @brief Gets a collation element by name.
544 * @param first beginning of the collation element name.
545 * @param last one-past-the-end of the collation element name.
547 * @returns a sequence of one or more characters that represents the
548 * collating element consisting of the character sequence designated by
549 * the iterator range [first, last). Returns an empty string if the
550 * character sequence is not a valid collating element.
552 * @todo Implement this function.
554 template<typename _Fwd_iter>
556 lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const;
559 * @brief Maps one or more characters to a named character
562 * @param first beginning of the character sequence.
563 * @param last one-past-the-end of the character sequence.
565 * @returns an unspecified value that represents the character
566 * classification named by the character sequence designated by the
567 * iterator range [first, last). The value returned shall be independent
568 * of the case of the characters in the character sequence. If the name
569 * is not recognized then returns a value that compares equal to 0.
571 * At least the following names (or their wide-character equivalent) are
589 * @todo Implement this function.
591 template<typename _Fwd_iter>
593 lookup_classname(_Fwd_iter __first, _Fwd_iter __last) const;
596 * @brief Determines if @p c is a member of an identified class.
598 * @param c a character.
599 * @param f a class type (as returned from lookup_classname).
601 * @returns true if the character @p c is a member of the classification
602 * represented by @p f, false otherwise.
604 * @throws std::bad_cast if the current locale does not have a ctype
608 isctype(_Ch_type __c, char_class_type __f) const;
611 * @brief Converts a digit to an int.
613 * @param ch a character representing a digit.
614 * @param radix the radix if the numeric conversion (limited to 8, 10,
617 * @returns the value represented by the digit ch in base radix if the
618 * character ch is a valid digit in base radix; otherwise returns -1.
621 value(_Ch_type __ch, int __radix) const;
624 * @brief Imbues the regex_traits object with a copy of a new locale.
626 * @param loc A locale.
628 * @returns a copy of the previous locale in use by the regex_traits
631 * @note Calling imbue with a different locale than the one currently in
632 * use invalidates all cached data held by *this.
635 imbue(locale_type __loc)
637 std::swap(_M_locale, __loc);
642 * @brief Gets a copy of the current locale in use by the regex_traits
647 { return _M_locale; }
650 locale_type _M_locale;
653 template<typename _Ch_type>
654 bool regex_traits<_Ch_type>::
655 isctype(_Ch_type __c, char_class_type __f) const
658 using std::use_facet;
659 const ctype<_Ch_type>& __ctype(use_facet<
660 ctype<_Ch_type> >(_M_locale));
662 if (__ctype.is(__c, __f))
665 // special case of underscore in [[:w:]]
666 if (__c == __ctype.widen('_'))
668 const char* const __wb[] = "w";
669 char_class_type __wt = this->lookup_classname(__wb,
670 __wb + sizeof(__wb));
675 // special case of [[:space:]] in [[:blank:]]
676 if (__c == __ctype.isspace(__c))
678 const char* const __bb[] = "blank";
679 char_class_type __bt = this->lookup_classname(__bb,
680 __bb + sizeof(__bb));
688 template<typename _Ch_type>
689 int regex_traits<_Ch_type>::
690 value(_Ch_type __ch, int __radix) const
692 std::basic_istringstream<_Ch_type> __is(string_type(1, __ch));
696 else if (__radix == 16)
699 return __is.fail() ? -1 : __v;
702 // [7.8] Class basic_regex
704 * Objects of specializations of this class represent regular expressions
705 * constructed from sequences of character type @p _Ch_type.
707 * Storage for the regular expression is allocated and deallocated as
708 * necessary by the member functions of this class.
710 template<typename _Ch_type, typename _Rx_traits = regex_traits<_Ch_type> >
715 typedef _Ch_type value_type;
716 typedef regex_constants::syntax_option_type flag_type;
717 typedef typename _Rx_traits::locale_type locale_type;
718 typedef typename _Rx_traits::string_type string_type;
722 * tr1 [7.8.1] std [28.8.1]
725 static const regex_constants::syntax_option_type icase
726 = regex_constants::icase;
727 static const regex_constants::syntax_option_type nosubs
728 = regex_constants::nosubs;
729 static const regex_constants::syntax_option_type optimize
730 = regex_constants::optimize;
731 static const regex_constants::syntax_option_type collate
732 = regex_constants::collate;
733 static const regex_constants::syntax_option_type ECMAScript
734 = regex_constants::ECMAScript;
735 static const regex_constants::syntax_option_type basic
736 = regex_constants::basic;
737 static const regex_constants::syntax_option_type extended
738 = regex_constants::extended;
739 static const regex_constants::syntax_option_type awk
740 = regex_constants::awk;
741 static const regex_constants::syntax_option_type grep
742 = regex_constants::grep;
743 static const regex_constants::syntax_option_type egrep
744 = regex_constants::egrep;
747 // [7.8.2] construct/copy/destroy
749 * Constructs a basic regular expression that does not match any
750 * character sequence.
753 : _M_flags(regex_constants::ECMAScript), _M_pattern(), _M_mark_count(0)
757 * @brief Constructs a basic regular expression from the sequence
758 * [p, p + char_traits<_Ch_type>::length(p)) interpreted according to the
761 * @param p A pointer to the start of a C-style null-terminated string
762 * containing a regular expression.
763 * @param f Flags indicating the syntax rules and options.
765 * @throws regex_error if @p p is not a valid regular expression.
768 basic_regex(const _Ch_type* __p,
769 flag_type __f = regex_constants::ECMAScript)
770 : _M_flags(__f), _M_pattern(__p), _M_mark_count(0)
774 * @brief Constructs a basic regular expression from the sequence
775 * [p, p + len) interpreted according to the flags in @p f.
777 * @param p A pointer to the start of a string containing a regular
779 * @param len The length of the string containing the regular expression.
780 * @param f Flags indicating the syntax rules and options.
782 * @throws regex_error if @p p is not a valid regular expression.
784 basic_regex(const _Ch_type* __p, std::size_t __len, flag_type __f)
785 : _M_flags(__f) , _M_pattern(__p, __len), _M_mark_count(0)
789 * @brief Copy-constructs a basic regular expression.
791 * @param rhs A @p regex object.
793 basic_regex(const basic_regex& __rhs)
794 : _M_flags(__rhs._M_flags), _M_pattern(__rhs._M_pattern),
795 _M_mark_count(__rhs._M_mark_count)
799 * @brief Constructs a basic regular expression from the string
800 * @p s interpreted according to the flags in @p f.
802 * @param s A string containing a regular expression.
803 * @param f Flags indicating the syntax rules and options.
805 * @throws regex_error if @p s is not a valid regular expression.
807 template<typename _Ch_traits, typename _Ch_alloc>
809 basic_regex(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
810 flag_type __f = regex_constants::ECMAScript)
811 : _M_flags(__f), _M_pattern(__s.begin(), __s.end()), _M_mark_count(0)
815 * @brief Constructs a basic regular expression from the range
816 * [first, last) interpreted according to the flags in @p f.
818 * @param first The start of a range containing a valid regular
820 * @param last The end of a range containing a valid regular
822 * @param f The format flags of the regular expression.
824 * @throws regex_error if @p [first, last) is not a valid regular
827 template<typename _InputIterator>
828 basic_regex(_InputIterator __first, _InputIterator __last,
829 flag_type __f = regex_constants::ECMAScript)
830 : _M_flags(__f), _M_pattern(__first, __last), _M_mark_count(0)
833 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
835 * @brief Constructs a basic regular expression from an initializer list.
837 * @param l The initializer list.
838 * @param f The format flags of the regular expression.
840 * @throws regex_error if @p l is not a valid regular expression.
842 basic_regex(initializer_list<_Ch_type> __l,
843 flag_type __f = regex_constants::ECMAScript)
844 : _M_flags(__f), _M_pattern(__l.begin(), __l.end()), _M_mark_count(0)
849 * @brief Destroys a basic regular expression.
855 * @brief Assigns one regular expression to another.
858 operator=(const basic_regex& __rhs)
859 { return this->assign(__rhs); }
862 * @brief Replaces a regular expression with a new one constructed from
863 * a C-style null-terminated string.
865 * @param A pointer to the start of a null-terminated C-style string
866 * containing a regular expression.
869 operator=(const _Ch_type* __p)
870 { return this->assign(__p, flags()); }
873 * @brief Replaces a regular expression with a new one constructed from
876 * @param A pointer to a string containing a regular expression.
878 template<typename _Ch_typeraits, typename _Allocator>
880 operator=(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s)
881 { return this->assign(__s, flags()); }
885 * @brief the real assignment operator.
887 * @param that Another regular expression object.
890 assign(const basic_regex& __that)
892 basic_regex __tmp(__that);
898 * @brief Assigns a new regular expression to a regex object from a
899 * C-style null-terminated string containing a regular expression
902 * @param p A pointer to a C-style null-terminated string containing
903 * a regular expression pattern.
904 * @param flags Syntax option flags.
906 * @throws regex_error if p does not contain a valid regular expression
907 * pattern interpreted according to @p flags. If regex_error is thrown,
908 * *this remains unchanged.
911 assign(const _Ch_type* __p,
912 flag_type __flags = regex_constants::ECMAScript)
913 { return this->assign(string_type(__p), __flags); }
916 * @brief Assigns a new regular expression to a regex object from a
917 * C-style string containing a regular expression pattern.
919 * @param p A pointer to a C-style string containing a
920 * regular expression pattern.
921 * @param len The length of the regular expression pattern string.
922 * @param flags Syntax option flags.
924 * @throws regex_error if p does not contain a valid regular expression
925 * pattern interpreted according to @p flags. If regex_error is thrown,
926 * *this remains unchanged.
929 assign(const _Ch_type* __p, std::size_t __len, flag_type __flags)
930 { return this->assign(string_type(__p, __len), __flags); }
933 * @brief Assigns a new regular expression to a regex object from a
934 * string containing a regular expression pattern.
936 * @param s A string containing a regular expression pattern.
937 * @param flags Syntax option flags.
939 * @throws regex_error if p does not contain a valid regular expression
940 * pattern interpreted according to @p flags. If regex_error is thrown,
941 * *this remains unchanged.
943 template<typename _Ch_typeraits, typename _Allocator>
945 assign(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s,
946 flag_type __f = regex_constants::ECMAScript)
948 basic_regex __tmp(__s, __f);
954 * @brief Assigns a new regular expression to a regex object.
956 * @param first The start of a range containing a valid regular
958 * @param last The end of a range containing a valid regular
960 * @param flags Syntax option flags.
962 * @throws regex_error if p does not contain a valid regular expression
963 * pattern interpreted according to @p flags. If regex_error is thrown,
964 * the object remains unchanged.
966 template<typename _InputIterator>
968 assign(_InputIterator __first, _InputIterator __last,
969 flag_type __flags = regex_constants::ECMAScript)
970 { return this->assign(string_type(__first, __last), __flags); }
972 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
974 * @brief Assigns a new regular expression to a regex object.
976 * @param l An initializer list representing a regular expression.
977 * @param flags Syntax option flags.
979 * @throws regex_error if @p l does not contain a valid regular
980 * expression pattern interpreted according to @p flags. If regex_error
981 * is thrown, the object remains unchanged.
984 assign(initializer_list<_Ch_type> __l,
985 flag_type __f = regex_constants::ECMAScript)
986 { return this->assign(__l.begin(), __l.end(), __f); }
989 // [7.8.4] const operations
991 * @brief Gets the number of marked subexpressions within the regular
996 { return _M_mark_count; }
999 * @brief Gets the flags used to construct the regular expression
1000 * or in the last call to assign().
1004 { return _M_flags; }
1008 * @brief Imbues the regular expression object with the given locale.
1010 * @param loc A locale.
1013 imbue(locale_type __loc)
1014 { return _M_traits.imbue(__loc); }
1017 * @brief Gets the locale currently imbued in the regular expression
1022 { return _M_traits.getloc(); }
1026 * @brief Swaps the contents of two regular expression objects.
1028 * @param rhs Another regular expression object.
1031 swap(basic_regex& __rhs)
1033 std::swap(_M_flags, __rhs._M_flags);
1034 std::swap(_M_pattern, __rhs._M_pattern);
1035 std::swap(_M_mark_count, __rhs._M_mark_count);
1036 std::swap(_M_traits, __rhs._M_traits);
1041 * @brief Compiles a regular expression pattern into a NFA.
1042 * @todo Implement this function.
1048 string_type _M_pattern;
1049 unsigned int _M_mark_count;
1050 _Rx_traits _M_traits;
1053 /** @brief Standard regular expressions. */
1054 typedef basic_regex<char> regex;
1055 #ifdef _GLIBCXX_USE_WCHAR_T
1056 /** @brief Standard wide-character regular expressions. */
1057 typedef basic_regex<wchar_t> wregex;
1061 // [7.8.6] basic_regex swap
1063 * @brief Swaps the contents of two regular expression objects.
1064 * @param lhs First regular expression.
1065 * @param rhs Second regular expression.
1067 template<typename _Ch_type, typename _Rx_traits>
1069 swap(basic_regex<_Ch_type, _Rx_traits>& __lhs,
1070 basic_regex<_Ch_type, _Rx_traits>& __rhs)
1071 { __lhs.swap(__rhs); }
1074 // [7.9] Class template sub_match
1076 * A sequence of characters matched by a particular marked sub-expression.
1078 * An object of this class is essentially a pair of iterators marking a
1079 * matched subexpression within a regular expression pattern match. Such
1080 * objects can be converted to and compared with std::basic_string objects
1081 * of a similar base character type as the pattern matched by the regular
1084 * The iterators that make up the pair are the usual half-open interval
1085 * referencing the actual original pattern matched.
1087 template<typename _BiIter>
1088 class sub_match : public std::pair<_BiIter, _BiIter>
1091 typedef typename iterator_traits<_BiIter>::value_type value_type;
1092 typedef typename iterator_traits<_BiIter>::difference_type
1094 typedef _BiIter iterator;
1100 * Gets the length of the matching sequence.
1104 { return this->matched ? std::distance(this->first, this->second) : 0; }
1107 * @brief Gets the matching sequence as a string.
1109 * @returns the matching sequence as a string.
1111 * This is the implicit conversion operator. It is identical to the
1112 * str() member function except that it will want to pop up in
1113 * unexpected places and cause a great deal of confusion and cursing
1116 operator basic_string<value_type>() const
1118 return this->matched
1119 ? std::basic_string<value_type>(this->first, this->second)
1120 : std::basic_string<value_type>();
1124 * @brief Gets the matching sequence as a string.
1126 * @returns the matching sequence as a string.
1128 basic_string<value_type>
1131 return this->matched
1132 ? std::basic_string<value_type>(this->first, this->second)
1133 : std::basic_string<value_type>();
1137 * @brief Compares this and another matched sequence.
1139 * @param s Another matched sequence to compare to this one.
1141 * @retval <0 this matched sequence will collate before @p s.
1142 * @retval =0 this matched sequence is equivalent to @p s.
1143 * @retval <0 this matched sequence will collate after @p s.
1146 compare(const sub_match& __s) const
1147 { return this->str().compare(__s.str()); }
1150 * @brief Compares this sub_match to a string.
1152 * @param s A string to compare to this sub_match.
1154 * @retval <0 this matched sequence will collate before @p s.
1155 * @retval =0 this matched sequence is equivalent to @p s.
1156 * @retval <0 this matched sequence will collate after @p s.
1159 compare(const basic_string<value_type>& __s) const
1160 { return this->str().compare(__s); }
1163 * @brief Compares this sub_match to a C-style string.
1165 * @param s A C-style string to compare to this sub_match.
1167 * @retval <0 this matched sequence will collate before @p s.
1168 * @retval =0 this matched sequence is equivalent to @p s.
1169 * @retval <0 this matched sequence will collate after @p s.
1172 compare(const value_type* __s) const
1173 { return this->str().compare(__s); }
1177 /** @brief Standard regex submatch over a C-style null-terminated string. */
1178 typedef sub_match<const char*> csub_match;
1179 /** @brief Standard regex submatch over a standard string. */
1180 typedef sub_match<string::const_iterator> ssub_match;
1181 #ifdef _GLIBCXX_USE_WCHAR_T
1182 /** @brief Regex submatch over a C-style null-terminated wide string. */
1183 typedef sub_match<const wchar_t*> wcsub_match;
1184 /** @brief Regex submatch over a standard wide string. */
1185 typedef sub_match<wstring::const_iterator> wssub_match;
1188 // [7.9.2] sub_match non-member operators
1191 * @brief Tests the equivalence of two regular expression submatches.
1192 * @param lhs First regular expression submatch.
1193 * @param rhs Second regular expression submatch.
1194 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1196 template<typename _BiIter>
1198 operator==(const sub_match<_BiIter>& __lhs,
1199 const sub_match<_BiIter>& __rhs)
1200 { return __lhs.compare(__rhs) == 0; }
1203 * @brief Tests the inequivalence of two regular expression submatches.
1204 * @param lhs First regular expression submatch.
1205 * @param rhs Second regular expression submatch.
1206 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1208 template<typename _BiIter>
1210 operator!=(const sub_match<_BiIter>& __lhs,
1211 const sub_match<_BiIter>& __rhs)
1212 { return __lhs.compare(__rhs) != 0; }
1215 * @brief Tests the ordering of two regular expression submatches.
1216 * @param lhs First regular expression submatch.
1217 * @param rhs Second regular expression submatch.
1218 * @returns true if @a lhs precedes @a rhs, false otherwise.
1220 template<typename _BiIter>
1222 operator<(const sub_match<_BiIter>& __lhs,
1223 const sub_match<_BiIter>& __rhs)
1224 { return __lhs.compare(__rhs) < 0; }
1227 * @brief Tests the ordering of two regular expression submatches.
1228 * @param lhs First regular expression submatch.
1229 * @param rhs Second regular expression submatch.
1230 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1232 template<typename _BiIter>
1234 operator<=(const sub_match<_BiIter>& __lhs,
1235 const sub_match<_BiIter>& __rhs)
1236 { return __lhs.compare(__rhs) <= 0; }
1239 * @brief Tests the ordering of two regular expression submatches.
1240 * @param lhs First regular expression submatch.
1241 * @param rhs Second regular expression submatch.
1242 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1244 template<typename _BiIter>
1246 operator>=(const sub_match<_BiIter>& __lhs,
1247 const sub_match<_BiIter>& __rhs)
1248 { return __lhs.compare(__rhs) >= 0; }
1251 * @brief Tests the ordering of two regular expression submatches.
1252 * @param lhs First regular expression submatch.
1253 * @param rhs Second regular expression submatch.
1254 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1256 template<typename _BiIter>
1258 operator>(const sub_match<_BiIter>& __lhs,
1259 const sub_match<_BiIter>& __rhs)
1260 { return __lhs.compare(__rhs) > 0; }
1263 * @brief Tests the equivalence of a string and a regular expression
1265 * @param lhs A string.
1266 * @param rhs A regular expression submatch.
1267 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1269 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1271 operator==(const basic_string<
1272 typename iterator_traits<_Bi_iter>::value_type,
1273 _Ch_traits, _Ch_alloc>& __lhs,
1274 const sub_match<_Bi_iter>& __rhs)
1275 { return __lhs == __rhs.str(); }
1278 * @brief Tests the inequivalence of a string and a regular expression
1280 * @param lhs A string.
1281 * @param rhs A regular expression submatch.
1282 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1284 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1286 operator!=(const basic_string<
1287 typename iterator_traits<_Bi_iter>::value_type,
1288 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1289 { return __lhs != __rhs.str(); }
1292 * @brief Tests the ordering of a string and a regular expression submatch.
1293 * @param lhs A string.
1294 * @param rhs A regular expression submatch.
1295 * @returns true if @a lhs precedes @a rhs, false otherwise.
1297 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1299 operator<(const basic_string<
1300 typename iterator_traits<_Bi_iter>::value_type,
1301 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1302 { return __lhs < __rhs.str(); }
1305 * @brief Tests the ordering of a string and a regular expression submatch.
1306 * @param lhs A string.
1307 * @param rhs A regular expression submatch.
1308 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1310 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1312 operator>(const basic_string<
1313 typename iterator_traits<_Bi_iter>::value_type,
1314 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1315 { return __lhs > __rhs.str(); }
1318 * @brief Tests the ordering of a string and a regular expression submatch.
1319 * @param lhs A string.
1320 * @param rhs A regular expression submatch.
1321 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1323 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1325 operator>=(const basic_string<
1326 typename iterator_traits<_Bi_iter>::value_type,
1327 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1328 { return __lhs >= __rhs.str(); }
1331 * @brief Tests the ordering of a string and a regular expression submatch.
1332 * @param lhs A string.
1333 * @param rhs A regular expression submatch.
1334 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1336 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1338 operator<=(const basic_string<
1339 typename iterator_traits<_Bi_iter>::value_type,
1340 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1341 { return __lhs <= __rhs.str(); }
1344 * @brief Tests the equivalence of a regular expression submatch and a
1346 * @param lhs A regular expression submatch.
1347 * @param rhs A string.
1348 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1350 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1352 operator==(const sub_match<_Bi_iter>& __lhs,
1354 typename iterator_traits<_Bi_iter>::value_type,
1355 _Ch_traits, _Ch_alloc>& __rhs)
1356 { return __lhs.str() == __rhs; }
1359 * @brief Tests the inequivalence of a regular expression submatch and a
1361 * @param lhs A regular expression submatch.
1362 * @param rhs A string.
1363 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1365 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1367 operator!=(const sub_match<_Bi_iter>& __lhs,
1369 typename iterator_traits<_Bi_iter>::value_type,
1370 _Ch_traits, _Ch_alloc>& __rhs)
1371 { return __lhs.str() != __rhs; }
1374 * @brief Tests the ordering of a regular expression submatch and a string.
1375 * @param lhs A regular expression submatch.
1376 * @param rhs A string.
1377 * @returns true if @a lhs precedes @a rhs, false otherwise.
1379 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1381 operator<(const sub_match<_Bi_iter>& __lhs,
1383 typename iterator_traits<_Bi_iter>::value_type,
1384 _Ch_traits, _Ch_alloc>& __rhs)
1385 { return __lhs.str() < __rhs; }
1388 * @brief Tests the ordering of a regular expression submatch and a string.
1389 * @param lhs A regular expression submatch.
1390 * @param rhs A string.
1391 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1393 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1395 operator>(const sub_match<_Bi_iter>& __lhs,
1397 typename iterator_traits<_Bi_iter>::value_type,
1398 _Ch_traits, _Ch_alloc>& __rhs)
1399 { return __lhs.str() > __rhs; }
1402 * @brief Tests the ordering of a regular expression submatch and a string.
1403 * @param lhs A regular expression submatch.
1404 * @param rhs A string.
1405 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1407 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1409 operator>=(const sub_match<_Bi_iter>& __lhs,
1411 typename iterator_traits<_Bi_iter>::value_type,
1412 _Ch_traits, _Ch_alloc>& __rhs)
1413 { return __lhs.str() >= __rhs; }
1416 * @brief Tests the ordering of a regular expression submatch and a string.
1417 * @param lhs A regular expression submatch.
1418 * @param rhs A string.
1419 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1421 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1423 operator<=(const sub_match<_Bi_iter>& __lhs,
1425 typename iterator_traits<_Bi_iter>::value_type,
1426 _Ch_traits, _Ch_alloc>& __rhs)
1427 { return __lhs.str() <= __rhs; }
1430 * @brief Tests the equivalence of a C string and a regular expression
1432 * @param lhs A C string.
1433 * @param rhs A regular expression submatch.
1434 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1436 template<typename _Bi_iter>
1438 operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1439 const sub_match<_Bi_iter>& __rhs)
1440 { return __lhs == __rhs.str(); }
1443 * @brief Tests the inequivalence of an iterator value and a regular
1444 * expression submatch.
1445 * @param lhs A regular expression submatch.
1446 * @param rhs A string.
1447 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1449 template<typename _Bi_iter>
1451 operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1452 const sub_match<_Bi_iter>& __rhs)
1453 { return __lhs != __rhs.str(); }
1456 * @brief Tests the ordering of a string and a regular expression submatch.
1457 * @param lhs A string.
1458 * @param rhs A regular expression submatch.
1459 * @returns true if @a lhs precedes @a rhs, false otherwise.
1461 template<typename _Bi_iter>
1463 operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1464 const sub_match<_Bi_iter>& __rhs)
1465 { return __lhs < __rhs.str(); }
1468 * @brief Tests the ordering of a string and a regular expression submatch.
1469 * @param lhs A string.
1470 * @param rhs A regular expression submatch.
1471 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1473 template<typename _Bi_iter>
1475 operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1476 const sub_match<_Bi_iter>& __rhs)
1477 { return __lhs > __rhs.str(); }
1480 * @brief Tests the ordering of a string and a regular expression submatch.
1481 * @param lhs A string.
1482 * @param rhs A regular expression submatch.
1483 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1485 template<typename _Bi_iter>
1487 operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1488 const sub_match<_Bi_iter>& __rhs)
1489 { return __lhs >= __rhs.str(); }
1492 * @brief Tests the ordering of a string and a regular expression submatch.
1493 * @param lhs A string.
1494 * @param rhs A regular expression submatch.
1495 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1497 template<typename _Bi_iter>
1499 operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1500 const sub_match<_Bi_iter>& __rhs)
1501 { return __lhs <= __rhs.str(); }
1504 * @brief Tests the equivalence of a regular expression submatch and a
1506 * @param lhs A regular expression submatch.
1507 * @param rhs A pointer to a string?
1508 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1510 template<typename _Bi_iter>
1512 operator==(const sub_match<_Bi_iter>& __lhs,
1513 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1514 { return __lhs.str() == __rhs; }
1517 * @brief Tests the inequivalence of a regular expression submatch and a
1519 * @param lhs A regular expression submatch.
1520 * @param rhs A pointer to a string.
1521 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1523 template<typename _Bi_iter>
1525 operator!=(const sub_match<_Bi_iter>& __lhs,
1526 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1527 { return __lhs.str() != __rhs; }
1530 * @brief Tests the ordering of a regular expression submatch and a string.
1531 * @param lhs A regular expression submatch.
1532 * @param rhs A string.
1533 * @returns true if @a lhs precedes @a rhs, false otherwise.
1535 template<typename _Bi_iter>
1537 operator<(const sub_match<_Bi_iter>& __lhs,
1538 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1539 { return __lhs.str() < __rhs; }
1542 * @brief Tests the ordering of a regular expression submatch and a string.
1543 * @param lhs A regular expression submatch.
1544 * @param rhs A string.
1545 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1547 template<typename _Bi_iter>
1549 operator>(const sub_match<_Bi_iter>& __lhs,
1550 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1551 { return __lhs.str() > __rhs; }
1554 * @brief Tests the ordering of a regular expression submatch and a string.
1555 * @param lhs A regular expression submatch.
1556 * @param rhs A string.
1557 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1559 template<typename _Bi_iter>
1561 operator>=(const sub_match<_Bi_iter>& __lhs,
1562 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1563 { return __lhs.str() >= __rhs; }
1566 * @brief Tests the ordering of a regular expression submatch and a string.
1567 * @param lhs A regular expression submatch.
1568 * @param rhs A string.
1569 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1571 template<typename _Bi_iter>
1573 operator<=(const sub_match<_Bi_iter>& __lhs,
1574 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1575 { return __lhs.str() <= __rhs; }
1578 * @brief Tests the equivalence of a string and a regular expression
1580 * @param lhs A string.
1581 * @param rhs A regular expression submatch.
1582 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1584 template<typename _Bi_iter>
1586 operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1587 const sub_match<_Bi_iter>& __rhs)
1588 { return __lhs == __rhs.str(); }
1591 * @brief Tests the inequivalence of a string and a regular expression
1593 * @param lhs A string.
1594 * @param rhs A regular expression submatch.
1595 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1597 template<typename _Bi_iter>
1599 operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1600 const sub_match<_Bi_iter>& __rhs)
1601 { return __lhs != __rhs.str(); }
1604 * @brief Tests the ordering of a string and a regular expression submatch.
1605 * @param lhs A string.
1606 * @param rhs A regular expression submatch.
1607 * @returns true if @a lhs precedes @a rhs, false otherwise.
1609 template<typename _Bi_iter>
1611 operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1612 const sub_match<_Bi_iter>& __rhs)
1613 { return __lhs < __rhs.str(); }
1616 * @brief Tests the ordering of a string and a regular expression submatch.
1617 * @param lhs A string.
1618 * @param rhs A regular expression submatch.
1619 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1621 template<typename _Bi_iter>
1623 operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1624 const sub_match<_Bi_iter>& __rhs)
1625 { return __lhs > __rhs.str(); }
1628 * @brief Tests the ordering of a string and a regular expression submatch.
1629 * @param lhs A string.
1630 * @param rhs A regular expression submatch.
1631 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1633 template<typename _Bi_iter>
1635 operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1636 const sub_match<_Bi_iter>& __rhs)
1637 { return __lhs >= __rhs.str(); }
1640 * @brief Tests the ordering of a string and a regular expression submatch.
1641 * @param lhs A string.
1642 * @param rhs A regular expression submatch.
1643 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1645 template<typename _Bi_iter>
1647 operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1648 const sub_match<_Bi_iter>& __rhs)
1649 { return __lhs <= __rhs.str(); }
1652 * @brief Tests the equivalence of a regular expression submatch and a
1654 * @param lhs A regular expression submatch.
1655 * @param rhs A const string reference.
1656 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1658 template<typename _Bi_iter>
1660 operator==(const sub_match<_Bi_iter>& __lhs,
1661 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1662 { return __lhs.str() == __rhs; }
1665 * @brief Tests the inequivalence of a regular expression submatch and a
1667 * @param lhs A regular expression submatch.
1668 * @param rhs A const string reference.
1669 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1671 template<typename _Bi_iter>
1673 operator!=(const sub_match<_Bi_iter>& __lhs,
1674 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1675 { return __lhs.str() != __rhs; }
1678 * @brief Tests the ordering of a regular expression submatch and a string.
1679 * @param lhs A regular expression submatch.
1680 * @param rhs A const string reference.
1681 * @returns true if @a lhs precedes @a rhs, false otherwise.
1683 template<typename _Bi_iter>
1685 operator<(const sub_match<_Bi_iter>& __lhs,
1686 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1687 { return __lhs.str() < __rhs; }
1690 * @brief Tests the ordering of a regular expression submatch and a string.
1691 * @param lhs A regular expression submatch.
1692 * @param rhs A const string reference.
1693 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1695 template<typename _Bi_iter>
1697 operator>(const sub_match<_Bi_iter>& __lhs,
1698 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1699 { return __lhs.str() > __rhs; }
1702 * @brief Tests the ordering of a regular expression submatch and a string.
1703 * @param lhs A regular expression submatch.
1704 * @param rhs A const string reference.
1705 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1707 template<typename _Bi_iter>
1709 operator>=(const sub_match<_Bi_iter>& __lhs,
1710 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1711 { return __lhs.str() >= __rhs; }
1714 * @brief Tests the ordering of a regular expression submatch and a string.
1715 * @param lhs A regular expression submatch.
1716 * @param rhs A const string reference.
1717 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1719 template<typename _Bi_iter>
1721 operator<=(const sub_match<_Bi_iter>& __lhs,
1722 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1723 { return __lhs.str() <= __rhs; }
1726 * @brief Inserts a matched string into an output stream.
1728 * @param os The output stream.
1729 * @param m A submatch string.
1731 * @returns the output stream with the submatch string inserted.
1733 template<typename _Ch_type, typename _Ch_traits, typename _Bi_iter>
1735 basic_ostream<_Ch_type, _Ch_traits>&
1736 operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os,
1737 const sub_match<_Bi_iter>& __m)
1738 { return __os << __m.str(); }
1740 // [7.10] Class template match_results
1742 * @brief The results of a match or search operation.
1744 * A collection of character sequences representing the result of a regular
1745 * expression match. Storage for the collection is allocated and freed as
1746 * necessary by the member functions of class template match_results.
1748 * This class satisfies the Sequence requirements, with the exception that
1749 * only the operations defined for a const-qualified Sequence are supported.
1751 * The sub_match object stored at index 0 represents sub-expression 0, i.e.
1752 * the whole match. In this case the sub_match member matched is always true.
1753 * The sub_match object stored at index n denotes what matched the marked
1754 * sub-expression n within the matched expression. If the sub-expression n
1755 * participated in a regular expression match then the sub_match member
1756 * matched evaluates to true, and members first and second denote the range
1757 * of characters [first, second) which formed that match. Otherwise matched
1758 * is false, and members first and second point to the end of the sequence
1759 * that was searched.
1763 template<typename _Bi_iter,
1764 typename _Allocator = allocator<sub_match<_Bi_iter> > >
1766 : private std::vector<std::_GLIBCXX_TR1 sub_match<_Bi_iter>, _Allocator>
1769 typedef std::vector<std::_GLIBCXX_TR1 sub_match<_Bi_iter>, _Allocator>
1774 * @name 10.? Public Types
1777 typedef sub_match<_Bi_iter> value_type;
1778 typedef typename _Allocator::const_reference const_reference;
1779 typedef const_reference reference;
1780 typedef typename _Base_type::const_iterator const_iterator;
1781 typedef const_iterator iterator;
1782 typedef typename iterator_traits<_Bi_iter>::difference_type
1784 typedef typename _Allocator::size_type size_type;
1785 typedef _Allocator allocator_type;
1786 typedef typename iterator_traits<_Bi_iter>::value_type char_type;
1787 typedef basic_string<char_type> string_type;
1792 * @name 10.1 Construction, Copying, and Destruction
1797 * @brief Constructs a default %match_results container.
1798 * @post size() returns 0 and str() returns an empty string.
1801 match_results(const _Allocator& __a = _Allocator())
1802 : _Base_type(__a), _M_matched(false)
1806 * @brief Copy constructs a %match_results.
1808 match_results(const match_results& __rhs)
1809 : _Base_type(__rhs), _M_matched(__rhs._M_matched),
1810 _M_prefix(__rhs._M_prefix), _M_suffix(__rhs._M_suffix)
1814 * @brief Assigns rhs to *this.
1817 operator=(const match_results& __rhs)
1819 match_results __tmp(__rhs);
1825 * @brief Destroys a %match_results object.
1838 * @brief Gets the number of matches and submatches.
1840 * The number of matches for a given regular expression will be either 0
1841 * if there was no match or mark_count() + 1 if a match was successful.
1842 * Some matches may be empty.
1844 * @returns the number of matches found.
1848 { return _M_matched ? _Base_type::size() + 1 : 0; }
1852 using _Base_type::max_size;
1855 * @brief Indicates if the %match_results contains no results.
1856 * @retval true The %match_results object is empty.
1857 * @retval false The %match_results object is not empty.
1861 { return size() == 0; }
1866 * @name 10.3 Element Access
1871 * @brief Gets the length of the indicated submatch.
1872 * @param sub indicates the submatch.
1874 * This function returns the length of the indicated submatch, or the
1875 * length of the entire match if @p sub is zero (the default).
1878 length(size_type __sub = 0) const
1879 { return _M_matched ? this->str(__sub).length() : 0; }
1882 * @brief Gets the offset of the beginning of the indicated submatch.
1883 * @param sub indicates the submatch.
1885 * This function returns the offset from the beginning of the target
1886 * sequence to the beginning of the submatch, unless the value of @p sub
1887 * is zero (the default), in which case this function returns the offset
1888 * from the beginning of the target sequence to the beginning of the
1892 position(size_type __sub = 0) const
1894 return _M_matched ? std::distance(this->prefix().first,
1895 (*this)[__sub].first) : 0;
1899 * @brief Gets the match or submatch converted to a string type.
1900 * @param sub indicates the submatch.
1902 * This function gets the submatch (or match, if @p sub is zero) extracted
1903 * from the target range and converted to the associated string type.
1906 str(size_type __sub = 0) const
1907 { return _M_matched ? (*this)[__sub].str() : string_type(); }
1910 * @brief Gets a %sub_match reference for the match or submatch.
1911 * @param sub indicates the submatch.
1913 * This function gets a reference to the indicated submatch, or the entire
1914 * match if @p sub is zero.
1916 * If @p sub >= size() then this function returns a %sub_match with a
1917 * special value indicating no submatch.
1920 operator[](size_type __sub) const
1921 { return _Base_type::operator[](__sub); }
1924 * @brief Gets a %sub_match representing the match prefix.
1926 * This function gets a reference to a %sub_match object representing the
1927 * part of the target range between the start of the target range and the
1928 * start of the match.
1932 { return _M_prefix; }
1935 * @brief Gets a %sub_match representing the match suffix.
1937 * This function gets a reference to a %sub_match object representing the
1938 * part of the target range between the end of the match and the end of
1943 { return _M_suffix; }
1946 * @brief Gets an iterator to the start of the %sub_match collection.
1950 { return _Base_type::begin(); }
1952 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
1954 * @brief Gets an iterator to the start of the %sub_match collection.
1958 { return _Base_type::begin(); }
1962 * @brief Gets an iterator to one-past-the-end of the collection.
1966 { return _Base_type::end(); }
1968 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
1970 * @brief Gets an iterator to one-past-the-end of the collection.
1974 { return _Base_type::end(); }
1980 * @name 10.4 Formatting
1982 * These functions perform formatted substitution of the matched character
1983 * sequences into their target. The format specifiers and escape sequences
1984 * accepted by these functions are determined by their @p flags parameter
1985 * as documented above.
1990 * @todo Implement this function.
1992 template<typename _Out_iter>
1994 format(_Out_iter __out, const string_type& __fmt,
1995 regex_constants::match_flag_type __flags
1996 = regex_constants::format_default) const;
1999 * @todo Implement this function.
2002 format(const string_type& __fmt,
2003 regex_constants::match_flag_type __flags
2004 = regex_constants::format_default) const;
2009 * @name 10.5 Allocator
2014 * @brief Gets a copy of the allocator.
2017 //get_allocator() const;
2018 using _Base_type::get_allocator;
2028 * @brief Swaps the contents of two match_results.
2031 swap(match_results& __that)
2033 _Base_type::swap(__that);
2034 std::swap(_M_matched, __that._M_matched);
2035 std::swap(_M_prefix, __that._M_prefix);
2036 std::swap(_M_suffix, __that._M_suffix);
2042 value_type _M_prefix;
2043 value_type _M_suffix;
2046 typedef match_results<const char*> cmatch;
2047 typedef match_results<string::const_iterator> smatch;
2048 #ifdef _GLIBCXX_USE_WCHAR_T
2049 typedef match_results<const wchar_t*> wcmatch;
2050 typedef match_results<wstring::const_iterator> wsmatch;
2053 // match_results comparisons
2055 * @brief Compares two match_results for equality.
2056 * @returns true if the two objects refer to the same match,
2058 * @todo Implement this function.
2060 template<typename _Bi_iter, typename _Allocator>
2062 operator==(const match_results<_Bi_iter, _Allocator>& __m1,
2063 const match_results<_Bi_iter, _Allocator>& __m2);
2066 * @brief Compares two match_results for inequality.
2067 * @returns true if the two objects do not refer to the same match,
2070 template<typename _Bi_iter, class _Allocator>
2072 operator!=(const match_results<_Bi_iter, _Allocator>& __m1,
2073 const match_results<_Bi_iter, _Allocator>& __m2)
2074 { return !(__m1 == __m2); }
2076 // [7.10.6] match_results swap
2078 * @brief Swaps two match results.
2079 * @param lhs A match result.
2080 * @param rhs A match result.
2082 * The contents of the two match_results objects are swapped.
2084 template<typename _Bi_iter, typename _Allocator>
2086 swap(match_results<_Bi_iter, _Allocator>& __lhs,
2087 match_results<_Bi_iter, _Allocator>& __rhs)
2088 { __lhs.swap(__rhs); }
2090 // [7.11.2] Function template regex_match
2092 * @name Matching, Searching, and Replacing
2097 * @brief Determines if there is a match between the regular expression @p e
2098 * and all of the character sequence [first, last).
2100 * @param first Beginning of the character sequence to match.
2101 * @param last One-past-the-end of the character sequence to match.
2102 * @param m The match results.
2103 * @param re The regular expression.
2104 * @param flags Controls how the regular expression is matched.
2106 * @retval true A match exists.
2107 * @retval false Otherwise.
2109 * @throws an exception of type regex_error.
2111 * @todo Implement this function.
2113 template<typename _Bi_iter, typename _Allocator,
2114 typename _Ch_type, typename _Rx_traits>
2116 regex_match(_Bi_iter __first, _Bi_iter __last,
2117 match_results<_Bi_iter, _Allocator>& __m,
2118 const basic_regex<_Ch_type, _Rx_traits>& __re,
2119 regex_constants::match_flag_type __flags
2120 = regex_constants::match_default);
2123 * @brief Indicates if there is a match between the regular expression @p e
2124 * and all of the character sequence [first, last).
2126 * @param first Beginning of the character sequence to match.
2127 * @param last One-past-the-end of the character sequence to match.
2128 * @param re The regular expression.
2129 * @param flags Controls how the regular expression is matched.
2131 * @retval true A match exists.
2132 * @retval false Otherwise.
2134 * @throws an exception of type regex_error.
2136 template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
2138 regex_match(_Bi_iter __first, _Bi_iter __last,
2139 const basic_regex<_Ch_type, _Rx_traits>& __re,
2140 regex_constants::match_flag_type __flags
2141 = regex_constants::match_default)
2143 match_results<_Bi_iter> __what;
2144 return regex_match(__first, __last, __what, __re, __flags);
2148 * @brief Determines if there is a match between the regular expression @p e
2149 * and a C-style null-terminated string.
2151 * @param s The C-style null-terminated string to match.
2152 * @param m The match results.
2153 * @param re The regular expression.
2154 * @param f Controls how the regular expression is matched.
2156 * @retval true A match exists.
2157 * @retval false Otherwise.
2159 * @throws an exception of type regex_error.
2161 template<typename _Ch_type, typename _Allocator, typename _Rx_traits>
2163 regex_match(const _Ch_type* __s,
2164 match_results<const _Ch_type*, _Allocator>& __m,
2165 const basic_regex<_Ch_type, _Rx_traits>& __re,
2166 regex_constants::match_flag_type __f
2167 = regex_constants::match_default)
2168 { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); }
2171 * @brief Determines if there is a match between the regular expression @p e
2174 * @param s The string to match.
2175 * @param m The match results.
2176 * @param re The regular expression.
2177 * @param flags Controls how the regular expression is matched.
2179 * @retval true A match exists.
2180 * @retval false Otherwise.
2182 * @throws an exception of type regex_error.
2184 template<typename _Ch_traits, typename _Ch_alloc,
2185 typename _Allocator, typename _Ch_type, typename _Rx_traits>
2187 regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
2188 match_results<typename basic_string<_Ch_type,
2189 _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
2190 const basic_regex<_Ch_type, _Rx_traits>& __re,
2191 regex_constants::match_flag_type __flags
2192 = regex_constants::match_default)
2193 { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }
2196 * @brief Indicates if there is a match between the regular expression @p e
2197 * and a C-style null-terminated string.
2199 * @param s The C-style null-terminated string to match.
2200 * @param re The regular expression.
2201 * @param f Controls how the regular expression is matched.
2203 * @retval true A match exists.
2204 * @retval false Otherwise.
2206 * @throws an exception of type regex_error.
2208 template<typename _Ch_type, class _Rx_traits>
2210 regex_match(const _Ch_type* __s,
2211 const basic_regex<_Ch_type, _Rx_traits>& __re,
2212 regex_constants::match_flag_type __f
2213 = regex_constants::match_default)
2214 { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); }
2217 * @brief Indicates if there is a match between the regular expression @p e
2220 * @param s [IN] The string to match.
2221 * @param re [IN] The regular expression.
2222 * @param flags [IN] Controls how the regular expression is matched.
2224 * @retval true A match exists.
2225 * @retval false Otherwise.
2227 * @throws an exception of type regex_error.
2229 template<typename _Ch_traits, typename _Str_allocator,
2230 typename _Ch_type, typename _Rx_traits>
2232 regex_match(const basic_string<_Ch_type, _Ch_traits, _Str_allocator>& __s,
2233 const basic_regex<_Ch_type, _Rx_traits>& __re,
2234 regex_constants::match_flag_type __flags
2235 = regex_constants::match_default)
2236 { return regex_match(__s.begin(), __s.end(), __re, __flags); }
2238 // [7.11.3] Function template regex_search
2240 * Searches for a regular expression within a range.
2241 * @param first [IN] The start of the string to search.
2242 * @param last [IN] One-past-the-end of the string to search.
2243 * @param m [OUT] The match results.
2244 * @param re [IN] The regular expression to search for.
2245 * @param flags [IN] Search policy flags.
2246 * @retval true A match was found within the string.
2247 * @retval false No match was found within the string, the content of %m is
2250 * @throws an exception of type regex_error.
2252 * @todo Implement this function.
2254 template<typename _Bi_iter, typename _Allocator,
2255 typename _Ch_type, typename _Rx_traits>
2257 regex_search(_Bi_iter __first, _Bi_iter __last,
2258 match_results<_Bi_iter, _Allocator>& __m,
2259 const basic_regex<_Ch_type, _Rx_traits>& __re,
2260 regex_constants::match_flag_type __flags
2261 = regex_constants::match_default);
2264 * Searches for a regular expression within a range.
2265 * @param first [IN] The start of the string to search.
2266 * @param last [IN] One-past-the-end of the string to search.
2267 * @param re [IN] The regular expression to search for.
2268 * @param flags [IN] Search policy flags.
2269 * @retval true A match was found within the string.
2270 * @retval false No match was found within the string.
2273 * @throws an exception of type regex_error.
2275 template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
2277 regex_search(_Bi_iter __first, _Bi_iter __last,
2278 const basic_regex<_Ch_type, _Rx_traits>& __re,
2279 regex_constants::match_flag_type __flags
2280 = regex_constants::match_default)
2282 match_results<_Bi_iter> __what;
2283 return regex_search(__first, __last, __what, __re, __flags);
2287 * @brief Searches for a regular expression within a C-string.
2288 * @param s [IN] A C-string to search for the regex.
2289 * @param m [OUT] The set of regex matches.
2290 * @param e [IN] The regex to search for in @p s.
2291 * @param f [IN] The search flags.
2292 * @retval true A match was found within the string.
2293 * @retval false No match was found within the string, the content of %m is
2297 * @throws an exception of type regex_error.
2299 template<typename _Ch_type, class _Allocator, class _Rx_traits>
2301 regex_search(const _Ch_type* __s,
2302 match_results<const _Ch_type*, _Allocator>& __m,
2303 const basic_regex<_Ch_type, _Rx_traits>& __e,
2304 regex_constants::match_flag_type __f
2305 = regex_constants::match_default)
2306 { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
2309 * @brief Searches for a regular expression within a C-string.
2310 * @param s [IN] The C-string to search.
2311 * @param e [IN] The regular expression to search for.
2312 * @param f [IN] Search policy flags.
2313 * @retval true A match was found within the string.
2314 * @retval false No match was found within the string.
2317 * @throws an exception of type regex_error.
2319 template<typename _Ch_type, typename _Rx_traits>
2321 regex_search(const _Ch_type* __s,
2322 const basic_regex<_Ch_type, _Rx_traits>& __e,
2323 regex_constants::match_flag_type __f
2324 = regex_constants::match_default)
2325 { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); }
2328 * @brief Searches for a regular expression within a string.
2329 * @param s [IN] The string to search.
2330 * @param e [IN] The regular expression to search for.
2331 * @param flags [IN] Search policy flags.
2332 * @retval true A match was found within the string.
2333 * @retval false No match was found within the string.
2336 * @throws an exception of type regex_error.
2338 template<typename _Ch_traits, typename _String_allocator,
2339 typename _Ch_type, typename _Rx_traits>
2341 regex_search(const basic_string<_Ch_type, _Ch_traits,
2342 _String_allocator>& __s,
2343 const basic_regex<_Ch_type, _Rx_traits>& __e,
2344 regex_constants::match_flag_type __flags
2345 = regex_constants::match_default)
2346 { return regex_search(__s.begin(), __s.end(), __e, __flags); }
2349 * @brief Searches for a regular expression within a string.
2350 * @param s [IN] A C++ string to search for the regex.
2351 * @param m [OUT] The set of regex matches.
2352 * @param e [IN] The regex to search for in @p s.
2353 * @param f [IN] The search flags.
2354 * @retval true A match was found within the string.
2355 * @retval false No match was found within the string, the content of %m is
2358 * @throws an exception of type regex_error.
2360 template<typename _Ch_traits, typename _Ch_alloc,
2361 typename _Allocator, typename _Ch_type,
2362 typename _Rx_traits>
2364 regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
2365 match_results<typename basic_string<_Ch_type,
2366 _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
2367 const basic_regex<_Ch_type, _Rx_traits>& __e,
2368 regex_constants::match_flag_type __f
2369 = regex_constants::match_default)
2370 { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
2372 // tr1 [7.11.4] std [28.11.4] Function template regex_replace
2383 * @throws an exception of type regex_error.
2385 * @todo Implement this function.
2387 template<typename _Out_iter, typename _Bi_iter,
2388 typename _Rx_traits, typename _Ch_type>
2390 regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
2391 const basic_regex<_Ch_type, _Rx_traits>& __e,
2392 const basic_string<_Ch_type>& __fmt,
2393 regex_constants::match_flag_type __flags
2394 = regex_constants::match_default);
2403 * @returns a copy of string @p s with replacements.
2405 * @throws an exception of type regex_error.
2407 template<typename _Rx_traits, typename _Ch_type>
2408 inline basic_string<_Ch_type>
2409 regex_replace(const basic_string<_Ch_type>& __s,
2410 const basic_regex<_Ch_type, _Rx_traits>& __e,
2411 const basic_string<_Ch_type>& __fmt,
2412 regex_constants::match_flag_type __flags
2413 = regex_constants::match_default)
2415 std::string __result;
2416 regex_replace(std::back_inserter(__result),
2417 __s.begin(), __s.end(), __e, __fmt, __flags);
2423 // tr1 [7.12.1] std [28.12] Class template regex_iterator
2425 * An iterator adaptor that will provide repeated calls of regex_search over
2426 * a range until no more matches remain.
2428 template<typename _Bi_iter,
2429 typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2430 typename _Rx_traits = regex_traits<_Ch_type> >
2431 class regex_iterator
2434 typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
2435 typedef match_results<_Bi_iter> value_type;
2436 typedef std::ptrdiff_t difference_type;
2437 typedef const value_type* pointer;
2438 typedef const value_type& reference;
2439 typedef std::forward_iterator_tag iterator_category;
2443 * @brief Provides a singular iterator, useful for indicating
2444 * one-past-the-end of a range.
2445 * @todo Implement this function.
2451 * Constructs a %regex_iterator...
2452 * @param a [IN] The start of a text range to search.
2453 * @param b [IN] One-past-the-end of the text range to search.
2454 * @param re [IN] The regular expression to match.
2455 * @param m [IN] Policy flags for match rules.
2456 * @todo Implement this function.
2459 regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2460 regex_constants::match_flag_type __m
2461 = regex_constants::match_default);
2464 * Copy constructs a %regex_iterator.
2465 * @todo Implement this function.
2468 regex_iterator(const regex_iterator& __rhs);
2471 * @todo Implement this function.
2475 operator=(const regex_iterator& __rhs);
2478 * @todo Implement this function.
2482 operator==(const regex_iterator& __rhs);
2485 * @todo Implement this function.
2489 operator!=(const regex_iterator& __rhs);
2492 * @todo Implement this function.
2499 * @todo Implement this function.
2506 * @todo Implement this function.
2513 * @todo Implement this function.
2520 // these members are shown for exposition only:
2523 const regex_type* pregex;
2524 regex_constants::match_flag_type flags;
2525 match_results<_Bi_iter> match;
2528 typedef regex_iterator<const char*> cregex_iterator;
2529 typedef regex_iterator<string::const_iterator> sregex_iterator;
2530 #ifdef _GLIBCXX_USE_WCHAR_T
2531 typedef regex_iterator<const wchar_t*> wcregex_iterator;
2532 typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
2535 // [7.12.2] Class template regex_token_iterator
2537 * Iterates over submatches in a range (or @a splits a text string).
2539 * The purpose of this iterator is to enumerate all, or all specified,
2540 * matches of a regular expression within a text range. The dereferenced
2541 * value of an iterator of this class is a std::tr1::sub_match object.
2543 template<typename _Bi_iter,
2544 typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2545 typename _Rx_traits = regex_traits<_Ch_type> >
2546 class regex_token_iterator
2549 typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
2550 typedef sub_match<_Bi_iter> value_type;
2551 typedef std::ptrdiff_t difference_type;
2552 typedef const value_type* pointer;
2553 typedef const value_type& reference;
2554 typedef std::forward_iterator_tag iterator_category;
2558 * @brief Default constructs a %regex_token_iterator.
2559 * @todo Implement this function.
2561 * A default-constructed %regex_token_iterator is a singular iterator
2562 * that will compare equal to the one-past-the-end value for any
2563 * iterator of the same type.
2565 regex_token_iterator();
2568 * Constructs a %regex_token_iterator...
2569 * @param a [IN] The start of the text to search.
2570 * @param b [IN] One-past-the-end of the text to search.
2571 * @param re [IN] The regular expression to search for.
2572 * @param submatch [IN] Which submatch to return. There are some
2573 * special values for this parameter:
2574 * - -1 each enumerated subexpression does NOT
2575 * match the regular expression (aka field
2577 * - 0 the entire string matching the
2578 * subexpression is returned for each match
2580 * - >0 enumerates only the indicated
2581 * subexpression from a match within the text.
2582 * @param m [IN] Policy flags for match rules.
2584 * @todo Implement this function.
2587 regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2589 regex_constants::match_flag_type __m
2590 = regex_constants::match_default);
2593 * Constructs a %regex_token_iterator...
2594 * @param a [IN] The start of the text to search.
2595 * @param b [IN] One-past-the-end of the text to search.
2596 * @param re [IN] The regular expression to search for.
2597 * @param submatches [IN] A list of subexpressions to return for each
2598 * regular expression match within the text.
2599 * @param m [IN] Policy flags for match rules.
2601 * @todo Implement this function.
2604 regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2605 const regex_type& __re,
2606 const std::vector<int>& __submatches,
2607 regex_constants::match_flag_type __m
2608 = regex_constants::match_default);
2611 * Constructs a %regex_token_iterator...
2612 * @param a [IN] The start of the text to search.
2613 * @param b [IN] One-past-the-end of the text to search.
2614 * @param re [IN] The regular expression to search for.
2615 * @param submatches [IN] A list of subexpressions to return for each
2616 * regular expression match within the text.
2617 * @param m [IN] Policy flags for match rules.
2619 * @todo Implement this function.
2622 template<std::size_t _Nm>
2623 regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2624 const regex_type& __re,
2625 const int (&__submatches)[_Nm],
2626 regex_constants::match_flag_type __m
2627 = regex_constants::match_default);
2630 * @brief Copy constructs a %regex_token_iterator.
2631 * @param rhs [IN] A %regex_token_iterator to copy.
2632 * @todo Implement this function.
2634 regex_token_iterator(const regex_token_iterator& __rhs);
2637 * @brief Assigns a %regex_token_iterator to another.
2638 * @param rhs [IN] A %regex_token_iterator to copy.
2639 * @todo Implement this function.
2641 regex_token_iterator&
2642 operator=(const regex_token_iterator& __rhs);
2645 * @brief Compares a %regex_token_iterator to another for equality.
2646 * @todo Implement this function.
2649 operator==(const regex_token_iterator& __rhs);
2652 * @brief Compares a %regex_token_iterator to another for inequality.
2653 * @todo Implement this function.
2656 operator!=(const regex_token_iterator& __rhs);
2659 * @brief Dereferences a %regex_token_iterator.
2660 * @todo Implement this function.
2666 * @brief Selects a %regex_token_iterator member.
2667 * @todo Implement this function.
2673 * @brief Increments a %regex_token_iterator.
2674 * @todo Implement this function.
2676 regex_token_iterator&
2680 * @brief Postincrements a %regex_token_iterator.
2681 * @todo Implement this function.
2683 regex_token_iterator
2686 private: // data members for exposition only:
2687 typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> position_iterator;
2689 position_iterator __position;
2690 const value_type* __result;
2691 value_type __suffix;
2693 std::vector<int> __subs;
2696 /** @brief Token iterator for C-style NULL-terminated strings. */
2697 typedef regex_token_iterator<const char*> cregex_token_iterator;
2698 /** @brief Token iterator for standard strings. */
2699 typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
2700 #ifdef _GLIBCXX_USE_WCHAR_T
2701 /** @brief Token iterator for C-style NULL-terminated wide strings. */
2702 typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
2703 /** @brief Token iterator for standard wide-character strings. */
2704 typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
2709 _GLIBCXX_END_NAMESPACE_TR1