1 // class template regex -*- C++ -*-
3 // Copyright (C) 2007-2014 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
27 * @author Stephen M. Webb <stephen.webb@bregmasoft.ca>
28 * This is a TR1 C++ Library header.
31 #ifndef _GLIBCXX_TR1_REGEX
32 #define _GLIBCXX_TR1_REGEX 1
34 #pragma GCC system_header
46 namespace std _GLIBCXX_VISIBILITY(default)
51 * @defgroup tr1_regex Regular Expressions
52 * A facility for performing regular expression pattern matching.
56 /** @namespace std::regex_constants
57 * @brief ISO C++ 0x entities sub namespace for regex.
59 namespace regex_constants
61 _GLIBCXX_BEGIN_NAMESPACE_VERSION
64 * @name 5.1 Regular Expression Syntax Options
83 * @brief This is a bitmask type indicating how to interpret the regex.
85 * The @c syntax_option_type is implementation defined but it is valid to
86 * perform bitwise operations on these values and expect the right thing to
89 * A valid value of type syntax_option_type shall have exactly one of the
90 * elements @c ECMAScript, @c basic, @c extended, @c awk, @c grep, @c egrep
93 typedef unsigned int syntax_option_type;
96 * Specifies that the matching of regular expressions against a character
97 * sequence shall be performed without regard to case.
99 static const syntax_option_type icase = 1 << _S_icase;
102 * Specifies that when a regular expression is matched against a character
103 * container sequence, no sub-expression matches are to be stored in the
104 * supplied match_results structure.
106 static const syntax_option_type nosubs = 1 << _S_nosubs;
109 * Specifies that the regular expression engine should pay more attention to
110 * the speed with which regular expressions are matched, and less to the
111 * speed with which regular expression objects are constructed. Otherwise
112 * it has no detectable effect on the program output.
114 static const syntax_option_type optimize = 1 << _S_optimize;
117 * Specifies that character ranges of the form [a-b] should be locale
120 static const syntax_option_type collate = 1 << _S_collate;
123 * Specifies that the grammar recognized by the regular expression engine is
124 * that used by ECMAScript in ECMA-262 [Ecma International, ECMAScript
125 * Language Specification, Standard Ecma-262, third edition, 1999], as
126 * modified in tr1 section [7.13]. This grammar is similar to that defined
127 * in the PERL scripting language but extended with elements found in the
128 * POSIX regular expression grammar.
130 static const syntax_option_type ECMAScript = 1 << _S_ECMAScript;
133 * Specifies that the grammar recognized by the regular expression engine is
134 * that used by POSIX basic regular expressions in IEEE Std 1003.1-2001,
135 * Portable Operating System Interface (POSIX), Base Definitions and
136 * Headers, Section 9, Regular Expressions [IEEE, Information Technology --
137 * Portable Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
139 static const syntax_option_type basic = 1 << _S_basic;
142 * Specifies that the grammar recognized by the regular expression engine is
143 * that used by POSIX extended regular expressions in IEEE Std 1003.1-2001,
144 * Portable Operating System Interface (POSIX), Base Definitions and Headers,
145 * Section 9, Regular Expressions.
147 static const syntax_option_type extended = 1 << _S_extended;
150 * Specifies that the grammar recognized by the regular expression engine is
151 * that used by POSIX utility awk in IEEE Std 1003.1-2001. This option is
152 * identical to syntax_option_type extended, except that C-style escape
153 * sequences are supported. These sequences are:
154 * \\\\, \\a, \\b, \\f,
155 * \\n, \\r, \\t , \\v,
156 * \\', ', and \\ddd
157 * (where ddd is one, two, or three octal digits).
159 static const syntax_option_type awk = 1 << _S_awk;
162 * Specifies that the grammar recognized by the regular expression engine is
163 * that used by POSIX utility grep in IEEE Std 1003.1-2001. This option is
164 * identical to syntax_option_type basic, except that newlines are treated
167 static const syntax_option_type grep = 1 << _S_grep;
170 * Specifies that the grammar recognized by the regular expression engine is
171 * that used by POSIX utility grep when given the -E option in
172 * IEEE Std 1003.1-2001. This option is identical to syntax_option_type
173 * extended, except that newlines are treated as whitespace.
175 static const syntax_option_type egrep = 1 << _S_egrep;
180 * @name 5.2 Matching Rules
182 * Matching a regular expression against a sequence of characters [first,
183 * last) proceeds according to the rules of the grammar specified for the
184 * regular expression object, modified according to the effects listed
185 * below for any bitmask elements set.
207 * @brief This is a bitmask type indicating regex matching rules.
209 * The @c match_flag_type is implementation defined but it is valid to
210 * perform bitwise operations on these values and expect the right thing to
213 typedef std::bitset<_S_match_flag_last> match_flag_type;
216 * The default matching rules.
218 static const match_flag_type match_default = 0;
221 * The first character in the sequence [first, last) is treated as though it
222 * is not at the beginning of a line, so the character (^) in the regular
223 * expression shall not match [first, first).
225 static const match_flag_type match_not_bol = 1 << _S_not_bol;
228 * The last character in the sequence [first, last) is treated as though it
229 * is not at the end of a line, so the character ($) in the regular
230 * expression shall not match [last, last).
232 static const match_flag_type match_not_eol = 1 << _S_not_eol;
235 * The expression \\b is not matched against the sub-sequence
238 static const match_flag_type match_not_bow = 1 << _S_not_bow;
241 * The expression \\b should not be matched against the sub-sequence
244 static const match_flag_type match_not_eow = 1 << _S_not_eow;
247 * If more than one match is possible then any match is an acceptable
250 static const match_flag_type match_any = 1 << _S_any;
253 * The expression does not match an empty sequence.
255 static const match_flag_type match_not_null = 1 << _S_not_null;
258 * The expression only matches a sub-sequence that begins at first .
260 static const match_flag_type match_continuous = 1 << _S_continuous;
263 * --first is a valid iterator position. When this flag is set then the
264 * flags match_not_bol and match_not_bow are ignored by the regular
265 * expression algorithms 7.11 and iterators 7.12.
267 static const match_flag_type match_prev_avail = 1 << _S_prev_avail;
270 * When a regular expression match is to be replaced by a new string, the
271 * new string is constructed using the rules used by the ECMAScript replace
272 * function in ECMA- 262 [Ecma International, ECMAScript Language
273 * Specification, Standard Ecma-262, third edition, 1999], part 15.5.4.11
274 * String.prototype.replace. In addition, during search and replace
275 * operations all non-overlapping occurrences of the regular expression
276 * are located and replaced, and sections of the input that did not match
277 * the expression are copied unchanged to the output string.
279 * Format strings (from ECMA-262 [15.5.4.11]):
280 * @li $$ The dollar-sign itself ($)
281 * @li $& The matched substring.
282 * @li $` The portion of @a string that precedes the matched substring.
283 * This would be match_results::prefix().
284 * @li $' The portion of @a string that follows the matched substring.
285 * This would be match_results::suffix().
286 * @li $n The nth capture, where n is in [1,9] and $n is not followed by a
287 * decimal digit. If n <= match_results::size() and the nth capture
288 * is undefined, use the empty string instead. If n >
289 * match_results::size(), the result is implementation-defined.
290 * @li $nn The nnth capture, where nn is a two-digit decimal number on
291 * [01, 99]. If nn <= match_results::size() and the nth capture is
292 * undefined, use the empty string instead. If
293 * nn > match_results::size(), the result is implementation-defined.
295 static const match_flag_type format_default = 0;
298 * When a regular expression match is to be replaced by a new string, the
299 * new string is constructed using the rules used by the POSIX sed utility
300 * in IEEE Std 1003.1- 2001 [IEEE, Information Technology -- Portable
301 * Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
303 static const match_flag_type format_sed = 1 << _S_sed;
306 * During a search and replace operation, sections of the character
307 * container sequence being searched that do not match the regular
308 * expression shall not be copied to the output string.
310 static const match_flag_type format_no_copy = 1 << _S_no_copy;
313 * When specified during a search and replace operation, only the first
314 * occurrence of the regular expression shall be replaced.
316 static const match_flag_type format_first_only = 1 << _S_first_only;
321 * @name 5.3 Error Types
343 /** The expression contained an invalid collating element name. */
344 static const error_type error_collate(_S_error_collate);
346 /** The expression contained an invalid character class name. */
347 static const error_type error_ctype(_S_error_ctype);
350 * The expression contained an invalid escaped character, or a trailing
353 static const error_type error_escape(_S_error_escape);
355 /** The expression contained an invalid back reference. */
356 static const error_type error_backref(_S_error_backref);
358 /** The expression contained mismatched [ and ]. */
359 static const error_type error_brack(_S_error_brack);
361 /** The expression contained mismatched ( and ). */
362 static const error_type error_paren(_S_error_paren);
364 /** The expression contained mismatched { and } */
365 static const error_type error_brace(_S_error_brace);
367 /** The expression contained an invalid range in a {} expression. */
368 static const error_type error_badbrace(_S_error_badbrace);
371 * The expression contained an invalid character range,
372 * such as [b-a] in most encodings.
374 static const error_type error_range(_S_error_range);
377 * There was insufficient memory to convert the expression into a
378 * finite state machine.
380 static const error_type error_space(_S_error_space);
383 * One of <em>*?+{</em> was not preceded by a valid regular expression.
385 static const error_type error_badrepeat(_S_error_badrepeat);
388 * The complexity of an attempted match against a regular expression
389 * exceeded a pre-set level.
391 static const error_type error_complexity(_S_error_complexity);
394 * There was insufficient memory to determine whether the
395 * regular expression could match the specified character sequence.
397 static const error_type error_stack(_S_error_stack);
400 _GLIBCXX_END_NAMESPACE_VERSION
403 _GLIBCXX_BEGIN_NAMESPACE_VERSION
405 // [7.8] Class regex_error
407 * @brief A regular expression exception class.
408 * @ingroup exceptions
410 * The regular expression library throws objects of this class on error.
413 : public std::runtime_error
417 * @brief Constructs a regex_error object.
419 * @param ecode the regex error code.
422 regex_error(regex_constants::error_type __ecode)
423 : std::runtime_error("regex_error"), _M_code(__ecode)
427 * @brief Gets the regex error code.
429 * @returns the regex error code.
431 regex_constants::error_type
436 regex_constants::error_type _M_code;
439 // [7.7] Class regex_traits
441 * @brief Describes aspects of a regular expression.
443 * A regular expression traits class that satisfies the requirements of tr1
446 * The class %regex is parameterized around a set of related types and
447 * functions used to complete the definition of its semantics. This class
448 * satisfies the requirements of such a traits class.
450 template<typename _Ch_type>
454 typedef _Ch_type char_type;
455 typedef std::basic_string<char_type> string_type;
456 typedef std::locale locale_type;
457 typedef std::ctype_base::mask char_class_type;
461 * @brief Constructs a default traits object.
467 * @brief Gives the length of a C-style string starting at @p __p.
469 * @param __p a pointer to the start of a character sequence.
471 * @returns the number of characters between @p *__p and the first
472 * default-initialized value of type @p char_type. In other words, uses
473 * the C-string algorithm for determining the length of a sequence of
477 length(const char_type* __p)
478 { return string_type::traits_type::length(__p); }
481 * @brief Performs the identity translation.
483 * @param c A character to the locale-specific character set.
488 translate(char_type __c) const
492 * @brief Translates a character into a case-insensitive equivalent.
494 * @param c A character to the locale-specific character set.
496 * @returns the locale-specific lower-case equivalent of c.
497 * @throws std::bad_cast if the imbued locale does not support the ctype
501 translate_nocase(char_type __c) const
504 using std::use_facet;
505 return use_facet<ctype<char_type> >(_M_locale).tolower(__c);
509 * @brief Gets a sort key for a character sequence.
511 * @param first beginning of the character sequence.
512 * @param last one-past-the-end of the character sequence.
514 * Returns a sort key for the character sequence designated by the
515 * iterator range [F1, F2) such that if the character sequence [G1, G2)
516 * sorts before the character sequence [H1, H2) then
517 * v.transform(G1, G2) < v.transform(H1, H2).
519 * What this really does is provide a more efficient way to compare a
520 * string to multiple other strings in locales with fancy collation
521 * rules and equivalence classes.
523 * @returns a locale-specific sort key equivalent to the input range.
525 * @throws std::bad_cast if the current locale does not have a collate
528 template<typename _Fwd_iter>
530 transform(_Fwd_iter __first, _Fwd_iter __last) const
533 using std::use_facet;
534 const collate<_Ch_type>& __c(use_facet<
535 collate<_Ch_type> >(_M_locale));
536 string_type __s(__first, __last);
537 return __c.transform(__s.data(), __s.data() + __s.size());
543 * @param first beginning of the character sequence.
544 * @param last one-past-the-end of the character sequence.
546 * Effects: if typeid(use_facet<collate<_Ch_type> >) ==
547 * typeid(collate_byname<_Ch_type>) and the form of the sort key
548 * returned by collate_byname<_Ch_type>::transform(first, last) is known
549 * and can be converted into a primary sort key then returns that key,
550 * otherwise returns an empty string. WTF??
552 * @todo Implement this function.
554 template<typename _Fwd_iter>
556 transform_primary(_Fwd_iter __first, _Fwd_iter __last) const;
559 * @brief Gets a collation element by name.
561 * @param first beginning of the collation element name.
562 * @param last one-past-the-end of the collation element name.
564 * @returns a sequence of one or more characters that represents the
565 * collating element consisting of the character sequence designated by
566 * the iterator range [first, last). Returns an empty string if the
567 * character sequence is not a valid collating element.
569 * @todo Implement this function.
571 template<typename _Fwd_iter>
573 lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const;
576 * @brief Maps one or more characters to a named character
579 * @param first beginning of the character sequence.
580 * @param last one-past-the-end of the character sequence.
582 * @returns an unspecified value that represents the character
583 * classification named by the character sequence designated by the
584 * iterator range [first, last). The value returned shall be independent
585 * of the case of the characters in the character sequence. If the name
586 * is not recognized then returns a value that compares equal to 0.
588 * At least the following names (or their wide-character equivalent) are
606 * @todo Implement this function.
608 template<typename _Fwd_iter>
610 lookup_classname(_Fwd_iter __first, _Fwd_iter __last) const;
613 * @brief Determines if @p c is a member of an identified class.
615 * @param c a character.
616 * @param f a class type (as returned from lookup_classname).
618 * @returns true if the character @p c is a member of the classification
619 * represented by @p f, false otherwise.
621 * @throws std::bad_cast if the current locale does not have a ctype
625 isctype(_Ch_type __c, char_class_type __f) const;
628 * @brief Converts a digit to an int.
630 * @param ch a character representing a digit.
631 * @param radix the radix if the numeric conversion (limited to 8, 10,
634 * @returns the value represented by the digit ch in base radix if the
635 * character ch is a valid digit in base radix; otherwise returns -1.
638 value(_Ch_type __ch, int __radix) const;
641 * @brief Imbues the regex_traits object with a copy of a new locale.
643 * @param loc A locale.
645 * @returns a copy of the previous locale in use by the regex_traits
648 * @note Calling imbue with a different locale than the one currently in
649 * use invalidates all cached data held by *this.
652 imbue(locale_type __loc)
654 std::swap(_M_locale, __loc);
659 * @brief Gets a copy of the current locale in use by the regex_traits
664 { return _M_locale; }
667 locale_type _M_locale;
670 template<typename _Ch_type>
671 bool regex_traits<_Ch_type>::
672 isctype(_Ch_type __c, char_class_type __f) const
675 using std::use_facet;
676 const ctype<_Ch_type>& __ctype(use_facet<
677 ctype<_Ch_type> >(_M_locale));
679 if (__ctype.is(__c, __f))
682 // special case of underscore in [[:w:]]
683 if (__c == __ctype.widen('_'))
685 const char* const __wb[] = "w";
686 char_class_type __wt = this->lookup_classname(__wb,
687 __wb + sizeof(__wb));
692 // special case of [[:space:]] in [[:blank:]]
693 if (__c == __ctype.isspace(__c))
695 const char* const __bb[] = "blank";
696 char_class_type __bt = this->lookup_classname(__bb,
697 __bb + sizeof(__bb));
705 template<typename _Ch_type>
706 int regex_traits<_Ch_type>::
707 value(_Ch_type __ch, int __radix) const
709 std::basic_istringstream<_Ch_type> __is(string_type(1, __ch));
713 else if (__radix == 16)
716 return __is.fail() ? -1 : __v;
719 // [7.8] Class basic_regex
721 * Objects of specializations of this class represent regular expressions
722 * constructed from sequences of character type @p _Ch_type.
724 * Storage for the regular expression is allocated and deallocated as
725 * necessary by the member functions of this class.
727 template<typename _Ch_type, typename _Rx_traits = regex_traits<_Ch_type> >
732 typedef _Ch_type value_type;
733 typedef regex_constants::syntax_option_type flag_type;
734 typedef typename _Rx_traits::locale_type locale_type;
735 typedef typename _Rx_traits::string_type string_type;
739 * tr1 [7.8.1] std [28.8.1]
742 static const regex_constants::syntax_option_type icase
743 = regex_constants::icase;
744 static const regex_constants::syntax_option_type nosubs
745 = regex_constants::nosubs;
746 static const regex_constants::syntax_option_type optimize
747 = regex_constants::optimize;
748 static const regex_constants::syntax_option_type collate
749 = regex_constants::collate;
750 static const regex_constants::syntax_option_type ECMAScript
751 = regex_constants::ECMAScript;
752 static const regex_constants::syntax_option_type basic
753 = regex_constants::basic;
754 static const regex_constants::syntax_option_type extended
755 = regex_constants::extended;
756 static const regex_constants::syntax_option_type awk
757 = regex_constants::awk;
758 static const regex_constants::syntax_option_type grep
759 = regex_constants::grep;
760 static const regex_constants::syntax_option_type egrep
761 = regex_constants::egrep;
764 // [7.8.2] construct/copy/destroy
766 * Constructs a basic regular expression that does not match any
767 * character sequence.
770 : _M_flags(regex_constants::ECMAScript), _M_pattern(), _M_mark_count(0)
774 * @brief Constructs a basic regular expression from the sequence
775 * [p, p + char_traits<_Ch_type>::length(p)) interpreted according to the
778 * @param p A pointer to the start of a C-style null-terminated string
779 * containing a 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.
785 basic_regex(const _Ch_type* __p,
786 flag_type __f = regex_constants::ECMAScript)
787 : _M_flags(__f), _M_pattern(__p), _M_mark_count(0)
791 * @brief Constructs a basic regular expression from the sequence
792 * [p, p + len) interpreted according to the flags in @p f.
794 * @param p A pointer to the start of a string containing a regular
796 * @param len The length of the string containing the regular expression.
797 * @param f Flags indicating the syntax rules and options.
799 * @throws regex_error if @p p is not a valid regular expression.
801 basic_regex(const _Ch_type* __p, std::size_t __len, flag_type __f)
802 : _M_flags(__f) , _M_pattern(__p, __len), _M_mark_count(0)
806 * @brief Copy-constructs a basic regular expression.
808 * @param rhs A @p regex object.
810 basic_regex(const basic_regex& __rhs)
811 : _M_flags(__rhs._M_flags), _M_pattern(__rhs._M_pattern),
812 _M_mark_count(__rhs._M_mark_count)
816 * @brief Constructs a basic regular expression from the string
817 * @p s interpreted according to the flags in @p f.
819 * @param s A string containing a regular expression.
820 * @param f Flags indicating the syntax rules and options.
822 * @throws regex_error if @p s is not a valid regular expression.
824 template<typename _Ch_traits, typename _Ch_alloc>
826 basic_regex(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
827 flag_type __f = regex_constants::ECMAScript)
828 : _M_flags(__f), _M_pattern(__s.begin(), __s.end()), _M_mark_count(0)
832 * @brief Constructs a basic regular expression from the range
833 * [first, last) interpreted according to the flags in @p f.
835 * @param first The start of a range containing a valid regular
837 * @param last The end of a range containing a valid regular
839 * @param f The format flags of the regular expression.
841 * @throws regex_error if @p [first, last) is not a valid regular
844 template<typename _InputIterator>
845 basic_regex(_InputIterator __first, _InputIterator __last,
846 flag_type __f = regex_constants::ECMAScript)
847 : _M_flags(__f), _M_pattern(__first, __last), _M_mark_count(0)
850 #ifdef _GLIBCXX_INCLUDE_AS_CXX11
852 * @brief Constructs a basic regular expression from an initializer list.
854 * @param l The initializer list.
855 * @param f The format flags of the regular expression.
857 * @throws regex_error if @p l is not a valid regular expression.
859 basic_regex(initializer_list<_Ch_type> __l,
860 flag_type __f = regex_constants::ECMAScript)
861 : _M_flags(__f), _M_pattern(__l.begin(), __l.end()), _M_mark_count(0)
866 * @brief Destroys a basic regular expression.
872 * @brief Assigns one regular expression to another.
875 operator=(const basic_regex& __rhs)
876 { return this->assign(__rhs); }
879 * @brief Replaces a regular expression with a new one constructed from
880 * a C-style null-terminated string.
882 * @param A pointer to the start of a null-terminated C-style string
883 * containing a regular expression.
886 operator=(const _Ch_type* __p)
887 { return this->assign(__p, flags()); }
890 * @brief Replaces a regular expression with a new one constructed from
893 * @param A pointer to a string containing a regular expression.
895 template<typename _Ch_typeraits, typename _Allocator>
897 operator=(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s)
898 { return this->assign(__s, flags()); }
902 * @brief the real assignment operator.
904 * @param that Another regular expression object.
907 assign(const basic_regex& __that)
909 basic_regex __tmp(__that);
915 * @brief Assigns a new regular expression to a regex object from a
916 * C-style null-terminated string containing a regular expression
919 * @param p A pointer to a C-style null-terminated string containing
920 * a regular expression pattern.
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,
929 flag_type __flags = regex_constants::ECMAScript)
930 { return this->assign(string_type(__p), __flags); }
933 * @brief Assigns a new regular expression to a regex object from a
934 * C-style string containing a regular expression pattern.
936 * @param p A pointer to a C-style string containing a
937 * regular expression pattern.
938 * @param len The length of the regular expression pattern string.
939 * @param flags Syntax option flags.
941 * @throws regex_error if p does not contain a valid regular expression
942 * pattern interpreted according to @p flags. If regex_error is thrown,
943 * *this remains unchanged.
946 assign(const _Ch_type* __p, std::size_t __len, flag_type __flags)
947 { return this->assign(string_type(__p, __len), __flags); }
950 * @brief Assigns a new regular expression to a regex object from a
951 * string containing a regular expression pattern.
953 * @param s A string containing a regular expression pattern.
954 * @param flags Syntax option flags.
956 * @throws regex_error if p does not contain a valid regular expression
957 * pattern interpreted according to @p flags. If regex_error is thrown,
958 * *this remains unchanged.
960 template<typename _Ch_typeraits, typename _Allocator>
962 assign(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s,
963 flag_type __f = regex_constants::ECMAScript)
965 basic_regex __tmp(__s, __f);
971 * @brief Assigns a new regular expression to a regex object.
973 * @param first The start of a range containing a valid regular
975 * @param last The end of a range containing a valid regular
977 * @param flags Syntax option flags.
979 * @throws regex_error if p does not contain a valid regular expression
980 * pattern interpreted according to @p flags. If regex_error is thrown,
981 * the object remains unchanged.
983 template<typename _InputIterator>
985 assign(_InputIterator __first, _InputIterator __last,
986 flag_type __flags = regex_constants::ECMAScript)
987 { return this->assign(string_type(__first, __last), __flags); }
989 #ifdef _GLIBCXX_INCLUDE_AS_CXX11
991 * @brief Assigns a new regular expression to a regex object.
993 * @param l An initializer list representing a regular expression.
994 * @param flags Syntax option flags.
996 * @throws regex_error if @p l does not contain a valid regular
997 * expression pattern interpreted according to @p flags. If regex_error
998 * is thrown, the object remains unchanged.
1001 assign(initializer_list<_Ch_type> __l,
1002 flag_type __f = regex_constants::ECMAScript)
1003 { return this->assign(__l.begin(), __l.end(), __f); }
1006 // [7.8.4] const operations
1008 * @brief Gets the number of marked subexpressions within the regular
1013 { return _M_mark_count; }
1016 * @brief Gets the flags used to construct the regular expression
1017 * or in the last call to assign().
1021 { return _M_flags; }
1025 * @brief Imbues the regular expression object with the given locale.
1027 * @param loc A locale.
1030 imbue(locale_type __loc)
1031 { return _M_traits.imbue(__loc); }
1034 * @brief Gets the locale currently imbued in the regular expression
1039 { return _M_traits.getloc(); }
1043 * @brief Swaps the contents of two regular expression objects.
1045 * @param rhs Another regular expression object.
1048 swap(basic_regex& __rhs)
1050 std::swap(_M_flags, __rhs._M_flags);
1051 std::swap(_M_pattern, __rhs._M_pattern);
1052 std::swap(_M_mark_count, __rhs._M_mark_count);
1053 std::swap(_M_traits, __rhs._M_traits);
1058 * @brief Compiles a regular expression pattern into a NFA.
1059 * @todo Implement this function.
1065 string_type _M_pattern;
1066 unsigned int _M_mark_count;
1067 _Rx_traits _M_traits;
1070 /** @brief Standard regular expressions. */
1071 typedef basic_regex<char> regex;
1072 #ifdef _GLIBCXX_USE_WCHAR_T
1073 /** @brief Standard wide-character regular expressions. */
1074 typedef basic_regex<wchar_t> wregex;
1078 // [7.8.6] basic_regex swap
1080 * @brief Swaps the contents of two regular expression objects.
1081 * @param lhs First regular expression.
1082 * @param rhs Second regular expression.
1084 template<typename _Ch_type, typename _Rx_traits>
1086 swap(basic_regex<_Ch_type, _Rx_traits>& __lhs,
1087 basic_regex<_Ch_type, _Rx_traits>& __rhs)
1088 { __lhs.swap(__rhs); }
1091 // [7.9] Class template sub_match
1093 * A sequence of characters matched by a particular marked sub-expression.
1095 * An object of this class is essentially a pair of iterators marking a
1096 * matched subexpression within a regular expression pattern match. Such
1097 * objects can be converted to and compared with std::basic_string objects
1098 * of a similar base character type as the pattern matched by the regular
1101 * The iterators that make up the pair are the usual half-open interval
1102 * referencing the actual original pattern matched.
1104 template<typename _BiIter>
1105 class sub_match : public std::pair<_BiIter, _BiIter>
1108 typedef typename iterator_traits<_BiIter>::value_type value_type;
1109 typedef typename iterator_traits<_BiIter>::difference_type
1111 typedef _BiIter iterator;
1117 * Gets the length of the matching sequence.
1121 { return this->matched ? std::distance(this->first, this->second) : 0; }
1124 * @brief Gets the matching sequence as a string.
1126 * @returns the matching sequence as a string.
1128 * This is the implicit conversion operator. It is identical to the
1129 * str() member function except that it will want to pop up in
1130 * unexpected places and cause a great deal of confusion and cursing
1133 operator basic_string<value_type>() const
1135 return this->matched
1136 ? std::basic_string<value_type>(this->first, this->second)
1137 : std::basic_string<value_type>();
1141 * @brief Gets the matching sequence as a string.
1143 * @returns the matching sequence as a string.
1145 basic_string<value_type>
1148 return this->matched
1149 ? std::basic_string<value_type>(this->first, this->second)
1150 : std::basic_string<value_type>();
1154 * @brief Compares this and another matched sequence.
1156 * @param s Another matched sequence to compare to this one.
1158 * @retval <0 this matched sequence will collate before @p s.
1159 * @retval =0 this matched sequence is equivalent to @p s.
1160 * @retval <0 this matched sequence will collate after @p s.
1163 compare(const sub_match& __s) const
1164 { return this->str().compare(__s.str()); }
1167 * @brief Compares this sub_match to a string.
1169 * @param s A string to compare to this sub_match.
1171 * @retval <0 this matched sequence will collate before @p s.
1172 * @retval =0 this matched sequence is equivalent to @p s.
1173 * @retval <0 this matched sequence will collate after @p s.
1176 compare(const basic_string<value_type>& __s) const
1177 { return this->str().compare(__s); }
1180 * @brief Compares this sub_match to a C-style string.
1182 * @param s A C-style string to compare to this sub_match.
1184 * @retval <0 this matched sequence will collate before @p s.
1185 * @retval =0 this matched sequence is equivalent to @p s.
1186 * @retval <0 this matched sequence will collate after @p s.
1189 compare(const value_type* __s) const
1190 { return this->str().compare(__s); }
1194 /** @brief Standard regex submatch over a C-style null-terminated string. */
1195 typedef sub_match<const char*> csub_match;
1196 /** @brief Standard regex submatch over a standard string. */
1197 typedef sub_match<string::const_iterator> ssub_match;
1198 #ifdef _GLIBCXX_USE_WCHAR_T
1199 /** @brief Regex submatch over a C-style null-terminated wide string. */
1200 typedef sub_match<const wchar_t*> wcsub_match;
1201 /** @brief Regex submatch over a standard wide string. */
1202 typedef sub_match<wstring::const_iterator> wssub_match;
1205 // [7.9.2] sub_match non-member operators
1208 * @brief Tests the equivalence of two regular expression submatches.
1209 * @param lhs First regular expression submatch.
1210 * @param rhs Second regular expression submatch.
1211 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1213 template<typename _BiIter>
1215 operator==(const sub_match<_BiIter>& __lhs,
1216 const sub_match<_BiIter>& __rhs)
1217 { return __lhs.compare(__rhs) == 0; }
1220 * @brief Tests the inequivalence of two regular expression submatches.
1221 * @param lhs First regular expression submatch.
1222 * @param rhs Second regular expression submatch.
1223 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1225 template<typename _BiIter>
1227 operator!=(const sub_match<_BiIter>& __lhs,
1228 const sub_match<_BiIter>& __rhs)
1229 { return __lhs.compare(__rhs) != 0; }
1232 * @brief Tests the ordering of two regular expression submatches.
1233 * @param lhs First regular expression submatch.
1234 * @param rhs Second regular expression submatch.
1235 * @returns true if @a lhs precedes @a rhs, false otherwise.
1237 template<typename _BiIter>
1239 operator<(const sub_match<_BiIter>& __lhs,
1240 const sub_match<_BiIter>& __rhs)
1241 { return __lhs.compare(__rhs) < 0; }
1244 * @brief Tests the ordering of two regular expression submatches.
1245 * @param lhs First regular expression submatch.
1246 * @param rhs Second regular expression submatch.
1247 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1249 template<typename _BiIter>
1251 operator<=(const sub_match<_BiIter>& __lhs,
1252 const sub_match<_BiIter>& __rhs)
1253 { return __lhs.compare(__rhs) <= 0; }
1256 * @brief Tests the ordering of two regular expression submatches.
1257 * @param lhs First regular expression submatch.
1258 * @param rhs Second regular expression submatch.
1259 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1261 template<typename _BiIter>
1263 operator>=(const sub_match<_BiIter>& __lhs,
1264 const sub_match<_BiIter>& __rhs)
1265 { return __lhs.compare(__rhs) >= 0; }
1268 * @brief Tests the ordering of two regular expression submatches.
1269 * @param lhs First regular expression submatch.
1270 * @param rhs Second regular expression submatch.
1271 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1273 template<typename _BiIter>
1275 operator>(const sub_match<_BiIter>& __lhs,
1276 const sub_match<_BiIter>& __rhs)
1277 { return __lhs.compare(__rhs) > 0; }
1280 * @brief Tests the equivalence of a string and a regular expression
1282 * @param lhs A string.
1283 * @param rhs A regular expression submatch.
1284 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1286 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1288 operator==(const basic_string<
1289 typename iterator_traits<_Bi_iter>::value_type,
1290 _Ch_traits, _Ch_alloc>& __lhs,
1291 const sub_match<_Bi_iter>& __rhs)
1292 { return __lhs == __rhs.str(); }
1295 * @brief Tests the inequivalence of a string and a regular expression
1297 * @param lhs A string.
1298 * @param rhs A regular expression submatch.
1299 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1301 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1303 operator!=(const basic_string<
1304 typename iterator_traits<_Bi_iter>::value_type,
1305 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1306 { return __lhs != __rhs.str(); }
1309 * @brief Tests the ordering of a string and a regular expression submatch.
1310 * @param lhs A string.
1311 * @param rhs A regular expression submatch.
1312 * @returns true if @a lhs precedes @a rhs, false otherwise.
1314 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1316 operator<(const basic_string<
1317 typename iterator_traits<_Bi_iter>::value_type,
1318 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1319 { return __lhs < __rhs.str(); }
1322 * @brief Tests the ordering of a string and a regular expression submatch.
1323 * @param lhs A string.
1324 * @param rhs A regular expression submatch.
1325 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1327 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1329 operator>(const basic_string<
1330 typename iterator_traits<_Bi_iter>::value_type,
1331 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1332 { return __lhs > __rhs.str(); }
1335 * @brief Tests the ordering of a string and a regular expression submatch.
1336 * @param lhs A string.
1337 * @param rhs A regular expression submatch.
1338 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1340 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1342 operator>=(const basic_string<
1343 typename iterator_traits<_Bi_iter>::value_type,
1344 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1345 { return __lhs >= __rhs.str(); }
1348 * @brief Tests the ordering of a string and a regular expression submatch.
1349 * @param lhs A string.
1350 * @param rhs A regular expression submatch.
1351 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1353 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1355 operator<=(const basic_string<
1356 typename iterator_traits<_Bi_iter>::value_type,
1357 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1358 { return __lhs <= __rhs.str(); }
1361 * @brief Tests the equivalence of a regular expression submatch and a
1363 * @param lhs A regular expression submatch.
1364 * @param rhs A string.
1365 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1367 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1369 operator==(const sub_match<_Bi_iter>& __lhs,
1371 typename iterator_traits<_Bi_iter>::value_type,
1372 _Ch_traits, _Ch_alloc>& __rhs)
1373 { return __lhs.str() == __rhs; }
1376 * @brief Tests the inequivalence of a regular expression submatch and a
1378 * @param lhs A regular expression submatch.
1379 * @param rhs A string.
1380 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1382 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1384 operator!=(const sub_match<_Bi_iter>& __lhs,
1386 typename iterator_traits<_Bi_iter>::value_type,
1387 _Ch_traits, _Ch_alloc>& __rhs)
1388 { return __lhs.str() != __rhs; }
1391 * @brief Tests the ordering of a regular expression submatch and a string.
1392 * @param lhs A regular expression submatch.
1393 * @param rhs A string.
1394 * @returns true if @a lhs precedes @a rhs, false otherwise.
1396 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1398 operator<(const sub_match<_Bi_iter>& __lhs,
1400 typename iterator_traits<_Bi_iter>::value_type,
1401 _Ch_traits, _Ch_alloc>& __rhs)
1402 { return __lhs.str() < __rhs; }
1405 * @brief Tests the ordering of a regular expression submatch and a string.
1406 * @param lhs A regular expression submatch.
1407 * @param rhs A string.
1408 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1410 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1412 operator>(const sub_match<_Bi_iter>& __lhs,
1414 typename iterator_traits<_Bi_iter>::value_type,
1415 _Ch_traits, _Ch_alloc>& __rhs)
1416 { return __lhs.str() > __rhs; }
1419 * @brief Tests the ordering of a regular expression submatch and a string.
1420 * @param lhs A regular expression submatch.
1421 * @param rhs A string.
1422 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1424 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1426 operator>=(const sub_match<_Bi_iter>& __lhs,
1428 typename iterator_traits<_Bi_iter>::value_type,
1429 _Ch_traits, _Ch_alloc>& __rhs)
1430 { return __lhs.str() >= __rhs; }
1433 * @brief Tests the ordering of a regular expression submatch and a string.
1434 * @param lhs A regular expression submatch.
1435 * @param rhs A string.
1436 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1438 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1440 operator<=(const sub_match<_Bi_iter>& __lhs,
1442 typename iterator_traits<_Bi_iter>::value_type,
1443 _Ch_traits, _Ch_alloc>& __rhs)
1444 { return __lhs.str() <= __rhs; }
1447 * @brief Tests the equivalence of a C string and a regular expression
1449 * @param lhs A C string.
1450 * @param rhs A regular expression submatch.
1451 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1453 template<typename _Bi_iter>
1455 operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1456 const sub_match<_Bi_iter>& __rhs)
1457 { return __lhs == __rhs.str(); }
1460 * @brief Tests the inequivalence of an iterator value and a regular
1461 * expression submatch.
1462 * @param lhs A regular expression submatch.
1463 * @param rhs A string.
1464 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1466 template<typename _Bi_iter>
1468 operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1469 const sub_match<_Bi_iter>& __rhs)
1470 { return __lhs != __rhs.str(); }
1473 * @brief Tests the ordering of a string and a regular expression submatch.
1474 * @param lhs A string.
1475 * @param rhs A regular expression submatch.
1476 * @returns true if @a lhs precedes @a rhs, false otherwise.
1478 template<typename _Bi_iter>
1480 operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1481 const sub_match<_Bi_iter>& __rhs)
1482 { return __lhs < __rhs.str(); }
1485 * @brief Tests the ordering of a string and a regular expression submatch.
1486 * @param lhs A string.
1487 * @param rhs A regular expression submatch.
1488 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1490 template<typename _Bi_iter>
1492 operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1493 const sub_match<_Bi_iter>& __rhs)
1494 { return __lhs > __rhs.str(); }
1497 * @brief Tests the ordering of a string and a regular expression submatch.
1498 * @param lhs A string.
1499 * @param rhs A regular expression submatch.
1500 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1502 template<typename _Bi_iter>
1504 operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1505 const sub_match<_Bi_iter>& __rhs)
1506 { return __lhs >= __rhs.str(); }
1509 * @brief Tests the ordering of a string and a regular expression submatch.
1510 * @param lhs A string.
1511 * @param rhs A regular expression submatch.
1512 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1514 template<typename _Bi_iter>
1516 operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1517 const sub_match<_Bi_iter>& __rhs)
1518 { return __lhs <= __rhs.str(); }
1521 * @brief Tests the equivalence of a regular expression submatch and a
1523 * @param lhs A regular expression submatch.
1524 * @param rhs A pointer to a string?
1525 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1527 template<typename _Bi_iter>
1529 operator==(const sub_match<_Bi_iter>& __lhs,
1530 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1531 { return __lhs.str() == __rhs; }
1534 * @brief Tests the inequivalence of a regular expression submatch and a
1536 * @param lhs A regular expression submatch.
1537 * @param rhs A pointer to a string.
1538 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1540 template<typename _Bi_iter>
1542 operator!=(const sub_match<_Bi_iter>& __lhs,
1543 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1544 { return __lhs.str() != __rhs; }
1547 * @brief Tests the ordering of a regular expression submatch and a string.
1548 * @param lhs A regular expression submatch.
1549 * @param rhs A string.
1550 * @returns true if @a lhs precedes @a rhs, false otherwise.
1552 template<typename _Bi_iter>
1554 operator<(const sub_match<_Bi_iter>& __lhs,
1555 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1556 { return __lhs.str() < __rhs; }
1559 * @brief Tests the ordering of a regular expression submatch and a string.
1560 * @param lhs A regular expression submatch.
1561 * @param rhs A string.
1562 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1564 template<typename _Bi_iter>
1566 operator>(const sub_match<_Bi_iter>& __lhs,
1567 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1568 { return __lhs.str() > __rhs; }
1571 * @brief Tests the ordering of a regular expression submatch and a string.
1572 * @param lhs A regular expression submatch.
1573 * @param rhs A string.
1574 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1576 template<typename _Bi_iter>
1578 operator>=(const sub_match<_Bi_iter>& __lhs,
1579 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1580 { return __lhs.str() >= __rhs; }
1583 * @brief Tests the ordering of a regular expression submatch and a string.
1584 * @param lhs A regular expression submatch.
1585 * @param rhs A string.
1586 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1588 template<typename _Bi_iter>
1590 operator<=(const sub_match<_Bi_iter>& __lhs,
1591 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1592 { return __lhs.str() <= __rhs; }
1595 * @brief Tests the equivalence of a string and a regular expression
1597 * @param lhs A string.
1598 * @param rhs A regular expression submatch.
1599 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1601 template<typename _Bi_iter>
1603 operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1604 const sub_match<_Bi_iter>& __rhs)
1605 { return __lhs == __rhs.str(); }
1608 * @brief Tests the inequivalence of a string and a regular expression
1610 * @param lhs A string.
1611 * @param rhs A regular expression submatch.
1612 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1614 template<typename _Bi_iter>
1616 operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1617 const sub_match<_Bi_iter>& __rhs)
1618 { return __lhs != __rhs.str(); }
1621 * @brief Tests the ordering of a string and a regular expression submatch.
1622 * @param lhs A string.
1623 * @param rhs A regular expression submatch.
1624 * @returns true if @a lhs precedes @a rhs, false otherwise.
1626 template<typename _Bi_iter>
1628 operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1629 const sub_match<_Bi_iter>& __rhs)
1630 { return __lhs < __rhs.str(); }
1633 * @brief Tests the ordering of a string and a regular expression submatch.
1634 * @param lhs A string.
1635 * @param rhs A regular expression submatch.
1636 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1638 template<typename _Bi_iter>
1640 operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1641 const sub_match<_Bi_iter>& __rhs)
1642 { return __lhs > __rhs.str(); }
1645 * @brief Tests the ordering of a string and a regular expression submatch.
1646 * @param lhs A string.
1647 * @param rhs A regular expression submatch.
1648 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1650 template<typename _Bi_iter>
1652 operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1653 const sub_match<_Bi_iter>& __rhs)
1654 { return __lhs >= __rhs.str(); }
1657 * @brief Tests the ordering of a string and a regular expression submatch.
1658 * @param lhs A string.
1659 * @param rhs A regular expression submatch.
1660 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1662 template<typename _Bi_iter>
1664 operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1665 const sub_match<_Bi_iter>& __rhs)
1666 { return __lhs <= __rhs.str(); }
1669 * @brief Tests the equivalence of a regular expression submatch and a
1671 * @param lhs A regular expression submatch.
1672 * @param rhs A const string reference.
1673 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1675 template<typename _Bi_iter>
1677 operator==(const sub_match<_Bi_iter>& __lhs,
1678 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1679 { return __lhs.str() == __rhs; }
1682 * @brief Tests the inequivalence of a regular expression submatch and a
1684 * @param lhs A regular expression submatch.
1685 * @param rhs A const string reference.
1686 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1688 template<typename _Bi_iter>
1690 operator!=(const sub_match<_Bi_iter>& __lhs,
1691 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1692 { return __lhs.str() != __rhs; }
1695 * @brief Tests the ordering of a regular expression submatch and a string.
1696 * @param lhs A regular expression submatch.
1697 * @param rhs A const string reference.
1698 * @returns true if @a lhs precedes @a rhs, false otherwise.
1700 template<typename _Bi_iter>
1702 operator<(const sub_match<_Bi_iter>& __lhs,
1703 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1704 { return __lhs.str() < __rhs; }
1707 * @brief Tests the ordering of a regular expression submatch and a string.
1708 * @param lhs A regular expression submatch.
1709 * @param rhs A const string reference.
1710 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1712 template<typename _Bi_iter>
1714 operator>(const sub_match<_Bi_iter>& __lhs,
1715 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1716 { return __lhs.str() > __rhs; }
1719 * @brief Tests the ordering of a regular expression submatch and a string.
1720 * @param lhs A regular expression submatch.
1721 * @param rhs A const string reference.
1722 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1724 template<typename _Bi_iter>
1726 operator>=(const sub_match<_Bi_iter>& __lhs,
1727 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1728 { return __lhs.str() >= __rhs; }
1731 * @brief Tests the ordering of a regular expression submatch and a string.
1732 * @param lhs A regular expression submatch.
1733 * @param rhs A const string reference.
1734 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1736 template<typename _Bi_iter>
1738 operator<=(const sub_match<_Bi_iter>& __lhs,
1739 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1740 { return __lhs.str() <= __rhs; }
1743 * @brief Inserts a matched string into an output stream.
1745 * @param os The output stream.
1746 * @param m A submatch string.
1748 * @returns the output stream with the submatch string inserted.
1750 template<typename _Ch_type, typename _Ch_traits, typename _Bi_iter>
1752 basic_ostream<_Ch_type, _Ch_traits>&
1753 operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os,
1754 const sub_match<_Bi_iter>& __m)
1755 { return __os << __m.str(); }
1757 // [7.10] Class template match_results
1759 * @brief The results of a match or search operation.
1761 * A collection of character sequences representing the result of a regular
1762 * expression match. Storage for the collection is allocated and freed as
1763 * necessary by the member functions of class template match_results.
1765 * This class satisfies the Sequence requirements, with the exception that
1766 * only the operations defined for a const-qualified Sequence are supported.
1768 * The sub_match object stored at index 0 represents sub-expression 0, i.e.
1769 * the whole match. In this case the sub_match member matched is always true.
1770 * The sub_match object stored at index n denotes what matched the marked
1771 * sub-expression n within the matched expression. If the sub-expression n
1772 * participated in a regular expression match then the sub_match member
1773 * matched evaluates to true, and members first and second denote the range
1774 * of characters [first, second) which formed that match. Otherwise matched
1775 * is false, and members first and second point to the end of the sequence
1776 * that was searched.
1780 template<typename _Bi_iter,
1781 typename _Allocator = allocator<sub_match<_Bi_iter> > >
1783 : private std::vector<std::tr1::sub_match<_Bi_iter>, _Allocator>
1786 typedef std::vector<std::tr1::sub_match<_Bi_iter>, _Allocator>
1791 * @name 10.? Public Types
1794 typedef sub_match<_Bi_iter> value_type;
1795 typedef typename _Allocator::const_reference const_reference;
1796 typedef const_reference reference;
1797 typedef typename _Base_type::const_iterator const_iterator;
1798 typedef const_iterator iterator;
1799 typedef typename iterator_traits<_Bi_iter>::difference_type
1801 typedef typename _Allocator::size_type size_type;
1802 typedef _Allocator allocator_type;
1803 typedef typename iterator_traits<_Bi_iter>::value_type char_type;
1804 typedef basic_string<char_type> string_type;
1809 * @name 10.1 Construction, Copying, and Destruction
1814 * @brief Constructs a default %match_results container.
1815 * @post size() returns 0 and str() returns an empty string.
1818 match_results(const _Allocator& __a = _Allocator())
1819 : _Base_type(__a), _M_matched(false)
1823 * @brief Copy constructs a %match_results.
1825 match_results(const match_results& __rhs)
1826 : _Base_type(__rhs), _M_matched(__rhs._M_matched),
1827 _M_prefix(__rhs._M_prefix), _M_suffix(__rhs._M_suffix)
1831 * @brief Assigns rhs to *this.
1834 operator=(const match_results& __rhs)
1836 match_results __tmp(__rhs);
1842 * @brief Destroys a %match_results object.
1855 * @brief Gets the number of matches and submatches.
1857 * The number of matches for a given regular expression will be either 0
1858 * if there was no match or mark_count() + 1 if a match was successful.
1859 * Some matches may be empty.
1861 * @returns the number of matches found.
1865 { return _M_matched ? _Base_type::size() + 1 : 0; }
1869 using _Base_type::max_size;
1872 * @brief Indicates if the %match_results contains no results.
1873 * @retval true The %match_results object is empty.
1874 * @retval false The %match_results object is not empty.
1878 { return size() == 0; }
1883 * @name 10.3 Element Access
1888 * @brief Gets the length of the indicated submatch.
1889 * @param sub indicates the submatch.
1891 * This function returns the length of the indicated submatch, or the
1892 * length of the entire match if @p sub is zero (the default).
1895 length(size_type __sub = 0) const
1896 { return _M_matched ? this->str(__sub).length() : 0; }
1899 * @brief Gets the offset of the beginning of the indicated submatch.
1900 * @param sub indicates the submatch.
1902 * This function returns the offset from the beginning of the target
1903 * sequence to the beginning of the submatch, unless the value of @p sub
1904 * is zero (the default), in which case this function returns the offset
1905 * from the beginning of the target sequence to the beginning of the
1909 position(size_type __sub = 0) const
1911 return _M_matched ? std::distance(this->prefix().first,
1912 (*this)[__sub].first) : 0;
1916 * @brief Gets the match or submatch converted to a string type.
1917 * @param sub indicates the submatch.
1919 * This function gets the submatch (or match, if @p sub is zero) extracted
1920 * from the target range and converted to the associated string type.
1923 str(size_type __sub = 0) const
1924 { return _M_matched ? (*this)[__sub].str() : string_type(); }
1927 * @brief Gets a %sub_match reference for the match or submatch.
1928 * @param sub indicates the submatch.
1930 * This function gets a reference to the indicated submatch, or the entire
1931 * match if @p sub is zero.
1933 * If @p sub >= size() then this function returns a %sub_match with a
1934 * special value indicating no submatch.
1937 operator[](size_type __sub) const
1938 { return _Base_type::operator[](__sub); }
1941 * @brief Gets a %sub_match representing the match prefix.
1943 * This function gets a reference to a %sub_match object representing the
1944 * part of the target range between the start of the target range and the
1945 * start of the match.
1949 { return _M_prefix; }
1952 * @brief Gets a %sub_match representing the match suffix.
1954 * This function gets a reference to a %sub_match object representing the
1955 * part of the target range between the end of the match and the end of
1960 { return _M_suffix; }
1963 * @brief Gets an iterator to the start of the %sub_match collection.
1967 { return _Base_type::begin(); }
1969 #ifdef _GLIBCXX_INCLUDE_AS_CXX11
1971 * @brief Gets an iterator to the start of the %sub_match collection.
1975 { return _Base_type::begin(); }
1979 * @brief Gets an iterator to one-past-the-end of the collection.
1983 { return _Base_type::end(); }
1985 #ifdef _GLIBCXX_INCLUDE_AS_CXX11
1987 * @brief Gets an iterator to one-past-the-end of the collection.
1991 { return _Base_type::end(); }
1997 * @name 10.4 Formatting
1999 * These functions perform formatted substitution of the matched
2000 * character sequences into their target. The format specifiers
2001 * and escape sequences accepted by these functions are
2002 * determined by their @p flags parameter as documented above.
2007 * @todo Implement this function.
2009 template<typename _Out_iter>
2011 format(_Out_iter __out, const string_type& __fmt,
2012 regex_constants::match_flag_type __flags
2013 = regex_constants::format_default) const;
2016 * @todo Implement this function.
2019 format(const string_type& __fmt,
2020 regex_constants::match_flag_type __flags
2021 = regex_constants::format_default) const;
2026 * @name 10.5 Allocator
2031 * @brief Gets a copy of the allocator.
2034 //get_allocator() const;
2035 using _Base_type::get_allocator;
2045 * @brief Swaps the contents of two match_results.
2048 swap(match_results& __that)
2050 _Base_type::swap(__that);
2051 std::swap(_M_matched, __that._M_matched);
2052 std::swap(_M_prefix, __that._M_prefix);
2053 std::swap(_M_suffix, __that._M_suffix);
2059 value_type _M_prefix;
2060 value_type _M_suffix;
2063 typedef match_results<const char*> cmatch;
2064 typedef match_results<string::const_iterator> smatch;
2065 #ifdef _GLIBCXX_USE_WCHAR_T
2066 typedef match_results<const wchar_t*> wcmatch;
2067 typedef match_results<wstring::const_iterator> wsmatch;
2070 // match_results comparisons
2072 * @brief Compares two match_results for equality.
2073 * @returns true if the two objects refer to the same match,
2075 * @todo Implement this function.
2077 template<typename _Bi_iter, typename _Allocator>
2079 operator==(const match_results<_Bi_iter, _Allocator>& __m1,
2080 const match_results<_Bi_iter, _Allocator>& __m2);
2083 * @brief Compares two match_results for inequality.
2084 * @returns true if the two objects do not refer to the same match,
2087 template<typename _Bi_iter, class _Allocator>
2089 operator!=(const match_results<_Bi_iter, _Allocator>& __m1,
2090 const match_results<_Bi_iter, _Allocator>& __m2)
2091 { return !(__m1 == __m2); }
2093 // [7.10.6] match_results swap
2095 * @brief Swaps two match results.
2096 * @param lhs A match result.
2097 * @param rhs A match result.
2099 * The contents of the two match_results objects are swapped.
2101 template<typename _Bi_iter, typename _Allocator>
2103 swap(match_results<_Bi_iter, _Allocator>& __lhs,
2104 match_results<_Bi_iter, _Allocator>& __rhs)
2105 { __lhs.swap(__rhs); }
2107 // [7.11.2] Function template regex_match
2109 * @name Matching, Searching, and Replacing
2114 * @brief Determines if there is a match between the regular expression @p e
2115 * and all of the character sequence [first, last).
2117 * @param first Beginning of the character sequence to match.
2118 * @param last One-past-the-end of the character sequence to match.
2119 * @param m The match results.
2120 * @param re The regular expression.
2121 * @param flags Controls how the regular expression is matched.
2123 * @retval true A match exists.
2124 * @retval false Otherwise.
2126 * @throws an exception of type regex_error.
2128 * @todo Implement this function.
2130 template<typename _Bi_iter, typename _Allocator,
2131 typename _Ch_type, typename _Rx_traits>
2133 regex_match(_Bi_iter __first, _Bi_iter __last,
2134 match_results<_Bi_iter, _Allocator>& __m,
2135 const basic_regex<_Ch_type, _Rx_traits>& __re,
2136 regex_constants::match_flag_type __flags
2137 = regex_constants::match_default);
2140 * @brief Indicates if there is a match between the regular expression @p e
2141 * and all of the character sequence [first, last).
2143 * @param first Beginning of the character sequence to match.
2144 * @param last One-past-the-end of the character sequence to match.
2145 * @param re The regular expression.
2146 * @param flags Controls how the regular expression is matched.
2148 * @retval true A match exists.
2149 * @retval false Otherwise.
2151 * @throws an exception of type regex_error.
2153 template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
2155 regex_match(_Bi_iter __first, _Bi_iter __last,
2156 const basic_regex<_Ch_type, _Rx_traits>& __re,
2157 regex_constants::match_flag_type __flags
2158 = regex_constants::match_default)
2160 match_results<_Bi_iter> __what;
2161 return regex_match(__first, __last, __what, __re, __flags);
2165 * @brief Determines if there is a match between the regular expression @p e
2166 * and a C-style null-terminated string.
2168 * @param s The C-style null-terminated string to match.
2169 * @param m The match results.
2170 * @param re The regular expression.
2171 * @param f Controls how the regular expression is matched.
2173 * @retval true A match exists.
2174 * @retval false Otherwise.
2176 * @throws an exception of type regex_error.
2178 template<typename _Ch_type, typename _Allocator, typename _Rx_traits>
2180 regex_match(const _Ch_type* __s,
2181 match_results<const _Ch_type*, _Allocator>& __m,
2182 const basic_regex<_Ch_type, _Rx_traits>& __re,
2183 regex_constants::match_flag_type __f
2184 = regex_constants::match_default)
2185 { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); }
2188 * @brief Determines if there is a match between the regular expression @p e
2191 * @param s The string to match.
2192 * @param m The match results.
2193 * @param re The regular expression.
2194 * @param flags Controls how the regular expression is matched.
2196 * @retval true A match exists.
2197 * @retval false Otherwise.
2199 * @throws an exception of type regex_error.
2201 template<typename _Ch_traits, typename _Ch_alloc,
2202 typename _Allocator, typename _Ch_type, typename _Rx_traits>
2204 regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
2205 match_results<typename basic_string<_Ch_type,
2206 _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
2207 const basic_regex<_Ch_type, _Rx_traits>& __re,
2208 regex_constants::match_flag_type __flags
2209 = regex_constants::match_default)
2210 { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }
2213 * @brief Indicates if there is a match between the regular expression @p e
2214 * and a C-style null-terminated string.
2216 * @param s The C-style null-terminated string to match.
2217 * @param re The regular expression.
2218 * @param f Controls how the regular expression is matched.
2220 * @retval true A match exists.
2221 * @retval false Otherwise.
2223 * @throws an exception of type regex_error.
2225 template<typename _Ch_type, class _Rx_traits>
2227 regex_match(const _Ch_type* __s,
2228 const basic_regex<_Ch_type, _Rx_traits>& __re,
2229 regex_constants::match_flag_type __f
2230 = regex_constants::match_default)
2231 { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); }
2234 * @brief Indicates if there is a match between the regular expression @p e
2237 * @param s [IN] The string to match.
2238 * @param re [IN] The regular expression.
2239 * @param flags [IN] Controls how the regular expression is matched.
2241 * @retval true A match exists.
2242 * @retval false Otherwise.
2244 * @throws an exception of type regex_error.
2246 template<typename _Ch_traits, typename _Str_allocator,
2247 typename _Ch_type, typename _Rx_traits>
2249 regex_match(const basic_string<_Ch_type, _Ch_traits, _Str_allocator>& __s,
2250 const basic_regex<_Ch_type, _Rx_traits>& __re,
2251 regex_constants::match_flag_type __flags
2252 = regex_constants::match_default)
2253 { return regex_match(__s.begin(), __s.end(), __re, __flags); }
2255 // [7.11.3] Function template regex_search
2257 * Searches for a regular expression within a range.
2258 * @param first [IN] The start of the string to search.
2259 * @param last [IN] One-past-the-end of the string to search.
2260 * @param m [OUT] The match results.
2261 * @param re [IN] The regular expression to search for.
2262 * @param flags [IN] Search policy flags.
2263 * @retval true A match was found within the string.
2264 * @retval false No match was found within the string, the content of %m is
2267 * @throws an exception of type regex_error.
2269 * @todo Implement this function.
2271 template<typename _Bi_iter, typename _Allocator,
2272 typename _Ch_type, typename _Rx_traits>
2274 regex_search(_Bi_iter __first, _Bi_iter __last,
2275 match_results<_Bi_iter, _Allocator>& __m,
2276 const basic_regex<_Ch_type, _Rx_traits>& __re,
2277 regex_constants::match_flag_type __flags
2278 = regex_constants::match_default);
2281 * Searches for a regular expression within a range.
2282 * @param first [IN] The start of the string to search.
2283 * @param last [IN] One-past-the-end of the string to search.
2284 * @param re [IN] The regular expression to search for.
2285 * @param flags [IN] Search policy flags.
2286 * @retval true A match was found within the string.
2287 * @retval false No match was found within the string.
2290 * @throws an exception of type regex_error.
2292 template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
2294 regex_search(_Bi_iter __first, _Bi_iter __last,
2295 const basic_regex<_Ch_type, _Rx_traits>& __re,
2296 regex_constants::match_flag_type __flags
2297 = regex_constants::match_default)
2299 match_results<_Bi_iter> __what;
2300 return regex_search(__first, __last, __what, __re, __flags);
2304 * @brief Searches for a regular expression within a C-string.
2305 * @param s [IN] A C-string to search for the regex.
2306 * @param m [OUT] The set of regex matches.
2307 * @param e [IN] The regex to search for in @p s.
2308 * @param f [IN] The search flags.
2309 * @retval true A match was found within the string.
2310 * @retval false No match was found within the string, the content of %m is
2314 * @throws an exception of type regex_error.
2316 template<typename _Ch_type, class _Allocator, class _Rx_traits>
2318 regex_search(const _Ch_type* __s,
2319 match_results<const _Ch_type*, _Allocator>& __m,
2320 const basic_regex<_Ch_type, _Rx_traits>& __e,
2321 regex_constants::match_flag_type __f
2322 = regex_constants::match_default)
2323 { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
2326 * @brief Searches for a regular expression within a C-string.
2327 * @param s [IN] The C-string to search.
2328 * @param e [IN] The regular expression to search for.
2329 * @param f [IN] Search policy flags.
2330 * @retval true A match was found within the string.
2331 * @retval false No match was found within the string.
2334 * @throws an exception of type regex_error.
2336 template<typename _Ch_type, typename _Rx_traits>
2338 regex_search(const _Ch_type* __s,
2339 const basic_regex<_Ch_type, _Rx_traits>& __e,
2340 regex_constants::match_flag_type __f
2341 = regex_constants::match_default)
2342 { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); }
2345 * @brief Searches for a regular expression within a string.
2346 * @param s [IN] The string to search.
2347 * @param e [IN] The regular expression to search for.
2348 * @param flags [IN] Search policy flags.
2349 * @retval true A match was found within the string.
2350 * @retval false No match was found within the string.
2353 * @throws an exception of type regex_error.
2355 template<typename _Ch_traits, typename _String_allocator,
2356 typename _Ch_type, typename _Rx_traits>
2358 regex_search(const basic_string<_Ch_type, _Ch_traits,
2359 _String_allocator>& __s,
2360 const basic_regex<_Ch_type, _Rx_traits>& __e,
2361 regex_constants::match_flag_type __flags
2362 = regex_constants::match_default)
2363 { return regex_search(__s.begin(), __s.end(), __e, __flags); }
2366 * @brief Searches for a regular expression within a string.
2367 * @param s [IN] A C++ string to search for the regex.
2368 * @param m [OUT] The set of regex matches.
2369 * @param e [IN] The regex to search for in @p s.
2370 * @param f [IN] The search flags.
2371 * @retval true A match was found within the string.
2372 * @retval false No match was found within the string, the content of %m is
2375 * @throws an exception of type regex_error.
2377 template<typename _Ch_traits, typename _Ch_alloc,
2378 typename _Allocator, typename _Ch_type,
2379 typename _Rx_traits>
2381 regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
2382 match_results<typename basic_string<_Ch_type,
2383 _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
2384 const basic_regex<_Ch_type, _Rx_traits>& __e,
2385 regex_constants::match_flag_type __f
2386 = regex_constants::match_default)
2387 { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
2389 // tr1 [7.11.4] std [28.11.4] Function template regex_replace
2400 * @throws an exception of type regex_error.
2402 * @todo Implement this function.
2404 template<typename _Out_iter, typename _Bi_iter,
2405 typename _Rx_traits, typename _Ch_type>
2407 regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
2408 const basic_regex<_Ch_type, _Rx_traits>& __e,
2409 const basic_string<_Ch_type>& __fmt,
2410 regex_constants::match_flag_type __flags
2411 = regex_constants::match_default);
2420 * @returns a copy of string @p s with replacements.
2422 * @throws an exception of type regex_error.
2424 template<typename _Rx_traits, typename _Ch_type>
2425 inline basic_string<_Ch_type>
2426 regex_replace(const basic_string<_Ch_type>& __s,
2427 const basic_regex<_Ch_type, _Rx_traits>& __e,
2428 const basic_string<_Ch_type>& __fmt,
2429 regex_constants::match_flag_type __flags
2430 = regex_constants::match_default)
2432 std::string __result;
2433 regex_replace(std::back_inserter(__result),
2434 __s.begin(), __s.end(), __e, __fmt, __flags);
2440 // tr1 [7.12.1] std [28.12] Class template regex_iterator
2442 * An iterator adaptor that will provide repeated calls of regex_search over
2443 * a range until no more matches remain.
2445 template<typename _Bi_iter,
2446 typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2447 typename _Rx_traits = regex_traits<_Ch_type> >
2448 class regex_iterator
2451 typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
2452 typedef match_results<_Bi_iter> value_type;
2453 typedef std::ptrdiff_t difference_type;
2454 typedef const value_type* pointer;
2455 typedef const value_type& reference;
2456 typedef std::forward_iterator_tag iterator_category;
2460 * @brief Provides a singular iterator, useful for indicating
2461 * one-past-the-end of a range.
2462 * @todo Implement this function.
2468 * Constructs a %regex_iterator...
2469 * @param a [IN] The start of a text range to search.
2470 * @param b [IN] One-past-the-end of the text range to search.
2471 * @param re [IN] The regular expression to match.
2472 * @param m [IN] Policy flags for match rules.
2473 * @todo Implement this function.
2476 regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2477 regex_constants::match_flag_type __m
2478 = regex_constants::match_default);
2481 * Copy constructs a %regex_iterator.
2482 * @todo Implement this function.
2485 regex_iterator(const regex_iterator& __rhs);
2488 * @todo Implement this function.
2492 operator=(const regex_iterator& __rhs);
2495 * @todo Implement this function.
2499 operator==(const regex_iterator& __rhs);
2502 * @todo Implement this function.
2506 operator!=(const regex_iterator& __rhs);
2509 * @todo Implement this function.
2516 * @todo Implement this function.
2523 * @todo Implement this function.
2530 * @todo Implement this function.
2537 // these members are shown for exposition only:
2540 const regex_type* pregex;
2541 regex_constants::match_flag_type flags;
2542 match_results<_Bi_iter> match;
2545 typedef regex_iterator<const char*> cregex_iterator;
2546 typedef regex_iterator<string::const_iterator> sregex_iterator;
2547 #ifdef _GLIBCXX_USE_WCHAR_T
2548 typedef regex_iterator<const wchar_t*> wcregex_iterator;
2549 typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
2552 // [7.12.2] Class template regex_token_iterator
2554 * Iterates over submatches in a range (or @a splits a text string).
2556 * The purpose of this iterator is to enumerate all, or all specified,
2557 * matches of a regular expression within a text range. The dereferenced
2558 * value of an iterator of this class is a std::tr1::sub_match object.
2560 template<typename _Bi_iter,
2561 typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2562 typename _Rx_traits = regex_traits<_Ch_type> >
2563 class regex_token_iterator
2566 typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
2567 typedef sub_match<_Bi_iter> value_type;
2568 typedef std::ptrdiff_t difference_type;
2569 typedef const value_type* pointer;
2570 typedef const value_type& reference;
2571 typedef std::forward_iterator_tag iterator_category;
2575 * @brief Default constructs a %regex_token_iterator.
2576 * @todo Implement this function.
2578 * A default-constructed %regex_token_iterator is a singular iterator
2579 * that will compare equal to the one-past-the-end value for any
2580 * iterator of the same type.
2582 regex_token_iterator();
2585 * Constructs a %regex_token_iterator...
2586 * @param a [IN] The start of the text to search.
2587 * @param b [IN] One-past-the-end of the text to search.
2588 * @param re [IN] The regular expression to search for.
2589 * @param submatch [IN] Which submatch to return. There are some
2590 * special values for this parameter:
2591 * - -1 each enumerated subexpression does NOT
2592 * match the regular expression (aka field
2594 * - 0 the entire string matching the
2595 * subexpression is returned for each match
2597 * - >0 enumerates only the indicated
2598 * subexpression from a 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, const regex_type& __re,
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 regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2622 const regex_type& __re,
2623 const std::vector<int>& __submatches,
2624 regex_constants::match_flag_type __m
2625 = regex_constants::match_default);
2628 * Constructs a %regex_token_iterator...
2629 * @param a [IN] The start of the text to search.
2630 * @param b [IN] One-past-the-end of the text to search.
2631 * @param re [IN] The regular expression to search for.
2632 * @param submatches [IN] A list of subexpressions to return for each
2633 * regular expression match within the text.
2634 * @param m [IN] Policy flags for match rules.
2636 * @todo Implement this function.
2639 template<std::size_t _Nm>
2640 regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2641 const regex_type& __re,
2642 const int (&__submatches)[_Nm],
2643 regex_constants::match_flag_type __m
2644 = regex_constants::match_default);
2647 * @brief Copy constructs a %regex_token_iterator.
2648 * @param rhs [IN] A %regex_token_iterator to copy.
2649 * @todo Implement this function.
2651 regex_token_iterator(const regex_token_iterator& __rhs);
2654 * @brief Assigns a %regex_token_iterator to another.
2655 * @param rhs [IN] A %regex_token_iterator to copy.
2656 * @todo Implement this function.
2658 regex_token_iterator&
2659 operator=(const regex_token_iterator& __rhs);
2662 * @brief Compares a %regex_token_iterator to another for equality.
2663 * @todo Implement this function.
2666 operator==(const regex_token_iterator& __rhs);
2669 * @brief Compares a %regex_token_iterator to another for inequality.
2670 * @todo Implement this function.
2673 operator!=(const regex_token_iterator& __rhs);
2676 * @brief Dereferences a %regex_token_iterator.
2677 * @todo Implement this function.
2683 * @brief Selects a %regex_token_iterator member.
2684 * @todo Implement this function.
2690 * @brief Increments a %regex_token_iterator.
2691 * @todo Implement this function.
2693 regex_token_iterator&
2697 * @brief Postincrements a %regex_token_iterator.
2698 * @todo Implement this function.
2700 regex_token_iterator
2703 private: // data members for exposition only:
2704 typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> position_iterator;
2706 position_iterator __position;
2707 const value_type* __result;
2708 value_type __suffix;
2710 std::vector<int> __subs;
2713 /** @brief Token iterator for C-style NULL-terminated strings. */
2714 typedef regex_token_iterator<const char*> cregex_token_iterator;
2715 /** @brief Token iterator for standard strings. */
2716 typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
2717 #ifdef _GLIBCXX_USE_WCHAR_T
2718 /** @brief Token iterator for C-style NULL-terminated wide strings. */
2719 typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
2720 /** @brief Token iterator for standard wide-character strings. */
2721 typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
2726 _GLIBCXX_END_NAMESPACE_VERSION
2730 #endif // _GLIBCXX_TR1_REGEX