1 // class template regex -*- C++ -*-
3 // Copyright (C) 2010-2013 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 * Do not attempt to use it directly. @headername{regex}
31 namespace std
_GLIBCXX_VISIBILITY(default)
35 _GLIBCXX_BEGIN_NAMESPACE_VERSION
37 enum class _RegexExecutorPolicy
: int
38 { _S_auto
, _S_alternate
};
40 template<typename _BiIter
, typename _Alloc
,
41 typename _CharT
, typename _TraitsT
,
42 _RegexExecutorPolicy __policy
,
45 __regex_algo_impl(_BiIter __s
,
47 match_results
<_BiIter
, _Alloc
>& __m
,
48 const basic_regex
<_CharT
, _TraitsT
>& __re
,
49 regex_constants::match_flag_type __flags
);
51 _GLIBCXX_END_NAMESPACE_VERSION
54 _GLIBCXX_BEGIN_NAMESPACE_VERSION
62 * @brief Class regex_traits. Describes aspects of a regular expression.
64 * A regular expression traits class that satisfies the requirements of
67 * The class %regex is parameterized around a set of related types and
68 * functions used to complete the definition of its semantics. This class
69 * satisfies the requirements of such a traits class.
71 template<typename _Ch_type
>
75 typedef _Ch_type char_type
;
76 typedef std::basic_string
<char_type
> string_type
;
77 typedef std::locale locale_type
;
81 typedef typename
std::ctype
<char_type
>::mask _BaseType
;
83 unsigned char _M_extended
;
84 static constexpr unsigned char _S_under
= 1 << 0;
85 // FIXME: _S_blank should be removed in the future,
86 // when locale's complete.
87 static constexpr unsigned char _S_blank
= 1 << 1;
88 static constexpr unsigned char _S_valid_mask
= 0x3;
90 constexpr _RegexMask(_BaseType __base
= 0,
91 unsigned char __extended
= 0)
92 : _M_base(__base
), _M_extended(__extended
)
96 operator&(_RegexMask __other
) const
98 return _RegexMask(_M_base
& __other
._M_base
,
99 _M_extended
& __other
._M_extended
);
103 operator|(_RegexMask __other
) const
105 return _RegexMask(_M_base
| __other
._M_base
,
106 _M_extended
| __other
._M_extended
);
110 operator^(_RegexMask __other
) const
112 return _RegexMask(_M_base
^ __other
._M_base
,
113 _M_extended
^ __other
._M_extended
);
118 { return _RegexMask(~_M_base
, ~_M_extended
); }
121 operator&=(_RegexMask __other
)
122 { return *this = (*this) & __other
; }
125 operator|=(_RegexMask __other
)
126 { return *this = (*this) | __other
; }
129 operator^=(_RegexMask __other
)
130 { return *this = (*this) ^ __other
; }
133 operator==(_RegexMask __other
) const
135 return (_M_extended
& _S_valid_mask
)
136 == (__other
._M_extended
& _S_valid_mask
)
137 && _M_base
== __other
._M_base
;
141 operator!=(_RegexMask __other
) const
142 { return !((*this) == __other
); }
146 typedef _RegexMask char_class_type
;
150 * @brief Constructs a default traits object.
155 * @brief Gives the length of a C-style string starting at @p __p.
157 * @param __p a pointer to the start of a character sequence.
159 * @returns the number of characters between @p *__p and the first
160 * default-initialized value of type @p char_type. In other words, uses
161 * the C-string algorithm for determining the length of a sequence of
165 length(const char_type
* __p
)
166 { return string_type::traits_type::length(__p
); }
169 * @brief Performs the identity translation.
171 * @param __c A character to the locale-specific character set.
176 translate(char_type __c
) const
180 * @brief Translates a character into a case-insensitive equivalent.
182 * @param __c A character to the locale-specific character set.
184 * @returns the locale-specific lower-case equivalent of __c.
185 * @throws std::bad_cast if the imbued locale does not support the ctype
189 translate_nocase(char_type __c
) const
191 typedef std::ctype
<char_type
> __ctype_type
;
192 const __ctype_type
& __fctyp(use_facet
<__ctype_type
>(_M_locale
));
193 return __fctyp
.tolower(__c
);
197 * @brief Gets a sort key for a character sequence.
199 * @param __first beginning of the character sequence.
200 * @param __last one-past-the-end of the character sequence.
202 * Returns a sort key for the character sequence designated by the
203 * iterator range [F1, F2) such that if the character sequence [G1, G2)
204 * sorts before the character sequence [H1, H2) then
205 * v.transform(G1, G2) < v.transform(H1, H2).
207 * What this really does is provide a more efficient way to compare a
208 * string to multiple other strings in locales with fancy collation
209 * rules and equivalence classes.
211 * @returns a locale-specific sort key equivalent to the input range.
213 * @throws std::bad_cast if the current locale does not have a collate
216 template<typename _Fwd_iter
>
218 transform(_Fwd_iter __first
, _Fwd_iter __last
) const
220 typedef std::collate
<char_type
> __collate_type
;
221 const __collate_type
& __fclt(use_facet
<__collate_type
>(_M_locale
));
222 string_type
__s(__first
, __last
);
223 return __fclt
.transform(__s
.data(), __s
.data() + __s
.size());
227 * @brief Gets a sort key for a character sequence, independent of case.
229 * @param __first beginning of the character sequence.
230 * @param __last one-past-the-end of the character sequence.
232 * Effects: if typeid(use_facet<collate<_Ch_type> >) ==
233 * typeid(collate_byname<_Ch_type>) and the form of the sort key
234 * returned by collate_byname<_Ch_type>::transform(__first, __last)
235 * is known and can be converted into a primary sort key
236 * then returns that key, otherwise returns an empty string.
238 * @todo Implement this function correctly.
240 template<typename _Fwd_iter
>
242 transform_primary(_Fwd_iter __first
, _Fwd_iter __last
) const
244 // TODO : this is not entirely correct.
245 // This function requires extra support from the platform.
247 // Read http://gcc.gnu.org/ml/libstdc++/2013-09/msg00117.html and
248 // http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2003/n1429.htm
250 typedef std::ctype
<char_type
> __ctype_type
;
251 const __ctype_type
& __fctyp(use_facet
<__ctype_type
>(_M_locale
));
252 std::vector
<char_type
> __s(__first
, __last
);
253 __fctyp
.tolower(__s
.data(), __s
.data() + __s
.size());
254 return this->transform(__s
.data(), __s
.data() + __s
.size());
258 * @brief Gets a collation element by name.
260 * @param __first beginning of the collation element name.
261 * @param __last one-past-the-end of the collation element name.
263 * @returns a sequence of one or more characters that represents the
264 * collating element consisting of the character sequence designated by
265 * the iterator range [__first, __last). Returns an empty string if the
266 * character sequence is not a valid collating element.
268 template<typename _Fwd_iter
>
270 lookup_collatename(_Fwd_iter __first
, _Fwd_iter __last
) const;
273 * @brief Maps one or more characters to a named character
276 * @param __first beginning of the character sequence.
277 * @param __last one-past-the-end of the character sequence.
278 * @param __icase ignores the case of the classification name.
280 * @returns an unspecified value that represents the character
281 * classification named by the character sequence designated by
282 * the iterator range [__first, __last). If @p icase is true,
283 * the returned mask identifies the classification regardless of
284 * the case of the characters to be matched (for example,
285 * [[:lower:]] is the same as [[:alpha:]]), otherwise a
286 * case-dependent classification is returned. The value
287 * returned shall be independent of the case of the characters
288 * in the character sequence. If the name is not recognized then
289 * returns a value that compares equal to 0.
291 * At least the following names (or their wide-character equivalent) are
309 template<typename _Fwd_iter
>
311 lookup_classname(_Fwd_iter __first
, _Fwd_iter __last
,
312 bool __icase
= false) const;
315 * @brief Determines if @p c is a member of an identified class.
317 * @param __c a character.
318 * @param __f a class type (as returned from lookup_classname).
320 * @returns true if the character @p __c is a member of the classification
321 * represented by @p __f, false otherwise.
323 * @throws std::bad_cast if the current locale does not have a ctype
327 isctype(_Ch_type __c
, char_class_type __f
) const;
330 * @brief Converts a digit to an int.
332 * @param __ch a character representing a digit.
333 * @param __radix the radix if the numeric conversion (limited to 8, 10,
336 * @returns the value represented by the digit __ch in base radix if the
337 * character __ch is a valid digit in base radix; otherwise returns -1.
340 value(_Ch_type __ch
, int __radix
) const;
343 * @brief Imbues the regex_traits object with a copy of a new locale.
345 * @param __loc A locale.
347 * @returns a copy of the previous locale in use by the regex_traits
350 * @note Calling imbue with a different locale than the one currently in
351 * use invalidates all cached data held by *this.
354 imbue(locale_type __loc
)
356 std::swap(_M_locale
, __loc
);
361 * @brief Gets a copy of the current locale in use by the regex_traits
366 { return _M_locale
; }
369 locale_type _M_locale
;
372 // [7.8] Class basic_regex
374 * Objects of specializations of this class represent regular expressions
375 * constructed from sequences of character type @p _Ch_type.
377 * Storage for the regular expression is allocated and deallocated as
378 * necessary by the member functions of this class.
380 template<typename _Ch_type
, typename _Rx_traits
= regex_traits
<_Ch_type
>>
384 static_assert(is_same
<_Ch_type
, typename
_Rx_traits::char_type
>::value
,
385 "regex traits class must have the same char_type");
388 typedef _Ch_type value_type
;
389 typedef _Rx_traits traits_type
;
390 typedef typename
traits_type::string_type string_type
;
391 typedef regex_constants::syntax_option_type flag_type
;
392 typedef typename
traits_type::locale_type locale_type
;
399 static constexpr flag_type icase
= regex_constants::icase
;
400 static constexpr flag_type nosubs
= regex_constants::nosubs
;
401 static constexpr flag_type optimize
= regex_constants::optimize
;
402 static constexpr flag_type collate
= regex_constants::collate
;
403 static constexpr flag_type ECMAScript
= regex_constants::ECMAScript
;
404 static constexpr flag_type basic
= regex_constants::basic
;
405 static constexpr flag_type extended
= regex_constants::extended
;
406 static constexpr flag_type awk
= regex_constants::awk
;
407 static constexpr flag_type grep
= regex_constants::grep
;
408 static constexpr flag_type egrep
= regex_constants::egrep
;
411 // [7.8.2] construct/copy/destroy
413 * Constructs a basic regular expression that does not match any
414 * character sequence.
417 : _M_flags(ECMAScript
), _M_automaton(nullptr)
421 * @brief Constructs a basic regular expression from the
422 * sequence [__p, __p + char_traits<_Ch_type>::length(__p))
423 * interpreted according to the flags in @p __f.
425 * @param __p A pointer to the start of a C-style null-terminated string
426 * containing a regular expression.
427 * @param __f Flags indicating the syntax rules and options.
429 * @throws regex_error if @p __p is not a valid regular expression.
432 basic_regex(const _Ch_type
* __p
, flag_type __f
= ECMAScript
)
433 : basic_regex(__p
, __p
+ _Rx_traits::length(__p
), __f
)
437 * @brief Constructs a basic regular expression from the sequence
438 * [p, p + len) interpreted according to the flags in @p f.
440 * @param __p A pointer to the start of a string containing a regular
442 * @param __len The length of the string containing the regular
444 * @param __f Flags indicating the syntax rules and options.
446 * @throws regex_error if @p __p is not a valid regular expression.
448 basic_regex(const _Ch_type
* __p
, std::size_t __len
,
449 flag_type __f
= ECMAScript
)
450 : basic_regex(__p
, __p
+ __len
, __f
)
454 * @brief Copy-constructs a basic regular expression.
456 * @param __rhs A @p regex object.
458 basic_regex(const basic_regex
& __rhs
) = default;
461 * @brief Move-constructs a basic regular expression.
463 * @param __rhs A @p regex object.
465 basic_regex(const basic_regex
&& __rhs
) noexcept
466 : _M_flags(__rhs
._M_flags
), _M_traits(__rhs
._M_traits
),
467 _M_automaton(std::move(__rhs
._M_automaton
))
471 * @brief Constructs a basic regular expression from the string
472 * @p s interpreted according to the flags in @p f.
474 * @param __s A string containing a regular expression.
475 * @param __f Flags indicating the syntax rules and options.
477 * @throws regex_error if @p __s is not a valid regular expression.
479 template<typename _Ch_traits
, typename _Ch_alloc
>
481 basic_regex(const std::basic_string
<_Ch_type
, _Ch_traits
,
483 flag_type __f
= ECMAScript
)
484 : basic_regex(__s
.begin(), __s
.end(), __f
)
488 * @brief Constructs a basic regular expression from the range
489 * [first, last) interpreted according to the flags in @p f.
491 * @param __first The start of a range containing a valid regular
493 * @param __last The end of a range containing a valid regular
495 * @param __f The format flags of the regular expression.
497 * @throws regex_error if @p [__first, __last) is not a valid regular
500 template<typename _FwdIter
>
501 basic_regex(_FwdIter __first
, _FwdIter __last
,
502 flag_type __f
= ECMAScript
)
504 _M_automaton(__detail::__compile_nfa(__first
, __last
, _M_traits
,
509 * @brief Constructs a basic regular expression from an initializer list.
511 * @param __l The initializer list.
512 * @param __f The format flags of the regular expression.
514 * @throws regex_error if @p __l is not a valid regular expression.
516 basic_regex(initializer_list
<_Ch_type
> __l
, flag_type __f
= ECMAScript
)
517 : basic_regex(__l
.begin(), __l
.end(), __f
)
521 * @brief Destroys a basic regular expression.
527 * @brief Assigns one regular expression to another.
530 operator=(const basic_regex
& __rhs
)
531 { return this->assign(__rhs
); }
534 * @brief Move-assigns one regular expression to another.
537 operator=(basic_regex
&& __rhs
) noexcept
538 { return this->assign(std::move(__rhs
)); }
541 * @brief Replaces a regular expression with a new one constructed from
542 * a C-style null-terminated string.
544 * @param __p A pointer to the start of a null-terminated C-style string
545 * containing a regular expression.
548 operator=(const _Ch_type
* __p
)
549 { return this->assign(__p
, flags()); }
552 * @brief Replaces a regular expression with a new one constructed from
555 * @param __s A pointer to a string containing a regular expression.
557 template<typename _Ch_typeraits
, typename _Alloc
>
559 operator=(const basic_string
<_Ch_type
, _Ch_typeraits
, _Alloc
>& __s
)
560 { return this->assign(__s
, flags()); }
564 * @brief the real assignment operator.
566 * @param __rhs Another regular expression object.
569 assign(const basic_regex
& __rhs
)
571 basic_regex
__tmp(__rhs
);
577 * @brief The move-assignment operator.
579 * @param __rhs Another regular expression object.
582 assign(basic_regex
&& __rhs
) noexcept
584 basic_regex
__tmp(std::move(__rhs
));
590 * @brief Assigns a new regular expression to a regex object from a
591 * C-style null-terminated string containing a regular expression
594 * @param __p A pointer to a C-style null-terminated string containing
595 * a regular expression pattern.
596 * @param __flags Syntax option flags.
598 * @throws regex_error if __p does not contain a valid regular
599 * expression pattern interpreted according to @p __flags. If
600 * regex_error is thrown, *this remains unchanged.
603 assign(const _Ch_type
* __p
, flag_type __flags
= ECMAScript
)
604 { return this->assign(string_type(__p
), __flags
); }
607 * @brief Assigns a new regular expression to a regex object from a
608 * C-style string containing a regular expression pattern.
610 * @param __p A pointer to a C-style string containing a
611 * regular expression pattern.
612 * @param __len The length of the regular expression pattern string.
613 * @param __flags Syntax option flags.
615 * @throws regex_error if p does not contain a valid regular
616 * expression pattern interpreted according to @p __flags. If
617 * regex_error is thrown, *this remains unchanged.
620 assign(const _Ch_type
* __p
, std::size_t __len
, flag_type __flags
)
621 { return this->assign(string_type(__p
, __len
), __flags
); }
624 * @brief Assigns a new regular expression to a regex object from a
625 * string containing a regular expression pattern.
627 * @param __s A string containing a regular expression pattern.
628 * @param __flags Syntax option flags.
630 * @throws regex_error if __s does not contain a valid regular
631 * expression pattern interpreted according to @p __flags. If
632 * regex_error is thrown, *this remains unchanged.
634 template<typename _Ch_typeraits
, typename _Alloc
>
636 assign(const basic_string
<_Ch_type
, _Ch_typeraits
, _Alloc
>& __s
,
637 flag_type __flags
= ECMAScript
)
640 _M_automaton
= __detail::__compile_nfa(__s
.begin(), __s
.end(),
641 _M_traits
, _M_flags
);
646 * @brief Assigns a new regular expression to a regex object.
648 * @param __first The start of a range containing a valid regular
650 * @param __last The end of a range containing a valid regular
652 * @param __flags Syntax option flags.
654 * @throws regex_error if p does not contain a valid regular
655 * expression pattern interpreted according to @p __flags. If
656 * regex_error is thrown, the object remains unchanged.
658 template<typename _InputIterator
>
660 assign(_InputIterator __first
, _InputIterator __last
,
661 flag_type __flags
= ECMAScript
)
662 { return this->assign(string_type(__first
, __last
), __flags
); }
665 * @brief Assigns a new regular expression to a regex object.
667 * @param __l An initializer list representing a regular expression.
668 * @param __flags Syntax option flags.
670 * @throws regex_error if @p __l does not contain a valid
671 * regular expression pattern interpreted according to @p
672 * __flags. If regex_error is thrown, the object remains
676 assign(initializer_list
<_Ch_type
> __l
, flag_type __flags
= ECMAScript
)
677 { return this->assign(__l
.begin(), __l
.end(), __flags
); }
679 // [7.8.4] const operations
681 * @brief Gets the number of marked subexpressions within the regular
686 { return _M_automaton
->_M_sub_count() - 1; }
689 * @brief Gets the flags used to construct the regular expression
690 * or in the last call to assign().
698 * @brief Imbues the regular expression object with the given locale.
700 * @param __loc A locale.
703 imbue(locale_type __loc
)
704 { return _M_traits
.imbue(__loc
); }
707 * @brief Gets the locale currently imbued in the regular expression
712 { return _M_traits
.getloc(); }
716 * @brief Swaps the contents of two regular expression objects.
718 * @param __rhs Another regular expression object.
721 swap(basic_regex
& __rhs
)
723 std::swap(_M_flags
, __rhs
._M_flags
);
724 std::swap(_M_traits
, __rhs
._M_traits
);
725 std::swap(_M_automaton
, __rhs
._M_automaton
);
728 #ifdef _GLIBCXX_DEBUG
730 _M_dot(std::ostream
& __ostr
)
731 { _M_automaton
->_M_dot(__ostr
); }
735 typedef std::shared_ptr
<__detail::_NFA
<_Rx_traits
>> _AutomatonPtr
;
737 template<typename _Bp
, typename _Ap
, typename _Cp
, typename _Rp
,
738 __detail::_RegexExecutorPolicy
, bool>
740 __detail::__regex_algo_impl(_Bp
, _Bp
, match_results
<_Bp
, _Ap
>&,
741 const basic_regex
<_Cp
, _Rp
>&,
742 regex_constants::match_flag_type
);
744 template<typename
, typename
, typename
, bool>
745 friend class __detail::_Executor
;
748 _Rx_traits _M_traits
;
749 _AutomatonPtr _M_automaton
;
752 /** @brief Standard regular expressions. */
753 typedef basic_regex
<char> regex
;
755 #ifdef _GLIBCXX_USE_WCHAR_T
756 /** @brief Standard wide-character regular expressions. */
757 typedef basic_regex
<wchar_t> wregex
;
761 // [7.8.6] basic_regex swap
763 * @brief Swaps the contents of two regular expression objects.
764 * @param __lhs First regular expression.
765 * @param __rhs Second regular expression.
767 template<typename _Ch_type
, typename _Rx_traits
>
769 swap(basic_regex
<_Ch_type
, _Rx_traits
>& __lhs
,
770 basic_regex
<_Ch_type
, _Rx_traits
>& __rhs
)
771 { __lhs
.swap(__rhs
); }
774 // [7.9] Class template sub_match
776 * A sequence of characters matched by a particular marked sub-expression.
778 * An object of this class is essentially a pair of iterators marking a
779 * matched subexpression within a regular expression pattern match. Such
780 * objects can be converted to and compared with std::basic_string objects
781 * of a similar base character type as the pattern matched by the regular
784 * The iterators that make up the pair are the usual half-open interval
785 * referencing the actual original pattern matched.
787 template<typename _BiIter
>
788 class sub_match
: public std::pair
<_BiIter
, _BiIter
>
790 typedef iterator_traits
<_BiIter
> __iter_traits
;
793 typedef typename
__iter_traits::value_type value_type
;
794 typedef typename
__iter_traits::difference_type difference_type
;
795 typedef _BiIter iterator
;
796 typedef std::basic_string
<value_type
> string_type
;
800 constexpr sub_match() : matched() { }
803 * Gets the length of the matching sequence.
807 { return this->matched
? std::distance(this->first
, this->second
) : 0; }
810 * @brief Gets the matching sequence as a string.
812 * @returns the matching sequence as a string.
814 * This is the implicit conversion operator. It is identical to the
815 * str() member function except that it will want to pop up in
816 * unexpected places and cause a great deal of confusion and cursing
819 operator string_type() const
822 ? string_type(this->first
, this->second
)
827 * @brief Gets the matching sequence as a string.
829 * @returns the matching sequence as a string.
835 ? string_type(this->first
, this->second
)
840 * @brief Compares this and another matched sequence.
842 * @param __s Another matched sequence to compare to this one.
844 * @retval <0 this matched sequence will collate before @p __s.
845 * @retval =0 this matched sequence is equivalent to @p __s.
846 * @retval <0 this matched sequence will collate after @p __s.
849 compare(const sub_match
& __s
) const
850 { return this->str().compare(__s
.str()); }
853 * @brief Compares this sub_match to a string.
855 * @param __s A string to compare to this sub_match.
857 * @retval <0 this matched sequence will collate before @p __s.
858 * @retval =0 this matched sequence is equivalent to @p __s.
859 * @retval <0 this matched sequence will collate after @p __s.
862 compare(const string_type
& __s
) const
863 { return this->str().compare(__s
); }
866 * @brief Compares this sub_match to a C-style string.
868 * @param __s A C-style string to compare to this sub_match.
870 * @retval <0 this matched sequence will collate before @p __s.
871 * @retval =0 this matched sequence is equivalent to @p __s.
872 * @retval <0 this matched sequence will collate after @p __s.
875 compare(const value_type
* __s
) const
876 { return this->str().compare(__s
); }
880 /** @brief Standard regex submatch over a C-style null-terminated string. */
881 typedef sub_match
<const char*> csub_match
;
883 /** @brief Standard regex submatch over a standard string. */
884 typedef sub_match
<string::const_iterator
> ssub_match
;
886 #ifdef _GLIBCXX_USE_WCHAR_T
887 /** @brief Regex submatch over a C-style null-terminated wide string. */
888 typedef sub_match
<const wchar_t*> wcsub_match
;
890 /** @brief Regex submatch over a standard wide string. */
891 typedef sub_match
<wstring::const_iterator
> wssub_match
;
894 // [7.9.2] sub_match non-member operators
897 * @brief Tests the equivalence of two regular expression submatches.
898 * @param __lhs First regular expression submatch.
899 * @param __rhs Second regular expression submatch.
900 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
902 template<typename _BiIter
>
904 operator==(const sub_match
<_BiIter
>& __lhs
, const sub_match
<_BiIter
>& __rhs
)
905 { return __lhs
.compare(__rhs
) == 0; }
908 * @brief Tests the inequivalence 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 is not equivalent to @a __rhs, false otherwise.
913 template<typename _BiIter
>
915 operator!=(const sub_match
<_BiIter
>& __lhs
, const sub_match
<_BiIter
>& __rhs
)
916 { return __lhs
.compare(__rhs
) != 0; }
919 * @brief Tests the ordering of two regular expression submatches.
920 * @param __lhs First regular expression submatch.
921 * @param __rhs Second regular expression submatch.
922 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
924 template<typename _BiIter
>
926 operator<(const sub_match
<_BiIter
>& __lhs
, const sub_match
<_BiIter
>& __rhs
)
927 { return __lhs
.compare(__rhs
) < 0; }
930 * @brief Tests the ordering of two regular expression submatches.
931 * @param __lhs First regular expression submatch.
932 * @param __rhs Second regular expression submatch.
933 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
935 template<typename _BiIter
>
937 operator<=(const sub_match
<_BiIter
>& __lhs
, const sub_match
<_BiIter
>& __rhs
)
938 { return __lhs
.compare(__rhs
) <= 0; }
941 * @brief Tests the ordering of two regular expression submatches.
942 * @param __lhs First regular expression submatch.
943 * @param __rhs Second regular expression submatch.
944 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
946 template<typename _BiIter
>
948 operator>=(const sub_match
<_BiIter
>& __lhs
, const sub_match
<_BiIter
>& __rhs
)
949 { return __lhs
.compare(__rhs
) >= 0; }
952 * @brief Tests the ordering of two regular expression submatches.
953 * @param __lhs First regular expression submatch.
954 * @param __rhs Second regular expression submatch.
955 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
957 template<typename _BiIter
>
959 operator>(const sub_match
<_BiIter
>& __lhs
, const sub_match
<_BiIter
>& __rhs
)
960 { return __lhs
.compare(__rhs
) > 0; }
962 // Alias for sub_match'd string.
963 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
964 using __sub_match_string
= basic_string
<
965 typename iterator_traits
<_Bi_iter
>::value_type
,
966 _Ch_traits
, _Ch_alloc
>;
969 * @brief Tests the equivalence of a string and a regular expression
971 * @param __lhs A string.
972 * @param __rhs A regular expression submatch.
973 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
975 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
977 operator==(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
978 const sub_match
<_Bi_iter
>& __rhs
)
979 { return __rhs
.compare(__lhs
.c_str()) == 0; }
982 * @brief Tests the inequivalence of a string and a regular expression
984 * @param __lhs A string.
985 * @param __rhs A regular expression submatch.
986 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
988 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
990 operator!=(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
991 const sub_match
<_Bi_iter
>& __rhs
)
992 { return !(__lhs
== __rhs
); }
995 * @brief Tests the ordering of a string and a regular expression submatch.
996 * @param __lhs A string.
997 * @param __rhs A regular expression submatch.
998 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1000 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1002 operator<(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
1003 const sub_match
<_Bi_iter
>& __rhs
)
1004 { return __rhs
.compare(__lhs
.c_str()) > 0; }
1007 * @brief Tests the ordering of a string and a regular expression submatch.
1008 * @param __lhs A string.
1009 * @param __rhs A regular expression submatch.
1010 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1012 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1014 operator>(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
1015 const sub_match
<_Bi_iter
>& __rhs
)
1016 { return __rhs
< __lhs
; }
1019 * @brief Tests the ordering of a string and a regular expression submatch.
1020 * @param __lhs A string.
1021 * @param __rhs A regular expression submatch.
1022 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1024 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1026 operator>=(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
1027 const sub_match
<_Bi_iter
>& __rhs
)
1028 { return !(__lhs
< __rhs
); }
1031 * @brief Tests the ordering of a string and a regular expression submatch.
1032 * @param __lhs A string.
1033 * @param __rhs A regular expression submatch.
1034 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1036 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1038 operator<=(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
1039 const sub_match
<_Bi_iter
>& __rhs
)
1040 { return !(__rhs
< __lhs
); }
1043 * @brief Tests the equivalence of a regular expression submatch and a
1045 * @param __lhs A regular expression submatch.
1046 * @param __rhs A string.
1047 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1049 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1051 operator==(const sub_match
<_Bi_iter
>& __lhs
,
1052 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1053 { return __lhs
.compare(__rhs
.c_str()) == 0; }
1056 * @brief Tests the inequivalence of a regular expression submatch and a
1058 * @param __lhs A regular expression submatch.
1059 * @param __rhs A string.
1060 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1062 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1064 operator!=(const sub_match
<_Bi_iter
>& __lhs
,
1065 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1066 { return !(__lhs
== __rhs
); }
1069 * @brief Tests the ordering of a regular expression submatch and a string.
1070 * @param __lhs A regular expression submatch.
1071 * @param __rhs A string.
1072 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1074 template<typename _Bi_iter
, class _Ch_traits
, class _Ch_alloc
>
1076 operator<(const sub_match
<_Bi_iter
>& __lhs
,
1077 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1078 { return __lhs
.compare(__rhs
.c_str()) < 0; }
1081 * @brief Tests the ordering of a regular expression submatch and a string.
1082 * @param __lhs A regular expression submatch.
1083 * @param __rhs A string.
1084 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1086 template<typename _Bi_iter
, class _Ch_traits
, class _Ch_alloc
>
1088 operator>(const sub_match
<_Bi_iter
>& __lhs
,
1089 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1090 { return __rhs
< __lhs
; }
1093 * @brief Tests the ordering of a regular expression submatch and a string.
1094 * @param __lhs A regular expression submatch.
1095 * @param __rhs A string.
1096 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1098 template<typename _Bi_iter
, class _Ch_traits
, class _Ch_alloc
>
1100 operator>=(const sub_match
<_Bi_iter
>& __lhs
,
1101 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1102 { return !(__lhs
< __rhs
); }
1105 * @brief Tests the ordering of a regular expression submatch and a string.
1106 * @param __lhs A regular expression submatch.
1107 * @param __rhs A string.
1108 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1110 template<typename _Bi_iter
, class _Ch_traits
, class _Ch_alloc
>
1112 operator<=(const sub_match
<_Bi_iter
>& __lhs
,
1113 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1114 { return !(__rhs
< __lhs
); }
1117 * @brief Tests the equivalence of a C string and a regular expression
1119 * @param __lhs A C string.
1120 * @param __rhs A regular expression submatch.
1121 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1123 template<typename _Bi_iter
>
1125 operator==(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1126 const sub_match
<_Bi_iter
>& __rhs
)
1127 { return __rhs
.compare(__lhs
) == 0; }
1130 * @brief Tests the inequivalence of an iterator value and a regular
1131 * expression submatch.
1132 * @param __lhs A regular expression submatch.
1133 * @param __rhs A string.
1134 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1136 template<typename _Bi_iter
>
1138 operator!=(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1139 const sub_match
<_Bi_iter
>& __rhs
)
1140 { return !(__lhs
== __rhs
); }
1143 * @brief Tests the ordering of a string and a regular expression submatch.
1144 * @param __lhs A string.
1145 * @param __rhs A regular expression submatch.
1146 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1148 template<typename _Bi_iter
>
1150 operator<(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1151 const sub_match
<_Bi_iter
>& __rhs
)
1152 { return __rhs
.compare(__lhs
) > 0; }
1155 * @brief Tests the ordering of a string and a regular expression submatch.
1156 * @param __lhs A string.
1157 * @param __rhs A regular expression submatch.
1158 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1160 template<typename _Bi_iter
>
1162 operator>(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1163 const sub_match
<_Bi_iter
>& __rhs
)
1164 { return __rhs
< __lhs
; }
1167 * @brief Tests the ordering of a string and a regular expression submatch.
1168 * @param __lhs A string.
1169 * @param __rhs A regular expression submatch.
1170 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1172 template<typename _Bi_iter
>
1174 operator>=(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1175 const sub_match
<_Bi_iter
>& __rhs
)
1176 { return !(__lhs
< __rhs
); }
1179 * @brief Tests the ordering of a string and a regular expression submatch.
1180 * @param __lhs A string.
1181 * @param __rhs A regular expression submatch.
1182 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1184 template<typename _Bi_iter
>
1186 operator<=(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1187 const sub_match
<_Bi_iter
>& __rhs
)
1188 { return !(__rhs
< __lhs
); }
1191 * @brief Tests the equivalence of a regular expression submatch and a
1193 * @param __lhs A regular expression submatch.
1194 * @param __rhs A pointer to a string?
1195 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1197 template<typename _Bi_iter
>
1199 operator==(const sub_match
<_Bi_iter
>& __lhs
,
1200 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1201 { return __lhs
.compare(__rhs
) == 0; }
1204 * @brief Tests the inequivalence of a regular expression submatch and a
1206 * @param __lhs A regular expression submatch.
1207 * @param __rhs A pointer to a string.
1208 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1210 template<typename _Bi_iter
>
1212 operator!=(const sub_match
<_Bi_iter
>& __lhs
,
1213 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1214 { return !(__lhs
== __rhs
); }
1217 * @brief Tests the ordering of a regular expression submatch and a string.
1218 * @param __lhs A regular expression submatch.
1219 * @param __rhs A string.
1220 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1222 template<typename _Bi_iter
>
1224 operator<(const sub_match
<_Bi_iter
>& __lhs
,
1225 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1226 { return __lhs
.compare(__rhs
) < 0; }
1229 * @brief Tests the ordering of a regular expression submatch and a string.
1230 * @param __lhs A regular expression submatch.
1231 * @param __rhs A string.
1232 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1234 template<typename _Bi_iter
>
1236 operator>(const sub_match
<_Bi_iter
>& __lhs
,
1237 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1238 { return __rhs
< __lhs
; }
1241 * @brief Tests the ordering of a regular expression submatch and a string.
1242 * @param __lhs A regular expression submatch.
1243 * @param __rhs A string.
1244 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1246 template<typename _Bi_iter
>
1248 operator>=(const sub_match
<_Bi_iter
>& __lhs
,
1249 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1250 { return !(__lhs
< __rhs
); }
1253 * @brief Tests the ordering of a regular expression submatch and a string.
1254 * @param __lhs A regular expression submatch.
1255 * @param __rhs A string.
1256 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1258 template<typename _Bi_iter
>
1260 operator<=(const sub_match
<_Bi_iter
>& __lhs
,
1261 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1262 { return !(__rhs
< __lhs
); }
1265 * @brief Tests the equivalence of a string and a regular expression
1267 * @param __lhs A string.
1268 * @param __rhs A regular expression submatch.
1269 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1271 template<typename _Bi_iter
>
1273 operator==(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1274 const sub_match
<_Bi_iter
>& __rhs
)
1276 typedef typename sub_match
<_Bi_iter
>::string_type string_type
;
1277 return __rhs
.compare(string_type(1, __lhs
)) == 0;
1281 * @brief Tests the inequivalence of a string and a regular expression
1283 * @param __lhs A string.
1284 * @param __rhs A regular expression submatch.
1285 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1287 template<typename _Bi_iter
>
1289 operator!=(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1290 const sub_match
<_Bi_iter
>& __rhs
)
1291 { return !(__lhs
== __rhs
); }
1294 * @brief Tests the ordering of a string and a regular expression submatch.
1295 * @param __lhs A string.
1296 * @param __rhs A regular expression submatch.
1297 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1299 template<typename _Bi_iter
>
1301 operator<(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1302 const sub_match
<_Bi_iter
>& __rhs
)
1304 typedef typename sub_match
<_Bi_iter
>::string_type string_type
;
1305 return __rhs
.compare(string_type(1, __lhs
)) > 0;
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 succeeds @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 __rhs
< __lhs
; }
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 does not precede @a __rhs, false otherwise.
1326 template<typename _Bi_iter
>
1328 operator>=(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1329 const sub_match
<_Bi_iter
>& __rhs
)
1330 { return !(__lhs
< __rhs
); }
1333 * @brief Tests the ordering of a string and a regular expression submatch.
1334 * @param __lhs A string.
1335 * @param __rhs A regular expression submatch.
1336 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1338 template<typename _Bi_iter
>
1340 operator<=(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1341 const sub_match
<_Bi_iter
>& __rhs
)
1342 { return !(__rhs
< __lhs
); }
1345 * @brief Tests the equivalence of a regular expression submatch and a
1347 * @param __lhs A regular expression submatch.
1348 * @param __rhs A const string reference.
1349 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1351 template<typename _Bi_iter
>
1353 operator==(const sub_match
<_Bi_iter
>& __lhs
,
1354 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1356 typedef typename sub_match
<_Bi_iter
>::string_type string_type
;
1357 return __lhs
.compare(string_type(1, __rhs
)) == 0;
1361 * @brief Tests the inequivalence of a regular expression submatch and a
1363 * @param __lhs A regular expression submatch.
1364 * @param __rhs A const string reference.
1365 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1367 template<typename _Bi_iter
>
1369 operator!=(const sub_match
<_Bi_iter
>& __lhs
,
1370 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1371 { return !(__lhs
== __rhs
); }
1374 * @brief Tests the ordering of a regular expression submatch and a string.
1375 * @param __lhs A regular expression submatch.
1376 * @param __rhs A const string reference.
1377 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1379 template<typename _Bi_iter
>
1381 operator<(const sub_match
<_Bi_iter
>& __lhs
,
1382 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1384 typedef typename sub_match
<_Bi_iter
>::string_type string_type
;
1385 return __lhs
.compare(string_type(1, __rhs
)) < 0;
1389 * @brief Tests the ordering of a regular expression submatch and a string.
1390 * @param __lhs A regular expression submatch.
1391 * @param __rhs A const string reference.
1392 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1394 template<typename _Bi_iter
>
1396 operator>(const sub_match
<_Bi_iter
>& __lhs
,
1397 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1398 { return __rhs
< __lhs
; }
1401 * @brief Tests the ordering of a regular expression submatch and a string.
1402 * @param __lhs A regular expression submatch.
1403 * @param __rhs A const string reference.
1404 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1406 template<typename _Bi_iter
>
1408 operator>=(const sub_match
<_Bi_iter
>& __lhs
,
1409 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1410 { return !(__lhs
< __rhs
); }
1413 * @brief Tests the ordering of a regular expression submatch and a string.
1414 * @param __lhs A regular expression submatch.
1415 * @param __rhs A const string reference.
1416 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1418 template<typename _Bi_iter
>
1420 operator<=(const sub_match
<_Bi_iter
>& __lhs
,
1421 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1422 { return !(__rhs
< __lhs
); }
1425 * @brief Inserts a matched string into an output stream.
1427 * @param __os The output stream.
1428 * @param __m A submatch string.
1430 * @returns the output stream with the submatch string inserted.
1432 template<typename _Ch_type
, typename _Ch_traits
, typename _Bi_iter
>
1434 basic_ostream
<_Ch_type
, _Ch_traits
>&
1435 operator<<(basic_ostream
<_Ch_type
, _Ch_traits
>& __os
,
1436 const sub_match
<_Bi_iter
>& __m
)
1437 { return __os
<< __m
.str(); }
1439 // [7.10] Class template match_results
1442 * Special sub_match object representing an unmatched sub-expression.
1444 template<typename _Bi_iter
>
1445 inline const sub_match
<_Bi_iter
>&
1448 static const sub_match
<_Bi_iter
> __unmatched
= sub_match
<_Bi_iter
>();
1453 * @brief The results of a match or search operation.
1455 * A collection of character sequences representing the result of a regular
1456 * expression match. Storage for the collection is allocated and freed as
1457 * necessary by the member functions of class template match_results.
1459 * This class satisfies the Sequence requirements, with the exception that
1460 * only the operations defined for a const-qualified Sequence are supported.
1462 * The sub_match object stored at index 0 represents sub-expression 0, i.e.
1463 * the whole match. In this case the %sub_match member matched is always true.
1464 * The sub_match object stored at index n denotes what matched the marked
1465 * sub-expression n within the matched expression. If the sub-expression n
1466 * participated in a regular expression match then the %sub_match member
1467 * matched evaluates to true, and members first and second denote the range
1468 * of characters [first, second) which formed that match. Otherwise matched
1469 * is false, and members first and second point to the end of the sequence
1470 * that was searched.
1474 template<typename _Bi_iter
,
1475 typename _Alloc
= allocator
<sub_match
<_Bi_iter
> > >
1477 : private std::vector
<sub_match
<_Bi_iter
>, _Alloc
>
1481 * The vector base is empty if this does not represent a successful match.
1482 * Otherwise it contains n+3 elements where n is the number of marked
1485 * [1] 1st marked subexpression
1487 * [n] nth marked subexpression
1491 typedef std::vector
<sub_match
<_Bi_iter
>, _Alloc
> _Base_type
;
1492 typedef std::iterator_traits
<_Bi_iter
> __iter_traits
;
1493 typedef regex_constants::match_flag_type match_flag_type
;
1497 * @name 10.? Public Types
1500 typedef sub_match
<_Bi_iter
> value_type
;
1501 typedef const value_type
& const_reference
;
1502 typedef const_reference reference
;
1503 typedef typename
_Base_type::const_iterator const_iterator
;
1504 typedef const_iterator iterator
;
1505 typedef typename
__iter_traits::difference_type difference_type
;
1506 typedef typename allocator_traits
<_Alloc
>::size_type size_type
;
1507 typedef _Alloc allocator_type
;
1508 typedef typename
__iter_traits::value_type char_type
;
1509 typedef std::basic_string
<char_type
> string_type
;
1514 * @name 28.10.1 Construction, Copying, and Destruction
1519 * @brief Constructs a default %match_results container.
1520 * @post size() returns 0 and str() returns an empty string.
1523 match_results(const _Alloc
& __a
= _Alloc())
1524 : _Base_type(__a
), _M_in_iterator(false)
1528 * @brief Copy constructs a %match_results.
1530 match_results(const match_results
& __rhs
)
1531 : _Base_type(__rhs
), _M_in_iterator(false)
1535 * @brief Move constructs a %match_results.
1537 match_results(match_results
&& __rhs
) noexcept
1538 : _Base_type(std::move(__rhs
)), _M_in_iterator(false)
1542 * @brief Assigns rhs to *this.
1545 operator=(const match_results
& __rhs
)
1547 match_results(__rhs
).swap(*this);
1552 * @brief Move-assigns rhs to *this.
1555 operator=(match_results
&& __rhs
)
1557 match_results(std::move(__rhs
)).swap(*this);
1562 * @brief Destroys a %match_results object.
1571 * @brief Indicates if the %match_results is ready.
1572 * @retval true The object has a fully-established result state.
1573 * @retval false The object is not ready.
1575 bool ready() const { return !_Base_type::empty(); }
1578 * @name 28.10.2 Size
1583 * @brief Gets the number of matches and submatches.
1585 * The number of matches for a given regular expression will be either 0
1586 * if there was no match or mark_count() + 1 if a match was successful.
1587 * Some matches may be empty.
1589 * @returns the number of matches found.
1594 size_type __size
= _Base_type::size();
1595 return (__size
&& _Base_type::operator[](0).matched
) ? __size
- 2 : 0;
1600 { return _Base_type::max_size(); }
1603 * @brief Indicates if the %match_results contains no results.
1604 * @retval true The %match_results object is empty.
1605 * @retval false The %match_results object is not empty.
1609 { return size() == 0; }
1614 * @name 10.3 Element Access
1619 * @brief Gets the length of the indicated submatch.
1620 * @param __sub indicates the submatch.
1621 * @pre ready() == true
1623 * This function returns the length of the indicated submatch, or the
1624 * length of the entire match if @p __sub is zero (the default).
1627 length(size_type __sub
= 0) const
1628 { return (*this)[__sub
].length(); }
1631 * @brief Gets the offset of the beginning of the indicated submatch.
1632 * @param __sub indicates the submatch.
1633 * @pre ready() == true
1635 * This function returns the offset from the beginning of the target
1636 * sequence to the beginning of the submatch, unless the value of @p __sub
1637 * is zero (the default), in which case this function returns the offset
1638 * from the beginning of the target sequence to the beginning of the
1641 * Returns -1 if @p __sub is out of range.
1644 position(size_type __sub
= 0) const
1648 return __sub
< size() ? std::distance(_M_begin
,
1649 (*this)[__sub
].first
) : -1;
1651 return __sub
< size() ? std::distance(this->prefix().first
,
1652 (*this)[__sub
].first
) : -1;
1656 * @brief Gets the match or submatch converted to a string type.
1657 * @param __sub indicates the submatch.
1658 * @pre ready() == true
1660 * This function gets the submatch (or match, if @p __sub is
1661 * zero) extracted from the target range and converted to the
1662 * associated string type.
1665 str(size_type __sub
= 0) const
1666 { return (*this)[__sub
].str(); }
1669 * @brief Gets a %sub_match reference for the match or submatch.
1670 * @param __sub indicates the submatch.
1671 * @pre ready() == true
1673 * This function gets a reference to the indicated submatch, or
1674 * the entire match if @p __sub is zero.
1676 * If @p __sub >= size() then this function returns a %sub_match with a
1677 * special value indicating no submatch.
1680 operator[](size_type __sub
) const
1682 _GLIBCXX_DEBUG_ASSERT( ready() );
1683 return __sub
< size()
1684 ? _Base_type::operator[](__sub
)
1685 : __unmatched_sub
<_Bi_iter
>();
1689 * @brief Gets a %sub_match representing the match prefix.
1690 * @pre ready() == true
1692 * This function gets a reference to a %sub_match object representing the
1693 * part of the target range between the start of the target range and the
1694 * start of the match.
1699 _GLIBCXX_DEBUG_ASSERT( ready() );
1701 ? _Base_type::operator[](_Base_type::size() - 2)
1702 : __unmatched_sub
<_Bi_iter
>();
1706 * @brief Gets a %sub_match representing the match suffix.
1707 * @pre ready() == true
1709 * This function gets a reference to a %sub_match object representing the
1710 * part of the target range between the end of the match and the end of
1716 _GLIBCXX_DEBUG_ASSERT( ready() );
1718 ? _Base_type::operator[](_Base_type::size() - 1)
1719 : __unmatched_sub
<_Bi_iter
>();
1723 * @brief Gets an iterator to the start of the %sub_match collection.
1727 { return _Base_type::begin(); }
1730 * @brief Gets an iterator to the start of the %sub_match collection.
1734 { return _Base_type::cbegin() + 2; }
1737 * @brief Gets an iterator to one-past-the-end of the collection.
1741 { return _Base_type::end() - 2; }
1744 * @brief Gets an iterator to one-past-the-end of the collection.
1748 { return _Base_type::cend(); }
1753 * @name 10.4 Formatting
1755 * These functions perform formatted substitution of the matched
1756 * character sequences into their target. The format specifiers and
1757 * escape sequences accepted by these functions are determined by
1758 * their @p flags parameter as documented above.
1763 * @pre ready() == true
1765 template<typename _Out_iter
>
1767 format(_Out_iter __out
, const char_type
* __fmt_first
,
1768 const char_type
* __fmt_last
,
1769 match_flag_type __flags
= regex_constants::format_default
) const;
1772 * @pre ready() == true
1774 template<typename _Out_iter
, typename _St
, typename _Sa
>
1776 format(_Out_iter __out
, const basic_string
<char_type
, _St
, _Sa
>& __fmt
,
1777 match_flag_type __flags
= regex_constants::format_default
) const
1779 return format(__out
, __fmt
.data(), __fmt
.data() + __fmt
.size(),
1784 * @pre ready() == true
1786 template<typename _Out_iter
, typename _St
, typename _Sa
>
1787 basic_string
<char_type
, _St
, _Sa
>
1788 format(const basic_string
<char_type
, _St
, _Sa
>& __fmt
,
1789 match_flag_type __flags
= regex_constants::format_default
) const
1791 basic_string
<char_type
, _St
, _Sa
> __result
;
1792 format(std::back_inserter(__result
), __fmt
, __flags
);
1797 * @pre ready() == true
1800 format(const char_type
* __fmt
,
1801 match_flag_type __flags
= regex_constants::format_default
) const
1803 string_type __result
;
1804 format(std::back_inserter(__result
),
1806 __fmt
+ char_traits
<char_type
>::length(__fmt
),
1814 * @name 10.5 Allocator
1819 * @brief Gets a copy of the allocator.
1822 get_allocator() const
1823 { return _Base_type::get_allocator(); }
1833 * @brief Swaps the contents of two match_results.
1836 swap(match_results
& __that
)
1837 { _Base_type::swap(__that
); }
1841 template<typename
, typename
, typename
, bool>
1842 friend class __detail::_Executor
;
1844 template<typename
, typename
, typename
>
1845 friend class regex_iterator
;
1847 template<typename _Bp
, typename _Ap
, typename _Cp
, typename _Rp
,
1848 __detail::_RegexExecutorPolicy
, bool>
1850 __detail::__regex_algo_impl(_Bp
, _Bp
, match_results
<_Bp
, _Ap
>&,
1851 const basic_regex
<_Cp
, _Rp
>&,
1852 regex_constants::match_flag_type
);
1855 bool _M_in_iterator
;
1858 typedef match_results
<const char*> cmatch
;
1859 typedef match_results
<string::const_iterator
> smatch
;
1860 #ifdef _GLIBCXX_USE_WCHAR_T
1861 typedef match_results
<const wchar_t*> wcmatch
;
1862 typedef match_results
<wstring::const_iterator
> wsmatch
;
1865 // match_results comparisons
1867 * @brief Compares two match_results for equality.
1868 * @returns true if the two objects refer to the same match,
1871 template<typename _Bi_iter
, typename _Alloc
>
1873 operator==(const match_results
<_Bi_iter
, _Alloc
>& __m1
,
1874 const match_results
<_Bi_iter
, _Alloc
>& __m2
)
1876 if (__m1
.ready() != __m2
.ready())
1878 if (!__m1
.ready()) // both are not ready
1880 if (__m1
.empty() != __m2
.empty())
1882 if (__m1
.empty()) // both are empty
1884 return __m1
.prefix() == __m2
.prefix()
1885 && __m1
.size() == __m2
.size()
1886 && std::equal(__m1
.begin(), __m1
.end(), __m2
.begin())
1887 && __m1
.suffix() == __m2
.suffix();
1891 * @brief Compares two match_results for inequality.
1892 * @returns true if the two objects do not refer to the same match,
1895 template<typename _Bi_iter
, class _Alloc
>
1897 operator!=(const match_results
<_Bi_iter
, _Alloc
>& __m1
,
1898 const match_results
<_Bi_iter
, _Alloc
>& __m2
)
1899 { return !(__m1
== __m2
); }
1901 // [7.10.6] match_results swap
1903 * @brief Swaps two match results.
1904 * @param __lhs A match result.
1905 * @param __rhs A match result.
1907 * The contents of the two match_results objects are swapped.
1909 template<typename _Bi_iter
, typename _Alloc
>
1911 swap(match_results
<_Bi_iter
, _Alloc
>& __lhs
,
1912 match_results
<_Bi_iter
, _Alloc
>& __rhs
)
1913 { __lhs
.swap(__rhs
); }
1915 // [7.11.2] Function template regex_match
1917 * @name Matching, Searching, and Replacing
1922 * @brief Determines if there is a match between the regular expression @p e
1923 * and all of the character sequence [first, last).
1925 * @param __s Start of the character sequence to match.
1926 * @param __e One-past-the-end of the character sequence to match.
1927 * @param __m The match results.
1928 * @param __re The regular expression.
1929 * @param __flags Controls how the regular expression is matched.
1931 * @retval true A match exists.
1932 * @retval false Otherwise.
1934 * @throws an exception of type regex_error.
1936 template<typename _Bi_iter
, typename _Alloc
,
1937 typename _Ch_type
, typename _Rx_traits
>
1939 regex_match(_Bi_iter __s
,
1941 match_results
<_Bi_iter
, _Alloc
>& __m
,
1942 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
1943 regex_constants::match_flag_type __flags
1944 = regex_constants::match_default
)
1946 return __detail::__regex_algo_impl
<_Bi_iter
, _Alloc
, _Ch_type
, _Rx_traits
,
1947 __detail::_RegexExecutorPolicy::_S_auto
, true>
1948 (__s
, __e
, __m
, __re
, __flags
);
1952 * @brief Indicates if there is a match between the regular expression @p e
1953 * and all of the character sequence [first, last).
1955 * @param __first Beginning of the character sequence to match.
1956 * @param __last One-past-the-end of the character sequence to match.
1957 * @param __re The regular expression.
1958 * @param __flags Controls how the regular expression is matched.
1960 * @retval true A match exists.
1961 * @retval false Otherwise.
1963 * @throws an exception of type regex_error.
1965 template<typename _Bi_iter
, typename _Ch_type
, typename _Rx_traits
>
1967 regex_match(_Bi_iter __first
, _Bi_iter __last
,
1968 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
1969 regex_constants::match_flag_type __flags
1970 = regex_constants::match_default
)
1972 match_results
<_Bi_iter
> __what
;
1973 return regex_match(__first
, __last
, __what
, __re
, __flags
);
1977 * @brief Determines if there is a match between the regular expression @p e
1978 * and a C-style null-terminated string.
1980 * @param __s The C-style null-terminated string to match.
1981 * @param __m The match results.
1982 * @param __re The regular expression.
1983 * @param __f Controls how the regular expression is matched.
1985 * @retval true A match exists.
1986 * @retval false Otherwise.
1988 * @throws an exception of type regex_error.
1990 template<typename _Ch_type
, typename _Alloc
, typename _Rx_traits
>
1992 regex_match(const _Ch_type
* __s
,
1993 match_results
<const _Ch_type
*, _Alloc
>& __m
,
1994 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
1995 regex_constants::match_flag_type __f
1996 = regex_constants::match_default
)
1997 { return regex_match(__s
, __s
+ _Rx_traits::length(__s
), __m
, __re
, __f
); }
2000 * @brief Determines if there is a match between the regular expression @p e
2003 * @param __s The string to match.
2004 * @param __m The match results.
2005 * @param __re The regular expression.
2006 * @param __flags Controls how the regular expression is matched.
2008 * @retval true A match exists.
2009 * @retval false Otherwise.
2011 * @throws an exception of type regex_error.
2013 template<typename _Ch_traits
, typename _Ch_alloc
,
2014 typename _Alloc
, typename _Ch_type
, typename _Rx_traits
>
2016 regex_match(const basic_string
<_Ch_type
, _Ch_traits
, _Ch_alloc
>& __s
,
2017 match_results
<typename basic_string
<_Ch_type
,
2018 _Ch_traits
, _Ch_alloc
>::const_iterator
, _Alloc
>& __m
,
2019 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2020 regex_constants::match_flag_type __flags
2021 = regex_constants::match_default
)
2022 { return regex_match(__s
.begin(), __s
.end(), __m
, __re
, __flags
); }
2025 * @brief Indicates if there is a match between the regular expression @p e
2026 * and a C-style null-terminated string.
2028 * @param __s The C-style null-terminated string to match.
2029 * @param __re The regular expression.
2030 * @param __f Controls how the regular expression is matched.
2032 * @retval true A match exists.
2033 * @retval false Otherwise.
2035 * @throws an exception of type regex_error.
2037 template<typename _Ch_type
, class _Rx_traits
>
2039 regex_match(const _Ch_type
* __s
,
2040 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2041 regex_constants::match_flag_type __f
2042 = regex_constants::match_default
)
2043 { return regex_match(__s
, __s
+ _Rx_traits::length(__s
), __re
, __f
); }
2046 * @brief Indicates if there is a match between the regular expression @p e
2049 * @param __s [IN] The string to match.
2050 * @param __re [IN] The regular expression.
2051 * @param __flags [IN] Controls how the regular expression is matched.
2053 * @retval true A match exists.
2054 * @retval false Otherwise.
2056 * @throws an exception of type regex_error.
2058 template<typename _Ch_traits
, typename _Str_allocator
,
2059 typename _Ch_type
, typename _Rx_traits
>
2061 regex_match(const basic_string
<_Ch_type
, _Ch_traits
, _Str_allocator
>& __s
,
2062 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2063 regex_constants::match_flag_type __flags
2064 = regex_constants::match_default
)
2065 { return regex_match(__s
.begin(), __s
.end(), __re
, __flags
); }
2067 // [7.11.3] Function template regex_search
2069 * Searches for a regular expression within a range.
2070 * @param __first [IN] The start of the string to search.
2071 * @param __last [IN] One-past-the-end of the string to search.
2072 * @param __m [OUT] The match results.
2073 * @param __re [IN] The regular expression to search for.
2074 * @param __flags [IN] Search policy flags.
2075 * @retval true A match was found within the string.
2076 * @retval false No match was found within the string, the content of %m is
2079 * @throws an exception of type regex_error.
2081 template<typename _Bi_iter
, typename _Alloc
,
2082 typename _Ch_type
, typename _Rx_traits
>
2084 regex_search(_Bi_iter __s
, _Bi_iter __e
,
2085 match_results
<_Bi_iter
, _Alloc
>& __m
,
2086 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2087 regex_constants::match_flag_type __flags
2088 = regex_constants::match_default
)
2090 return __detail::__regex_algo_impl
<_Bi_iter
, _Alloc
, _Ch_type
, _Rx_traits
,
2091 __detail::_RegexExecutorPolicy::_S_auto
, false>
2092 (__s
, __e
, __m
, __re
, __flags
);
2096 * Searches for a regular expression within a range.
2097 * @param __first [IN] The start of the string to search.
2098 * @param __last [IN] One-past-the-end of the string to search.
2099 * @param __re [IN] The regular expression to search for.
2100 * @param __flags [IN] Search policy flags.
2101 * @retval true A match was found within the string.
2102 * @retval false No match was found within the string.
2104 * @throws an exception of type regex_error.
2106 template<typename _Bi_iter
, typename _Ch_type
, typename _Rx_traits
>
2108 regex_search(_Bi_iter __first
, _Bi_iter __last
,
2109 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2110 regex_constants::match_flag_type __flags
2111 = regex_constants::match_default
)
2113 match_results
<_Bi_iter
> __what
;
2114 return regex_search(__first
, __last
, __what
, __re
, __flags
);
2118 * @brief Searches for a regular expression within a C-string.
2119 * @param __s [IN] A C-string to search for the regex.
2120 * @param __m [OUT] The set of regex matches.
2121 * @param __e [IN] The regex to search for in @p s.
2122 * @param __f [IN] The search flags.
2123 * @retval true A match was found within the string.
2124 * @retval false No match was found within the string, the content of %m is
2127 * @throws an exception of type regex_error.
2129 template<typename _Ch_type
, class _Alloc
, class _Rx_traits
>
2131 regex_search(const _Ch_type
* __s
,
2132 match_results
<const _Ch_type
*, _Alloc
>& __m
,
2133 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2134 regex_constants::match_flag_type __f
2135 = regex_constants::match_default
)
2136 { return regex_search(__s
, __s
+ _Rx_traits::length(__s
), __m
, __e
, __f
); }
2139 * @brief Searches for a regular expression within a C-string.
2140 * @param __s [IN] The C-string to search.
2141 * @param __e [IN] The regular expression to search for.
2142 * @param __f [IN] Search policy flags.
2143 * @retval true A match was found within the string.
2144 * @retval false No match was found within the string.
2146 * @throws an exception of type regex_error.
2148 template<typename _Ch_type
, typename _Rx_traits
>
2150 regex_search(const _Ch_type
* __s
,
2151 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2152 regex_constants::match_flag_type __f
2153 = regex_constants::match_default
)
2154 { return regex_search(__s
, __s
+ _Rx_traits::length(__s
), __e
, __f
); }
2157 * @brief Searches for a regular expression within a string.
2158 * @param __s [IN] The string to search.
2159 * @param __e [IN] The regular expression to search for.
2160 * @param __flags [IN] Search policy flags.
2161 * @retval true A match was found within the string.
2162 * @retval false No match was found within the string.
2164 * @throws an exception of type regex_error.
2166 template<typename _Ch_traits
, typename _String_allocator
,
2167 typename _Ch_type
, typename _Rx_traits
>
2169 regex_search(const basic_string
<_Ch_type
, _Ch_traits
,
2170 _String_allocator
>& __s
,
2171 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2172 regex_constants::match_flag_type __flags
2173 = regex_constants::match_default
)
2174 { return regex_search(__s
.begin(), __s
.end(), __e
, __flags
); }
2177 * @brief Searches for a regular expression within a string.
2178 * @param __s [IN] A C++ string to search for the regex.
2179 * @param __m [OUT] The set of regex matches.
2180 * @param __e [IN] The regex to search for in @p s.
2181 * @param __f [IN] The search flags.
2182 * @retval true A match was found within the string.
2183 * @retval false No match was found within the string, the content of %m is
2186 * @throws an exception of type regex_error.
2188 template<typename _Ch_traits
, typename _Ch_alloc
,
2189 typename _Alloc
, typename _Ch_type
,
2190 typename _Rx_traits
>
2192 regex_search(const basic_string
<_Ch_type
, _Ch_traits
, _Ch_alloc
>& __s
,
2193 match_results
<typename basic_string
<_Ch_type
,
2194 _Ch_traits
, _Ch_alloc
>::const_iterator
, _Alloc
>& __m
,
2195 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2196 regex_constants::match_flag_type __f
2197 = regex_constants::match_default
)
2198 { return regex_search(__s
.begin(), __s
.end(), __m
, __e
, __f
); }
2200 // std [28.11.4] Function template regex_replace
2202 * @brief Search for a regular expression within a range for multiple times,
2203 and replace the matched parts through filling a format string.
2204 * @param __out [OUT] The output iterator.
2205 * @param __first [IN] The start of the string to search.
2206 * @param __last [IN] One-past-the-end of the string to search.
2207 * @param __e [IN] The regular expression to search for.
2208 * @param __fmt [IN] The format string.
2209 * @param __flags [IN] Search and replace policy flags.
2212 * @throws an exception of type regex_error.
2214 template<typename _Out_iter
, typename _Bi_iter
,
2215 typename _Rx_traits
, typename _Ch_type
,
2216 typename _St
, typename _Sa
>
2218 regex_replace(_Out_iter __out
, _Bi_iter __first
, _Bi_iter __last
,
2219 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2220 const basic_string
<_Ch_type
, _St
, _Sa
>& __fmt
,
2221 regex_constants::match_flag_type __flags
2222 = regex_constants::match_default
)
2224 return regex_replace(__out
, __first
, __last
, __e
, __fmt
.c_str(), __flags
);
2228 * @brief Search for a regular expression within a range for multiple times,
2229 and replace the matched parts through filling a format C-string.
2230 * @param __out [OUT] The output iterator.
2231 * @param __first [IN] The start of the string to search.
2232 * @param __last [IN] One-past-the-end of the string to search.
2233 * @param __e [IN] The regular expression to search for.
2234 * @param __fmt [IN] The format C-string.
2235 * @param __flags [IN] Search and replace policy flags.
2238 * @throws an exception of type regex_error.
2240 template<typename _Out_iter
, typename _Bi_iter
,
2241 typename _Rx_traits
, typename _Ch_type
>
2243 regex_replace(_Out_iter __out
, _Bi_iter __first
, _Bi_iter __last
,
2244 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2245 const _Ch_type
* __fmt
,
2246 regex_constants::match_flag_type __flags
2247 = regex_constants::match_default
);
2250 * @brief Search for a regular expression within a string for multiple times,
2251 and replace the matched parts through filling a format string.
2252 * @param __s [IN] The string to search and replace.
2253 * @param __e [IN] The regular expression to search for.
2254 * @param __fmt [IN] The format string.
2255 * @param __flags [IN] Search and replace policy flags.
2257 * @returns The string after replacing.
2258 * @throws an exception of type regex_error.
2260 template<typename _Rx_traits
, typename _Ch_type
,
2261 typename _St
, typename _Sa
, typename _Fst
, typename _Fsa
>
2262 inline basic_string
<_Ch_type
, _St
, _Sa
>
2263 regex_replace(const basic_string
<_Ch_type
, _St
, _Sa
>& __s
,
2264 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2265 const basic_string
<_Ch_type
, _Fst
, _Fsa
>& __fmt
,
2266 regex_constants::match_flag_type __flags
2267 = regex_constants::match_default
)
2269 basic_string
<_Ch_type
, _St
, _Sa
> __result
;
2270 regex_replace(std::back_inserter(__result
),
2271 __s
.begin(), __s
.end(), __e
, __fmt
, __flags
);
2276 * @brief Search for a regular expression within a string for multiple times,
2277 and replace the matched parts through filling a format C-string.
2278 * @param __s [IN] The string to search and replace.
2279 * @param __e [IN] The regular expression to search for.
2280 * @param __fmt [IN] The format C-string.
2281 * @param __flags [IN] Search and replace policy flags.
2283 * @returns The string after replacing.
2284 * @throws an exception of type regex_error.
2286 template<typename _Rx_traits
, typename _Ch_type
,
2287 typename _St
, typename _Sa
>
2288 inline basic_string
<_Ch_type
, _St
, _Sa
>
2289 regex_replace(const basic_string
<_Ch_type
, _St
, _Sa
>& __s
,
2290 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2291 const _Ch_type
* __fmt
,
2292 regex_constants::match_flag_type __flags
2293 = regex_constants::match_default
)
2295 basic_string
<_Ch_type
, _St
, _Sa
> __result
;
2296 regex_replace(std::back_inserter(__result
),
2297 __s
.begin(), __s
.end(), __e
, __fmt
, __flags
);
2302 * @brief Search for a regular expression within a C-string for multiple
2303 times, and replace the matched parts through filling a format string.
2304 * @param __s [IN] The C-string to search and replace.
2305 * @param __e [IN] The regular expression to search for.
2306 * @param __fmt [IN] The format string.
2307 * @param __flags [IN] Search and replace policy flags.
2309 * @returns The string after replacing.
2310 * @throws an exception of type regex_error.
2312 template<typename _Rx_traits
, typename _Ch_type
,
2313 typename _St
, typename _Sa
>
2314 inline basic_string
<_Ch_type
>
2315 regex_replace(const _Ch_type
* __s
,
2316 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2317 const basic_string
<_Ch_type
, _St
, _Sa
>& __fmt
,
2318 regex_constants::match_flag_type __flags
2319 = regex_constants::match_default
)
2321 basic_string
<_Ch_type
> __result
;
2322 regex_replace(std::back_inserter(__result
), __s
,
2323 __s
+ char_traits
<_Ch_type
>::length(__s
),
2324 __e
, __fmt
, __flags
);
2329 * @brief Search for a regular expression within a C-string for multiple
2330 times, and replace the matched parts through filling a format C-string.
2331 * @param __s [IN] The C-string to search and replace.
2332 * @param __e [IN] The regular expression to search for.
2333 * @param __fmt [IN] The format C-string.
2334 * @param __flags [IN] Search and replace policy flags.
2336 * @returns The string after replacing.
2337 * @throws an exception of type regex_error.
2339 template<typename _Rx_traits
, typename _Ch_type
>
2340 inline basic_string
<_Ch_type
>
2341 regex_replace(const _Ch_type
* __s
,
2342 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2343 const _Ch_type
* __fmt
,
2344 regex_constants::match_flag_type __flags
2345 = regex_constants::match_default
)
2347 basic_string
<_Ch_type
> __result
;
2348 regex_replace(std::back_inserter(__result
), __s
,
2349 __s
+ char_traits
<_Ch_type
>::length(__s
),
2350 __e
, __fmt
, __flags
);
2356 // std [28.12] Class template regex_iterator
2358 * An iterator adaptor that will provide repeated calls of regex_search over
2359 * a range until no more matches remain.
2361 template<typename _Bi_iter
,
2362 typename _Ch_type
= typename iterator_traits
<_Bi_iter
>::value_type
,
2363 typename _Rx_traits
= regex_traits
<_Ch_type
> >
2364 class regex_iterator
2367 typedef basic_regex
<_Ch_type
, _Rx_traits
> regex_type
;
2368 typedef match_results
<_Bi_iter
> value_type
;
2369 typedef std::ptrdiff_t difference_type
;
2370 typedef const value_type
* pointer
;
2371 typedef const value_type
& reference
;
2372 typedef std::forward_iterator_tag iterator_category
;
2375 * @brief Provides a singular iterator, useful for indicating
2376 * one-past-the-end of a range.
2383 * Constructs a %regex_iterator...
2384 * @param __a [IN] The start of a text range to search.
2385 * @param __b [IN] One-past-the-end of the text range to search.
2386 * @param __re [IN] The regular expression to match.
2387 * @param __m [IN] Policy flags for match rules.
2389 regex_iterator(_Bi_iter __a
, _Bi_iter __b
, const regex_type
& __re
,
2390 regex_constants::match_flag_type __m
2391 = regex_constants::match_default
)
2392 : _M_begin(__a
), _M_end(__b
), _M_pregex(&__re
), _M_flags(__m
), _M_match()
2394 if (!regex_search(_M_begin
, _M_end
, _M_match
, *_M_pregex
, _M_flags
))
2395 *this = regex_iterator();
2399 * Copy constructs a %regex_iterator.
2401 regex_iterator(const regex_iterator
& __rhs
) = default;
2404 * @brief Assigns one %regex_iterator to another.
2407 operator=(const regex_iterator
& __rhs
) = default;
2410 * @brief Tests the equivalence of two regex iterators.
2413 operator==(const regex_iterator
& __rhs
) const;
2416 * @brief Tests the inequivalence of two regex iterators.
2419 operator!=(const regex_iterator
& __rhs
) const
2420 { return !(*this == __rhs
); }
2423 * @brief Dereferences a %regex_iterator.
2427 { return _M_match
; }
2430 * @brief Selects a %regex_iterator member.
2434 { return &_M_match
; }
2437 * @brief Increments a %regex_iterator.
2443 * @brief Postincrements a %regex_iterator.
2456 const regex_type
* _M_pregex
;
2457 regex_constants::match_flag_type _M_flags
;
2458 match_results
<_Bi_iter
> _M_match
;
2461 typedef regex_iterator
<const char*> cregex_iterator
;
2462 typedef regex_iterator
<string::const_iterator
> sregex_iterator
;
2463 #ifdef _GLIBCXX_USE_WCHAR_T
2464 typedef regex_iterator
<const wchar_t*> wcregex_iterator
;
2465 typedef regex_iterator
<wstring::const_iterator
> wsregex_iterator
;
2468 // [7.12.2] Class template regex_token_iterator
2470 * Iterates over submatches in a range (or @a splits a text string).
2472 * The purpose of this iterator is to enumerate all, or all specified,
2473 * matches of a regular expression within a text range. The dereferenced
2474 * value of an iterator of this class is a std::sub_match object.
2476 template<typename _Bi_iter
,
2477 typename _Ch_type
= typename iterator_traits
<_Bi_iter
>::value_type
,
2478 typename _Rx_traits
= regex_traits
<_Ch_type
> >
2479 class regex_token_iterator
2482 typedef basic_regex
<_Ch_type
, _Rx_traits
> regex_type
;
2483 typedef sub_match
<_Bi_iter
> value_type
;
2484 typedef std::ptrdiff_t difference_type
;
2485 typedef const value_type
* pointer
;
2486 typedef const value_type
& reference
;
2487 typedef std::forward_iterator_tag iterator_category
;
2491 * @brief Default constructs a %regex_token_iterator.
2493 * A default-constructed %regex_token_iterator is a singular iterator
2494 * that will compare equal to the one-past-the-end value for any
2495 * iterator of the same type.
2497 regex_token_iterator()
2498 : _M_position(), _M_subs(), _M_suffix(), _M_n(0), _M_result(nullptr),
2503 * Constructs a %regex_token_iterator...
2504 * @param __a [IN] The start of the text to search.
2505 * @param __b [IN] One-past-the-end of the text to search.
2506 * @param __re [IN] The regular expression to search for.
2507 * @param __submatch [IN] Which submatch to return. There are some
2508 * special values for this parameter:
2509 * - -1 each enumerated subexpression does NOT
2510 * match the regular expression (aka field
2512 * - 0 the entire string matching the
2513 * subexpression is returned for each match
2515 * - >0 enumerates only the indicated
2516 * subexpression from a match within the text.
2517 * @param __m [IN] Policy flags for match rules.
2519 regex_token_iterator(_Bi_iter __a
, _Bi_iter __b
, const regex_type
& __re
,
2521 regex_constants::match_flag_type __m
2522 = regex_constants::match_default
)
2523 : _M_position(__a
, __b
, __re
, __m
), _M_subs(1, __submatch
), _M_n(0)
2524 { _M_init(__a
, __b
); }
2527 * Constructs a %regex_token_iterator...
2528 * @param __a [IN] The start of the text to search.
2529 * @param __b [IN] One-past-the-end of the text to search.
2530 * @param __re [IN] The regular expression to search for.
2531 * @param __submatches [IN] A list of subexpressions to return for each
2532 * regular expression match within the text.
2533 * @param __m [IN] Policy flags for match rules.
2535 regex_token_iterator(_Bi_iter __a
, _Bi_iter __b
,
2536 const regex_type
& __re
,
2537 const std::vector
<int>& __submatches
,
2538 regex_constants::match_flag_type __m
2539 = regex_constants::match_default
)
2540 : _M_position(__a
, __b
, __re
, __m
), _M_subs(__submatches
), _M_n(0)
2541 { _M_init(__a
, __b
); }
2544 * Constructs a %regex_token_iterator...
2545 * @param __a [IN] The start of the text to search.
2546 * @param __b [IN] One-past-the-end of the text to search.
2547 * @param __re [IN] The regular expression to search for.
2548 * @param __submatches [IN] A list of subexpressions to return for each
2549 * regular expression match within the text.
2550 * @param __m [IN] Policy flags for match rules.
2552 regex_token_iterator(_Bi_iter __a
, _Bi_iter __b
,
2553 const regex_type
& __re
,
2554 initializer_list
<int> __submatches
,
2555 regex_constants::match_flag_type __m
2556 = regex_constants::match_default
)
2557 : _M_position(__a
, __b
, __re
, __m
), _M_subs(__submatches
), _M_n(0)
2558 { _M_init(__a
, __b
); }
2561 * Constructs a %regex_token_iterator...
2562 * @param __a [IN] The start of the text to search.
2563 * @param __b [IN] One-past-the-end of the text to search.
2564 * @param __re [IN] The regular expression to search for.
2565 * @param __submatches [IN] A list of subexpressions to return for each
2566 * regular expression match within the text.
2567 * @param __m [IN] Policy flags for match rules.
2569 template<std::size_t _Nm
>
2570 regex_token_iterator(_Bi_iter __a
, _Bi_iter __b
,
2571 const regex_type
& __re
,
2572 const int (&__submatches
)[_Nm
],
2573 regex_constants::match_flag_type __m
2574 = regex_constants::match_default
)
2575 : _M_position(__a
, __b
, __re
, __m
),
2576 _M_subs(__submatches
, *(&__submatches
+1)), _M_n(0)
2577 { _M_init(__a
, __b
); }
2580 * @brief Copy constructs a %regex_token_iterator.
2581 * @param __rhs [IN] A %regex_token_iterator to copy.
2583 regex_token_iterator(const regex_token_iterator
& __rhs
)
2584 : _M_position(__rhs
._M_position
), _M_subs(__rhs
._M_subs
),
2585 _M_suffix(__rhs
._M_suffix
), _M_n(__rhs
._M_n
), _M_result(__rhs
._M_result
),
2586 _M_has_m1(__rhs
._M_has_m1
)
2588 if (__rhs
._M_result
== &__rhs
._M_suffix
)
2589 _M_result
= &_M_suffix
;
2593 * @brief Assigns a %regex_token_iterator to another.
2594 * @param __rhs [IN] A %regex_token_iterator to copy.
2596 regex_token_iterator
&
2597 operator=(const regex_token_iterator
& __rhs
);
2600 * @brief Compares a %regex_token_iterator to another for equality.
2603 operator==(const regex_token_iterator
& __rhs
) const;
2606 * @brief Compares a %regex_token_iterator to another for inequality.
2609 operator!=(const regex_token_iterator
& __rhs
) const
2610 { return !(*this == __rhs
); }
2613 * @brief Dereferences a %regex_token_iterator.
2617 { return *_M_result
; }
2620 * @brief Selects a %regex_token_iterator member.
2624 { return _M_result
; }
2627 * @brief Increments a %regex_token_iterator.
2629 regex_token_iterator
&
2633 * @brief Postincrements a %regex_token_iterator.
2635 regex_token_iterator
2644 typedef regex_iterator
<_Bi_iter
, _Ch_type
, _Rx_traits
> _Position
;
2647 _M_init(_Bi_iter __a
, _Bi_iter __b
);
2650 _M_current_match() const
2652 if (_M_subs
[_M_n
] == -1)
2653 return (*_M_position
).prefix();
2655 return (*_M_position
)[_M_subs
[_M_n
]];
2660 { return _M_result
== nullptr; }
2662 _Position _M_position
;
2663 std::vector
<int> _M_subs
;
2664 value_type _M_suffix
;
2666 const value_type
* _M_result
;
2668 // Show whether _M_subs contains -1
2672 /** @brief Token iterator for C-style NULL-terminated strings. */
2673 typedef regex_token_iterator
<const char*> cregex_token_iterator
;
2675 /** @brief Token iterator for standard strings. */
2676 typedef regex_token_iterator
<string::const_iterator
> sregex_token_iterator
;
2678 #ifdef _GLIBCXX_USE_WCHAR_T
2679 /** @brief Token iterator for C-style NULL-terminated wide strings. */
2680 typedef regex_token_iterator
<const wchar_t*> wcregex_token_iterator
;
2682 /** @brief Token iterator for standard wide-character strings. */
2683 typedef regex_token_iterator
<wstring::const_iterator
> wsregex_token_iterator
;
2687 _GLIBCXX_END_NAMESPACE_VERSION
2690 #include <bits/regex.tcc>