1 // class template regex -*- C++ -*-
3 // Copyright (C) 2007-2023 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
36 #include <bits/requires_hosted.h> // TR1
48 namespace std _GLIBCXX_VISIBILITY(default)
50 _GLIBCXX_BEGIN_NAMESPACE_VERSION
55 * @defgroup tr1_regex Regular Expressions
56 * A facility for performing regular expression pattern matching.
60 /** @namespace std::regex_constants
61 * @brief ISO C++ 0x entities sub namespace for regex.
63 namespace regex_constants
66 * @name 5.1 Regular Expression Syntax Options
85 * @brief This is a bitmask type indicating how to interpret the regex.
87 * The @c syntax_option_type is implementation defined but it is valid to
88 * perform bitwise operations on these values and expect the right thing to
91 * A valid value of type syntax_option_type shall have exactly one of the
92 * elements @c ECMAScript, @c basic, @c extended, @c awk, @c grep, @c egrep
95 typedef unsigned int syntax_option_type;
98 * Specifies that the matching of regular expressions against a character
99 * sequence shall be performed without regard to case.
101 static const syntax_option_type icase = 1 << _S_icase;
104 * Specifies that when a regular expression is matched against a character
105 * container sequence, no sub-expression matches are to be stored in the
106 * supplied match_results structure.
108 static const syntax_option_type nosubs = 1 << _S_nosubs;
111 * Specifies that the regular expression engine should pay more attention to
112 * the speed with which regular expressions are matched, and less to the
113 * speed with which regular expression objects are constructed. Otherwise
114 * it has no detectable effect on the program output.
116 static const syntax_option_type optimize = 1 << _S_optimize;
119 * Specifies that character ranges of the form [a-b] should be locale
122 static const syntax_option_type collate = 1 << _S_collate;
125 * Specifies that the grammar recognized by the regular expression engine is
126 * that used by ECMAScript in ECMA-262 [Ecma International, ECMAScript
127 * Language Specification, Standard Ecma-262, third edition, 1999], as
128 * modified in tr1 section [7.13]. This grammar is similar to that defined
129 * in the PERL scripting language but extended with elements found in the
130 * POSIX regular expression grammar.
132 static const syntax_option_type ECMAScript = 1 << _S_ECMAScript;
135 * Specifies that the grammar recognized by the regular expression engine is
136 * that used by POSIX basic regular expressions in IEEE Std 1003.1-2001,
137 * Portable Operating System Interface (POSIX), Base Definitions and
138 * Headers, Section 9, Regular Expressions [IEEE, Information Technology --
139 * Portable Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
141 static const syntax_option_type basic = 1 << _S_basic;
144 * Specifies that the grammar recognized by the regular expression engine is
145 * that used by POSIX extended regular expressions in IEEE Std 1003.1-2001,
146 * Portable Operating System Interface (POSIX), Base Definitions and Headers,
147 * Section 9, Regular Expressions.
149 static const syntax_option_type extended = 1 << _S_extended;
152 * Specifies that the grammar recognized by the regular expression engine is
153 * that used by POSIX utility awk in IEEE Std 1003.1-2001. This option is
154 * identical to syntax_option_type extended, except that C-style escape
155 * sequences are supported. These sequences are:
156 * \\\\, \\a, \\b, \\f,
157 * \\n, \\r, \\t , \\v,
158 * \\', ', and \\ddd
159 * (where ddd is one, two, or three octal digits).
161 static const syntax_option_type awk = 1 << _S_awk;
164 * Specifies that the grammar recognized by the regular expression engine is
165 * that used by POSIX utility grep in IEEE Std 1003.1-2001. This option is
166 * identical to syntax_option_type basic, except that newlines are treated
169 static const syntax_option_type grep = 1 << _S_grep;
172 * Specifies that the grammar recognized by the regular expression engine is
173 * that used by POSIX utility grep when given the -E option in
174 * IEEE Std 1003.1-2001. This option is identical to syntax_option_type
175 * extended, except that newlines are treated as whitespace.
177 static const syntax_option_type egrep = 1 << _S_egrep;
182 * @name 5.2 Matching Rules
184 * Matching a regular expression against a sequence of characters [first,
185 * last) proceeds according to the rules of the grammar specified for the
186 * regular expression object, modified according to the effects listed
187 * below for any bitmask elements set.
209 * @brief This is a bitmask type indicating regex matching rules.
211 * The @c match_flag_type is implementation defined but it is valid to
212 * perform bitwise operations on these values and expect the right thing to
215 typedef std::bitset<_S_match_flag_last> match_flag_type;
218 * The default matching rules.
220 static const match_flag_type match_default = 0;
223 * The first character in the sequence [first, last) is treated as though it
224 * is not at the beginning of a line, so the character (^) in the regular
225 * expression shall not match [first, first).
227 static const match_flag_type match_not_bol = 1 << _S_not_bol;
230 * The last character in the sequence [first, last) is treated as though it
231 * is not at the end of a line, so the character ($) in the regular
232 * expression shall not match [last, last).
234 static const match_flag_type match_not_eol = 1 << _S_not_eol;
237 * The expression \\b is not matched against the sub-sequence
240 static const match_flag_type match_not_bow = 1 << _S_not_bow;
243 * The expression \\b should not be matched against the sub-sequence
246 static const match_flag_type match_not_eow = 1 << _S_not_eow;
249 * If more than one match is possible then any match is an acceptable
252 static const match_flag_type match_any = 1 << _S_any;
255 * The expression does not match an empty sequence.
257 static const match_flag_type match_not_null = 1 << _S_not_null;
260 * The expression only matches a sub-sequence that begins at first .
262 static const match_flag_type match_continuous = 1 << _S_continuous;
265 * --first is a valid iterator position. When this flag is set then the
266 * flags match_not_bol and match_not_bow are ignored by the regular
267 * expression algorithms 7.11 and iterators 7.12.
269 static const match_flag_type match_prev_avail = 1 << _S_prev_avail;
272 * When a regular expression match is to be replaced by a new string, the
273 * new string is constructed using the rules used by the ECMAScript replace
274 * function in ECMA- 262 [Ecma International, ECMAScript Language
275 * Specification, Standard Ecma-262, third edition, 1999], part 15.5.4.11
276 * String.prototype.replace. In addition, during search and replace
277 * operations all non-overlapping occurrences of the regular expression
278 * are located and replaced, and sections of the input that did not match
279 * the expression are copied unchanged to the output string.
281 * Format strings (from ECMA-262 [15.5.4.11]):
282 * @li $$ The dollar-sign itself ($)
283 * @li $& The matched substring.
284 * @li $` The portion of @a string that precedes the matched substring.
285 * This would be match_results::prefix().
286 * @li $' The portion of @a string that follows the matched substring.
287 * This would be match_results::suffix().
288 * @li $n The nth capture, where n is in [1,9] and $n is not followed by a
289 * decimal digit. If n <= match_results::size() and the nth capture
290 * is undefined, use the empty string instead. If n >
291 * match_results::size(), the result is implementation-defined.
292 * @li $nn The nnth capture, where nn is a two-digit decimal number on
293 * [01, 99]. If nn <= match_results::size() and the nth capture is
294 * undefined, use the empty string instead. If
295 * nn > match_results::size(), the result is implementation-defined.
297 static const match_flag_type format_default = 0;
300 * When a regular expression match is to be replaced by a new string, the
301 * new string is constructed using the rules used by the POSIX sed utility
302 * in IEEE Std 1003.1- 2001 [IEEE, Information Technology -- Portable
303 * Operating System Interface (POSIX), IEEE Standard 1003.1-2001].
305 static const match_flag_type format_sed = 1 << _S_sed;
308 * During a search and replace operation, sections of the character
309 * container sequence being searched that do not match the regular
310 * expression shall not be copied to the output string.
312 static const match_flag_type format_no_copy = 1 << _S_no_copy;
315 * When specified during a search and replace operation, only the first
316 * occurrence of the regular expression shall be replaced.
318 static const match_flag_type format_first_only = 1 << _S_first_only;
323 * @name 5.3 Error Types
345 /** The expression contained an invalid collating element name. */
346 static const error_type error_collate(_S_error_collate);
348 /** The expression contained an invalid character class name. */
349 static const error_type error_ctype(_S_error_ctype);
352 * The expression contained an invalid escaped character, or a trailing
355 static const error_type error_escape(_S_error_escape);
357 /** The expression contained an invalid back reference. */
358 static const error_type error_backref(_S_error_backref);
360 /** The expression contained mismatched [ and ]. */
361 static const error_type error_brack(_S_error_brack);
363 /** The expression contained mismatched ( and ). */
364 static const error_type error_paren(_S_error_paren);
366 /** The expression contained mismatched { and } */
367 static const error_type error_brace(_S_error_brace);
369 /** The expression contained an invalid range in a {} expression. */
370 static const error_type error_badbrace(_S_error_badbrace);
373 * The expression contained an invalid character range,
374 * such as [b-a] in most encodings.
376 static const error_type error_range(_S_error_range);
379 * There was insufficient memory to convert the expression into a
380 * finite state machine.
382 static const error_type error_space(_S_error_space);
385 * One of <em>*?+{</em> was not preceded by a valid regular expression.
387 static const error_type error_badrepeat(_S_error_badrepeat);
390 * The complexity of an attempted match against a regular expression
391 * exceeded a pre-set level.
393 static const error_type error_complexity(_S_error_complexity);
396 * There was insufficient memory to determine whether the
397 * regular expression could match the specified character sequence.
399 static const error_type error_stack(_S_error_stack);
404 // [7.8] Class regex_error
406 * @brief A regular expression exception class.
407 * @ingroup exceptions
409 * The regular expression library throws objects of this class on error.
412 : public std::runtime_error
416 * @brief Constructs a regex_error object.
418 * @param ecode the regex error code.
421 regex_error(regex_constants::error_type __ecode)
422 : std::runtime_error("regex_error"), _M_code(__ecode)
426 * @brief Gets the regex error code.
428 * @returns the regex error code.
430 regex_constants::error_type
435 regex_constants::error_type _M_code;
438 // [7.7] Class regex_traits
440 * @brief Describes aspects of a regular expression.
442 * A regular expression traits class that satisfies the requirements of tr1
445 * The class %regex is parameterized around a set of related types and
446 * functions used to complete the definition of its semantics. This class
447 * satisfies the requirements of such a traits class.
449 template<typename _Ch_type>
453 typedef _Ch_type char_type;
454 typedef std::basic_string<char_type> string_type;
455 typedef std::locale locale_type;
456 typedef std::ctype_base::mask char_class_type;
460 * @brief Constructs a default traits object.
466 * @brief Gives the length of a C-style string starting at @p __p.
468 * @param __p a pointer to the start of a character sequence.
470 * @returns the number of characters between @p *__p and the first
471 * default-initialized value of type @p char_type. In other words, uses
472 * the C-string algorithm for determining the length of a sequence of
476 length(const char_type* __p)
477 { return string_type::traits_type::length(__p); }
480 * @brief Performs the identity translation.
482 * @param c A character to the locale-specific character set.
487 translate(char_type __c) const
491 * @brief Translates a character into a case-insensitive equivalent.
493 * @param c A character to the locale-specific character set.
495 * @returns the locale-specific lower-case equivalent of c.
496 * @throws std::bad_cast if the imbued locale does not support the ctype
500 translate_nocase(char_type __c) const
503 using std::use_facet;
504 return use_facet<ctype<char_type> >(_M_locale).tolower(__c);
508 * @brief Gets a sort key for a character sequence.
510 * @param first beginning of the character sequence.
511 * @param last one-past-the-end of the character sequence.
513 * Returns a sort key for the character sequence designated by the
514 * iterator range [F1, F2) such that if the character sequence [G1, G2)
515 * sorts before the character sequence [H1, H2) then
516 * v.transform(G1, G2) < v.transform(H1, H2).
518 * What this really does is provide a more efficient way to compare a
519 * string to multiple other strings in locales with fancy collation
520 * rules and equivalence classes.
522 * @returns a locale-specific sort key equivalent to the input range.
524 * @throws std::bad_cast if the current locale does not have a collate
527 template<typename _Fwd_iter>
529 transform(_Fwd_iter __first, _Fwd_iter __last) const
532 using std::use_facet;
533 const collate<_Ch_type>& __c(use_facet<
534 collate<_Ch_type> >(_M_locale));
535 string_type __s(__first, __last);
536 return __c.transform(__s.data(), __s.data() + __s.size());
542 * @param first beginning of the character sequence.
543 * @param last one-past-the-end of the character sequence.
545 * Effects: if typeid(use_facet<collate<_Ch_type> >) ==
546 * typeid(collate_byname<_Ch_type>) and the form of the sort key
547 * returned by collate_byname<_Ch_type>::transform(first, last) is known
548 * and can be converted into a primary sort key then returns that key,
549 * otherwise returns an empty string. WTF??
551 * @todo Implement this function.
553 template<typename _Fwd_iter>
555 transform_primary(_Fwd_iter __first, _Fwd_iter __last) const;
558 * @brief Gets a collation element by name.
560 * @param first beginning of the collation element name.
561 * @param last one-past-the-end of the collation element name.
563 * @returns a sequence of one or more characters that represents the
564 * collating element consisting of the character sequence designated by
565 * the iterator range [first, last). Returns an empty string if the
566 * character sequence is not a valid collating element.
568 * @todo Implement this function.
570 template<typename _Fwd_iter>
572 lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const;
575 * @brief Maps one or more characters to a named character
578 * @param first beginning of the character sequence.
579 * @param last one-past-the-end of the character sequence.
581 * @returns an unspecified value that represents the character
582 * classification named by the character sequence designated by the
583 * iterator range [first, last). The value returned shall be independent
584 * of the case of the characters in the character sequence. If the name
585 * is not recognized then returns a value that compares equal to 0.
587 * At least the following names (or their wide-character equivalent) are
605 * @todo Implement this function.
607 template<typename _Fwd_iter>
609 lookup_classname(_Fwd_iter __first, _Fwd_iter __last) const;
612 * @brief Determines if @p c is a member of an identified class.
614 * @param c a character.
615 * @param f a class type (as returned from lookup_classname).
617 * @returns true if the character @p c is a member of the classification
618 * represented by @p f, false otherwise.
620 * @throws std::bad_cast if the current locale does not have a ctype
624 isctype(_Ch_type __c, char_class_type __f) const;
627 * @brief Converts a digit to an int.
629 * @param ch a character representing a digit.
630 * @param radix the radix if the numeric conversion (limited to 8, 10,
633 * @returns the value represented by the digit ch in base radix if the
634 * character ch is a valid digit in base radix; otherwise returns -1.
637 value(_Ch_type __ch, int __radix) const;
640 * @brief Imbues the regex_traits object with a copy of a new locale.
642 * @param loc A locale.
644 * @returns a copy of the previous locale in use by the regex_traits
647 * @note Calling imbue with a different locale than the one currently in
648 * use invalidates all cached data held by *this.
651 imbue(locale_type __loc)
653 std::swap(_M_locale, __loc);
658 * @brief Gets a copy of the current locale in use by the regex_traits
663 { return _M_locale; }
666 locale_type _M_locale;
669 template<typename _Ch_type>
670 bool regex_traits<_Ch_type>::
671 isctype(_Ch_type __c, char_class_type __f) const
674 using std::use_facet;
675 const ctype<_Ch_type>& __ctype(use_facet<
676 ctype<_Ch_type> >(_M_locale));
678 if (__ctype.is(__c, __f))
681 // special case of underscore in [[:w:]]
682 if (__c == __ctype.widen('_'))
684 const char* const __wb[] = "w";
685 char_class_type __wt = this->lookup_classname(__wb,
686 __wb + sizeof(__wb));
691 // special case of [[:space:]] in [[:blank:]]
692 if (__c == __ctype.isspace(__c))
694 const char* const __bb[] = "blank";
695 char_class_type __bt = this->lookup_classname(__bb,
696 __bb + sizeof(__bb));
704 template<typename _Ch_type>
705 int regex_traits<_Ch_type>::
706 value(_Ch_type __ch, int __radix) const
708 std::basic_istringstream<_Ch_type> __is(string_type(1, __ch));
712 else if (__radix == 16)
715 return __is.fail() ? -1 : __v;
718 // [7.8] Class basic_regex
720 * Objects of specializations of this class represent regular expressions
721 * constructed from sequences of character type @p _Ch_type.
723 * Storage for the regular expression is allocated and deallocated as
724 * necessary by the member functions of this class.
726 template<typename _Ch_type, typename _Rx_traits = regex_traits<_Ch_type> >
731 typedef _Ch_type value_type;
732 typedef regex_constants::syntax_option_type flag_type;
733 typedef typename _Rx_traits::locale_type locale_type;
734 typedef typename _Rx_traits::string_type string_type;
738 * tr1 [7.8.1] std [28.8.1]
741 static const regex_constants::syntax_option_type icase
742 = regex_constants::icase;
743 static const regex_constants::syntax_option_type nosubs
744 = regex_constants::nosubs;
745 static const regex_constants::syntax_option_type optimize
746 = regex_constants::optimize;
747 static const regex_constants::syntax_option_type collate
748 = regex_constants::collate;
749 static const regex_constants::syntax_option_type ECMAScript
750 = regex_constants::ECMAScript;
751 static const regex_constants::syntax_option_type basic
752 = regex_constants::basic;
753 static const regex_constants::syntax_option_type extended
754 = regex_constants::extended;
755 static const regex_constants::syntax_option_type awk
756 = regex_constants::awk;
757 static const regex_constants::syntax_option_type grep
758 = regex_constants::grep;
759 static const regex_constants::syntax_option_type egrep
760 = regex_constants::egrep;
763 // [7.8.2] construct/copy/destroy
765 * Constructs a basic regular expression that does not match any
766 * character sequence.
769 : _M_flags(regex_constants::ECMAScript), _M_pattern(), _M_mark_count(0)
773 * @brief Constructs a basic regular expression from the sequence
774 * [p, p + char_traits<_Ch_type>::length(p)) interpreted according to the
777 * @param p A pointer to the start of a C-style null-terminated string
778 * containing a regular expression.
779 * @param f Flags indicating the syntax rules and options.
781 * @throws regex_error if @p p is not a valid regular expression.
784 basic_regex(const _Ch_type* __p,
785 flag_type __f = regex_constants::ECMAScript)
786 : _M_flags(__f), _M_pattern(__p), _M_mark_count(0)
790 * @brief Constructs a basic regular expression from the sequence
791 * [p, p + len) interpreted according to the flags in @p f.
793 * @param p A pointer to the start of a string containing a regular
795 * @param len The length of the string containing the regular expression.
796 * @param f Flags indicating the syntax rules and options.
798 * @throws regex_error if @p p is not a valid regular expression.
800 basic_regex(const _Ch_type* __p, std::size_t __len, flag_type __f)
801 : _M_flags(__f) , _M_pattern(__p, __len), _M_mark_count(0)
805 * @brief Copy-constructs a basic regular expression.
807 * @param rhs A @p regex object.
809 basic_regex(const basic_regex& __rhs)
810 : _M_flags(__rhs._M_flags), _M_pattern(__rhs._M_pattern),
811 _M_mark_count(__rhs._M_mark_count)
815 * @brief Constructs a basic regular expression from the string
816 * @p s interpreted according to the flags in @p f.
818 * @param s A string containing a regular expression.
819 * @param f Flags indicating the syntax rules and options.
821 * @throws regex_error if @p s is not a valid regular expression.
823 template<typename _Ch_traits, typename _Ch_alloc>
825 basic_regex(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
826 flag_type __f = regex_constants::ECMAScript)
827 : _M_flags(__f), _M_pattern(__s.begin(), __s.end()), _M_mark_count(0)
831 * @brief Constructs a basic regular expression from the range
832 * [first, last) interpreted according to the flags in @p f.
834 * @param first The start of a range containing a valid regular
836 * @param last The end of a range containing a valid regular
838 * @param f The format flags of the regular expression.
840 * @throws regex_error if @p [first, last) is not a valid regular
843 template<typename _InputIterator>
844 basic_regex(_InputIterator __first, _InputIterator __last,
845 flag_type __f = regex_constants::ECMAScript)
846 : _M_flags(__f), _M_pattern(__first, __last), _M_mark_count(0)
849 #ifdef _GLIBCXX_INCLUDE_AS_CXX11
851 * @brief Constructs a basic regular expression from an initializer list.
853 * @param l The initializer list.
854 * @param f The format flags of the regular expression.
856 * @throws regex_error if @p l is not a valid regular expression.
858 basic_regex(initializer_list<_Ch_type> __l,
859 flag_type __f = regex_constants::ECMAScript)
860 : _M_flags(__f), _M_pattern(__l.begin(), __l.end()), _M_mark_count(0)
865 * @brief Destroys a basic regular expression.
871 * @brief Assigns one regular expression to another.
874 operator=(const basic_regex& __rhs)
875 { return this->assign(__rhs); }
878 * @brief Replaces a regular expression with a new one constructed from
879 * a C-style null-terminated string.
881 * @param A pointer to the start of a null-terminated C-style string
882 * containing a regular expression.
885 operator=(const _Ch_type* __p)
886 { return this->assign(__p, flags()); }
889 * @brief Replaces a regular expression with a new one constructed from
892 * @param A pointer to a string containing a regular expression.
894 template<typename _Ch_typeraits, typename _Allocator>
896 operator=(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s)
897 { return this->assign(__s, flags()); }
901 * @brief the real assignment operator.
903 * @param that Another regular expression object.
906 assign(const basic_regex& __that)
908 basic_regex __tmp(__that);
914 * @brief Assigns a new regular expression to a regex object from a
915 * C-style null-terminated string containing a regular expression
918 * @param p A pointer to a C-style null-terminated string containing
919 * a regular expression pattern.
920 * @param flags Syntax option flags.
922 * @throws regex_error if p does not contain a valid regular expression
923 * pattern interpreted according to @p flags. If regex_error is thrown,
924 * *this remains unchanged.
927 assign(const _Ch_type* __p,
928 flag_type __flags = regex_constants::ECMAScript)
929 { return this->assign(string_type(__p), __flags); }
932 * @brief Assigns a new regular expression to a regex object from a
933 * C-style string containing a regular expression pattern.
935 * @param p A pointer to a C-style string containing a
936 * regular expression pattern.
937 * @param len The length of the regular expression pattern string.
938 * @param flags Syntax option flags.
940 * @throws regex_error if p does not contain a valid regular expression
941 * pattern interpreted according to @p flags. If regex_error is thrown,
942 * *this remains unchanged.
945 assign(const _Ch_type* __p, std::size_t __len, flag_type __flags)
946 { return this->assign(string_type(__p, __len), __flags); }
949 * @brief Assigns a new regular expression to a regex object from a
950 * string containing a regular expression pattern.
952 * @param s A string containing a regular expression pattern.
953 * @param flags Syntax option flags.
955 * @throws regex_error if p does not contain a valid regular expression
956 * pattern interpreted according to @p flags. If regex_error is thrown,
957 * *this remains unchanged.
959 template<typename _Ch_typeraits, typename _Allocator>
961 assign(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s,
962 flag_type __f = regex_constants::ECMAScript)
964 basic_regex __tmp(__s, __f);
970 * @brief Assigns a new regular expression to a regex object.
972 * @param first The start of a range containing a valid regular
974 * @param last The end of a range containing a valid regular
976 * @param flags Syntax option flags.
978 * @throws regex_error if p does not contain a valid regular expression
979 * pattern interpreted according to @p flags. If regex_error is thrown,
980 * the object remains unchanged.
982 template<typename _InputIterator>
984 assign(_InputIterator __first, _InputIterator __last,
985 flag_type __flags = regex_constants::ECMAScript)
986 { return this->assign(string_type(__first, __last), __flags); }
988 #ifdef _GLIBCXX_INCLUDE_AS_CXX11
990 * @brief Assigns a new regular expression to a regex object.
992 * @param l An initializer list representing a regular expression.
993 * @param flags Syntax option flags.
995 * @throws regex_error if @p l does not contain a valid regular
996 * expression pattern interpreted according to @p flags. If regex_error
997 * is thrown, the object remains unchanged.
1000 assign(initializer_list<_Ch_type> __l,
1001 flag_type __f = regex_constants::ECMAScript)
1002 { return this->assign(__l.begin(), __l.end(), __f); }
1005 // [7.8.4] const operations
1007 * @brief Gets the number of marked subexpressions within the regular
1012 { return _M_mark_count; }
1015 * @brief Gets the flags used to construct the regular expression
1016 * or in the last call to assign().
1020 { return _M_flags; }
1024 * @brief Imbues the regular expression object with the given locale.
1026 * @param loc A locale.
1029 imbue(locale_type __loc)
1030 { return _M_traits.imbue(__loc); }
1033 * @brief Gets the locale currently imbued in the regular expression
1038 { return _M_traits.getloc(); }
1042 * @brief Swaps the contents of two regular expression objects.
1044 * @param rhs Another regular expression object.
1047 swap(basic_regex& __rhs)
1049 std::swap(_M_flags, __rhs._M_flags);
1050 std::swap(_M_pattern, __rhs._M_pattern);
1051 std::swap(_M_mark_count, __rhs._M_mark_count);
1052 std::swap(_M_traits, __rhs._M_traits);
1057 * @brief Compiles a regular expression pattern into a NFA.
1058 * @todo Implement this function.
1064 string_type _M_pattern;
1065 unsigned int _M_mark_count;
1066 _Rx_traits _M_traits;
1069 /** @brief Standard regular expressions. */
1070 typedef basic_regex<char> regex;
1071 #ifdef _GLIBCXX_USE_WCHAR_T
1072 /** @brief Standard wide-character regular expressions. */
1073 typedef basic_regex<wchar_t> wregex;
1077 // [7.8.6] basic_regex swap
1079 * @brief Swaps the contents of two regular expression objects.
1080 * @param lhs First regular expression.
1081 * @param rhs Second regular expression.
1083 template<typename _Ch_type, typename _Rx_traits>
1085 swap(basic_regex<_Ch_type, _Rx_traits>& __lhs,
1086 basic_regex<_Ch_type, _Rx_traits>& __rhs)
1087 { __lhs.swap(__rhs); }
1090 // [7.9] Class template sub_match
1092 * A sequence of characters matched by a particular marked sub-expression.
1094 * An object of this class is essentially a pair of iterators marking a
1095 * matched subexpression within a regular expression pattern match. Such
1096 * objects can be converted to and compared with std::basic_string objects
1097 * of a similar base character type as the pattern matched by the regular
1100 * The iterators that make up the pair are the usual half-open interval
1101 * referencing the actual original pattern matched.
1103 template<typename _BiIter>
1104 class sub_match : public std::pair<_BiIter, _BiIter>
1107 typedef typename iterator_traits<_BiIter>::value_type value_type;
1108 typedef typename iterator_traits<_BiIter>::difference_type
1110 typedef _BiIter iterator;
1116 * Gets the length of the matching sequence.
1120 { return this->matched ? std::distance(this->first, this->second) : 0; }
1123 * @brief Gets the matching sequence as a string.
1125 * @returns the matching sequence as a string.
1127 * This is the implicit conversion operator. It is identical to the
1128 * str() member function except that it will want to pop up in
1129 * unexpected places and cause a great deal of confusion and cursing
1132 operator basic_string<value_type>() const
1134 return this->matched
1135 ? std::basic_string<value_type>(this->first, this->second)
1136 : std::basic_string<value_type>();
1140 * @brief Gets the matching sequence as a string.
1142 * @returns the matching sequence as a string.
1144 basic_string<value_type>
1147 return this->matched
1148 ? std::basic_string<value_type>(this->first, this->second)
1149 : std::basic_string<value_type>();
1153 * @brief Compares this and another matched sequence.
1155 * @param s Another matched sequence to compare to this one.
1157 * @retval <0 this matched sequence will collate before @p s.
1158 * @retval =0 this matched sequence is equivalent to @p s.
1159 * @retval <0 this matched sequence will collate after @p s.
1162 compare(const sub_match& __s) const
1163 { return this->str().compare(__s.str()); }
1166 * @brief Compares this sub_match to a string.
1168 * @param s A string to compare to this sub_match.
1170 * @retval <0 this matched sequence will collate before @p s.
1171 * @retval =0 this matched sequence is equivalent to @p s.
1172 * @retval <0 this matched sequence will collate after @p s.
1175 compare(const basic_string<value_type>& __s) const
1176 { return this->str().compare(__s); }
1179 * @brief Compares this sub_match to a C-style string.
1181 * @param s A C-style string to compare to this sub_match.
1183 * @retval <0 this matched sequence will collate before @p s.
1184 * @retval =0 this matched sequence is equivalent to @p s.
1185 * @retval <0 this matched sequence will collate after @p s.
1188 compare(const value_type* __s) const
1189 { return this->str().compare(__s); }
1193 /** @brief Standard regex submatch over a C-style null-terminated string. */
1194 typedef sub_match<const char*> csub_match;
1195 /** @brief Standard regex submatch over a standard string. */
1196 typedef sub_match<string::const_iterator> ssub_match;
1197 #ifdef _GLIBCXX_USE_WCHAR_T
1198 /** @brief Regex submatch over a C-style null-terminated wide string. */
1199 typedef sub_match<const wchar_t*> wcsub_match;
1200 /** @brief Regex submatch over a standard wide string. */
1201 typedef sub_match<wstring::const_iterator> wssub_match;
1204 // [7.9.2] sub_match non-member operators
1207 * @brief Tests the equivalence of two regular expression submatches.
1208 * @param lhs First regular expression submatch.
1209 * @param rhs Second regular expression submatch.
1210 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1212 template<typename _BiIter>
1214 operator==(const sub_match<_BiIter>& __lhs,
1215 const sub_match<_BiIter>& __rhs)
1216 { return __lhs.compare(__rhs) == 0; }
1219 * @brief Tests the inequivalence of two regular expression submatches.
1220 * @param lhs First regular expression submatch.
1221 * @param rhs Second regular expression submatch.
1222 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1224 template<typename _BiIter>
1226 operator!=(const sub_match<_BiIter>& __lhs,
1227 const sub_match<_BiIter>& __rhs)
1228 { return __lhs.compare(__rhs) != 0; }
1231 * @brief Tests the ordering of two regular expression submatches.
1232 * @param lhs First regular expression submatch.
1233 * @param rhs Second regular expression submatch.
1234 * @returns true if @a lhs precedes @a rhs, false otherwise.
1236 template<typename _BiIter>
1238 operator<(const sub_match<_BiIter>& __lhs,
1239 const sub_match<_BiIter>& __rhs)
1240 { return __lhs.compare(__rhs) < 0; }
1243 * @brief Tests the ordering of two regular expression submatches.
1244 * @param lhs First regular expression submatch.
1245 * @param rhs Second regular expression submatch.
1246 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1248 template<typename _BiIter>
1250 operator<=(const sub_match<_BiIter>& __lhs,
1251 const sub_match<_BiIter>& __rhs)
1252 { return __lhs.compare(__rhs) <= 0; }
1255 * @brief Tests the ordering of two regular expression submatches.
1256 * @param lhs First regular expression submatch.
1257 * @param rhs Second regular expression submatch.
1258 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1260 template<typename _BiIter>
1262 operator>=(const sub_match<_BiIter>& __lhs,
1263 const sub_match<_BiIter>& __rhs)
1264 { return __lhs.compare(__rhs) >= 0; }
1267 * @brief Tests the ordering of two regular expression submatches.
1268 * @param lhs First regular expression submatch.
1269 * @param rhs Second regular expression submatch.
1270 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1272 template<typename _BiIter>
1274 operator>(const sub_match<_BiIter>& __lhs,
1275 const sub_match<_BiIter>& __rhs)
1276 { return __lhs.compare(__rhs) > 0; }
1279 * @brief Tests the equivalence of a string and a regular expression
1281 * @param lhs A string.
1282 * @param rhs A regular expression submatch.
1283 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1285 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1287 operator==(const basic_string<
1288 typename iterator_traits<_Bi_iter>::value_type,
1289 _Ch_traits, _Ch_alloc>& __lhs,
1290 const sub_match<_Bi_iter>& __rhs)
1291 { return __lhs == __rhs.str(); }
1294 * @brief Tests the inequivalence of a string and a regular expression
1296 * @param lhs A string.
1297 * @param rhs A regular expression submatch.
1298 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1300 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1302 operator!=(const basic_string<
1303 typename iterator_traits<_Bi_iter>::value_type,
1304 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1305 { return __lhs != __rhs.str(); }
1308 * @brief Tests the ordering of a string and a regular expression submatch.
1309 * @param lhs A string.
1310 * @param rhs A regular expression submatch.
1311 * @returns true if @a lhs precedes @a rhs, false otherwise.
1313 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1315 operator<(const basic_string<
1316 typename iterator_traits<_Bi_iter>::value_type,
1317 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1318 { return __lhs < __rhs.str(); }
1321 * @brief Tests the ordering of a string and a regular expression submatch.
1322 * @param lhs A string.
1323 * @param rhs A regular expression submatch.
1324 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1326 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1328 operator>(const basic_string<
1329 typename iterator_traits<_Bi_iter>::value_type,
1330 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1331 { return __lhs > __rhs.str(); }
1334 * @brief Tests the ordering of a string and a regular expression submatch.
1335 * @param lhs A string.
1336 * @param rhs A regular expression submatch.
1337 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1339 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1341 operator>=(const basic_string<
1342 typename iterator_traits<_Bi_iter>::value_type,
1343 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1344 { return __lhs >= __rhs.str(); }
1347 * @brief Tests the ordering of a string and a regular expression submatch.
1348 * @param lhs A string.
1349 * @param rhs A regular expression submatch.
1350 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1352 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1354 operator<=(const basic_string<
1355 typename iterator_traits<_Bi_iter>::value_type,
1356 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1357 { return __lhs <= __rhs.str(); }
1360 * @brief Tests the equivalence of a regular expression submatch and a
1362 * @param lhs A regular expression submatch.
1363 * @param rhs A string.
1364 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1366 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1368 operator==(const sub_match<_Bi_iter>& __lhs,
1370 typename iterator_traits<_Bi_iter>::value_type,
1371 _Ch_traits, _Ch_alloc>& __rhs)
1372 { return __lhs.str() == __rhs; }
1375 * @brief Tests the inequivalence of a regular expression submatch and a
1377 * @param lhs A regular expression submatch.
1378 * @param rhs A string.
1379 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1381 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1383 operator!=(const sub_match<_Bi_iter>& __lhs,
1385 typename iterator_traits<_Bi_iter>::value_type,
1386 _Ch_traits, _Ch_alloc>& __rhs)
1387 { return __lhs.str() != __rhs; }
1390 * @brief Tests the ordering of a regular expression submatch and a string.
1391 * @param lhs A regular expression submatch.
1392 * @param rhs A string.
1393 * @returns true if @a lhs precedes @a rhs, false otherwise.
1395 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1397 operator<(const sub_match<_Bi_iter>& __lhs,
1399 typename iterator_traits<_Bi_iter>::value_type,
1400 _Ch_traits, _Ch_alloc>& __rhs)
1401 { return __lhs.str() < __rhs; }
1404 * @brief Tests the ordering of a regular expression submatch and a string.
1405 * @param lhs A regular expression submatch.
1406 * @param rhs A string.
1407 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1409 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1411 operator>(const sub_match<_Bi_iter>& __lhs,
1413 typename iterator_traits<_Bi_iter>::value_type,
1414 _Ch_traits, _Ch_alloc>& __rhs)
1415 { return __lhs.str() > __rhs; }
1418 * @brief Tests the ordering of a regular expression submatch and a string.
1419 * @param lhs A regular expression submatch.
1420 * @param rhs A string.
1421 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1423 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1425 operator>=(const sub_match<_Bi_iter>& __lhs,
1427 typename iterator_traits<_Bi_iter>::value_type,
1428 _Ch_traits, _Ch_alloc>& __rhs)
1429 { return __lhs.str() >= __rhs; }
1432 * @brief Tests the ordering of a regular expression submatch and a string.
1433 * @param lhs A regular expression submatch.
1434 * @param rhs A string.
1435 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1437 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1439 operator<=(const sub_match<_Bi_iter>& __lhs,
1441 typename iterator_traits<_Bi_iter>::value_type,
1442 _Ch_traits, _Ch_alloc>& __rhs)
1443 { return __lhs.str() <= __rhs; }
1446 * @brief Tests the equivalence of a C string and a regular expression
1448 * @param lhs A C string.
1449 * @param rhs A regular expression submatch.
1450 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1452 template<typename _Bi_iter>
1454 operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1455 const sub_match<_Bi_iter>& __rhs)
1456 { return __lhs == __rhs.str(); }
1459 * @brief Tests the inequivalence of an iterator value and a regular
1460 * expression submatch.
1461 * @param lhs A regular expression submatch.
1462 * @param rhs A string.
1463 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1465 template<typename _Bi_iter>
1467 operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1468 const sub_match<_Bi_iter>& __rhs)
1469 { return __lhs != __rhs.str(); }
1472 * @brief Tests the ordering of a string and a regular expression submatch.
1473 * @param lhs A string.
1474 * @param rhs A regular expression submatch.
1475 * @returns true if @a lhs precedes @a rhs, false otherwise.
1477 template<typename _Bi_iter>
1479 operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1480 const sub_match<_Bi_iter>& __rhs)
1481 { return __lhs < __rhs.str(); }
1484 * @brief Tests the ordering of a string and a regular expression submatch.
1485 * @param lhs A string.
1486 * @param rhs A regular expression submatch.
1487 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1489 template<typename _Bi_iter>
1491 operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1492 const sub_match<_Bi_iter>& __rhs)
1493 { return __lhs > __rhs.str(); }
1496 * @brief Tests the ordering of a string and a regular expression submatch.
1497 * @param lhs A string.
1498 * @param rhs A regular expression submatch.
1499 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1501 template<typename _Bi_iter>
1503 operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1504 const sub_match<_Bi_iter>& __rhs)
1505 { return __lhs >= __rhs.str(); }
1508 * @brief Tests the ordering of a string and a regular expression submatch.
1509 * @param lhs A string.
1510 * @param rhs A regular expression submatch.
1511 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1513 template<typename _Bi_iter>
1515 operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1516 const sub_match<_Bi_iter>& __rhs)
1517 { return __lhs <= __rhs.str(); }
1520 * @brief Tests the equivalence of a regular expression submatch and a
1522 * @param lhs A regular expression submatch.
1523 * @param rhs A pointer to a string?
1524 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1526 template<typename _Bi_iter>
1528 operator==(const sub_match<_Bi_iter>& __lhs,
1529 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1530 { return __lhs.str() == __rhs; }
1533 * @brief Tests the inequivalence of a regular expression submatch and a
1535 * @param lhs A regular expression submatch.
1536 * @param rhs A pointer to a string.
1537 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1539 template<typename _Bi_iter>
1541 operator!=(const sub_match<_Bi_iter>& __lhs,
1542 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1543 { return __lhs.str() != __rhs; }
1546 * @brief Tests the ordering of a regular expression submatch and a string.
1547 * @param lhs A regular expression submatch.
1548 * @param rhs A string.
1549 * @returns true if @a lhs precedes @a rhs, false otherwise.
1551 template<typename _Bi_iter>
1553 operator<(const sub_match<_Bi_iter>& __lhs,
1554 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1555 { return __lhs.str() < __rhs; }
1558 * @brief Tests the ordering of a regular expression submatch and a string.
1559 * @param lhs A regular expression submatch.
1560 * @param rhs A string.
1561 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1563 template<typename _Bi_iter>
1565 operator>(const sub_match<_Bi_iter>& __lhs,
1566 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1567 { return __lhs.str() > __rhs; }
1570 * @brief Tests the ordering of a regular expression submatch and a string.
1571 * @param lhs A regular expression submatch.
1572 * @param rhs A string.
1573 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1575 template<typename _Bi_iter>
1577 operator>=(const sub_match<_Bi_iter>& __lhs,
1578 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1579 { return __lhs.str() >= __rhs; }
1582 * @brief Tests the ordering of a regular expression submatch and a string.
1583 * @param lhs A regular expression submatch.
1584 * @param rhs A string.
1585 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1587 template<typename _Bi_iter>
1589 operator<=(const sub_match<_Bi_iter>& __lhs,
1590 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1591 { return __lhs.str() <= __rhs; }
1594 * @brief Tests the equivalence of a string and a regular expression
1596 * @param lhs A string.
1597 * @param rhs A regular expression submatch.
1598 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1600 template<typename _Bi_iter>
1602 operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1603 const sub_match<_Bi_iter>& __rhs)
1604 { return __lhs == __rhs.str(); }
1607 * @brief Tests the inequivalence of a string and a regular expression
1609 * @param lhs A string.
1610 * @param rhs A regular expression submatch.
1611 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1613 template<typename _Bi_iter>
1615 operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1616 const sub_match<_Bi_iter>& __rhs)
1617 { return __lhs != __rhs.str(); }
1620 * @brief Tests the ordering of a string and a regular expression submatch.
1621 * @param lhs A string.
1622 * @param rhs A regular expression submatch.
1623 * @returns true if @a lhs precedes @a rhs, false otherwise.
1625 template<typename _Bi_iter>
1627 operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1628 const sub_match<_Bi_iter>& __rhs)
1629 { return __lhs < __rhs.str(); }
1632 * @brief Tests the ordering of a string and a regular expression submatch.
1633 * @param lhs A string.
1634 * @param rhs A regular expression submatch.
1635 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1637 template<typename _Bi_iter>
1639 operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1640 const sub_match<_Bi_iter>& __rhs)
1641 { return __lhs > __rhs.str(); }
1644 * @brief Tests the ordering of a string and a regular expression submatch.
1645 * @param lhs A string.
1646 * @param rhs A regular expression submatch.
1647 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1649 template<typename _Bi_iter>
1651 operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1652 const sub_match<_Bi_iter>& __rhs)
1653 { return __lhs >= __rhs.str(); }
1656 * @brief Tests the ordering of a string and a regular expression submatch.
1657 * @param lhs A string.
1658 * @param rhs A regular expression submatch.
1659 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1661 template<typename _Bi_iter>
1663 operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1664 const sub_match<_Bi_iter>& __rhs)
1665 { return __lhs <= __rhs.str(); }
1668 * @brief Tests the equivalence of a regular expression submatch and a
1670 * @param lhs A regular expression submatch.
1671 * @param rhs A const string reference.
1672 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1674 template<typename _Bi_iter>
1676 operator==(const sub_match<_Bi_iter>& __lhs,
1677 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1678 { return __lhs.str() == __rhs; }
1681 * @brief Tests the inequivalence of a regular expression submatch and a
1683 * @param lhs A regular expression submatch.
1684 * @param rhs A const string reference.
1685 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1687 template<typename _Bi_iter>
1689 operator!=(const sub_match<_Bi_iter>& __lhs,
1690 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1691 { return __lhs.str() != __rhs; }
1694 * @brief Tests the ordering of a regular expression submatch and a string.
1695 * @param lhs A regular expression submatch.
1696 * @param rhs A const string reference.
1697 * @returns true if @a lhs precedes @a rhs, false otherwise.
1699 template<typename _Bi_iter>
1701 operator<(const sub_match<_Bi_iter>& __lhs,
1702 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1703 { return __lhs.str() < __rhs; }
1706 * @brief Tests the ordering of a regular expression submatch and a string.
1707 * @param lhs A regular expression submatch.
1708 * @param rhs A const string reference.
1709 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1711 template<typename _Bi_iter>
1713 operator>(const sub_match<_Bi_iter>& __lhs,
1714 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1715 { return __lhs.str() > __rhs; }
1718 * @brief Tests the ordering of a regular expression submatch and a string.
1719 * @param lhs A regular expression submatch.
1720 * @param rhs A const string reference.
1721 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1723 template<typename _Bi_iter>
1725 operator>=(const sub_match<_Bi_iter>& __lhs,
1726 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1727 { return __lhs.str() >= __rhs; }
1730 * @brief Tests the ordering of a regular expression submatch and a string.
1731 * @param lhs A regular expression submatch.
1732 * @param rhs A const string reference.
1733 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1735 template<typename _Bi_iter>
1737 operator<=(const sub_match<_Bi_iter>& __lhs,
1738 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1739 { return __lhs.str() <= __rhs; }
1742 * @brief Inserts a matched string into an output stream.
1744 * @param os The output stream.
1745 * @param m A submatch string.
1747 * @returns the output stream with the submatch string inserted.
1749 template<typename _Ch_type, typename _Ch_traits, typename _Bi_iter>
1751 basic_ostream<_Ch_type, _Ch_traits>&
1752 operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os,
1753 const sub_match<_Bi_iter>& __m)
1754 { return __os << __m.str(); }
1756 // [7.10] Class template match_results
1758 * @brief The results of a match or search operation.
1760 * A collection of character sequences representing the result of a regular
1761 * expression match. Storage for the collection is allocated and freed as
1762 * necessary by the member functions of class template match_results.
1764 * This class satisfies the Sequence requirements, with the exception that
1765 * only the operations defined for a const-qualified Sequence are supported.
1767 * The sub_match object stored at index 0 represents sub-expression 0, i.e.
1768 * the whole match. In this case the sub_match member matched is always true.
1769 * The sub_match object stored at index n denotes what matched the marked
1770 * sub-expression n within the matched expression. If the sub-expression n
1771 * participated in a regular expression match then the sub_match member
1772 * matched evaluates to true, and members first and second denote the range
1773 * of characters [first, second) which formed that match. Otherwise matched
1774 * is false, and members first and second point to the end of the sequence
1775 * that was searched.
1779 template<typename _Bi_iter,
1780 typename _Allocator = allocator<sub_match<_Bi_iter> > >
1782 : private std::vector<std::tr1::sub_match<_Bi_iter>, _Allocator>
1785 typedef std::vector<std::tr1::sub_match<_Bi_iter>, _Allocator>
1790 * @name 10.? Public Types
1793 typedef sub_match<_Bi_iter> value_type;
1794 typedef typename _Base_type::const_reference const_reference;
1795 typedef const_reference reference;
1796 typedef typename _Base_type::const_iterator const_iterator;
1797 typedef const_iterator iterator;
1798 typedef typename iterator_traits<_Bi_iter>::difference_type
1800 typedef typename _Allocator::size_type size_type;
1801 typedef _Allocator allocator_type;
1802 typedef typename iterator_traits<_Bi_iter>::value_type char_type;
1803 typedef basic_string<char_type> string_type;
1808 * @name 10.1 Construction, Copying, and Destruction
1813 * @brief Constructs a default %match_results container.
1814 * @post size() returns 0 and str() returns an empty string.
1817 match_results(const _Allocator& __a = _Allocator())
1818 : _Base_type(__a), _M_matched(false)
1822 * @brief Copy constructs a %match_results.
1824 match_results(const match_results& __rhs)
1825 : _Base_type(__rhs), _M_matched(__rhs._M_matched),
1826 _M_prefix(__rhs._M_prefix), _M_suffix(__rhs._M_suffix)
1830 * @brief Assigns rhs to *this.
1833 operator=(const match_results& __rhs)
1835 match_results __tmp(__rhs);
1841 * @brief Destroys a %match_results object.
1854 * @brief Gets the number of matches and submatches.
1856 * The number of matches for a given regular expression will be either 0
1857 * if there was no match or mark_count() + 1 if a match was successful.
1858 * Some matches may be empty.
1860 * @returns the number of matches found.
1864 { return _M_matched ? _Base_type::size() + 1 : 0; }
1868 using _Base_type::max_size;
1871 * @brief Indicates if the %match_results contains no results.
1872 * @retval true The %match_results object is empty.
1873 * @retval false The %match_results object is not empty.
1875 _GLIBCXX_NODISCARD bool
1877 { return size() == 0; }
1882 * @name 10.3 Element Access
1887 * @brief Gets the length of the indicated submatch.
1888 * @param sub indicates the submatch.
1890 * This function returns the length of the indicated submatch, or the
1891 * length of the entire match if @p sub is zero (the default).
1894 length(size_type __sub = 0) const
1895 { return _M_matched ? this->str(__sub).length() : 0; }
1898 * @brief Gets the offset of the beginning of the indicated submatch.
1899 * @param sub indicates the submatch.
1901 * This function returns the offset from the beginning of the target
1902 * sequence to the beginning of the submatch, unless the value of @p sub
1903 * is zero (the default), in which case this function returns the offset
1904 * from the beginning of the target sequence to the beginning of the
1908 position(size_type __sub = 0) const
1910 return _M_matched ? std::distance(this->prefix().first,
1911 (*this)[__sub].first) : 0;
1915 * @brief Gets the match or submatch converted to a string type.
1916 * @param sub indicates the submatch.
1918 * This function gets the submatch (or match, if @p sub is zero) extracted
1919 * from the target range and converted to the associated string type.
1922 str(size_type __sub = 0) const
1923 { return _M_matched ? (*this)[__sub].str() : string_type(); }
1926 * @brief Gets a %sub_match reference for the match or submatch.
1927 * @param sub indicates the submatch.
1929 * This function gets a reference to the indicated submatch, or the entire
1930 * match if @p sub is zero.
1932 * If @p sub >= size() then this function returns a %sub_match with a
1933 * special value indicating no submatch.
1936 operator[](size_type __sub) const
1937 { return _Base_type::operator[](__sub); }
1940 * @brief Gets a %sub_match representing the match prefix.
1942 * This function gets a reference to a %sub_match object representing the
1943 * part of the target range between the start of the target range and the
1944 * start of the match.
1948 { return _M_prefix; }
1951 * @brief Gets a %sub_match representing the match suffix.
1953 * This function gets a reference to a %sub_match object representing the
1954 * part of the target range between the end of the match and the end of
1959 { return _M_suffix; }
1962 * @brief Gets an iterator to the start of the %sub_match collection.
1966 { return _Base_type::begin(); }
1968 #ifdef _GLIBCXX_INCLUDE_AS_CXX11
1970 * @brief Gets an iterator to the start of the %sub_match collection.
1974 { return _Base_type::begin(); }
1978 * @brief Gets an iterator to one-past-the-end of the collection.
1982 { return _Base_type::end(); }
1984 #ifdef _GLIBCXX_INCLUDE_AS_CXX11
1986 * @brief Gets an iterator to one-past-the-end of the collection.
1990 { return _Base_type::end(); }
1996 * @name 10.4 Formatting
1998 * These functions perform formatted substitution of the matched
1999 * character sequences into their target. The format specifiers
2000 * and escape sequences accepted by these functions are
2001 * determined by their @p flags parameter as documented above.
2006 * @todo Implement this function.
2008 template<typename _Out_iter>
2010 format(_Out_iter __out, const string_type& __fmt,
2011 regex_constants::match_flag_type __flags
2012 = regex_constants::format_default) const;
2015 * @todo Implement this function.
2018 format(const string_type& __fmt,
2019 regex_constants::match_flag_type __flags
2020 = regex_constants::format_default) const;
2025 * @name 10.5 Allocator
2030 * @brief Gets a copy of the allocator.
2033 //get_allocator() const;
2034 using _Base_type::get_allocator;
2044 * @brief Swaps the contents of two match_results.
2047 swap(match_results& __that)
2049 _Base_type::swap(__that);
2050 std::swap(_M_matched, __that._M_matched);
2051 std::swap(_M_prefix, __that._M_prefix);
2052 std::swap(_M_suffix, __that._M_suffix);
2058 value_type _M_prefix;
2059 value_type _M_suffix;
2062 typedef match_results<const char*> cmatch;
2063 typedef match_results<string::const_iterator> smatch;
2064 #ifdef _GLIBCXX_USE_WCHAR_T
2065 typedef match_results<const wchar_t*> wcmatch;
2066 typedef match_results<wstring::const_iterator> wsmatch;
2069 // match_results comparisons
2071 * @brief Compares two match_results for equality.
2072 * @returns true if the two objects refer to the same match,
2074 * @todo Implement this function.
2076 template<typename _Bi_iter, typename _Allocator>
2078 operator==(const match_results<_Bi_iter, _Allocator>& __m1,
2079 const match_results<_Bi_iter, _Allocator>& __m2);
2082 * @brief Compares two match_results for inequality.
2083 * @returns true if the two objects do not refer to the same match,
2086 template<typename _Bi_iter, class _Allocator>
2088 operator!=(const match_results<_Bi_iter, _Allocator>& __m1,
2089 const match_results<_Bi_iter, _Allocator>& __m2)
2090 { return !(__m1 == __m2); }
2092 // [7.10.6] match_results swap
2094 * @brief Swaps two match results.
2095 * @param lhs A match result.
2096 * @param rhs A match result.
2098 * The contents of the two match_results objects are swapped.
2100 template<typename _Bi_iter, typename _Allocator>
2102 swap(match_results<_Bi_iter, _Allocator>& __lhs,
2103 match_results<_Bi_iter, _Allocator>& __rhs)
2104 { __lhs.swap(__rhs); }
2106 // [7.11.2] Function template regex_match
2108 * @name Matching, Searching, and Replacing
2113 * @brief Determines if there is a match between the regular expression @p e
2114 * and all of the character sequence [first, last).
2116 * @param first Beginning of the character sequence to match.
2117 * @param last One-past-the-end of the character sequence to match.
2118 * @param m The match results.
2119 * @param re The regular expression.
2120 * @param flags Controls how the regular expression is matched.
2122 * @retval true A match exists.
2123 * @retval false Otherwise.
2125 * @throws an exception of type regex_error.
2127 * @todo Implement this function.
2129 template<typename _Bi_iter, typename _Allocator,
2130 typename _Ch_type, typename _Rx_traits>
2132 regex_match(_Bi_iter __first, _Bi_iter __last,
2133 match_results<_Bi_iter, _Allocator>& __m,
2134 const basic_regex<_Ch_type, _Rx_traits>& __re,
2135 regex_constants::match_flag_type __flags
2136 = regex_constants::match_default);
2139 * @brief Indicates if there is a match between the regular expression @p e
2140 * and all of the character sequence [first, last).
2142 * @param first Beginning of the character sequence to match.
2143 * @param last One-past-the-end of the character sequence to match.
2144 * @param re The regular expression.
2145 * @param flags Controls how the regular expression is matched.
2147 * @retval true A match exists.
2148 * @retval false Otherwise.
2150 * @throws an exception of type regex_error.
2152 template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
2154 regex_match(_Bi_iter __first, _Bi_iter __last,
2155 const basic_regex<_Ch_type, _Rx_traits>& __re,
2156 regex_constants::match_flag_type __flags
2157 = regex_constants::match_default)
2159 match_results<_Bi_iter> __what;
2160 return regex_match(__first, __last, __what, __re, __flags);
2164 * @brief Determines if there is a match between the regular expression @p e
2165 * and a C-style null-terminated string.
2167 * @param s The C-style null-terminated string to match.
2168 * @param m The match results.
2169 * @param re The regular expression.
2170 * @param f Controls how the regular expression is matched.
2172 * @retval true A match exists.
2173 * @retval false Otherwise.
2175 * @throws an exception of type regex_error.
2177 template<typename _Ch_type, typename _Allocator, typename _Rx_traits>
2179 regex_match(const _Ch_type* __s,
2180 match_results<const _Ch_type*, _Allocator>& __m,
2181 const basic_regex<_Ch_type, _Rx_traits>& __re,
2182 regex_constants::match_flag_type __f
2183 = regex_constants::match_default)
2184 { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); }
2187 * @brief Determines if there is a match between the regular expression @p e
2190 * @param s The string to match.
2191 * @param m The match results.
2192 * @param re The regular expression.
2193 * @param flags Controls how the regular expression is matched.
2195 * @retval true A match exists.
2196 * @retval false Otherwise.
2198 * @throws an exception of type regex_error.
2200 template<typename _Ch_traits, typename _Ch_alloc,
2201 typename _Allocator, typename _Ch_type, typename _Rx_traits>
2203 regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
2204 match_results<typename basic_string<_Ch_type,
2205 _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
2206 const basic_regex<_Ch_type, _Rx_traits>& __re,
2207 regex_constants::match_flag_type __flags
2208 = regex_constants::match_default)
2209 { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }
2212 * @brief Indicates if there is a match between the regular expression @p e
2213 * and a C-style null-terminated string.
2215 * @param s The C-style null-terminated string to match.
2216 * @param re The regular expression.
2217 * @param f Controls how the regular expression is matched.
2219 * @retval true A match exists.
2220 * @retval false Otherwise.
2222 * @throws an exception of type regex_error.
2224 template<typename _Ch_type, class _Rx_traits>
2226 regex_match(const _Ch_type* __s,
2227 const basic_regex<_Ch_type, _Rx_traits>& __re,
2228 regex_constants::match_flag_type __f
2229 = regex_constants::match_default)
2230 { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); }
2233 * @brief Indicates if there is a match between the regular expression @p e
2236 * @param s [IN] The string to match.
2237 * @param re [IN] The regular expression.
2238 * @param flags [IN] Controls how the regular expression is matched.
2240 * @retval true A match exists.
2241 * @retval false Otherwise.
2243 * @throws an exception of type regex_error.
2245 template<typename _Ch_traits, typename _Str_allocator,
2246 typename _Ch_type, typename _Rx_traits>
2248 regex_match(const basic_string<_Ch_type, _Ch_traits, _Str_allocator>& __s,
2249 const basic_regex<_Ch_type, _Rx_traits>& __re,
2250 regex_constants::match_flag_type __flags
2251 = regex_constants::match_default)
2252 { return regex_match(__s.begin(), __s.end(), __re, __flags); }
2254 // [7.11.3] Function template regex_search
2256 * Searches for a regular expression within a range.
2257 * @param first [IN] The start of the string to search.
2258 * @param last [IN] One-past-the-end of the string to search.
2259 * @param m [OUT] The match results.
2260 * @param re [IN] The regular expression to search for.
2261 * @param flags [IN] Search policy flags.
2262 * @retval true A match was found within the string.
2263 * @retval false No match was found within the string, the content of %m is
2266 * @throws an exception of type regex_error.
2268 * @todo Implement this function.
2270 template<typename _Bi_iter, typename _Allocator,
2271 typename _Ch_type, typename _Rx_traits>
2273 regex_search(_Bi_iter __first, _Bi_iter __last,
2274 match_results<_Bi_iter, _Allocator>& __m,
2275 const basic_regex<_Ch_type, _Rx_traits>& __re,
2276 regex_constants::match_flag_type __flags
2277 = regex_constants::match_default);
2280 * Searches for a regular expression within a range.
2281 * @param first [IN] The start of the string to search.
2282 * @param last [IN] One-past-the-end of the string to search.
2283 * @param re [IN] The regular expression to search for.
2284 * @param flags [IN] Search policy flags.
2285 * @retval true A match was found within the string.
2286 * @retval false No match was found within the string.
2289 * @throws an exception of type regex_error.
2291 template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
2293 regex_search(_Bi_iter __first, _Bi_iter __last,
2294 const basic_regex<_Ch_type, _Rx_traits>& __re,
2295 regex_constants::match_flag_type __flags
2296 = regex_constants::match_default)
2298 match_results<_Bi_iter> __what;
2299 return regex_search(__first, __last, __what, __re, __flags);
2303 * @brief Searches for a regular expression within a C-string.
2304 * @param s [IN] A C-string to search for the regex.
2305 * @param m [OUT] The set of regex matches.
2306 * @param e [IN] The regex to search for in @p s.
2307 * @param f [IN] The search flags.
2308 * @retval true A match was found within the string.
2309 * @retval false No match was found within the string, the content of %m is
2313 * @throws an exception of type regex_error.
2315 template<typename _Ch_type, class _Allocator, class _Rx_traits>
2317 regex_search(const _Ch_type* __s,
2318 match_results<const _Ch_type*, _Allocator>& __m,
2319 const basic_regex<_Ch_type, _Rx_traits>& __e,
2320 regex_constants::match_flag_type __f
2321 = regex_constants::match_default)
2322 { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
2325 * @brief Searches for a regular expression within a C-string.
2326 * @param s [IN] The C-string to search.
2327 * @param e [IN] The regular expression to search for.
2328 * @param f [IN] Search policy flags.
2329 * @retval true A match was found within the string.
2330 * @retval false No match was found within the string.
2333 * @throws an exception of type regex_error.
2335 template<typename _Ch_type, typename _Rx_traits>
2337 regex_search(const _Ch_type* __s,
2338 const basic_regex<_Ch_type, _Rx_traits>& __e,
2339 regex_constants::match_flag_type __f
2340 = regex_constants::match_default)
2341 { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); }
2344 * @brief Searches for a regular expression within a string.
2345 * @param s [IN] The string to search.
2346 * @param e [IN] The regular expression to search for.
2347 * @param flags [IN] Search policy flags.
2348 * @retval true A match was found within the string.
2349 * @retval false No match was found within the string.
2352 * @throws an exception of type regex_error.
2354 template<typename _Ch_traits, typename _String_allocator,
2355 typename _Ch_type, typename _Rx_traits>
2357 regex_search(const basic_string<_Ch_type, _Ch_traits,
2358 _String_allocator>& __s,
2359 const basic_regex<_Ch_type, _Rx_traits>& __e,
2360 regex_constants::match_flag_type __flags
2361 = regex_constants::match_default)
2362 { return regex_search(__s.begin(), __s.end(), __e, __flags); }
2365 * @brief Searches for a regular expression within a string.
2366 * @param s [IN] A C++ string to search for the regex.
2367 * @param m [OUT] The set of regex matches.
2368 * @param e [IN] The regex to search for in @p s.
2369 * @param f [IN] The search flags.
2370 * @retval true A match was found within the string.
2371 * @retval false No match was found within the string, the content of %m is
2374 * @throws an exception of type regex_error.
2376 template<typename _Ch_traits, typename _Ch_alloc,
2377 typename _Allocator, typename _Ch_type,
2378 typename _Rx_traits>
2380 regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
2381 match_results<typename basic_string<_Ch_type,
2382 _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
2383 const basic_regex<_Ch_type, _Rx_traits>& __e,
2384 regex_constants::match_flag_type __f
2385 = regex_constants::match_default)
2386 { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
2388 // tr1 [7.11.4] std [28.11.4] Function template regex_replace
2399 * @throws an exception of type regex_error.
2401 * @todo Implement this function.
2403 template<typename _Out_iter, typename _Bi_iter,
2404 typename _Rx_traits, typename _Ch_type>
2406 regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
2407 const basic_regex<_Ch_type, _Rx_traits>& __e,
2408 const basic_string<_Ch_type>& __fmt,
2409 regex_constants::match_flag_type __flags
2410 = regex_constants::match_default);
2419 * @returns a copy of string @p s with replacements.
2421 * @throws an exception of type regex_error.
2423 template<typename _Rx_traits, typename _Ch_type>
2424 inline basic_string<_Ch_type>
2425 regex_replace(const basic_string<_Ch_type>& __s,
2426 const basic_regex<_Ch_type, _Rx_traits>& __e,
2427 const basic_string<_Ch_type>& __fmt,
2428 regex_constants::match_flag_type __flags
2429 = regex_constants::match_default)
2431 std::string __result;
2432 regex_replace(std::back_inserter(__result),
2433 __s.begin(), __s.end(), __e, __fmt, __flags);
2439 // tr1 [7.12.1] std [28.12] Class template regex_iterator
2441 * An iterator adaptor that will provide repeated calls of regex_search over
2442 * a range until no more matches remain.
2444 template<typename _Bi_iter,
2445 typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2446 typename _Rx_traits = regex_traits<_Ch_type> >
2447 class regex_iterator
2450 typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
2451 typedef match_results<_Bi_iter> value_type;
2452 typedef std::ptrdiff_t difference_type;
2453 typedef const value_type* pointer;
2454 typedef const value_type& reference;
2455 typedef std::forward_iterator_tag iterator_category;
2459 * @brief Provides a singular iterator, useful for indicating
2460 * one-past-the-end of a range.
2461 * @todo Implement this function.
2467 * Constructs a %regex_iterator...
2468 * @param a [IN] The start of a text range to search.
2469 * @param b [IN] One-past-the-end of the text range to search.
2470 * @param re [IN] The regular expression to match.
2471 * @param m [IN] Policy flags for match rules.
2472 * @todo Implement this function.
2475 regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2476 regex_constants::match_flag_type __m
2477 = regex_constants::match_default);
2480 * Copy constructs a %regex_iterator.
2481 * @todo Implement this function.
2484 regex_iterator(const regex_iterator& __rhs);
2487 * @todo Implement this function.
2491 operator=(const regex_iterator& __rhs);
2494 * @todo Implement this function.
2498 operator==(const regex_iterator& __rhs);
2501 * @todo Implement this function.
2505 operator!=(const regex_iterator& __rhs);
2508 * @todo Implement this function.
2515 * @todo Implement this function.
2522 * @todo Implement this function.
2529 * @todo Implement this function.
2536 // these members are shown for exposition only:
2539 const regex_type* pregex;
2540 regex_constants::match_flag_type flags;
2541 match_results<_Bi_iter> match;
2544 typedef regex_iterator<const char*> cregex_iterator;
2545 typedef regex_iterator<string::const_iterator> sregex_iterator;
2546 #ifdef _GLIBCXX_USE_WCHAR_T
2547 typedef regex_iterator<const wchar_t*> wcregex_iterator;
2548 typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
2551 // [7.12.2] Class template regex_token_iterator
2553 * Iterates over submatches in a range (or @a splits a text string).
2555 * The purpose of this iterator is to enumerate all, or all specified,
2556 * matches of a regular expression within a text range. The dereferenced
2557 * value of an iterator of this class is a std::tr1::sub_match object.
2559 template<typename _Bi_iter,
2560 typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2561 typename _Rx_traits = regex_traits<_Ch_type> >
2562 class regex_token_iterator
2565 typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
2566 typedef sub_match<_Bi_iter> value_type;
2567 typedef std::ptrdiff_t difference_type;
2568 typedef const value_type* pointer;
2569 typedef const value_type& reference;
2570 typedef std::forward_iterator_tag iterator_category;
2574 * @brief Default constructs a %regex_token_iterator.
2575 * @todo Implement this function.
2577 * A default-constructed %regex_token_iterator is a singular iterator
2578 * that will compare equal to the one-past-the-end value for any
2579 * iterator of the same type.
2581 regex_token_iterator();
2584 * Constructs a %regex_token_iterator...
2585 * @param a [IN] The start of the text to search.
2586 * @param b [IN] One-past-the-end of the text to search.
2587 * @param re [IN] The regular expression to search for.
2588 * @param submatch [IN] Which submatch to return. There are some
2589 * special values for this parameter:
2590 * - -1 each enumerated subexpression does NOT
2591 * match the regular expression (aka field
2593 * - 0 the entire string matching the
2594 * subexpression is returned for each match
2596 * - >0 enumerates only the indicated
2597 * subexpression from a match within the text.
2598 * @param m [IN] Policy flags for match rules.
2600 * @todo Implement this function.
2603 regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2605 regex_constants::match_flag_type __m
2606 = regex_constants::match_default);
2609 * Constructs a %regex_token_iterator...
2610 * @param a [IN] The start of the text to search.
2611 * @param b [IN] One-past-the-end of the text to search.
2612 * @param re [IN] The regular expression to search for.
2613 * @param submatches [IN] A list of subexpressions to return for each
2614 * regular expression match within the text.
2615 * @param m [IN] Policy flags for match rules.
2617 * @todo Implement this function.
2620 regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2621 const regex_type& __re,
2622 const std::vector<int>& __submatches,
2623 regex_constants::match_flag_type __m
2624 = regex_constants::match_default);
2627 * Constructs a %regex_token_iterator...
2628 * @param a [IN] The start of the text to search.
2629 * @param b [IN] One-past-the-end of the text to search.
2630 * @param re [IN] The regular expression to search for.
2631 * @param submatches [IN] A list of subexpressions to return for each
2632 * regular expression match within the text.
2633 * @param m [IN] Policy flags for match rules.
2635 * @todo Implement this function.
2638 template<std::size_t _Nm>
2639 regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2640 const regex_type& __re,
2641 const int (&__submatches)[_Nm],
2642 regex_constants::match_flag_type __m
2643 = regex_constants::match_default);
2646 * @brief Copy constructs a %regex_token_iterator.
2647 * @param rhs [IN] A %regex_token_iterator to copy.
2648 * @todo Implement this function.
2650 regex_token_iterator(const regex_token_iterator& __rhs);
2653 * @brief Assigns a %regex_token_iterator to another.
2654 * @param rhs [IN] A %regex_token_iterator to copy.
2655 * @todo Implement this function.
2657 regex_token_iterator&
2658 operator=(const regex_token_iterator& __rhs);
2661 * @brief Compares a %regex_token_iterator to another for equality.
2662 * @todo Implement this function.
2665 operator==(const regex_token_iterator& __rhs);
2668 * @brief Compares a %regex_token_iterator to another for inequality.
2669 * @todo Implement this function.
2672 operator!=(const regex_token_iterator& __rhs);
2675 * @brief Dereferences a %regex_token_iterator.
2676 * @todo Implement this function.
2682 * @brief Selects a %regex_token_iterator member.
2683 * @todo Implement this function.
2689 * @brief Increments a %regex_token_iterator.
2690 * @todo Implement this function.
2692 regex_token_iterator&
2696 * @brief Postincrements a %regex_token_iterator.
2697 * @todo Implement this function.
2699 regex_token_iterator
2702 private: // data members for exposition only:
2703 typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> position_iterator;
2705 position_iterator __position;
2706 const value_type* __result;
2707 value_type __suffix;
2709 std::vector<int> __subs;
2712 /** @brief Token iterator for C-style NULL-terminated strings. */
2713 typedef regex_token_iterator<const char*> cregex_token_iterator;
2714 /** @brief Token iterator for standard strings. */
2715 typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
2716 #ifdef _GLIBCXX_USE_WCHAR_T
2717 /** @brief Token iterator for C-style NULL-terminated wide strings. */
2718 typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
2719 /** @brief Token iterator for standard wide-character strings. */
2720 typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
2726 _GLIBCXX_END_NAMESPACE_VERSION
2729 #endif // _GLIBCXX_TR1_REGEX