1 // class template regex -*- C++ -*-
3 // Copyright (C) 2010 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
27 * This is an internal header file, included by other library headers.
28 * You should not attempt to use it directly.
35 * @defgroup regex Regular Expressions
36 * A facility for performing regular expression pattern matching.
40 // [7.7] Class regex_traits
42 * @brief Describes aspects of a regular expression.
44 * A regular expression traits class that satisfies the requirements of
47 * The class %regex is parameterized around a set of related types and
48 * functions used to complete the definition of its semantics. This class
49 * satisfies the requirements of such a traits class.
51 template<typename _Ch_type>
55 typedef _Ch_type char_type;
56 typedef std::basic_string<char_type> string_type;
57 typedef std::locale locale_type;
58 typedef std::ctype_base::mask char_class_type;
62 * @brief Constructs a default traits object.
68 * @brief Gives the length of a C-style string starting at @p __p.
70 * @param __p a pointer to the start of a character sequence.
72 * @returns the number of characters between @p *__p and the first
73 * default-initialized value of type @p char_type. In other words, uses
74 * the C-string algorithm for determining the length of a sequence of
78 length(const char_type* __p)
79 { return string_type::traits_type::length(__p); }
82 * @brief Performs the identity translation.
84 * @param c A character to the locale-specific character set.
89 translate(char_type __c) const
93 * @brief Translates a character into a case-insensitive equivalent.
95 * @param c A character to the locale-specific character set.
97 * @returns the locale-specific lower-case equivalent of c.
98 * @throws std::bad_cast if the imbued locale does not support the ctype
102 translate_nocase(char_type __c) const
105 using std::use_facet;
106 return use_facet<ctype<char_type> >(_M_locale).tolower(__c);
110 * @brief Gets a sort key for a character sequence.
112 * @param first beginning of the character sequence.
113 * @param last one-past-the-end of the character sequence.
115 * Returns a sort key for the character sequence designated by the
116 * iterator range [F1, F2) such that if the character sequence [G1, G2)
117 * sorts before the character sequence [H1, H2) then
118 * v.transform(G1, G2) < v.transform(H1, H2).
120 * What this really does is provide a more efficient way to compare a
121 * string to multiple other strings in locales with fancy collation
122 * rules and equivalence classes.
124 * @returns a locale-specific sort key equivalent to the input range.
126 * @throws std::bad_cast if the current locale does not have a collate
129 template<typename _Fwd_iter>
131 transform(_Fwd_iter __first, _Fwd_iter __last) const
134 using std::use_facet;
135 const collate<_Ch_type>& __c(use_facet<
136 collate<_Ch_type> >(_M_locale));
137 string_type __s(__first, __last);
138 return __c.transform(__s.data(), __s.data() + __s.size());
142 * @brief Gets a sort key for a character sequence, independant of case.
144 * @param first beginning of the character sequence.
145 * @param last one-past-the-end of the character sequence.
147 * Effects: if typeid(use_facet<collate<_Ch_type> >) ==
148 * typeid(collate_byname<_Ch_type>) and the form of the sort key
149 * returned by collate_byname<_Ch_type>::transform(first, last) is known
150 * and can be converted into a primary sort key then returns that key,
151 * otherwise returns an empty string.
153 * @todo Implement this function.
155 template<typename _Fwd_iter>
157 transform_primary(_Fwd_iter __first, _Fwd_iter __last) const
158 { return string_type(); }
161 * @brief Gets a collation element by name.
163 * @param first beginning of the collation element name.
164 * @param last one-past-the-end of the collation element name.
166 * @returns a sequence of one or more characters that represents the
167 * collating element consisting of the character sequence designated by
168 * the iterator range [first, last). Returns an empty string if the
169 * character sequence is not a valid collating element.
171 * @todo Implement this function.
173 template<typename _Fwd_iter>
175 lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const
176 { return string_type(); }
179 * @brief Maps one or more characters to a named character
182 * @param first beginning of the character sequence.
183 * @param last one-past-the-end of the character sequence.
184 * @param icase ignores the case of the classification name.
186 * @returns an unspecified value that represents the character
187 * classification named by the character sequence designated by the
188 * iterator range [first, last). If @p icase is true, the returned mask
189 * identifies the classification regardless of the case of the characters
190 * to be matched (for example, [[:lower:]] is the same as [[:alpha:]]),
191 * otherwise a case-dependant classification is returned. The value
192 * returned shall be independent of the case of the characters in the
193 * character sequence. If the name is not recognized then returns a value
194 * that compares equal to 0.
196 * At least the following names (or their wide-character equivalent) are
214 * @todo Implement this function.
216 template<typename _Fwd_iter>
218 lookup_classname(_Fwd_iter __first, _Fwd_iter __last,
219 bool __icase = false) const
223 * @brief Determines if @p c is a member of an identified class.
225 * @param c a character.
226 * @param f a class type (as returned from lookup_classname).
228 * @returns true if the character @p c is a member of the classification
229 * represented by @p f, false otherwise.
231 * @throws std::bad_cast if the current locale does not have a ctype
235 isctype(_Ch_type __c, char_class_type __f) const;
238 * @brief Converts a digit to an int.
240 * @param ch a character representing a digit.
241 * @param radix the radix if the numeric conversion (limited to 8, 10,
244 * @returns the value represented by the digit ch in base radix if the
245 * character ch is a valid digit in base radix; otherwise returns -1.
248 value(_Ch_type __ch, int __radix) const;
251 * @brief Imbues the regex_traits object with a copy of a new locale.
253 * @param loc A locale.
255 * @returns a copy of the previous locale in use by the regex_traits
258 * @note Calling imbue with a different locale than the one currently in
259 * use invalidates all cached data held by *this.
262 imbue(locale_type __loc)
264 std::swap(_M_locale, __loc);
269 * @brief Gets a copy of the current locale in use by the regex_traits
274 { return _M_locale; }
277 locale_type _M_locale;
280 template<typename _Ch_type>
282 regex_traits<_Ch_type>::
283 isctype(_Ch_type __c, char_class_type __f) const
286 using std::use_facet;
287 const ctype<_Ch_type>& __ctype(use_facet<
288 ctype<_Ch_type> >(_M_locale));
290 if (__ctype.is(__c, __f))
293 // special case of underscore in [[:w:]]
294 if (__c == __ctype.widen('_'))
296 const char __wb[] = "w";
297 char_class_type __wt = this->lookup_classname(__wb,
298 __wb + sizeof(__wb));
303 // special case of [[:space:]] in [[:blank:]]
304 if (__ctype.is(std::ctype_base::space, __c))
306 const char __bb[] = "blank";
307 char_class_type __bt = this->lookup_classname(__bb,
308 __bb + sizeof(__bb));
316 template<typename _Ch_type>
318 regex_traits<_Ch_type>::
319 value(_Ch_type __ch, int __radix) const
321 std::basic_istringstream<_Ch_type> __is(string_type(1, __ch));
325 else if (__radix == 16)
328 return __is.fail() ? -1 : __v;
331 // [7.8] Class basic_regex
333 * Objects of specializations of this class represent regular expressions
334 * constructed from sequences of character type @p _Ch_type.
336 * Storage for the regular expression is allocated and deallocated as
337 * necessary by the member functions of this class.
339 template<typename _Ch_type, typename _Rx_traits = regex_traits<_Ch_type> >
344 typedef _Ch_type value_type;
345 typedef regex_constants::syntax_option_type flag_type;
346 typedef typename _Rx_traits::locale_type locale_type;
347 typedef typename _Rx_traits::string_type string_type;
352 * @todo These should be constexpr.
355 static const regex_constants::syntax_option_type icase
356 = regex_constants::icase;
357 static const regex_constants::syntax_option_type nosubs
358 = regex_constants::nosubs;
359 static const regex_constants::syntax_option_type optimize
360 = regex_constants::optimize;
361 static const regex_constants::syntax_option_type collate
362 = regex_constants::collate;
363 static const regex_constants::syntax_option_type ECMAScript
364 = regex_constants::ECMAScript;
365 static const regex_constants::syntax_option_type basic
366 = regex_constants::basic;
367 static const regex_constants::syntax_option_type extended
368 = regex_constants::extended;
369 static const regex_constants::syntax_option_type awk
370 = regex_constants::awk;
371 static const regex_constants::syntax_option_type grep
372 = regex_constants::grep;
373 static const regex_constants::syntax_option_type egrep
374 = regex_constants::egrep;
377 // [7.8.2] construct/copy/destroy
379 * Constructs a basic regular expression that does not match any
380 * character sequence.
383 : _M_flags(regex_constants::ECMAScript),
384 _M_automaton(__regex::__compile<const _Ch_type*, _Rx_traits>(0, 0,
385 _M_traits, _M_flags))
389 * @brief Constructs a basic regular expression from the sequence
390 * [p, p + char_traits<_Ch_type>::length(p)) interpreted according to the
393 * @param p A pointer to the start of a C-style null-terminated string
394 * containing a regular expression.
395 * @param f Flags indicating the syntax rules and options.
397 * @throws regex_error if @p p is not a valid regular expression.
400 basic_regex(const _Ch_type* __p,
401 flag_type __f = regex_constants::ECMAScript)
403 _M_automaton(__regex::__compile(__p, __p + _Rx_traits::length(__p),
404 _M_traits, _M_flags))
408 * @brief Constructs a basic regular expression from the sequence
409 * [p, p + len) interpreted according to the flags in @p f.
411 * @param p A pointer to the start of a string containing a regular
413 * @param len The length of the string containing the regular expression.
414 * @param f Flags indicating the syntax rules and options.
416 * @throws regex_error if @p p is not a valid regular expression.
418 basic_regex(const _Ch_type* __p, std::size_t __len, flag_type __f)
420 _M_automaton(__regex::__compile(__p, __p + __len, _M_traits, _M_flags))
424 * @brief Copy-constructs a basic regular expression.
426 * @param rhs A @p regex object.
428 basic_regex(const basic_regex& __rhs)
429 : _M_flags(__rhs._M_flags), _M_traits(__rhs._M_traits),
430 _M_automaton(__rhs._M_automaton)
434 * @brief Move-constructs a basic regular expression.
436 * @param rhs A @p regex object.
438 basic_regex(const basic_regex&& __rhs)
439 : _M_flags(__rhs._M_flags), _M_traits(__rhs._M_traits),
440 _M_automaton(std::move(__rhs._M_automaton))
444 * @brief Constructs a basic regular expression from the string
445 * @p s interpreted according to the flags in @p f.
447 * @param s A string containing a regular expression.
448 * @param f Flags indicating the syntax rules and options.
450 * @throws regex_error if @p s is not a valid regular expression.
452 template<typename _Ch_traits, typename _Ch_alloc>
454 basic_regex(const std::basic_string<_Ch_type, _Ch_traits,
456 flag_type __f = regex_constants::ECMAScript)
458 _M_automaton(__regex::__compile(__s.begin(), __s.end(),
459 _M_traits, _M_flags))
463 * @brief Constructs a basic regular expression from the range
464 * [first, last) interpreted according to the flags in @p f.
466 * @param first The start of a range containing a valid regular
468 * @param last The end of a range containing a valid regular
470 * @param f The format flags of the regular expression.
472 * @throws regex_error if @p [first, last) is not a valid regular
475 template<typename _InputIterator>
476 basic_regex(_InputIterator __first, _InputIterator __last,
477 flag_type __f = regex_constants::ECMAScript)
479 _M_automaton(__regex::__compile(__first, __last, _M_traits, _M_flags))
483 * @brief Constructs a basic regular expression from an initializer list.
485 * @param l The initializer list.
486 * @param f The format flags of the regular expression.
488 * @throws regex_error if @p l is not a valid regular expression.
490 basic_regex(initializer_list<_Ch_type> __l,
491 flag_type __f = regex_constants::ECMAScript)
493 _M_automaton(__regex::__compile(__l.begin(), __l.end(),
494 _M_traits, _M_flags))
498 * @brief Destroys a basic regular expression.
504 * @brief Assigns one regular expression to another.
507 operator=(const basic_regex& __rhs)
508 { return this->assign(__rhs); }
511 * @brief Move-assigns one regular expression to another.
514 operator=(basic_regex&& __rhs)
515 { return this->assign(std::move(__rhs)); }
518 * @brief Replaces a regular expression with a new one constructed from
519 * a C-style null-terminated string.
521 * @param A pointer to the start of a null-terminated C-style string
522 * containing a regular expression.
525 operator=(const _Ch_type* __p)
526 { return this->assign(__p, flags()); }
529 * @brief Replaces a regular expression with a new one constructed from
532 * @param A pointer to a string containing a regular expression.
534 template<typename _Ch_typeraits, typename _Allocator>
536 operator=(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s)
537 { return this->assign(__s, flags()); }
541 * @brief the real assignment operator.
543 * @param rhs Another regular expression object.
546 assign(const basic_regex& __rhs)
548 basic_regex __tmp(__rhs);
554 * @brief The move-assignment operator.
556 * @param rhs Another regular expression object.
559 assign(basic_regex&& __rhs)
561 basic_regex __tmp(std::move(__rhs));
567 * @brief Assigns a new regular expression to a regex object from a
568 * C-style null-terminated string containing a regular expression
571 * @param p A pointer to a C-style null-terminated string containing
572 * a regular expression pattern.
573 * @param flags Syntax option flags.
575 * @throws regex_error if p does not contain a valid regular expression
576 * pattern interpreted according to @p flags. If regex_error is thrown,
577 * *this remains unchanged.
580 assign(const _Ch_type* __p,
581 flag_type __flags = regex_constants::ECMAScript)
582 { return this->assign(string_type(__p), __flags); }
585 * @brief Assigns a new regular expression to a regex object from a
586 * C-style string containing a regular expression pattern.
588 * @param p A pointer to a C-style string containing a
589 * regular expression pattern.
590 * @param len The length of the regular expression pattern string.
591 * @param flags Syntax option flags.
593 * @throws regex_error if p does not contain a valid regular expression
594 * pattern interpreted according to @p flags. If regex_error is thrown,
595 * *this remains unchanged.
598 assign(const _Ch_type* __p, std::size_t __len, flag_type __flags)
599 { return this->assign(string_type(__p, __len), __flags); }
602 * @brief Assigns a new regular expression to a regex object from a
603 * string containing a regular expression pattern.
605 * @param s A string containing a regular expression pattern.
606 * @param flags Syntax option flags.
608 * @throws regex_error if p does not contain a valid regular expression
609 * pattern interpreted according to @p flags. If regex_error is thrown,
610 * *this remains unchanged.
612 template<typename _Ch_typeraits, typename _Allocator>
614 assign(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s,
615 flag_type __f = regex_constants::ECMAScript)
617 basic_regex __tmp(__s, __f);
623 * @brief Assigns a new regular expression to a regex object.
625 * @param first The start of a range containing a valid regular
627 * @param last The end of a range containing a valid regular
629 * @param flags Syntax option flags.
631 * @throws regex_error if p does not contain a valid regular expression
632 * pattern interpreted according to @p flags. If regex_error is thrown,
633 * the object remains unchanged.
635 template<typename _InputIterator>
637 assign(_InputIterator __first, _InputIterator __last,
638 flag_type __flags = regex_constants::ECMAScript)
639 { return this->assign(string_type(__first, __last), __flags); }
642 * @brief Assigns a new regular expression to a regex object.
644 * @param l An initializer list representing a regular expression.
645 * @param flags Syntax option flags.
647 * @throws regex_error if @p l does not contain a valid regular
648 * expression pattern interpreted according to @p flags. If regex_error
649 * is thrown, the object remains unchanged.
652 assign(initializer_list<_Ch_type> __l,
653 flag_type __f = regex_constants::ECMAScript)
654 { return this->assign(__l.begin(), __l.end(), __f); }
656 // [7.8.4] const operations
658 * @brief Gets the number of marked subexpressions within the regular
663 { return _M_automaton->_M_sub_count() - 1; }
666 * @brief Gets the flags used to construct the regular expression
667 * or in the last call to assign().
675 * @brief Imbues the regular expression object with the given locale.
677 * @param loc A locale.
680 imbue(locale_type __loc)
681 { return _M_traits.imbue(__loc); }
684 * @brief Gets the locale currently imbued in the regular expression
689 { return _M_traits.getloc(); }
693 * @brief Swaps the contents of two regular expression objects.
695 * @param rhs Another regular expression object.
698 swap(basic_regex& __rhs)
700 std::swap(_M_flags, __rhs._M_flags);
701 std::swap(_M_traits, __rhs._M_traits);
702 std::swap(_M_automaton, __rhs._M_automaton);
705 #ifdef _GLIBCXX_DEBUG
707 _M_dot(std::ostream& __ostr)
708 { _M_automaton->_M_dot(__ostr); }
711 const __regex::_AutomatonPtr&
712 _M_get_automaton() const
713 { return _M_automaton; }
717 _Rx_traits _M_traits;
718 __regex::_AutomatonPtr _M_automaton;
721 /** @brief Standard regular expressions. */
722 typedef basic_regex<char> regex;
723 #ifdef _GLIBCXX_USE_WCHAR_T
724 /** @brief Standard wide-character regular expressions. */
725 typedef basic_regex<wchar_t> wregex;
729 // [7.8.6] basic_regex swap
731 * @brief Swaps the contents of two regular expression objects.
732 * @param lhs First regular expression.
733 * @param rhs Second regular expression.
735 template<typename _Ch_type, typename _Rx_traits>
737 swap(basic_regex<_Ch_type, _Rx_traits>& __lhs,
738 basic_regex<_Ch_type, _Rx_traits>& __rhs)
739 { __lhs.swap(__rhs); }
742 // [7.9] Class template sub_match
744 * A sequence of characters matched by a particular marked sub-expression.
746 * An object of this class is essentially a pair of iterators marking a
747 * matched subexpression within a regular expression pattern match. Such
748 * objects can be converted to and compared with std::basic_string objects
749 * of a similar base character type as the pattern matched by the regular
752 * The iterators that make up the pair are the usual half-open interval
753 * referencing the actual original pattern matched.
755 template<typename _BiIter>
756 class sub_match : public std::pair<_BiIter, _BiIter>
759 typedef typename iterator_traits<_BiIter>::value_type value_type;
760 typedef typename iterator_traits<_BiIter>::difference_type
762 typedef _BiIter iterator;
763 typedef std::basic_string<value_type> string_type;
769 * Gets the length of the matching sequence.
773 { return this->matched ? std::distance(this->first, this->second) : 0; }
776 * @brief Gets the matching sequence as a string.
778 * @returns the matching sequence as a string.
780 * This is the implicit conversion operator. It is identical to the
781 * str() member function except that it will want to pop up in
782 * unexpected places and cause a great deal of confusion and cursing
785 operator string_type() const
788 ? string_type(this->first, this->second)
793 * @brief Gets the matching sequence as a string.
795 * @returns the matching sequence as a string.
801 ? string_type(this->first, this->second)
806 * @brief Compares this and another matched sequence.
808 * @param s Another matched sequence to compare to this one.
810 * @retval <0 this matched sequence will collate before @p s.
811 * @retval =0 this matched sequence is equivalent to @p s.
812 * @retval <0 this matched sequence will collate after @p s.
815 compare(const sub_match& __s) const
816 { return this->str().compare(__s.str()); }
819 * @brief Compares this sub_match to a string.
821 * @param s A string to compare to this sub_match.
823 * @retval <0 this matched sequence will collate before @p s.
824 * @retval =0 this matched sequence is equivalent to @p s.
825 * @retval <0 this matched sequence will collate after @p s.
828 compare(const string_type& __s) const
829 { return this->str().compare(__s); }
832 * @brief Compares this sub_match to a C-style string.
834 * @param s A C-style string to compare to this sub_match.
836 * @retval <0 this matched sequence will collate before @p s.
837 * @retval =0 this matched sequence is equivalent to @p s.
838 * @retval <0 this matched sequence will collate after @p s.
841 compare(const value_type* __s) const
842 { return this->str().compare(__s); }
846 /** @brief Standard regex submatch over a C-style null-terminated string. */
847 typedef sub_match<const char*> csub_match;
848 /** @brief Standard regex submatch over a standard string. */
849 typedef sub_match<string::const_iterator> ssub_match;
850 #ifdef _GLIBCXX_USE_WCHAR_T
851 /** @brief Regex submatch over a C-style null-terminated wide string. */
852 typedef sub_match<const wchar_t*> wcsub_match;
853 /** @brief Regex submatch over a standard wide string. */
854 typedef sub_match<wstring::const_iterator> wssub_match;
857 // [7.9.2] sub_match non-member operators
860 * @brief Tests the equivalence of two regular expression submatches.
861 * @param lhs First regular expression submatch.
862 * @param rhs Second regular expression submatch.
863 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
865 template<typename _BiIter>
867 operator==(const sub_match<_BiIter>& __lhs,
868 const sub_match<_BiIter>& __rhs)
869 { return __lhs.compare(__rhs) == 0; }
872 * @brief Tests the inequivalence of two regular expression submatches.
873 * @param lhs First regular expression submatch.
874 * @param rhs Second regular expression submatch.
875 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
877 template<typename _BiIter>
879 operator!=(const sub_match<_BiIter>& __lhs,
880 const sub_match<_BiIter>& __rhs)
881 { return __lhs.compare(__rhs) != 0; }
884 * @brief Tests the ordering of two regular expression submatches.
885 * @param lhs First regular expression submatch.
886 * @param rhs Second regular expression submatch.
887 * @returns true if @a lhs precedes @a rhs, false otherwise.
889 template<typename _BiIter>
891 operator<(const sub_match<_BiIter>& __lhs,
892 const sub_match<_BiIter>& __rhs)
893 { return __lhs.compare(__rhs) < 0; }
896 * @brief Tests the ordering of two regular expression submatches.
897 * @param lhs First regular expression submatch.
898 * @param rhs Second regular expression submatch.
899 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
901 template<typename _BiIter>
903 operator<=(const sub_match<_BiIter>& __lhs,
904 const sub_match<_BiIter>& __rhs)
905 { return __lhs.compare(__rhs) <= 0; }
908 * @brief Tests the ordering of two regular expression submatches.
909 * @param lhs First regular expression submatch.
910 * @param rhs Second regular expression submatch.
911 * @returns true if @a lhs does not precede @a rhs, false otherwise.
913 template<typename _BiIter>
915 operator>=(const sub_match<_BiIter>& __lhs,
916 const sub_match<_BiIter>& __rhs)
917 { return __lhs.compare(__rhs) >= 0; }
920 * @brief Tests the ordering of two regular expression submatches.
921 * @param lhs First regular expression submatch.
922 * @param rhs Second regular expression submatch.
923 * @returns true if @a lhs succeeds @a rhs, false otherwise.
925 template<typename _BiIter>
927 operator>(const sub_match<_BiIter>& __lhs,
928 const sub_match<_BiIter>& __rhs)
929 { return __lhs.compare(__rhs) > 0; }
932 * @brief Tests the equivalence of a string and a regular expression
934 * @param lhs A string.
935 * @param rhs A regular expression submatch.
936 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
938 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
940 operator==(const basic_string<
941 typename iterator_traits<_Bi_iter>::value_type,
942 _Ch_traits, _Ch_alloc>& __lhs,
943 const sub_match<_Bi_iter>& __rhs)
944 { return __lhs == __rhs.str(); }
947 * @brief Tests the inequivalence of a string and a regular expression
949 * @param lhs A string.
950 * @param rhs A regular expression submatch.
951 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
953 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
955 operator!=(const basic_string<
956 typename iterator_traits<_Bi_iter>::value_type,
957 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
958 { return __lhs != __rhs.str(); }
961 * @brief Tests the ordering of a string and a regular expression submatch.
962 * @param lhs A string.
963 * @param rhs A regular expression submatch.
964 * @returns true if @a lhs precedes @a rhs, false otherwise.
966 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
968 operator<(const basic_string<
969 typename iterator_traits<_Bi_iter>::value_type,
970 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
971 { return __lhs < __rhs.str(); }
974 * @brief Tests the ordering of a string and a regular expression submatch.
975 * @param lhs A string.
976 * @param rhs A regular expression submatch.
977 * @returns true if @a lhs succeeds @a rhs, false otherwise.
979 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
981 operator>(const basic_string<
982 typename iterator_traits<_Bi_iter>::value_type,
983 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
984 { return __lhs > __rhs.str(); }
987 * @brief Tests the ordering of a string and a regular expression submatch.
988 * @param lhs A string.
989 * @param rhs A regular expression submatch.
990 * @returns true if @a lhs does not precede @a rhs, false otherwise.
992 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
994 operator>=(const basic_string<
995 typename iterator_traits<_Bi_iter>::value_type,
996 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
997 { return __lhs >= __rhs.str(); }
1000 * @brief Tests the ordering of a string and a regular expression submatch.
1001 * @param lhs A string.
1002 * @param rhs A regular expression submatch.
1003 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1005 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1007 operator<=(const basic_string<
1008 typename iterator_traits<_Bi_iter>::value_type,
1009 _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
1010 { return __lhs <= __rhs.str(); }
1013 * @brief Tests the equivalence of a regular expression submatch and a
1015 * @param lhs A regular expression submatch.
1016 * @param rhs A string.
1017 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1019 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1021 operator==(const sub_match<_Bi_iter>& __lhs,
1023 typename iterator_traits<_Bi_iter>::value_type,
1024 _Ch_traits, _Ch_alloc>& __rhs)
1025 { return __lhs.str() == __rhs; }
1028 * @brief Tests the inequivalence of a regular expression submatch and a
1030 * @param lhs A regular expression submatch.
1031 * @param rhs A string.
1032 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1034 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1036 operator!=(const sub_match<_Bi_iter>& __lhs,
1038 typename iterator_traits<_Bi_iter>::value_type,
1039 _Ch_traits, _Ch_alloc>& __rhs)
1040 { return __lhs.str() != __rhs; }
1043 * @brief Tests the ordering of a regular expression submatch and a string.
1044 * @param lhs A regular expression submatch.
1045 * @param rhs A string.
1046 * @returns true if @a lhs precedes @a rhs, false otherwise.
1048 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1050 operator<(const sub_match<_Bi_iter>& __lhs,
1052 typename iterator_traits<_Bi_iter>::value_type,
1053 _Ch_traits, _Ch_alloc>& __rhs)
1054 { return __lhs.str() < __rhs; }
1057 * @brief Tests the ordering of a regular expression submatch and a string.
1058 * @param lhs A regular expression submatch.
1059 * @param rhs A string.
1060 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1062 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1064 operator>(const sub_match<_Bi_iter>& __lhs,
1066 typename iterator_traits<_Bi_iter>::value_type,
1067 _Ch_traits, _Ch_alloc>& __rhs)
1068 { return __lhs.str() > __rhs; }
1071 * @brief Tests the ordering of a regular expression submatch and a string.
1072 * @param lhs A regular expression submatch.
1073 * @param rhs A string.
1074 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1076 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1078 operator>=(const sub_match<_Bi_iter>& __lhs,
1080 typename iterator_traits<_Bi_iter>::value_type,
1081 _Ch_traits, _Ch_alloc>& __rhs)
1082 { return __lhs.str() >= __rhs; }
1085 * @brief Tests the ordering of a regular expression submatch and a string.
1086 * @param lhs A regular expression submatch.
1087 * @param rhs A string.
1088 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1090 template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
1092 operator<=(const sub_match<_Bi_iter>& __lhs,
1094 typename iterator_traits<_Bi_iter>::value_type,
1095 _Ch_traits, _Ch_alloc>& __rhs)
1096 { return __lhs.str() <= __rhs; }
1099 * @brief Tests the equivalence of a C string and a regular expression
1101 * @param lhs A C string.
1102 * @param rhs A regular expression submatch.
1103 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1105 template<typename _Bi_iter>
1107 operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1108 const sub_match<_Bi_iter>& __rhs)
1109 { return __lhs == __rhs.str(); }
1112 * @brief Tests the inequivalence of an iterator value and a regular
1113 * expression submatch.
1114 * @param lhs A regular expression submatch.
1115 * @param rhs A string.
1116 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1118 template<typename _Bi_iter>
1120 operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1121 const sub_match<_Bi_iter>& __rhs)
1122 { return __lhs != __rhs.str(); }
1125 * @brief Tests the ordering of a string and a regular expression submatch.
1126 * @param lhs A string.
1127 * @param rhs A regular expression submatch.
1128 * @returns true if @a lhs precedes @a rhs, false otherwise.
1130 template<typename _Bi_iter>
1132 operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1133 const sub_match<_Bi_iter>& __rhs)
1134 { return __lhs < __rhs.str(); }
1137 * @brief Tests the ordering of a string and a regular expression submatch.
1138 * @param lhs A string.
1139 * @param rhs A regular expression submatch.
1140 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1142 template<typename _Bi_iter>
1144 operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1145 const sub_match<_Bi_iter>& __rhs)
1146 { return __lhs > __rhs.str(); }
1149 * @brief Tests the ordering of a string and a regular expression submatch.
1150 * @param lhs A string.
1151 * @param rhs A regular expression submatch.
1152 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1154 template<typename _Bi_iter>
1156 operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1157 const sub_match<_Bi_iter>& __rhs)
1158 { return __lhs >= __rhs.str(); }
1161 * @brief Tests the ordering of a string and a regular expression submatch.
1162 * @param lhs A string.
1163 * @param rhs A regular expression submatch.
1164 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1166 template<typename _Bi_iter>
1168 operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1169 const sub_match<_Bi_iter>& __rhs)
1170 { return __lhs <= __rhs.str(); }
1173 * @brief Tests the equivalence of a regular expression submatch and a
1175 * @param lhs A regular expression submatch.
1176 * @param rhs A pointer to a string?
1177 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1179 template<typename _Bi_iter>
1181 operator==(const sub_match<_Bi_iter>& __lhs,
1182 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1183 { return __lhs.str() == __rhs; }
1186 * @brief Tests the inequivalence of a regular expression submatch and a
1188 * @param lhs A regular expression submatch.
1189 * @param rhs A pointer to a string.
1190 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1192 template<typename _Bi_iter>
1194 operator!=(const sub_match<_Bi_iter>& __lhs,
1195 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1196 { return __lhs.str() != __rhs; }
1199 * @brief Tests the ordering of a regular expression submatch and a string.
1200 * @param lhs A regular expression submatch.
1201 * @param rhs A string.
1202 * @returns true if @a lhs precedes @a rhs, false otherwise.
1204 template<typename _Bi_iter>
1206 operator<(const sub_match<_Bi_iter>& __lhs,
1207 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1208 { return __lhs.str() < __rhs; }
1211 * @brief Tests the ordering of a regular expression submatch and a string.
1212 * @param lhs A regular expression submatch.
1213 * @param rhs A string.
1214 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1216 template<typename _Bi_iter>
1218 operator>(const sub_match<_Bi_iter>& __lhs,
1219 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1220 { return __lhs.str() > __rhs; }
1223 * @brief Tests the ordering of a regular expression submatch and a string.
1224 * @param lhs A regular expression submatch.
1225 * @param rhs A string.
1226 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1228 template<typename _Bi_iter>
1230 operator>=(const sub_match<_Bi_iter>& __lhs,
1231 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1232 { return __lhs.str() >= __rhs; }
1235 * @brief Tests the ordering of a regular expression submatch and a string.
1236 * @param lhs A regular expression submatch.
1237 * @param rhs A string.
1238 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1240 template<typename _Bi_iter>
1242 operator<=(const sub_match<_Bi_iter>& __lhs,
1243 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1244 { return __lhs.str() <= __rhs; }
1247 * @brief Tests the equivalence of a string and a regular expression
1249 * @param lhs A string.
1250 * @param rhs A regular expression submatch.
1251 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1253 template<typename _Bi_iter>
1255 operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1256 const sub_match<_Bi_iter>& __rhs)
1257 { return __lhs == __rhs.str(); }
1260 * @brief Tests the inequivalence of a string and a regular expression
1262 * @param lhs A string.
1263 * @param rhs A regular expression submatch.
1264 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1266 template<typename _Bi_iter>
1268 operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1269 const sub_match<_Bi_iter>& __rhs)
1270 { return __lhs != __rhs.str(); }
1273 * @brief Tests the ordering of a string and a regular expression submatch.
1274 * @param lhs A string.
1275 * @param rhs A regular expression submatch.
1276 * @returns true if @a lhs precedes @a rhs, false otherwise.
1278 template<typename _Bi_iter>
1280 operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1281 const sub_match<_Bi_iter>& __rhs)
1282 { return __lhs < __rhs.str(); }
1285 * @brief Tests the ordering of a string and a regular expression submatch.
1286 * @param lhs A string.
1287 * @param rhs A regular expression submatch.
1288 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1290 template<typename _Bi_iter>
1292 operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1293 const sub_match<_Bi_iter>& __rhs)
1294 { return __lhs > __rhs.str(); }
1297 * @brief Tests the ordering of a string and a regular expression submatch.
1298 * @param lhs A string.
1299 * @param rhs A regular expression submatch.
1300 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1302 template<typename _Bi_iter>
1304 operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1305 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 does not succeed @a rhs, false otherwise.
1314 template<typename _Bi_iter>
1316 operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1317 const sub_match<_Bi_iter>& __rhs)
1318 { return __lhs <= __rhs.str(); }
1321 * @brief Tests the equivalence of a regular expression submatch and a
1323 * @param lhs A regular expression submatch.
1324 * @param rhs A const string reference.
1325 * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
1327 template<typename _Bi_iter>
1329 operator==(const sub_match<_Bi_iter>& __lhs,
1330 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1331 { return __lhs.str() == __rhs; }
1334 * @brief Tests the inequivalence of a regular expression submatch and a
1336 * @param lhs A regular expression submatch.
1337 * @param rhs A const string reference.
1338 * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
1340 template<typename _Bi_iter>
1342 operator!=(const sub_match<_Bi_iter>& __lhs,
1343 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1344 { return __lhs.str() != __rhs; }
1347 * @brief Tests the ordering of a regular expression submatch and a string.
1348 * @param lhs A regular expression submatch.
1349 * @param rhs A const string reference.
1350 * @returns true if @a lhs precedes @a rhs, false otherwise.
1352 template<typename _Bi_iter>
1354 operator<(const sub_match<_Bi_iter>& __lhs,
1355 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1356 { return __lhs.str() < __rhs; }
1359 * @brief Tests the ordering of a regular expression submatch and a string.
1360 * @param lhs A regular expression submatch.
1361 * @param rhs A const string reference.
1362 * @returns true if @a lhs succeeds @a rhs, false otherwise.
1364 template<typename _Bi_iter>
1366 operator>(const sub_match<_Bi_iter>& __lhs,
1367 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1368 { return __lhs.str() > __rhs; }
1371 * @brief Tests the ordering of a regular expression submatch and a string.
1372 * @param lhs A regular expression submatch.
1373 * @param rhs A const string reference.
1374 * @returns true if @a lhs does not precede @a rhs, false otherwise.
1376 template<typename _Bi_iter>
1378 operator>=(const sub_match<_Bi_iter>& __lhs,
1379 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1380 { return __lhs.str() >= __rhs; }
1383 * @brief Tests the ordering of a regular expression submatch and a string.
1384 * @param lhs A regular expression submatch.
1385 * @param rhs A const string reference.
1386 * @returns true if @a lhs does not succeed @a rhs, false otherwise.
1388 template<typename _Bi_iter>
1390 operator<=(const sub_match<_Bi_iter>& __lhs,
1391 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1392 { return __lhs.str() <= __rhs; }
1395 * @brief Inserts a matched string into an output stream.
1397 * @param os The output stream.
1398 * @param m A submatch string.
1400 * @returns the output stream with the submatch string inserted.
1402 template<typename _Ch_type, typename _Ch_traits, typename _Bi_iter>
1404 basic_ostream<_Ch_type, _Ch_traits>&
1405 operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os,
1406 const sub_match<_Bi_iter>& __m)
1407 { return __os << __m.str(); }
1409 // [7.10] Class template match_results
1412 * Special sub_match object representing an unmatched sub-expression.
1414 template<typename _Bi_iter>
1415 inline const sub_match<_Bi_iter>&
1418 static const sub_match<_Bi_iter> __unmatched = sub_match<_Bi_iter>();
1423 * @brief The results of a match or search operation.
1425 * A collection of character sequences representing the result of a regular
1426 * expression match. Storage for the collection is allocated and freed as
1427 * necessary by the member functions of class template match_results.
1429 * This class satisfies the Sequence requirements, with the exception that
1430 * only the operations defined for a const-qualified Sequence are supported.
1432 * The sub_match object stored at index 0 represents sub-expression 0, i.e.
1433 * the whole match. In this case the %sub_match member matched is always true.
1434 * The sub_match object stored at index n denotes what matched the marked
1435 * sub-expression n within the matched expression. If the sub-expression n
1436 * participated in a regular expression match then the %sub_match member
1437 * matched evaluates to true, and members first and second denote the range
1438 * of characters [first, second) which formed that match. Otherwise matched
1439 * is false, and members first and second point to the end of the sequence
1440 * that was searched.
1444 template<typename _Bi_iter,
1445 typename _Allocator = allocator<sub_match<_Bi_iter> > >
1447 : private std::vector<std::sub_match<_Bi_iter>, _Allocator>
1451 * The vector base is empty if this does not represent a successful match.
1452 * Otherwise it contains n+3 elements where n is the number of marked
1455 * [1] 1st marked subexpression
1457 * [n] nth marked subexpression
1461 typedef std::vector<std::sub_match<_Bi_iter>, _Allocator>
1466 * @name 10.? Public Types
1469 typedef sub_match<_Bi_iter> value_type;
1470 typedef const value_type& const_reference;
1471 typedef const_reference reference;
1472 typedef typename _Base_type::const_iterator const_iterator;
1473 typedef const_iterator iterator;
1474 typedef typename std::iterator_traits<_Bi_iter>::difference_type
1476 /* TODO: needs allocator_traits */
1477 typedef typename _Allocator::size_type size_type;
1478 typedef _Allocator allocator_type;
1479 typedef typename std::iterator_traits<_Bi_iter>::value_type
1481 typedef std::basic_string<char_type> string_type;
1486 * @name 10.1 Construction, Copying, and Destruction
1491 * @brief Constructs a default %match_results container.
1492 * @post size() returns 0 and str() returns an empty string.
1495 match_results(const _Allocator& __a = _Allocator())
1500 * @brief Copy constructs a %match_results.
1502 match_results(const match_results& __rhs)
1507 * @brief Assigns rhs to *this.
1510 operator=(const match_results __rhs)
1512 match_results(__rhs).swap(*this);
1517 * @brief Destroys a %match_results object.
1530 * @brief Gets the number of matches and submatches.
1532 * The number of matches for a given regular expression will be either 0
1533 * if there was no match or mark_count() + 1 if a match was successful.
1534 * Some matches may be empty.
1536 * @returns the number of matches found.
1541 size_type __size = _Base_type::size();
1542 return (__size && _Base_type::operator[](0).matched) ? __size - 2 : 0;
1547 { return _Base_type::max_size(); }
1550 * @brief Indicates if the %match_results contains no results.
1551 * @retval true The %match_results object is empty.
1552 * @retval false The %match_results object is not empty.
1556 { return _Base_type::empty(); }
1561 * @name 10.3 Element Access
1566 * @brief Gets the length of the indicated submatch.
1567 * @param sub indicates the submatch.
1569 * This function returns the length of the indicated submatch, or the
1570 * length of the entire match if @p sub is zero (the default).
1573 length(size_type __sub = 0) const
1574 { return this[__sub].length(); }
1577 * @brief Gets the offset of the beginning of the indicated submatch.
1578 * @param sub indicates the submatch.
1580 * This function returns the offset from the beginning of the target
1581 * sequence to the beginning of the submatch, unless the value of @p sub
1582 * is zero (the default), in which case this function returns the offset
1583 * from the beginning of the target sequence to the beginning of the
1586 * Returns -1 if @p sub is out of range.
1589 position(size_type __sub = 0) const
1591 return __sub < size() ? std::distance(this->prefix().first,
1592 (*this)[__sub].first) : -1;
1596 * @brief Gets the match or submatch converted to a string type.
1597 * @param sub indicates the submatch.
1599 * This function gets the submatch (or match, if @p sub is zero) extracted
1600 * from the target range and converted to the associated string type.
1603 str(size_type __sub = 0) const
1604 { return (*this)[__sub].str(); }
1607 * @brief Gets a %sub_match reference for the match or submatch.
1608 * @param sub indicates the submatch.
1610 * This function gets a reference to the indicated submatch, or the entire
1611 * match if @p sub is zero.
1613 * If @p sub >= size() then this function returns a %sub_match with a
1614 * special value indicating no submatch.
1617 operator[](size_type __sub) const
1619 return __sub < size()
1620 ? _Base_type::operator[](__sub)
1621 : __unmatched_sub<_Bi_iter>();
1625 * @brief Gets a %sub_match representing the match prefix.
1627 * This function gets a reference to a %sub_match object representing the
1628 * part of the target range between the start of the target range and the
1629 * start of the match.
1635 ? _Base_type::operator[](_Base_type::size() - 2)
1636 : __unmatched_sub<_Bi_iter>();
1640 * @brief Gets a %sub_match representing the match suffix.
1642 * This function gets a reference to a %sub_match object representing the
1643 * part of the target range between the end of the match and the end of
1650 ? _Base_type::operator[](_Base_type::size() - 1)
1651 : __unmatched_sub<_Bi_iter>();
1655 * @brief Gets an iterator to the start of the %sub_match collection.
1659 { return _Base_type::begin(); }
1662 * @brief Gets an iterator to the start of the %sub_match collection.
1666 { return _Base_type::cbegin(); }
1669 * @brief Gets an iterator to one-past-the-end of the collection.
1675 ? _Base_type::end() - 2
1676 : _Base_type::end();
1680 * @brief Gets an iterator to one-past-the-end of the collection.
1686 ? _Base_type::cend() - 2
1687 : _Base_type::cend();
1693 * @name 10.4 Formatting
1695 * These functions perform formatted substitution of the matched character
1696 * sequences into their target. The format specifiers and escape sequences
1697 * accepted by these functions are determined by their @p flags parameter
1698 * as documented above.
1703 * @todo Implement this function.
1705 template<typename _Out_iter>
1707 format(_Out_iter __out, const string_type& __fmt,
1708 regex_constants::match_flag_type __flags
1709 = regex_constants::format_default) const
1713 * @todo Implement this function.
1716 format(const string_type& __fmt,
1717 regex_constants::match_flag_type __flags
1718 = regex_constants::format_default) const;
1723 * @name 10.5 Allocator
1728 * @brief Gets a copy of the allocator.
1731 get_allocator() const
1732 { return _Base_type::get_allocator(); }
1742 * @brief Swaps the contents of two match_results.
1745 swap(match_results& __that)
1746 { _Base_type::swap(__that); }
1750 friend class __regex::_SpecializedResults<_Bi_iter, _Allocator>;
1753 typedef match_results<const char*> cmatch;
1754 typedef match_results<string::const_iterator> smatch;
1755 #ifdef _GLIBCXX_USE_WCHAR_T
1756 typedef match_results<const wchar_t*> wcmatch;
1757 typedef match_results<wstring::const_iterator> wsmatch;
1760 // match_results comparisons
1762 * @brief Compares two match_results for equality.
1763 * @returns true if the two objects refer to the same match,
1765 * @todo Implement this function.
1767 template<typename _Bi_iter, typename _Allocator>
1769 operator==(const match_results<_Bi_iter, _Allocator>& __m1,
1770 const match_results<_Bi_iter, _Allocator>& __m2);
1773 * @brief Compares two match_results for inequality.
1774 * @returns true if the two objects do not refer to the same match,
1777 template<typename _Bi_iter, class _Allocator>
1779 operator!=(const match_results<_Bi_iter, _Allocator>& __m1,
1780 const match_results<_Bi_iter, _Allocator>& __m2)
1781 { return !(__m1 == __m2); }
1783 // [7.10.6] match_results swap
1785 * @brief Swaps two match results.
1786 * @param lhs A match result.
1787 * @param rhs A match result.
1789 * The contents of the two match_results objects are swapped.
1791 template<typename _Bi_iter, typename _Allocator>
1793 swap(match_results<_Bi_iter, _Allocator>& __lhs,
1794 match_results<_Bi_iter, _Allocator>& __rhs)
1795 { __lhs.swap(__rhs); }
1797 // [7.11.2] Function template regex_match
1799 * @name Matching, Searching, and Replacing
1804 * @brief Determines if there is a match between the regular expression @p e
1805 * and all of the character sequence [first, last).
1807 * @param s Start of the character sequence to match.
1808 * @param e One-past-the-end of the character sequence to match.
1809 * @param m The match results.
1810 * @param re The regular expression.
1811 * @param flags Controls how the regular expression is matched.
1813 * @retval true A match exists.
1814 * @retval false Otherwise.
1816 * @throws an exception of type regex_error.
1818 * @todo Implement this function.
1820 template<typename _Bi_iter, typename _Allocator,
1821 typename _Ch_type, typename _Rx_traits>
1823 regex_match(_Bi_iter __s,
1825 match_results<_Bi_iter, _Allocator>& __m,
1826 const basic_regex<_Ch_type, _Rx_traits>& __re,
1827 regex_constants::match_flag_type __flags
1828 = regex_constants::match_default)
1830 __regex::_AutomatonPtr __a = __re._M_get_automaton();
1831 __regex::_Automaton::_SizeT __sz = __a->_M_sub_count();
1832 __regex::_SpecializedCursor<_Bi_iter> __cs(__s, __e);
1833 __regex::_SpecializedResults<_Bi_iter, _Allocator> __r(__sz, __cs, __m);
1834 __regex::_Grep_matcher __matcher(__cs, __r, __a, __flags);
1835 return __m[0].matched;
1839 * @brief Indicates if there is a match between the regular expression @p e
1840 * and all of the character sequence [first, last).
1842 * @param first Beginning of the character sequence to match.
1843 * @param last One-past-the-end of the character sequence to match.
1844 * @param re The regular expression.
1845 * @param flags Controls how the regular expression is matched.
1847 * @retval true A match exists.
1848 * @retval false Otherwise.
1850 * @throws an exception of type regex_error.
1852 template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
1854 regex_match(_Bi_iter __first, _Bi_iter __last,
1855 const basic_regex<_Ch_type, _Rx_traits>& __re,
1856 regex_constants::match_flag_type __flags
1857 = regex_constants::match_default)
1859 match_results<_Bi_iter> __what;
1860 return regex_match(__first, __last, __what, __re, __flags);
1864 * @brief Determines if there is a match between the regular expression @p e
1865 * and a C-style null-terminated string.
1867 * @param s The C-style null-terminated string to match.
1868 * @param m The match results.
1869 * @param re The regular expression.
1870 * @param f Controls how the regular expression is matched.
1872 * @retval true A match exists.
1873 * @retval false Otherwise.
1875 * @throws an exception of type regex_error.
1877 template<typename _Ch_type, typename _Allocator, typename _Rx_traits>
1879 regex_match(const _Ch_type* __s,
1880 match_results<const _Ch_type*, _Allocator>& __m,
1881 const basic_regex<_Ch_type, _Rx_traits>& __re,
1882 regex_constants::match_flag_type __f
1883 = regex_constants::match_default)
1884 { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); }
1887 * @brief Determines if there is a match between the regular expression @p e
1890 * @param s The string to match.
1891 * @param m The match results.
1892 * @param re The regular expression.
1893 * @param flags Controls how the regular expression is matched.
1895 * @retval true A match exists.
1896 * @retval false Otherwise.
1898 * @throws an exception of type regex_error.
1900 template<typename _Ch_traits, typename _Ch_alloc,
1901 typename _Allocator, typename _Ch_type, typename _Rx_traits>
1903 regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
1904 match_results<typename basic_string<_Ch_type,
1905 _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
1906 const basic_regex<_Ch_type, _Rx_traits>& __re,
1907 regex_constants::match_flag_type __flags
1908 = regex_constants::match_default)
1909 { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }
1912 * @brief Indicates if there is a match between the regular expression @p e
1913 * and a C-style null-terminated string.
1915 * @param s The C-style null-terminated string to match.
1916 * @param re The regular expression.
1917 * @param f Controls how the regular expression is matched.
1919 * @retval true A match exists.
1920 * @retval false Otherwise.
1922 * @throws an exception of type regex_error.
1924 template<typename _Ch_type, class _Rx_traits>
1926 regex_match(const _Ch_type* __s,
1927 const basic_regex<_Ch_type, _Rx_traits>& __re,
1928 regex_constants::match_flag_type __f
1929 = regex_constants::match_default)
1930 { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); }
1933 * @brief Indicates if there is a match between the regular expression @p e
1936 * @param s [IN] The string to match.
1937 * @param re [IN] The regular expression.
1938 * @param flags [IN] Controls how the regular expression is matched.
1940 * @retval true A match exists.
1941 * @retval false Otherwise.
1943 * @throws an exception of type regex_error.
1945 template<typename _Ch_traits, typename _Str_allocator,
1946 typename _Ch_type, typename _Rx_traits>
1948 regex_match(const basic_string<_Ch_type, _Ch_traits, _Str_allocator>& __s,
1949 const basic_regex<_Ch_type, _Rx_traits>& __re,
1950 regex_constants::match_flag_type __flags
1951 = regex_constants::match_default)
1952 { return regex_match(__s.begin(), __s.end(), __re, __flags); }
1954 // [7.11.3] Function template regex_search
1956 * Searches for a regular expression within a range.
1957 * @param first [IN] The start of the string to search.
1958 * @param last [IN] One-past-the-end of the string to search.
1959 * @param m [OUT] The match results.
1960 * @param re [IN] The regular expression to search for.
1961 * @param flags [IN] Search policy flags.
1962 * @retval true A match was found within the string.
1963 * @retval false No match was found within the string, the content of %m is
1966 * @throws an exception of type regex_error.
1968 * @todo Implement this function.
1970 template<typename _Bi_iter, typename _Allocator,
1971 typename _Ch_type, typename _Rx_traits>
1973 regex_search(_Bi_iter __first, _Bi_iter __last,
1974 match_results<_Bi_iter, _Allocator>& __m,
1975 const basic_regex<_Ch_type, _Rx_traits>& __re,
1976 regex_constants::match_flag_type __flags
1977 = regex_constants::match_default)
1981 * Searches for a regular expression within a range.
1982 * @param first [IN] The start of the string to search.
1983 * @param last [IN] One-past-the-end of the string to search.
1984 * @param re [IN] The regular expression to search for.
1985 * @param flags [IN] Search policy flags.
1986 * @retval true A match was found within the string.
1987 * @retval false No match was found within the string.
1990 * @throws an exception of type regex_error.
1992 template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
1994 regex_search(_Bi_iter __first, _Bi_iter __last,
1995 const basic_regex<_Ch_type, _Rx_traits>& __re,
1996 regex_constants::match_flag_type __flags
1997 = regex_constants::match_default)
1999 match_results<_Bi_iter> __what;
2000 return regex_search(__first, __last, __what, __re, __flags);
2004 * @brief Searches for a regular expression within a C-string.
2005 * @param s [IN] A C-string to search for the regex.
2006 * @param m [OUT] The set of regex matches.
2007 * @param e [IN] The regex to search for in @p s.
2008 * @param f [IN] The search flags.
2009 * @retval true A match was found within the string.
2010 * @retval false No match was found within the string, the content of %m is
2014 * @throws an exception of type regex_error.
2016 template<typename _Ch_type, class _Allocator, class _Rx_traits>
2018 regex_search(const _Ch_type* __s,
2019 match_results<const _Ch_type*, _Allocator>& __m,
2020 const basic_regex<_Ch_type, _Rx_traits>& __e,
2021 regex_constants::match_flag_type __f
2022 = regex_constants::match_default)
2023 { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
2026 * @brief Searches for a regular expression within a C-string.
2027 * @param s [IN] The C-string to search.
2028 * @param e [IN] The regular expression to search for.
2029 * @param f [IN] Search policy flags.
2030 * @retval true A match was found within the string.
2031 * @retval false No match was found within the string.
2034 * @throws an exception of type regex_error.
2036 template<typename _Ch_type, typename _Rx_traits>
2038 regex_search(const _Ch_type* __s,
2039 const basic_regex<_Ch_type, _Rx_traits>& __e,
2040 regex_constants::match_flag_type __f
2041 = regex_constants::match_default)
2042 { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); }
2045 * @brief Searches for a regular expression within a string.
2046 * @param s [IN] The string to search.
2047 * @param e [IN] The regular expression to search for.
2048 * @param flags [IN] Search policy flags.
2049 * @retval true A match was found within the string.
2050 * @retval false No match was found within the string.
2053 * @throws an exception of type regex_error.
2055 template<typename _Ch_traits, typename _String_allocator,
2056 typename _Ch_type, typename _Rx_traits>
2058 regex_search(const basic_string<_Ch_type, _Ch_traits,
2059 _String_allocator>& __s,
2060 const basic_regex<_Ch_type, _Rx_traits>& __e,
2061 regex_constants::match_flag_type __flags
2062 = regex_constants::match_default)
2063 { return regex_search(__s.begin(), __s.end(), __e, __flags); }
2066 * @brief Searches for a regular expression within a string.
2067 * @param s [IN] A C++ string to search for the regex.
2068 * @param m [OUT] The set of regex matches.
2069 * @param e [IN] The regex to search for in @p s.
2070 * @param f [IN] The search flags.
2071 * @retval true A match was found within the string.
2072 * @retval false No match was found within the string, the content of %m is
2075 * @throws an exception of type regex_error.
2077 template<typename _Ch_traits, typename _Ch_alloc,
2078 typename _Allocator, typename _Ch_type,
2079 typename _Rx_traits>
2081 regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
2082 match_results<typename basic_string<_Ch_type,
2083 _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
2084 const basic_regex<_Ch_type, _Rx_traits>& __e,
2085 regex_constants::match_flag_type __f
2086 = regex_constants::match_default)
2087 { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
2089 // std [28.11.4] Function template regex_replace
2100 * @throws an exception of type regex_error.
2102 * @todo Implement this function.
2104 template<typename _Out_iter, typename _Bi_iter,
2105 typename _Rx_traits, typename _Ch_type>
2107 regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
2108 const basic_regex<_Ch_type, _Rx_traits>& __e,
2109 const basic_string<_Ch_type>& __fmt,
2110 regex_constants::match_flag_type __flags
2111 = regex_constants::match_default)
2121 * @returns a copy of string @p s with replacements.
2123 * @throws an exception of type regex_error.
2125 template<typename _Rx_traits, typename _Ch_type>
2126 inline basic_string<_Ch_type>
2127 regex_replace(const basic_string<_Ch_type>& __s,
2128 const basic_regex<_Ch_type, _Rx_traits>& __e,
2129 const basic_string<_Ch_type>& __fmt,
2130 regex_constants::match_flag_type __flags
2131 = regex_constants::match_default)
2133 std::string __result;
2134 regex_replace(std::back_inserter(__result),
2135 __s.begin(), __s.end(), __e, __fmt, __flags);
2141 // std [28.12] Class template regex_iterator
2143 * An iterator adaptor that will provide repeated calls of regex_search over
2144 * a range until no more matches remain.
2146 template<typename _Bi_iter,
2147 typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2148 typename _Rx_traits = regex_traits<_Ch_type> >
2149 class regex_iterator
2152 typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
2153 typedef match_results<_Bi_iter> value_type;
2154 typedef std::ptrdiff_t difference_type;
2155 typedef const value_type* pointer;
2156 typedef const value_type& reference;
2157 typedef std::forward_iterator_tag iterator_category;
2161 * @brief Provides a singular iterator, useful for indicating
2162 * one-past-the-end of a range.
2163 * @todo Implement this function.
2169 * Constructs a %regex_iterator...
2170 * @param a [IN] The start of a text range to search.
2171 * @param b [IN] One-past-the-end of the text range to search.
2172 * @param re [IN] The regular expression to match.
2173 * @param m [IN] Policy flags for match rules.
2174 * @todo Implement this function.
2177 regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2178 regex_constants::match_flag_type __m
2179 = regex_constants::match_default);
2182 * Copy constructs a %regex_iterator.
2183 * @todo Implement this function.
2186 regex_iterator(const regex_iterator& __rhs);
2189 * @todo Implement this function.
2193 operator=(const regex_iterator& __rhs);
2196 * @todo Implement this function.
2200 operator==(const regex_iterator& __rhs);
2203 * @todo Implement this function.
2207 operator!=(const regex_iterator& __rhs);
2210 * @todo Implement this function.
2217 * @todo Implement this function.
2224 * @todo Implement this function.
2231 * @todo Implement this function.
2238 // these members are shown for exposition only:
2241 const regex_type* pregex;
2242 regex_constants::match_flag_type flags;
2243 match_results<_Bi_iter> match;
2246 typedef regex_iterator<const char*> cregex_iterator;
2247 typedef regex_iterator<string::const_iterator> sregex_iterator;
2248 #ifdef _GLIBCXX_USE_WCHAR_T
2249 typedef regex_iterator<const wchar_t*> wcregex_iterator;
2250 typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
2253 // [7.12.2] Class template regex_token_iterator
2255 * Iterates over submatches in a range (or @a splits a text string).
2257 * The purpose of this iterator is to enumerate all, or all specified,
2258 * matches of a regular expression within a text range. The dereferenced
2259 * value of an iterator of this class is a std::sub_match object.
2261 template<typename _Bi_iter,
2262 typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2263 typename _Rx_traits = regex_traits<_Ch_type> >
2264 class regex_token_iterator
2267 typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
2268 typedef sub_match<_Bi_iter> value_type;
2269 typedef std::ptrdiff_t difference_type;
2270 typedef const value_type* pointer;
2271 typedef const value_type& reference;
2272 typedef std::forward_iterator_tag iterator_category;
2276 * @brief Default constructs a %regex_token_iterator.
2277 * @todo Implement this function.
2279 * A default-constructed %regex_token_iterator is a singular iterator
2280 * that will compare equal to the one-past-the-end value for any
2281 * iterator of the same type.
2283 regex_token_iterator();
2286 * Constructs a %regex_token_iterator...
2287 * @param a [IN] The start of the text to search.
2288 * @param b [IN] One-past-the-end of the text to search.
2289 * @param re [IN] The regular expression to search for.
2290 * @param submatch [IN] Which submatch to return. There are some
2291 * special values for this parameter:
2292 * - -1 each enumerated subexpression does NOT
2293 * match the regular expression (aka field
2295 * - 0 the entire string matching the
2296 * subexpression is returned for each match
2298 * - >0 enumerates only the indicated
2299 * subexpression from a match within the text.
2300 * @param m [IN] Policy flags for match rules.
2302 * @todo Implement this function.
2305 regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2307 regex_constants::match_flag_type __m
2308 = regex_constants::match_default);
2311 * Constructs a %regex_token_iterator...
2312 * @param a [IN] The start of the text to search.
2313 * @param b [IN] One-past-the-end of the text to search.
2314 * @param re [IN] The regular expression to search for.
2315 * @param submatches [IN] A list of subexpressions to return for each
2316 * regular expression match within the text.
2317 * @param m [IN] Policy flags for match rules.
2319 * @todo Implement this function.
2322 regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2323 const regex_type& __re,
2324 const std::vector<int>& __submatches,
2325 regex_constants::match_flag_type __m
2326 = regex_constants::match_default);
2329 * Constructs a %regex_token_iterator...
2330 * @param a [IN] The start of the text to search.
2331 * @param b [IN] One-past-the-end of the text to search.
2332 * @param re [IN] The regular expression to search for.
2333 * @param submatches [IN] A list of subexpressions to return for each
2334 * regular expression match within the text.
2335 * @param m [IN] Policy flags for match rules.
2337 * @todo Implement this function.
2340 template<std::size_t _Nm>
2341 regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2342 const regex_type& __re,
2343 const int (&__submatches)[_Nm],
2344 regex_constants::match_flag_type __m
2345 = regex_constants::match_default);
2348 * @brief Copy constructs a %regex_token_iterator.
2349 * @param rhs [IN] A %regex_token_iterator to copy.
2350 * @todo Implement this function.
2352 regex_token_iterator(const regex_token_iterator& __rhs);
2355 * @brief Assigns a %regex_token_iterator to another.
2356 * @param rhs [IN] A %regex_token_iterator to copy.
2357 * @todo Implement this function.
2359 regex_token_iterator&
2360 operator=(const regex_token_iterator& __rhs);
2363 * @brief Compares a %regex_token_iterator to another for equality.
2364 * @todo Implement this function.
2367 operator==(const regex_token_iterator& __rhs);
2370 * @brief Compares a %regex_token_iterator to another for inequality.
2371 * @todo Implement this function.
2374 operator!=(const regex_token_iterator& __rhs);
2377 * @brief Dereferences a %regex_token_iterator.
2378 * @todo Implement this function.
2384 * @brief Selects a %regex_token_iterator member.
2385 * @todo Implement this function.
2391 * @brief Increments a %regex_token_iterator.
2392 * @todo Implement this function.
2394 regex_token_iterator&
2398 * @brief Postincrements a %regex_token_iterator.
2399 * @todo Implement this function.
2401 regex_token_iterator
2404 private: // data members for exposition only:
2405 typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> position_iterator;
2407 position_iterator __position;
2408 const value_type* __result;
2409 value_type __suffix;
2411 std::vector<int> __subs;
2414 /** @brief Token iterator for C-style NULL-terminated strings. */
2415 typedef regex_token_iterator<const char*> cregex_token_iterator;
2416 /** @brief Token iterator for standard strings. */
2417 typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
2418 #ifdef _GLIBCXX_USE_WCHAR_T
2419 /** @brief Token iterator for C-style NULL-terminated wide strings. */
2420 typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
2421 /** @brief Token iterator for standard wide-character strings. */
2422 typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;