1 // class template regex -*- C++ -*-
3 // Copyright (C) 2010-2014 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
27 * 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)
33 _GLIBCXX_BEGIN_NAMESPACE_VERSION
34 template<typename
, typename
>
37 template<typename
, typename
>
40 _GLIBCXX_END_NAMESPACE_VERSION
44 _GLIBCXX_BEGIN_NAMESPACE_VERSION
46 enum class _RegexExecutorPolicy
: int
47 { _S_auto
, _S_alternate
};
49 template<typename _BiIter
, typename _Alloc
,
50 typename _CharT
, typename _TraitsT
,
51 _RegexExecutorPolicy __policy
,
54 __regex_algo_impl(_BiIter __s
,
56 match_results
<_BiIter
, _Alloc
>& __m
,
57 const basic_regex
<_CharT
, _TraitsT
>& __re
,
58 regex_constants::match_flag_type __flags
);
60 template<typename
, typename
, typename
, bool>
63 template<typename _TraitsT
>
64 inline std::shared_ptr
<_NFA
<_TraitsT
>>
65 __compile_nfa(const typename
_TraitsT::char_type
* __first
,
66 const typename
_TraitsT::char_type
* __last
,
67 const typename
_TraitsT::locale_type
& __loc
,
68 regex_constants::syntax_option_type __flags
);
70 _GLIBCXX_END_NAMESPACE_VERSION
73 _GLIBCXX_BEGIN_NAMESPACE_VERSION
81 * @brief Describes aspects of a regular expression.
83 * A regular expression traits class that satisfies the requirements of
86 * The class %regex is parameterized around a set of related types and
87 * functions used to complete the definition of its semantics. This class
88 * satisfies the requirements of such a traits class.
90 template<typename _Ch_type
>
94 typedef _Ch_type char_type
;
95 typedef std::basic_string
<char_type
> string_type
;
96 typedef std::locale locale_type
;
100 typedef typename
std::ctype
<char_type
>::mask _BaseType
;
102 unsigned char _M_extended
;
103 static constexpr unsigned char _S_under
= 1 << 0;
104 // FIXME: _S_blank should be removed in the future,
105 // when locale's complete.
106 static constexpr unsigned char _S_blank
= 1 << 1;
107 static constexpr unsigned char _S_valid_mask
= 0x3;
109 constexpr _RegexMask(_BaseType __base
= 0,
110 unsigned char __extended
= 0)
111 : _M_base(__base
), _M_extended(__extended
)
115 operator&(_RegexMask __other
) const
117 return _RegexMask(_M_base
& __other
._M_base
,
118 _M_extended
& __other
._M_extended
);
122 operator|(_RegexMask __other
) const
124 return _RegexMask(_M_base
| __other
._M_base
,
125 _M_extended
| __other
._M_extended
);
129 operator^(_RegexMask __other
) const
131 return _RegexMask(_M_base
^ __other
._M_base
,
132 _M_extended
^ __other
._M_extended
);
137 { return _RegexMask(~_M_base
, ~_M_extended
); }
140 operator&=(_RegexMask __other
)
141 { return *this = (*this) & __other
; }
144 operator|=(_RegexMask __other
)
145 { return *this = (*this) | __other
; }
148 operator^=(_RegexMask __other
)
149 { return *this = (*this) ^ __other
; }
152 operator==(_RegexMask __other
) const
154 return (_M_extended
& _S_valid_mask
)
155 == (__other
._M_extended
& _S_valid_mask
)
156 && _M_base
== __other
._M_base
;
160 operator!=(_RegexMask __other
) const
161 { return !((*this) == __other
); }
165 typedef _RegexMask char_class_type
;
169 * @brief Constructs a default traits object.
174 * @brief Gives the length of a C-style string starting at @p __p.
176 * @param __p a pointer to the start of a character sequence.
178 * @returns the number of characters between @p *__p and the first
179 * default-initialized value of type @p char_type. In other words, uses
180 * the C-string algorithm for determining the length of a sequence of
184 length(const char_type
* __p
)
185 { return string_type::traits_type::length(__p
); }
188 * @brief Performs the identity translation.
190 * @param __c A character to the locale-specific character set.
195 translate(char_type __c
) const
199 * @brief Translates a character into a case-insensitive equivalent.
201 * @param __c A character to the locale-specific character set.
203 * @returns the locale-specific lower-case equivalent of __c.
204 * @throws std::bad_cast if the imbued locale does not support the ctype
208 translate_nocase(char_type __c
) const
210 typedef std::ctype
<char_type
> __ctype_type
;
211 const __ctype_type
& __fctyp(use_facet
<__ctype_type
>(_M_locale
));
212 return __fctyp
.tolower(__c
);
216 * @brief Gets a sort key for a character sequence.
218 * @param __first beginning of the character sequence.
219 * @param __last one-past-the-end of the character sequence.
221 * Returns a sort key for the character sequence designated by the
222 * iterator range [F1, F2) such that if the character sequence [G1, G2)
223 * sorts before the character sequence [H1, H2) then
224 * v.transform(G1, G2) < v.transform(H1, H2).
226 * What this really does is provide a more efficient way to compare a
227 * string to multiple other strings in locales with fancy collation
228 * rules and equivalence classes.
230 * @returns a locale-specific sort key equivalent to the input range.
232 * @throws std::bad_cast if the current locale does not have a collate
235 template<typename _Fwd_iter
>
237 transform(_Fwd_iter __first
, _Fwd_iter __last
) const
239 typedef std::collate
<char_type
> __collate_type
;
240 const __collate_type
& __fclt(use_facet
<__collate_type
>(_M_locale
));
241 string_type
__s(__first
, __last
);
242 return __fclt
.transform(__s
.data(), __s
.data() + __s
.size());
246 * @brief Gets a sort key for a character sequence, independent of case.
248 * @param __first beginning of the character sequence.
249 * @param __last one-past-the-end of the character sequence.
251 * Effects: if typeid(use_facet<collate<_Ch_type> >) ==
252 * typeid(collate_byname<_Ch_type>) and the form of the sort key
253 * returned by collate_byname<_Ch_type>::transform(__first, __last)
254 * is known and can be converted into a primary sort key
255 * then returns that key, otherwise returns an empty string.
257 * @todo Implement this function correctly.
259 template<typename _Fwd_iter
>
261 transform_primary(_Fwd_iter __first
, _Fwd_iter __last
) const
263 // TODO : this is not entirely correct.
264 // This function requires extra support from the platform.
266 // Read http://gcc.gnu.org/ml/libstdc++/2013-09/msg00117.html and
267 // http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2003/n1429.htm
269 typedef std::ctype
<char_type
> __ctype_type
;
270 const __ctype_type
& __fctyp(use_facet
<__ctype_type
>(_M_locale
));
271 std::vector
<char_type
> __s(__first
, __last
);
272 __fctyp
.tolower(__s
.data(), __s
.data() + __s
.size());
273 return this->transform(__s
.data(), __s
.data() + __s
.size());
277 * @brief Gets a collation element by name.
279 * @param __first beginning of the collation element name.
280 * @param __last one-past-the-end of the collation element name.
282 * @returns a sequence of one or more characters that represents the
283 * collating element consisting of the character sequence designated by
284 * the iterator range [__first, __last). Returns an empty string if the
285 * character sequence is not a valid collating element.
287 template<typename _Fwd_iter
>
289 lookup_collatename(_Fwd_iter __first
, _Fwd_iter __last
) const;
292 * @brief Maps one or more characters to a named character
295 * @param __first beginning of the character sequence.
296 * @param __last one-past-the-end of the character sequence.
297 * @param __icase ignores the case of the classification name.
299 * @returns an unspecified value that represents the character
300 * classification named by the character sequence designated by
301 * the iterator range [__first, __last). If @p icase is true,
302 * the returned mask identifies the classification regardless of
303 * the case of the characters to be matched (for example,
304 * [[:lower:]] is the same as [[:alpha:]]), otherwise a
305 * case-dependent classification is returned. The value
306 * returned shall be independent of the case of the characters
307 * in the character sequence. If the name is not recognized then
308 * returns a value that compares equal to 0.
310 * At least the following names (or their wide-character equivalent) are
328 template<typename _Fwd_iter
>
330 lookup_classname(_Fwd_iter __first
, _Fwd_iter __last
,
331 bool __icase
= false) const;
334 * @brief Determines if @p c is a member of an identified class.
336 * @param __c a character.
337 * @param __f a class type (as returned from lookup_classname).
339 * @returns true if the character @p __c is a member of the classification
340 * represented by @p __f, false otherwise.
342 * @throws std::bad_cast if the current locale does not have a ctype
346 isctype(_Ch_type __c
, char_class_type __f
) const;
349 * @brief Converts a digit to an int.
351 * @param __ch a character representing a digit.
352 * @param __radix the radix if the numeric conversion (limited to 8, 10,
355 * @returns the value represented by the digit __ch in base radix if the
356 * character __ch is a valid digit in base radix; otherwise returns -1.
359 value(_Ch_type __ch
, int __radix
) const;
362 * @brief Imbues the regex_traits object with a copy of a new locale.
364 * @param __loc A locale.
366 * @returns a copy of the previous locale in use by the regex_traits
369 * @note Calling imbue with a different locale than the one currently in
370 * use invalidates all cached data held by *this.
373 imbue(locale_type __loc
)
375 std::swap(_M_locale
, __loc
);
380 * @brief Gets a copy of the current locale in use by the regex_traits
385 { return _M_locale
; }
388 locale_type _M_locale
;
391 // [7.8] Class basic_regex
393 * Objects of specializations of this class represent regular expressions
394 * constructed from sequences of character type @p _Ch_type.
396 * Storage for the regular expression is allocated and deallocated as
397 * necessary by the member functions of this class.
399 template<typename _Ch_type
, typename _Rx_traits
= regex_traits
<_Ch_type
>>
403 static_assert(is_same
<_Ch_type
, typename
_Rx_traits::char_type
>::value
,
404 "regex traits class must have the same char_type");
407 typedef _Ch_type value_type
;
408 typedef _Rx_traits traits_type
;
409 typedef typename
traits_type::string_type string_type
;
410 typedef regex_constants::syntax_option_type flag_type
;
411 typedef typename
traits_type::locale_type locale_type
;
418 static constexpr flag_type icase
= regex_constants::icase
;
419 static constexpr flag_type nosubs
= regex_constants::nosubs
;
420 static constexpr flag_type optimize
= regex_constants::optimize
;
421 static constexpr flag_type collate
= regex_constants::collate
;
422 static constexpr flag_type ECMAScript
= regex_constants::ECMAScript
;
423 static constexpr flag_type basic
= regex_constants::basic
;
424 static constexpr flag_type extended
= regex_constants::extended
;
425 static constexpr flag_type awk
= regex_constants::awk
;
426 static constexpr flag_type grep
= regex_constants::grep
;
427 static constexpr flag_type egrep
= regex_constants::egrep
;
430 // [7.8.2] construct/copy/destroy
432 * Constructs a basic regular expression that does not match any
433 * character sequence.
436 : _M_flags(ECMAScript
), _M_loc(), _M_original_str(), _M_automaton(nullptr)
440 * @brief Constructs a basic regular expression from the
441 * sequence [__p, __p + char_traits<_Ch_type>::length(__p))
442 * interpreted according to the flags in @p __f.
444 * @param __p A pointer to the start of a C-style null-terminated string
445 * containing a regular expression.
446 * @param __f Flags indicating the syntax rules and options.
448 * @throws regex_error if @p __p is not a valid regular expression.
451 basic_regex(const _Ch_type
* __p
, flag_type __f
= ECMAScript
)
452 : basic_regex(__p
, __p
+ _Rx_traits::length(__p
), __f
)
456 * @brief Constructs a basic regular expression from the sequence
457 * [p, p + len) interpreted according to the flags in @p f.
459 * @param __p A pointer to the start of a string containing a regular
461 * @param __len The length of the string containing the regular
463 * @param __f Flags indicating the syntax rules and options.
465 * @throws regex_error if @p __p is not a valid regular expression.
467 basic_regex(const _Ch_type
* __p
, std::size_t __len
,
468 flag_type __f
= ECMAScript
)
469 : basic_regex(__p
, __p
+ __len
, __f
)
473 * @brief Copy-constructs a basic regular expression.
475 * @param __rhs A @p regex object.
477 basic_regex(const basic_regex
& __rhs
) = default;
480 * @brief Move-constructs a basic regular expression.
482 * @param __rhs A @p regex object.
484 basic_regex(basic_regex
&& __rhs
) noexcept
= default;
487 * @brief Constructs a basic regular expression from the string
488 * @p s interpreted according to the flags in @p f.
490 * @param __s A string containing a regular expression.
491 * @param __f Flags indicating the syntax rules and options.
493 * @throws regex_error if @p __s is not a valid regular expression.
495 template<typename _Ch_traits
, typename _Ch_alloc
>
497 basic_regex(const std::basic_string
<_Ch_type
, _Ch_traits
,
499 flag_type __f
= ECMAScript
)
500 : basic_regex(__s
.begin(), __s
.end(), __f
)
504 * @brief Constructs a basic regular expression from the range
505 * [first, last) interpreted according to the flags in @p f.
507 * @param __first The start of a range containing a valid regular
509 * @param __last The end of a range containing a valid regular
511 * @param __f The format flags of the regular expression.
513 * @throws regex_error if @p [__first, __last) is not a valid regular
516 template<typename _FwdIter
>
517 basic_regex(_FwdIter __first
, _FwdIter __last
,
518 flag_type __f
= ECMAScript
)
521 _M_original_str(__first
, __last
),
522 _M_automaton(__detail::__compile_nfa
<_Rx_traits
>(
523 _M_original_str
.c_str(),
524 _M_original_str
.c_str() + _M_original_str
.size(),
530 * @brief Constructs a basic regular expression from an initializer list.
532 * @param __l The initializer list.
533 * @param __f The format flags of the regular expression.
535 * @throws regex_error if @p __l is not a valid regular expression.
537 basic_regex(initializer_list
<_Ch_type
> __l
, flag_type __f
= ECMAScript
)
538 : basic_regex(__l
.begin(), __l
.end(), __f
)
542 * @brief Destroys a basic regular expression.
548 * @brief Assigns one regular expression to another.
551 operator=(const basic_regex
& __rhs
)
552 { return this->assign(__rhs
); }
555 * @brief Move-assigns one regular expression to another.
558 operator=(basic_regex
&& __rhs
) noexcept
559 { return this->assign(std::move(__rhs
)); }
562 * @brief Replaces a regular expression with a new one constructed from
563 * a C-style null-terminated string.
565 * @param __p A pointer to the start of a null-terminated C-style string
566 * containing a regular expression.
569 operator=(const _Ch_type
* __p
)
570 { return this->assign(__p
, flags()); }
573 * @brief Replaces a regular expression with a new one constructed from
576 * @param __s A pointer to a string containing a regular expression.
578 template<typename _Ch_traits
, typename _Alloc
>
580 operator=(const basic_string
<_Ch_type
, _Ch_traits
, _Alloc
>& __s
)
581 { return this->assign(__s
, flags()); }
585 * @brief the real assignment operator.
587 * @param __rhs Another regular expression object.
590 assign(const basic_regex
& __rhs
)
592 basic_regex
__tmp(__rhs
);
598 * @brief The move-assignment operator.
600 * @param __rhs Another regular expression object.
603 assign(basic_regex
&& __rhs
) noexcept
605 basic_regex
__tmp(std::move(__rhs
));
611 * @brief Assigns a new regular expression to a regex object from a
612 * C-style null-terminated string containing a regular expression
615 * @param __p A pointer to a C-style null-terminated string containing
616 * a regular expression pattern.
617 * @param __flags Syntax option flags.
619 * @throws regex_error if __p does not contain a valid regular
620 * expression pattern interpreted according to @p __flags. If
621 * regex_error is thrown, *this remains unchanged.
624 assign(const _Ch_type
* __p
, flag_type __flags
= ECMAScript
)
625 { return this->assign(string_type(__p
), __flags
); }
628 * @brief Assigns a new regular expression to a regex object from a
629 * C-style string containing a regular expression pattern.
631 * @param __p A pointer to a C-style string containing a
632 * regular expression pattern.
633 * @param __len The length of the regular expression pattern string.
634 * @param __flags Syntax option flags.
636 * @throws regex_error if p does not contain a valid regular
637 * expression pattern interpreted according to @p __flags. If
638 * regex_error is thrown, *this remains unchanged.
641 assign(const _Ch_type
* __p
, std::size_t __len
, flag_type __flags
)
642 { return this->assign(string_type(__p
, __len
), __flags
); }
645 * @brief Assigns a new regular expression to a regex object from a
646 * string containing a regular expression pattern.
648 * @param __s A string containing a regular expression pattern.
649 * @param __flags Syntax option flags.
651 * @throws regex_error if __s does not contain a valid regular
652 * expression pattern interpreted according to @p __flags. If
653 * regex_error is thrown, *this remains unchanged.
655 template<typename _Ch_traits
, typename _Alloc
>
657 assign(const basic_string
<_Ch_type
, _Ch_traits
, _Alloc
>& __s
,
658 flag_type __flags
= ECMAScript
)
661 _M_original_str
.assign(__s
.begin(), __s
.end());
662 auto __p
= _M_original_str
.c_str();
663 _M_automaton
= __detail::__compile_nfa
<_Rx_traits
>(
665 __p
+ _M_original_str
.size(),
672 * @brief Assigns a new regular expression to a regex object.
674 * @param __first The start of a range containing a valid regular
676 * @param __last The end of a range containing a valid regular
678 * @param __flags Syntax option flags.
680 * @throws regex_error if p does not contain a valid regular
681 * expression pattern interpreted according to @p __flags. If
682 * regex_error is thrown, the object remains unchanged.
684 template<typename _InputIterator
>
686 assign(_InputIterator __first
, _InputIterator __last
,
687 flag_type __flags
= ECMAScript
)
688 { return this->assign(string_type(__first
, __last
), __flags
); }
691 * @brief Assigns a new regular expression to a regex object.
693 * @param __l An initializer list representing a regular expression.
694 * @param __flags Syntax option flags.
696 * @throws regex_error if @p __l does not contain a valid
697 * regular expression pattern interpreted according to @p
698 * __flags. If regex_error is thrown, the object remains
702 assign(initializer_list
<_Ch_type
> __l
, flag_type __flags
= ECMAScript
)
703 { return this->assign(__l
.begin(), __l
.end(), __flags
); }
705 // [7.8.4] const operations
707 * @brief Gets the number of marked subexpressions within the regular
712 { return _M_automaton
->_M_sub_count() - 1; }
715 * @brief Gets the flags used to construct the regular expression
716 * or in the last call to assign().
724 * @brief Imbues the regular expression object with the given locale.
726 * @param __loc A locale.
729 imbue(locale_type __loc
)
731 std::swap(__loc
, _M_loc
);
732 if (_M_automaton
!= nullptr)
733 this->assign(_M_original_str
, _M_flags
);
738 * @brief Gets the locale currently imbued in the regular expression
747 * @brief Swaps the contents of two regular expression objects.
749 * @param __rhs Another regular expression object.
752 swap(basic_regex
& __rhs
)
754 std::swap(_M_flags
, __rhs
._M_flags
);
755 std::swap(_M_loc
, __rhs
._M_loc
);
756 std::swap(_M_original_str
, __rhs
._M_original_str
);
757 std::swap(_M_automaton
, __rhs
._M_automaton
);
760 #ifdef _GLIBCXX_DEBUG
762 _M_dot(std::ostream
& __ostr
)
763 { _M_automaton
->_M_dot(__ostr
); }
767 typedef std::shared_ptr
<__detail::_NFA
<_Rx_traits
>> _AutomatonPtr
;
769 template<typename _Bp
, typename _Ap
, typename _Cp
, typename _Rp
,
770 __detail::_RegexExecutorPolicy
, bool>
772 __detail::__regex_algo_impl(_Bp
, _Bp
, match_results
<_Bp
, _Ap
>&,
773 const basic_regex
<_Cp
, _Rp
>&,
774 regex_constants::match_flag_type
);
776 template<typename
, typename
, typename
, bool>
777 friend class __detail::_Executor
;
781 basic_string
<_Ch_type
> _M_original_str
;
782 _AutomatonPtr _M_automaton
;
785 /** @brief Standard regular expressions. */
786 typedef basic_regex
<char> regex
;
788 #ifdef _GLIBCXX_USE_WCHAR_T
789 /** @brief Standard wide-character regular expressions. */
790 typedef basic_regex
<wchar_t> wregex
;
794 // [7.8.6] basic_regex swap
796 * @brief Swaps the contents of two regular expression objects.
797 * @param __lhs First regular expression.
798 * @param __rhs Second regular expression.
800 template<typename _Ch_type
, typename _Rx_traits
>
802 swap(basic_regex
<_Ch_type
, _Rx_traits
>& __lhs
,
803 basic_regex
<_Ch_type
, _Rx_traits
>& __rhs
)
804 { __lhs
.swap(__rhs
); }
807 // [7.9] Class template sub_match
809 * A sequence of characters matched by a particular marked sub-expression.
811 * An object of this class is essentially a pair of iterators marking a
812 * matched subexpression within a regular expression pattern match. Such
813 * objects can be converted to and compared with std::basic_string objects
814 * of a similar base character type as the pattern matched by the regular
817 * The iterators that make up the pair are the usual half-open interval
818 * referencing the actual original pattern matched.
820 template<typename _BiIter
>
821 class sub_match
: public std::pair
<_BiIter
, _BiIter
>
823 typedef iterator_traits
<_BiIter
> __iter_traits
;
826 typedef typename
__iter_traits::value_type value_type
;
827 typedef typename
__iter_traits::difference_type difference_type
;
828 typedef _BiIter iterator
;
829 typedef std::basic_string
<value_type
> string_type
;
833 constexpr sub_match() : matched() { }
836 * Gets the length of the matching sequence.
840 { return this->matched
? std::distance(this->first
, this->second
) : 0; }
843 * @brief Gets the matching sequence as a string.
845 * @returns the matching sequence as a string.
847 * This is the implicit conversion operator. It is identical to the
848 * str() member function except that it will want to pop up in
849 * unexpected places and cause a great deal of confusion and cursing
852 operator string_type() const
855 ? string_type(this->first
, this->second
)
860 * @brief Gets the matching sequence as a string.
862 * @returns the matching sequence as a string.
868 ? string_type(this->first
, this->second
)
873 * @brief Compares this and another matched sequence.
875 * @param __s Another matched sequence to compare to this one.
877 * @retval <0 this matched sequence will collate before @p __s.
878 * @retval =0 this matched sequence is equivalent to @p __s.
879 * @retval <0 this matched sequence will collate after @p __s.
882 compare(const sub_match
& __s
) const
883 { return this->str().compare(__s
.str()); }
886 * @brief Compares this sub_match to a string.
888 * @param __s A string to compare to this sub_match.
890 * @retval <0 this matched sequence will collate before @p __s.
891 * @retval =0 this matched sequence is equivalent to @p __s.
892 * @retval <0 this matched sequence will collate after @p __s.
895 compare(const string_type
& __s
) const
896 { return this->str().compare(__s
); }
899 * @brief Compares this sub_match to a C-style string.
901 * @param __s A C-style string to compare to this sub_match.
903 * @retval <0 this matched sequence will collate before @p __s.
904 * @retval =0 this matched sequence is equivalent to @p __s.
905 * @retval <0 this matched sequence will collate after @p __s.
908 compare(const value_type
* __s
) const
909 { return this->str().compare(__s
); }
913 /** @brief Standard regex submatch over a C-style null-terminated string. */
914 typedef sub_match
<const char*> csub_match
;
916 /** @brief Standard regex submatch over a standard string. */
917 typedef sub_match
<string::const_iterator
> ssub_match
;
919 #ifdef _GLIBCXX_USE_WCHAR_T
920 /** @brief Regex submatch over a C-style null-terminated wide string. */
921 typedef sub_match
<const wchar_t*> wcsub_match
;
923 /** @brief Regex submatch over a standard wide string. */
924 typedef sub_match
<wstring::const_iterator
> wssub_match
;
927 // [7.9.2] sub_match non-member operators
930 * @brief Tests the equivalence 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 is equivalent to @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 inequivalence 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 is not equivalent to @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 precedes @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; }
963 * @brief Tests the ordering of two regular expression submatches.
964 * @param __lhs First regular expression submatch.
965 * @param __rhs Second regular expression submatch.
966 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
968 template<typename _BiIter
>
970 operator<=(const sub_match
<_BiIter
>& __lhs
, const sub_match
<_BiIter
>& __rhs
)
971 { return __lhs
.compare(__rhs
) <= 0; }
974 * @brief Tests the ordering of two regular expression submatches.
975 * @param __lhs First regular expression submatch.
976 * @param __rhs Second regular expression submatch.
977 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
979 template<typename _BiIter
>
981 operator>=(const sub_match
<_BiIter
>& __lhs
, const sub_match
<_BiIter
>& __rhs
)
982 { return __lhs
.compare(__rhs
) >= 0; }
985 * @brief Tests the ordering of two regular expression submatches.
986 * @param __lhs First regular expression submatch.
987 * @param __rhs Second regular expression submatch.
988 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
990 template<typename _BiIter
>
992 operator>(const sub_match
<_BiIter
>& __lhs
, const sub_match
<_BiIter
>& __rhs
)
993 { return __lhs
.compare(__rhs
) > 0; }
995 // Alias for sub_match'd string.
996 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
997 using __sub_match_string
= basic_string
<
998 typename iterator_traits
<_Bi_iter
>::value_type
,
999 _Ch_traits
, _Ch_alloc
>;
1002 * @brief Tests the equivalence of a string and a regular expression
1004 * @param __lhs A string.
1005 * @param __rhs A regular expression submatch.
1006 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1008 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1010 operator==(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
1011 const sub_match
<_Bi_iter
>& __rhs
)
1012 { return __rhs
.compare(__lhs
.c_str()) == 0; }
1015 * @brief Tests the inequivalence of a string and a regular expression
1017 * @param __lhs A string.
1018 * @param __rhs A regular expression submatch.
1019 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1021 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1023 operator!=(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
1024 const sub_match
<_Bi_iter
>& __rhs
)
1025 { return !(__lhs
== __rhs
); }
1028 * @brief Tests the ordering of a string and a regular expression submatch.
1029 * @param __lhs A string.
1030 * @param __rhs A regular expression submatch.
1031 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1033 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1035 operator<(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
1036 const sub_match
<_Bi_iter
>& __rhs
)
1037 { return __rhs
.compare(__lhs
.c_str()) > 0; }
1040 * @brief Tests the ordering of a string and a regular expression submatch.
1041 * @param __lhs A string.
1042 * @param __rhs A regular expression submatch.
1043 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1045 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1047 operator>(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
1048 const sub_match
<_Bi_iter
>& __rhs
)
1049 { return __rhs
< __lhs
; }
1052 * @brief Tests the ordering of a string and a regular expression submatch.
1053 * @param __lhs A string.
1054 * @param __rhs A regular expression submatch.
1055 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1057 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1059 operator>=(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
1060 const sub_match
<_Bi_iter
>& __rhs
)
1061 { return !(__lhs
< __rhs
); }
1064 * @brief Tests the ordering of a string and a regular expression submatch.
1065 * @param __lhs A string.
1066 * @param __rhs A regular expression submatch.
1067 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1069 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1071 operator<=(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
1072 const sub_match
<_Bi_iter
>& __rhs
)
1073 { return !(__rhs
< __lhs
); }
1076 * @brief Tests the equivalence of a regular expression submatch and a
1078 * @param __lhs A regular expression submatch.
1079 * @param __rhs A string.
1080 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1082 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1084 operator==(const sub_match
<_Bi_iter
>& __lhs
,
1085 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1086 { return __lhs
.compare(__rhs
.c_str()) == 0; }
1089 * @brief Tests the inequivalence of a regular expression submatch and a
1091 * @param __lhs A regular expression submatch.
1092 * @param __rhs A string.
1093 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1095 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1097 operator!=(const sub_match
<_Bi_iter
>& __lhs
,
1098 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1099 { return !(__lhs
== __rhs
); }
1102 * @brief Tests the ordering of a regular expression submatch and a string.
1103 * @param __lhs A regular expression submatch.
1104 * @param __rhs A string.
1105 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1107 template<typename _Bi_iter
, class _Ch_traits
, class _Ch_alloc
>
1109 operator<(const sub_match
<_Bi_iter
>& __lhs
,
1110 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1111 { return __lhs
.compare(__rhs
.c_str()) < 0; }
1114 * @brief Tests the ordering of a regular expression submatch and a string.
1115 * @param __lhs A regular expression submatch.
1116 * @param __rhs A string.
1117 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1119 template<typename _Bi_iter
, class _Ch_traits
, class _Ch_alloc
>
1121 operator>(const sub_match
<_Bi_iter
>& __lhs
,
1122 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1123 { return __rhs
< __lhs
; }
1126 * @brief Tests the ordering of a regular expression submatch and a string.
1127 * @param __lhs A regular expression submatch.
1128 * @param __rhs A string.
1129 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1131 template<typename _Bi_iter
, class _Ch_traits
, class _Ch_alloc
>
1133 operator>=(const sub_match
<_Bi_iter
>& __lhs
,
1134 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1135 { return !(__lhs
< __rhs
); }
1138 * @brief Tests the ordering of a regular expression submatch and a string.
1139 * @param __lhs A regular expression submatch.
1140 * @param __rhs A string.
1141 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1143 template<typename _Bi_iter
, class _Ch_traits
, class _Ch_alloc
>
1145 operator<=(const sub_match
<_Bi_iter
>& __lhs
,
1146 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1147 { return !(__rhs
< __lhs
); }
1150 * @brief Tests the equivalence of a C string and a regular expression
1152 * @param __lhs A C string.
1153 * @param __rhs A regular expression submatch.
1154 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1156 template<typename _Bi_iter
>
1158 operator==(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1159 const sub_match
<_Bi_iter
>& __rhs
)
1160 { return __rhs
.compare(__lhs
) == 0; }
1163 * @brief Tests the inequivalence of an iterator value and a regular
1164 * expression submatch.
1165 * @param __lhs A regular expression submatch.
1166 * @param __rhs A string.
1167 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1169 template<typename _Bi_iter
>
1171 operator!=(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1172 const sub_match
<_Bi_iter
>& __rhs
)
1173 { return !(__lhs
== __rhs
); }
1176 * @brief Tests the ordering of a string and a regular expression submatch.
1177 * @param __lhs A string.
1178 * @param __rhs A regular expression submatch.
1179 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1181 template<typename _Bi_iter
>
1183 operator<(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1184 const sub_match
<_Bi_iter
>& __rhs
)
1185 { return __rhs
.compare(__lhs
) > 0; }
1188 * @brief Tests the ordering of a string and a regular expression submatch.
1189 * @param __lhs A string.
1190 * @param __rhs A regular expression submatch.
1191 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1193 template<typename _Bi_iter
>
1195 operator>(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1196 const sub_match
<_Bi_iter
>& __rhs
)
1197 { return __rhs
< __lhs
; }
1200 * @brief Tests the ordering of a string and a regular expression submatch.
1201 * @param __lhs A string.
1202 * @param __rhs A regular expression submatch.
1203 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1205 template<typename _Bi_iter
>
1207 operator>=(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1208 const sub_match
<_Bi_iter
>& __rhs
)
1209 { return !(__lhs
< __rhs
); }
1212 * @brief Tests the ordering of a string and a regular expression submatch.
1213 * @param __lhs A string.
1214 * @param __rhs A regular expression submatch.
1215 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1217 template<typename _Bi_iter
>
1219 operator<=(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1220 const sub_match
<_Bi_iter
>& __rhs
)
1221 { return !(__rhs
< __lhs
); }
1224 * @brief Tests the equivalence of a regular expression submatch and a
1226 * @param __lhs A regular expression submatch.
1227 * @param __rhs A pointer to a string?
1228 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1230 template<typename _Bi_iter
>
1232 operator==(const sub_match
<_Bi_iter
>& __lhs
,
1233 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1234 { return __lhs
.compare(__rhs
) == 0; }
1237 * @brief Tests the inequivalence of a regular expression submatch and a
1239 * @param __lhs A regular expression submatch.
1240 * @param __rhs A pointer to a string.
1241 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1243 template<typename _Bi_iter
>
1245 operator!=(const sub_match
<_Bi_iter
>& __lhs
,
1246 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1247 { return !(__lhs
== __rhs
); }
1250 * @brief Tests the ordering of a regular expression submatch and a string.
1251 * @param __lhs A regular expression submatch.
1252 * @param __rhs A string.
1253 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1255 template<typename _Bi_iter
>
1257 operator<(const sub_match
<_Bi_iter
>& __lhs
,
1258 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1259 { return __lhs
.compare(__rhs
) < 0; }
1262 * @brief Tests the ordering of a regular expression submatch and a string.
1263 * @param __lhs A regular expression submatch.
1264 * @param __rhs A string.
1265 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1267 template<typename _Bi_iter
>
1269 operator>(const sub_match
<_Bi_iter
>& __lhs
,
1270 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1271 { return __rhs
< __lhs
; }
1274 * @brief Tests the ordering of a regular expression submatch and a string.
1275 * @param __lhs A regular expression submatch.
1276 * @param __rhs A string.
1277 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1279 template<typename _Bi_iter
>
1281 operator>=(const sub_match
<_Bi_iter
>& __lhs
,
1282 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1283 { return !(__lhs
< __rhs
); }
1286 * @brief Tests the ordering of a regular expression submatch and a string.
1287 * @param __lhs A regular expression submatch.
1288 * @param __rhs A string.
1289 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1291 template<typename _Bi_iter
>
1293 operator<=(const sub_match
<_Bi_iter
>& __lhs
,
1294 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1295 { return !(__rhs
< __lhs
); }
1298 * @brief Tests the equivalence of a string and a regular expression
1300 * @param __lhs A string.
1301 * @param __rhs A regular expression submatch.
1302 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1304 template<typename _Bi_iter
>
1306 operator==(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1307 const sub_match
<_Bi_iter
>& __rhs
)
1309 typedef typename sub_match
<_Bi_iter
>::string_type string_type
;
1310 return __rhs
.compare(string_type(1, __lhs
)) == 0;
1314 * @brief Tests the inequivalence of a string and a regular expression
1316 * @param __lhs A string.
1317 * @param __rhs A regular expression submatch.
1318 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1320 template<typename _Bi_iter
>
1322 operator!=(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1323 const sub_match
<_Bi_iter
>& __rhs
)
1324 { return !(__lhs
== __rhs
); }
1327 * @brief Tests the ordering of a string and a regular expression submatch.
1328 * @param __lhs A string.
1329 * @param __rhs A regular expression submatch.
1330 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1332 template<typename _Bi_iter
>
1334 operator<(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1335 const sub_match
<_Bi_iter
>& __rhs
)
1337 typedef typename sub_match
<_Bi_iter
>::string_type string_type
;
1338 return __rhs
.compare(string_type(1, __lhs
)) > 0;
1342 * @brief Tests the ordering of a string and a regular expression submatch.
1343 * @param __lhs A string.
1344 * @param __rhs A regular expression submatch.
1345 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1347 template<typename _Bi_iter
>
1349 operator>(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1350 const sub_match
<_Bi_iter
>& __rhs
)
1351 { return __rhs
< __lhs
; }
1354 * @brief Tests the ordering of a string and a regular expression submatch.
1355 * @param __lhs A string.
1356 * @param __rhs A regular expression submatch.
1357 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1359 template<typename _Bi_iter
>
1361 operator>=(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1362 const sub_match
<_Bi_iter
>& __rhs
)
1363 { return !(__lhs
< __rhs
); }
1366 * @brief Tests the ordering of a string and a regular expression submatch.
1367 * @param __lhs A string.
1368 * @param __rhs A regular expression submatch.
1369 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1371 template<typename _Bi_iter
>
1373 operator<=(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1374 const sub_match
<_Bi_iter
>& __rhs
)
1375 { return !(__rhs
< __lhs
); }
1378 * @brief Tests the equivalence of a regular expression submatch and a
1380 * @param __lhs A regular expression submatch.
1381 * @param __rhs A const string reference.
1382 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1384 template<typename _Bi_iter
>
1386 operator==(const sub_match
<_Bi_iter
>& __lhs
,
1387 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1389 typedef typename sub_match
<_Bi_iter
>::string_type string_type
;
1390 return __lhs
.compare(string_type(1, __rhs
)) == 0;
1394 * @brief Tests the inequivalence of a regular expression submatch and a
1396 * @param __lhs A regular expression submatch.
1397 * @param __rhs A const string reference.
1398 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1400 template<typename _Bi_iter
>
1402 operator!=(const sub_match
<_Bi_iter
>& __lhs
,
1403 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1404 { return !(__lhs
== __rhs
); }
1407 * @brief Tests the ordering of a regular expression submatch and a string.
1408 * @param __lhs A regular expression submatch.
1409 * @param __rhs A const string reference.
1410 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1412 template<typename _Bi_iter
>
1414 operator<(const sub_match
<_Bi_iter
>& __lhs
,
1415 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1417 typedef typename sub_match
<_Bi_iter
>::string_type string_type
;
1418 return __lhs
.compare(string_type(1, __rhs
)) < 0;
1422 * @brief Tests the ordering of a regular expression submatch and a string.
1423 * @param __lhs A regular expression submatch.
1424 * @param __rhs A const string reference.
1425 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1427 template<typename _Bi_iter
>
1429 operator>(const sub_match
<_Bi_iter
>& __lhs
,
1430 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1431 { return __rhs
< __lhs
; }
1434 * @brief Tests the ordering of a regular expression submatch and a string.
1435 * @param __lhs A regular expression submatch.
1436 * @param __rhs A const string reference.
1437 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1439 template<typename _Bi_iter
>
1441 operator>=(const sub_match
<_Bi_iter
>& __lhs
,
1442 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1443 { return !(__lhs
< __rhs
); }
1446 * @brief Tests the ordering of a regular expression submatch and a string.
1447 * @param __lhs A regular expression submatch.
1448 * @param __rhs A const string reference.
1449 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1451 template<typename _Bi_iter
>
1453 operator<=(const sub_match
<_Bi_iter
>& __lhs
,
1454 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1455 { return !(__rhs
< __lhs
); }
1458 * @brief Inserts a matched string into an output stream.
1460 * @param __os The output stream.
1461 * @param __m A submatch string.
1463 * @returns the output stream with the submatch string inserted.
1465 template<typename _Ch_type
, typename _Ch_traits
, typename _Bi_iter
>
1467 basic_ostream
<_Ch_type
, _Ch_traits
>&
1468 operator<<(basic_ostream
<_Ch_type
, _Ch_traits
>& __os
,
1469 const sub_match
<_Bi_iter
>& __m
)
1470 { return __os
<< __m
.str(); }
1472 // [7.10] Class template match_results
1475 * Special sub_match object representing an unmatched sub-expression.
1477 template<typename _Bi_iter
>
1478 inline const sub_match
<_Bi_iter
>&
1481 static const sub_match
<_Bi_iter
> __unmatched
= sub_match
<_Bi_iter
>();
1486 * @brief The results of a match or search operation.
1488 * A collection of character sequences representing the result of a regular
1489 * expression match. Storage for the collection is allocated and freed as
1490 * necessary by the member functions of class template match_results.
1492 * This class satisfies the Sequence requirements, with the exception that
1493 * only the operations defined for a const-qualified Sequence are supported.
1495 * The sub_match object stored at index 0 represents sub-expression 0, i.e.
1496 * the whole match. In this case the %sub_match member matched is always true.
1497 * The sub_match object stored at index n denotes what matched the marked
1498 * sub-expression n within the matched expression. If the sub-expression n
1499 * participated in a regular expression match then the %sub_match member
1500 * matched evaluates to true, and members first and second denote the range
1501 * of characters [first, second) which formed that match. Otherwise matched
1502 * is false, and members first and second point to the end of the sequence
1503 * that was searched.
1507 template<typename _Bi_iter
,
1508 typename _Alloc
= allocator
<sub_match
<_Bi_iter
> > >
1510 : private std::vector
<sub_match
<_Bi_iter
>, _Alloc
>
1514 * The vector base is empty if this does not represent a successful match.
1515 * Otherwise it contains n+3 elements where n is the number of marked
1518 * [1] 1st marked subexpression
1520 * [n] nth marked subexpression
1524 typedef std::vector
<sub_match
<_Bi_iter
>, _Alloc
> _Base_type
;
1525 typedef std::iterator_traits
<_Bi_iter
> __iter_traits
;
1526 typedef regex_constants::match_flag_type match_flag_type
;
1530 * @name 10.? Public Types
1533 typedef sub_match
<_Bi_iter
> value_type
;
1534 typedef const value_type
& const_reference
;
1535 typedef const_reference reference
;
1536 typedef typename
_Base_type::const_iterator const_iterator
;
1537 typedef const_iterator iterator
;
1538 typedef typename
__iter_traits::difference_type difference_type
;
1539 typedef typename allocator_traits
<_Alloc
>::size_type size_type
;
1540 typedef _Alloc allocator_type
;
1541 typedef typename
__iter_traits::value_type char_type
;
1542 typedef std::basic_string
<char_type
> string_type
;
1547 * @name 28.10.1 Construction, Copying, and Destruction
1552 * @brief Constructs a default %match_results container.
1553 * @post size() returns 0 and str() returns an empty string.
1556 match_results(const _Alloc
& __a
= _Alloc())
1557 : _Base_type(__a
), _M_in_iterator(false)
1561 * @brief Copy constructs a %match_results.
1563 match_results(const match_results
& __rhs
)
1564 : _Base_type(__rhs
), _M_in_iterator(false)
1568 * @brief Move constructs a %match_results.
1570 match_results(match_results
&& __rhs
) noexcept
1571 : _Base_type(std::move(__rhs
)), _M_in_iterator(false)
1575 * @brief Assigns rhs to *this.
1578 operator=(const match_results
& __rhs
)
1580 match_results(__rhs
).swap(*this);
1585 * @brief Move-assigns rhs to *this.
1588 operator=(match_results
&& __rhs
)
1590 match_results(std::move(__rhs
)).swap(*this);
1595 * @brief Destroys a %match_results object.
1604 * @brief Indicates if the %match_results is ready.
1605 * @retval true The object has a fully-established result state.
1606 * @retval false The object is not ready.
1608 bool ready() const { return !_Base_type::empty(); }
1611 * @name 28.10.2 Size
1616 * @brief Gets the number of matches and submatches.
1618 * The number of matches for a given regular expression will be either 0
1619 * if there was no match or mark_count() + 1 if a match was successful.
1620 * Some matches may be empty.
1622 * @returns the number of matches found.
1627 size_type __size
= _Base_type::size();
1628 return (__size
&& _Base_type::operator[](0).matched
) ? __size
- 2 : 0;
1633 { return _Base_type::max_size(); }
1636 * @brief Indicates if the %match_results contains no results.
1637 * @retval true The %match_results object is empty.
1638 * @retval false The %match_results object is not empty.
1642 { return size() == 0; }
1647 * @name 10.3 Element Access
1652 * @brief Gets the length of the indicated submatch.
1653 * @param __sub indicates the submatch.
1654 * @pre ready() == true
1656 * This function returns the length of the indicated submatch, or the
1657 * length of the entire match if @p __sub is zero (the default).
1660 length(size_type __sub
= 0) const
1661 { return (*this)[__sub
].length(); }
1664 * @brief Gets the offset of the beginning of the indicated submatch.
1665 * @param __sub indicates the submatch.
1666 * @pre ready() == true
1668 * This function returns the offset from the beginning of the target
1669 * sequence to the beginning of the submatch, unless the value of @p __sub
1670 * is zero (the default), in which case this function returns the offset
1671 * from the beginning of the target sequence to the beginning of the
1674 * Returns -1 if @p __sub is out of range.
1677 position(size_type __sub
= 0) const
1681 return __sub
< size() ? std::distance(_M_begin
,
1682 (*this)[__sub
].first
) : -1;
1684 return __sub
< size() ? std::distance(this->prefix().first
,
1685 (*this)[__sub
].first
) : -1;
1689 * @brief Gets the match or submatch converted to a string type.
1690 * @param __sub indicates the submatch.
1691 * @pre ready() == true
1693 * This function gets the submatch (or match, if @p __sub is
1694 * zero) extracted from the target range and converted to the
1695 * associated string type.
1698 str(size_type __sub
= 0) const
1699 { return (*this)[__sub
].str(); }
1702 * @brief Gets a %sub_match reference for the match or submatch.
1703 * @param __sub indicates the submatch.
1704 * @pre ready() == true
1706 * This function gets a reference to the indicated submatch, or
1707 * the entire match if @p __sub is zero.
1709 * If @p __sub >= size() then this function returns a %sub_match with a
1710 * special value indicating no submatch.
1713 operator[](size_type __sub
) const
1715 _GLIBCXX_DEBUG_ASSERT( ready() );
1716 return __sub
< size()
1717 ? _Base_type::operator[](__sub
)
1718 : __unmatched_sub
<_Bi_iter
>();
1722 * @brief Gets a %sub_match representing the match prefix.
1723 * @pre ready() == true
1725 * This function gets a reference to a %sub_match object representing the
1726 * part of the target range between the start of the target range and the
1727 * start of the match.
1732 _GLIBCXX_DEBUG_ASSERT( ready() );
1734 ? _Base_type::operator[](_Base_type::size() - 2)
1735 : __unmatched_sub
<_Bi_iter
>();
1739 * @brief Gets a %sub_match representing the match suffix.
1740 * @pre ready() == true
1742 * This function gets a reference to a %sub_match object representing the
1743 * part of the target range between the end of the match and the end of
1749 _GLIBCXX_DEBUG_ASSERT( ready() );
1751 ? _Base_type::operator[](_Base_type::size() - 1)
1752 : __unmatched_sub
<_Bi_iter
>();
1756 * @brief Gets an iterator to the start of the %sub_match collection.
1760 { return _Base_type::begin(); }
1763 * @brief Gets an iterator to the start of the %sub_match collection.
1767 { return _Base_type::cbegin() + 2; }
1770 * @brief Gets an iterator to one-past-the-end of the collection.
1774 { return _Base_type::end() - 2; }
1777 * @brief Gets an iterator to one-past-the-end of the collection.
1781 { return _Base_type::cend(); }
1786 * @name 10.4 Formatting
1788 * These functions perform formatted substitution of the matched
1789 * character sequences into their target. The format specifiers and
1790 * escape sequences accepted by these functions are determined by
1791 * their @p flags parameter as documented above.
1796 * @pre ready() == true
1798 template<typename _Out_iter
>
1800 format(_Out_iter __out
, const char_type
* __fmt_first
,
1801 const char_type
* __fmt_last
,
1802 match_flag_type __flags
= regex_constants::format_default
) const;
1805 * @pre ready() == true
1807 template<typename _Out_iter
, typename _St
, typename _Sa
>
1809 format(_Out_iter __out
, const basic_string
<char_type
, _St
, _Sa
>& __fmt
,
1810 match_flag_type __flags
= regex_constants::format_default
) const
1812 return format(__out
, __fmt
.data(), __fmt
.data() + __fmt
.size(),
1817 * @pre ready() == true
1819 template<typename _St
, typename _Sa
>
1820 basic_string
<char_type
, _St
, _Sa
>
1821 format(const basic_string
<char_type
, _St
, _Sa
>& __fmt
,
1822 match_flag_type __flags
= regex_constants::format_default
) const
1824 basic_string
<char_type
, _St
, _Sa
> __result
;
1825 format(std::back_inserter(__result
), __fmt
, __flags
);
1830 * @pre ready() == true
1833 format(const char_type
* __fmt
,
1834 match_flag_type __flags
= regex_constants::format_default
) const
1836 string_type __result
;
1837 format(std::back_inserter(__result
),
1839 __fmt
+ char_traits
<char_type
>::length(__fmt
),
1847 * @name 10.5 Allocator
1852 * @brief Gets a copy of the allocator.
1855 get_allocator() const
1856 { return _Base_type::get_allocator(); }
1866 * @brief Swaps the contents of two match_results.
1869 swap(match_results
& __that
)
1870 { _Base_type::swap(__that
); }
1874 template<typename
, typename
, typename
, bool>
1875 friend class __detail::_Executor
;
1877 template<typename
, typename
, typename
>
1878 friend class regex_iterator
;
1880 template<typename _Bp
, typename _Ap
, typename _Cp
, typename _Rp
,
1881 __detail::_RegexExecutorPolicy
, bool>
1883 __detail::__regex_algo_impl(_Bp
, _Bp
, match_results
<_Bp
, _Ap
>&,
1884 const basic_regex
<_Cp
, _Rp
>&,
1885 regex_constants::match_flag_type
);
1888 bool _M_in_iterator
;
1891 typedef match_results
<const char*> cmatch
;
1892 typedef match_results
<string::const_iterator
> smatch
;
1893 #ifdef _GLIBCXX_USE_WCHAR_T
1894 typedef match_results
<const wchar_t*> wcmatch
;
1895 typedef match_results
<wstring::const_iterator
> wsmatch
;
1898 // match_results comparisons
1900 * @brief Compares two match_results for equality.
1901 * @returns true if the two objects refer to the same match,
1904 template<typename _Bi_iter
, typename _Alloc
>
1906 operator==(const match_results
<_Bi_iter
, _Alloc
>& __m1
,
1907 const match_results
<_Bi_iter
, _Alloc
>& __m2
)
1909 if (__m1
.ready() != __m2
.ready())
1911 if (!__m1
.ready()) // both are not ready
1913 if (__m1
.empty() != __m2
.empty())
1915 if (__m1
.empty()) // both are empty
1917 return __m1
.prefix() == __m2
.prefix()
1918 && __m1
.size() == __m2
.size()
1919 && std::equal(__m1
.begin(), __m1
.end(), __m2
.begin())
1920 && __m1
.suffix() == __m2
.suffix();
1924 * @brief Compares two match_results for inequality.
1925 * @returns true if the two objects do not refer to the same match,
1928 template<typename _Bi_iter
, class _Alloc
>
1930 operator!=(const match_results
<_Bi_iter
, _Alloc
>& __m1
,
1931 const match_results
<_Bi_iter
, _Alloc
>& __m2
)
1932 { return !(__m1
== __m2
); }
1934 // [7.10.6] match_results swap
1936 * @brief Swaps two match results.
1937 * @param __lhs A match result.
1938 * @param __rhs A match result.
1940 * The contents of the two match_results objects are swapped.
1942 template<typename _Bi_iter
, typename _Alloc
>
1944 swap(match_results
<_Bi_iter
, _Alloc
>& __lhs
,
1945 match_results
<_Bi_iter
, _Alloc
>& __rhs
)
1946 { __lhs
.swap(__rhs
); }
1948 // [7.11.2] Function template regex_match
1950 * @name Matching, Searching, and Replacing
1955 * @brief Determines if there is a match between the regular expression @p e
1956 * and all of the character sequence [first, last).
1958 * @param __s Start of the character sequence to match.
1959 * @param __e One-past-the-end of the character sequence to match.
1960 * @param __m The match results.
1961 * @param __re The regular expression.
1962 * @param __flags Controls how the regular expression is matched.
1964 * @retval true A match exists.
1965 * @retval false Otherwise.
1967 * @throws an exception of type regex_error.
1969 template<typename _Bi_iter
, typename _Alloc
,
1970 typename _Ch_type
, typename _Rx_traits
>
1972 regex_match(_Bi_iter __s
,
1974 match_results
<_Bi_iter
, _Alloc
>& __m
,
1975 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
1976 regex_constants::match_flag_type __flags
1977 = regex_constants::match_default
)
1979 return __detail::__regex_algo_impl
<_Bi_iter
, _Alloc
, _Ch_type
, _Rx_traits
,
1980 __detail::_RegexExecutorPolicy::_S_auto
, true>
1981 (__s
, __e
, __m
, __re
, __flags
);
1985 * @brief Indicates if there is a match between the regular expression @p e
1986 * and all of the character sequence [first, last).
1988 * @param __first Beginning of the character sequence to match.
1989 * @param __last One-past-the-end of the character sequence to match.
1990 * @param __re The regular expression.
1991 * @param __flags Controls how the regular expression is matched.
1993 * @retval true A match exists.
1994 * @retval false Otherwise.
1996 * @throws an exception of type regex_error.
1998 template<typename _Bi_iter
, typename _Ch_type
, typename _Rx_traits
>
2000 regex_match(_Bi_iter __first
, _Bi_iter __last
,
2001 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2002 regex_constants::match_flag_type __flags
2003 = regex_constants::match_default
)
2005 match_results
<_Bi_iter
> __what
;
2006 return regex_match(__first
, __last
, __what
, __re
, __flags
);
2010 * @brief Determines if there is a match between the regular expression @p e
2011 * and a C-style null-terminated string.
2013 * @param __s The C-style null-terminated string to match.
2014 * @param __m The match results.
2015 * @param __re The regular expression.
2016 * @param __f Controls how the regular expression is matched.
2018 * @retval true A match exists.
2019 * @retval false Otherwise.
2021 * @throws an exception of type regex_error.
2023 template<typename _Ch_type
, typename _Alloc
, typename _Rx_traits
>
2025 regex_match(const _Ch_type
* __s
,
2026 match_results
<const _Ch_type
*, _Alloc
>& __m
,
2027 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2028 regex_constants::match_flag_type __f
2029 = regex_constants::match_default
)
2030 { return regex_match(__s
, __s
+ _Rx_traits::length(__s
), __m
, __re
, __f
); }
2033 * @brief Determines if there is a match between the regular expression @p e
2036 * @param __s The string to match.
2037 * @param __m The match results.
2038 * @param __re The regular expression.
2039 * @param __flags Controls how the regular expression is matched.
2041 * @retval true A match exists.
2042 * @retval false Otherwise.
2044 * @throws an exception of type regex_error.
2046 template<typename _Ch_traits
, typename _Ch_alloc
,
2047 typename _Alloc
, typename _Ch_type
, typename _Rx_traits
>
2049 regex_match(const basic_string
<_Ch_type
, _Ch_traits
, _Ch_alloc
>& __s
,
2050 match_results
<typename basic_string
<_Ch_type
,
2051 _Ch_traits
, _Ch_alloc
>::const_iterator
, _Alloc
>& __m
,
2052 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2053 regex_constants::match_flag_type __flags
2054 = regex_constants::match_default
)
2055 { return regex_match(__s
.begin(), __s
.end(), __m
, __re
, __flags
); }
2058 * @brief Indicates if there is a match between the regular expression @p e
2059 * and a C-style null-terminated string.
2061 * @param __s The C-style null-terminated string to match.
2062 * @param __re The regular expression.
2063 * @param __f Controls how the regular expression is matched.
2065 * @retval true A match exists.
2066 * @retval false Otherwise.
2068 * @throws an exception of type regex_error.
2070 template<typename _Ch_type
, class _Rx_traits
>
2072 regex_match(const _Ch_type
* __s
,
2073 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2074 regex_constants::match_flag_type __f
2075 = regex_constants::match_default
)
2076 { return regex_match(__s
, __s
+ _Rx_traits::length(__s
), __re
, __f
); }
2079 * @brief Indicates if there is a match between the regular expression @p e
2082 * @param __s [IN] The string to match.
2083 * @param __re [IN] The regular expression.
2084 * @param __flags [IN] Controls how the regular expression is matched.
2086 * @retval true A match exists.
2087 * @retval false Otherwise.
2089 * @throws an exception of type regex_error.
2091 template<typename _Ch_traits
, typename _Str_allocator
,
2092 typename _Ch_type
, typename _Rx_traits
>
2094 regex_match(const basic_string
<_Ch_type
, _Ch_traits
, _Str_allocator
>& __s
,
2095 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2096 regex_constants::match_flag_type __flags
2097 = regex_constants::match_default
)
2098 { return regex_match(__s
.begin(), __s
.end(), __re
, __flags
); }
2100 // [7.11.3] Function template regex_search
2102 * Searches for a regular expression within a range.
2103 * @param __s [IN] The start of the string to search.
2104 * @param __e [IN] One-past-the-end of the string to search.
2105 * @param __m [OUT] The match results.
2106 * @param __re [IN] The regular expression to search for.
2107 * @param __flags [IN] Search policy flags.
2108 * @retval true A match was found within the string.
2109 * @retval false No match was found within the string, the content of %m is
2112 * @throws an exception of type regex_error.
2114 template<typename _Bi_iter
, typename _Alloc
,
2115 typename _Ch_type
, typename _Rx_traits
>
2117 regex_search(_Bi_iter __s
, _Bi_iter __e
,
2118 match_results
<_Bi_iter
, _Alloc
>& __m
,
2119 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2120 regex_constants::match_flag_type __flags
2121 = regex_constants::match_default
)
2123 return __detail::__regex_algo_impl
<_Bi_iter
, _Alloc
, _Ch_type
, _Rx_traits
,
2124 __detail::_RegexExecutorPolicy::_S_auto
, false>
2125 (__s
, __e
, __m
, __re
, __flags
);
2129 * Searches for a regular expression within a range.
2130 * @param __first [IN] The start of the string to search.
2131 * @param __last [IN] One-past-the-end of the string to search.
2132 * @param __re [IN] The regular expression to search for.
2133 * @param __flags [IN] Search policy flags.
2134 * @retval true A match was found within the string.
2135 * @retval false No match was found within the string.
2137 * @throws an exception of type regex_error.
2139 template<typename _Bi_iter
, typename _Ch_type
, typename _Rx_traits
>
2141 regex_search(_Bi_iter __first
, _Bi_iter __last
,
2142 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2143 regex_constants::match_flag_type __flags
2144 = regex_constants::match_default
)
2146 match_results
<_Bi_iter
> __what
;
2147 return regex_search(__first
, __last
, __what
, __re
, __flags
);
2151 * @brief Searches for a regular expression within a C-string.
2152 * @param __s [IN] A C-string to search for the regex.
2153 * @param __m [OUT] The set of regex matches.
2154 * @param __e [IN] The regex to search for in @p s.
2155 * @param __f [IN] The search flags.
2156 * @retval true A match was found within the string.
2157 * @retval false No match was found within the string, the content of %m is
2160 * @throws an exception of type regex_error.
2162 template<typename _Ch_type
, class _Alloc
, class _Rx_traits
>
2164 regex_search(const _Ch_type
* __s
,
2165 match_results
<const _Ch_type
*, _Alloc
>& __m
,
2166 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2167 regex_constants::match_flag_type __f
2168 = regex_constants::match_default
)
2169 { return regex_search(__s
, __s
+ _Rx_traits::length(__s
), __m
, __e
, __f
); }
2172 * @brief Searches for a regular expression within a C-string.
2173 * @param __s [IN] The C-string to search.
2174 * @param __e [IN] The regular expression to search for.
2175 * @param __f [IN] Search policy flags.
2176 * @retval true A match was found within the string.
2177 * @retval false No match was found within the string.
2179 * @throws an exception of type regex_error.
2181 template<typename _Ch_type
, typename _Rx_traits
>
2183 regex_search(const _Ch_type
* __s
,
2184 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2185 regex_constants::match_flag_type __f
2186 = regex_constants::match_default
)
2187 { return regex_search(__s
, __s
+ _Rx_traits::length(__s
), __e
, __f
); }
2190 * @brief Searches for a regular expression within a string.
2191 * @param __s [IN] The string to search.
2192 * @param __e [IN] The regular expression to search for.
2193 * @param __flags [IN] Search policy flags.
2194 * @retval true A match was found within the string.
2195 * @retval false No match was found within the string.
2197 * @throws an exception of type regex_error.
2199 template<typename _Ch_traits
, typename _String_allocator
,
2200 typename _Ch_type
, typename _Rx_traits
>
2202 regex_search(const basic_string
<_Ch_type
, _Ch_traits
,
2203 _String_allocator
>& __s
,
2204 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2205 regex_constants::match_flag_type __flags
2206 = regex_constants::match_default
)
2207 { return regex_search(__s
.begin(), __s
.end(), __e
, __flags
); }
2210 * @brief Searches for a regular expression within a string.
2211 * @param __s [IN] A C++ string to search for the regex.
2212 * @param __m [OUT] The set of regex matches.
2213 * @param __e [IN] The regex to search for in @p s.
2214 * @param __f [IN] The search flags.
2215 * @retval true A match was found within the string.
2216 * @retval false No match was found within the string, the content of %m is
2219 * @throws an exception of type regex_error.
2221 template<typename _Ch_traits
, typename _Ch_alloc
,
2222 typename _Alloc
, typename _Ch_type
,
2223 typename _Rx_traits
>
2225 regex_search(const basic_string
<_Ch_type
, _Ch_traits
, _Ch_alloc
>& __s
,
2226 match_results
<typename basic_string
<_Ch_type
,
2227 _Ch_traits
, _Ch_alloc
>::const_iterator
, _Alloc
>& __m
,
2228 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2229 regex_constants::match_flag_type __f
2230 = regex_constants::match_default
)
2231 { return regex_search(__s
.begin(), __s
.end(), __m
, __e
, __f
); }
2233 // std [28.11.4] Function template regex_replace
2235 * @brief Search for a regular expression within a range for multiple times,
2236 and replace the matched parts through filling a format string.
2237 * @param __out [OUT] The output iterator.
2238 * @param __first [IN] The start of the string to search.
2239 * @param __last [IN] One-past-the-end of the string to search.
2240 * @param __e [IN] The regular expression to search for.
2241 * @param __fmt [IN] The format string.
2242 * @param __flags [IN] Search and replace policy flags.
2245 * @throws an exception of type regex_error.
2247 template<typename _Out_iter
, typename _Bi_iter
,
2248 typename _Rx_traits
, typename _Ch_type
,
2249 typename _St
, typename _Sa
>
2251 regex_replace(_Out_iter __out
, _Bi_iter __first
, _Bi_iter __last
,
2252 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2253 const basic_string
<_Ch_type
, _St
, _Sa
>& __fmt
,
2254 regex_constants::match_flag_type __flags
2255 = regex_constants::match_default
)
2257 return regex_replace(__out
, __first
, __last
, __e
, __fmt
.c_str(), __flags
);
2261 * @brief Search for a regular expression within a range for multiple times,
2262 and replace the matched parts through filling a format C-string.
2263 * @param __out [OUT] The output iterator.
2264 * @param __first [IN] The start of the string to search.
2265 * @param __last [IN] One-past-the-end of the string to search.
2266 * @param __e [IN] The regular expression to search for.
2267 * @param __fmt [IN] The format C-string.
2268 * @param __flags [IN] Search and replace policy flags.
2271 * @throws an exception of type regex_error.
2273 template<typename _Out_iter
, typename _Bi_iter
,
2274 typename _Rx_traits
, typename _Ch_type
>
2276 regex_replace(_Out_iter __out
, _Bi_iter __first
, _Bi_iter __last
,
2277 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2278 const _Ch_type
* __fmt
,
2279 regex_constants::match_flag_type __flags
2280 = regex_constants::match_default
);
2283 * @brief Search for a regular expression within a string for multiple times,
2284 and replace the matched parts through filling a format string.
2285 * @param __s [IN] The string to search and replace.
2286 * @param __e [IN] The regular expression to search for.
2287 * @param __fmt [IN] The format string.
2288 * @param __flags [IN] Search and replace policy flags.
2290 * @returns The string after replacing.
2291 * @throws an exception of type regex_error.
2293 template<typename _Rx_traits
, typename _Ch_type
,
2294 typename _St
, typename _Sa
, typename _Fst
, typename _Fsa
>
2295 inline basic_string
<_Ch_type
, _St
, _Sa
>
2296 regex_replace(const basic_string
<_Ch_type
, _St
, _Sa
>& __s
,
2297 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2298 const basic_string
<_Ch_type
, _Fst
, _Fsa
>& __fmt
,
2299 regex_constants::match_flag_type __flags
2300 = regex_constants::match_default
)
2302 basic_string
<_Ch_type
, _St
, _Sa
> __result
;
2303 regex_replace(std::back_inserter(__result
),
2304 __s
.begin(), __s
.end(), __e
, __fmt
, __flags
);
2309 * @brief Search for a regular expression within a string for multiple times,
2310 and replace the matched parts through filling a format C-string.
2311 * @param __s [IN] The string to search and replace.
2312 * @param __e [IN] The regular expression to search for.
2313 * @param __fmt [IN] The format C-string.
2314 * @param __flags [IN] Search and replace policy flags.
2316 * @returns The string after replacing.
2317 * @throws an exception of type regex_error.
2319 template<typename _Rx_traits
, typename _Ch_type
,
2320 typename _St
, typename _Sa
>
2321 inline basic_string
<_Ch_type
, _St
, _Sa
>
2322 regex_replace(const basic_string
<_Ch_type
, _St
, _Sa
>& __s
,
2323 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2324 const _Ch_type
* __fmt
,
2325 regex_constants::match_flag_type __flags
2326 = regex_constants::match_default
)
2328 basic_string
<_Ch_type
, _St
, _Sa
> __result
;
2329 regex_replace(std::back_inserter(__result
),
2330 __s
.begin(), __s
.end(), __e
, __fmt
, __flags
);
2335 * @brief Search for a regular expression within a C-string for multiple
2336 times, and replace the matched parts through filling a format string.
2337 * @param __s [IN] The C-string to search and replace.
2338 * @param __e [IN] The regular expression to search for.
2339 * @param __fmt [IN] The format string.
2340 * @param __flags [IN] Search and replace policy flags.
2342 * @returns The string after replacing.
2343 * @throws an exception of type regex_error.
2345 template<typename _Rx_traits
, typename _Ch_type
,
2346 typename _St
, typename _Sa
>
2347 inline basic_string
<_Ch_type
>
2348 regex_replace(const _Ch_type
* __s
,
2349 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2350 const basic_string
<_Ch_type
, _St
, _Sa
>& __fmt
,
2351 regex_constants::match_flag_type __flags
2352 = regex_constants::match_default
)
2354 basic_string
<_Ch_type
> __result
;
2355 regex_replace(std::back_inserter(__result
), __s
,
2356 __s
+ char_traits
<_Ch_type
>::length(__s
),
2357 __e
, __fmt
, __flags
);
2362 * @brief Search for a regular expression within a C-string for multiple
2363 times, and replace the matched parts through filling a format C-string.
2364 * @param __s [IN] The C-string to search and replace.
2365 * @param __e [IN] The regular expression to search for.
2366 * @param __fmt [IN] The format C-string.
2367 * @param __flags [IN] Search and replace policy flags.
2369 * @returns The string after replacing.
2370 * @throws an exception of type regex_error.
2372 template<typename _Rx_traits
, typename _Ch_type
>
2373 inline basic_string
<_Ch_type
>
2374 regex_replace(const _Ch_type
* __s
,
2375 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2376 const _Ch_type
* __fmt
,
2377 regex_constants::match_flag_type __flags
2378 = regex_constants::match_default
)
2380 basic_string
<_Ch_type
> __result
;
2381 regex_replace(std::back_inserter(__result
), __s
,
2382 __s
+ char_traits
<_Ch_type
>::length(__s
),
2383 __e
, __fmt
, __flags
);
2389 // std [28.12] Class template regex_iterator
2391 * An iterator adaptor that will provide repeated calls of regex_search over
2392 * a range until no more matches remain.
2394 template<typename _Bi_iter
,
2395 typename _Ch_type
= typename iterator_traits
<_Bi_iter
>::value_type
,
2396 typename _Rx_traits
= regex_traits
<_Ch_type
> >
2397 class regex_iterator
2400 typedef basic_regex
<_Ch_type
, _Rx_traits
> regex_type
;
2401 typedef match_results
<_Bi_iter
> value_type
;
2402 typedef std::ptrdiff_t difference_type
;
2403 typedef const value_type
* pointer
;
2404 typedef const value_type
& reference
;
2405 typedef std::forward_iterator_tag iterator_category
;
2408 * @brief Provides a singular iterator, useful for indicating
2409 * one-past-the-end of a range.
2416 * Constructs a %regex_iterator...
2417 * @param __a [IN] The start of a text range to search.
2418 * @param __b [IN] One-past-the-end of the text range to search.
2419 * @param __re [IN] The regular expression to match.
2420 * @param __m [IN] Policy flags for match rules.
2422 regex_iterator(_Bi_iter __a
, _Bi_iter __b
, const regex_type
& __re
,
2423 regex_constants::match_flag_type __m
2424 = regex_constants::match_default
)
2425 : _M_begin(__a
), _M_end(__b
), _M_pregex(&__re
), _M_flags(__m
), _M_match()
2427 if (!regex_search(_M_begin
, _M_end
, _M_match
, *_M_pregex
, _M_flags
))
2428 *this = regex_iterator();
2432 * Copy constructs a %regex_iterator.
2434 regex_iterator(const regex_iterator
& __rhs
) = default;
2437 * @brief Assigns one %regex_iterator to another.
2440 operator=(const regex_iterator
& __rhs
) = default;
2443 * @brief Tests the equivalence of two regex iterators.
2446 operator==(const regex_iterator
& __rhs
) const;
2449 * @brief Tests the inequivalence of two regex iterators.
2452 operator!=(const regex_iterator
& __rhs
) const
2453 { return !(*this == __rhs
); }
2456 * @brief Dereferences a %regex_iterator.
2460 { return _M_match
; }
2463 * @brief Selects a %regex_iterator member.
2467 { return &_M_match
; }
2470 * @brief Increments a %regex_iterator.
2476 * @brief Postincrements a %regex_iterator.
2489 const regex_type
* _M_pregex
;
2490 regex_constants::match_flag_type _M_flags
;
2491 match_results
<_Bi_iter
> _M_match
;
2494 typedef regex_iterator
<const char*> cregex_iterator
;
2495 typedef regex_iterator
<string::const_iterator
> sregex_iterator
;
2496 #ifdef _GLIBCXX_USE_WCHAR_T
2497 typedef regex_iterator
<const wchar_t*> wcregex_iterator
;
2498 typedef regex_iterator
<wstring::const_iterator
> wsregex_iterator
;
2501 // [7.12.2] Class template regex_token_iterator
2503 * Iterates over submatches in a range (or @a splits a text string).
2505 * The purpose of this iterator is to enumerate all, or all specified,
2506 * matches of a regular expression within a text range. The dereferenced
2507 * value of an iterator of this class is a std::sub_match object.
2509 template<typename _Bi_iter
,
2510 typename _Ch_type
= typename iterator_traits
<_Bi_iter
>::value_type
,
2511 typename _Rx_traits
= regex_traits
<_Ch_type
> >
2512 class regex_token_iterator
2515 typedef basic_regex
<_Ch_type
, _Rx_traits
> regex_type
;
2516 typedef sub_match
<_Bi_iter
> value_type
;
2517 typedef std::ptrdiff_t difference_type
;
2518 typedef const value_type
* pointer
;
2519 typedef const value_type
& reference
;
2520 typedef std::forward_iterator_tag iterator_category
;
2524 * @brief Default constructs a %regex_token_iterator.
2526 * A default-constructed %regex_token_iterator is a singular iterator
2527 * that will compare equal to the one-past-the-end value for any
2528 * iterator of the same type.
2530 regex_token_iterator()
2531 : _M_position(), _M_subs(), _M_suffix(), _M_n(0), _M_result(nullptr),
2536 * Constructs a %regex_token_iterator...
2537 * @param __a [IN] The start of the text to search.
2538 * @param __b [IN] One-past-the-end of the text to search.
2539 * @param __re [IN] The regular expression to search for.
2540 * @param __submatch [IN] Which submatch to return. There are some
2541 * special values for this parameter:
2542 * - -1 each enumerated subexpression does NOT
2543 * match the regular expression (aka field
2545 * - 0 the entire string matching the
2546 * subexpression is returned for each match
2548 * - >0 enumerates only the indicated
2549 * subexpression from a match within the text.
2550 * @param __m [IN] Policy flags for match rules.
2552 regex_token_iterator(_Bi_iter __a
, _Bi_iter __b
, const regex_type
& __re
,
2554 regex_constants::match_flag_type __m
2555 = regex_constants::match_default
)
2556 : _M_position(__a
, __b
, __re
, __m
), _M_subs(1, __submatch
), _M_n(0)
2557 { _M_init(__a
, __b
); }
2560 * Constructs a %regex_token_iterator...
2561 * @param __a [IN] The start of the text to search.
2562 * @param __b [IN] One-past-the-end of the text to search.
2563 * @param __re [IN] The regular expression to search for.
2564 * @param __submatches [IN] A list of subexpressions to return for each
2565 * regular expression match within the text.
2566 * @param __m [IN] Policy flags for match rules.
2568 regex_token_iterator(_Bi_iter __a
, _Bi_iter __b
,
2569 const regex_type
& __re
,
2570 const std::vector
<int>& __submatches
,
2571 regex_constants::match_flag_type __m
2572 = regex_constants::match_default
)
2573 : _M_position(__a
, __b
, __re
, __m
), _M_subs(__submatches
), _M_n(0)
2574 { _M_init(__a
, __b
); }
2577 * Constructs a %regex_token_iterator...
2578 * @param __a [IN] The start of the text to search.
2579 * @param __b [IN] One-past-the-end of the text to search.
2580 * @param __re [IN] The regular expression to search for.
2581 * @param __submatches [IN] A list of subexpressions to return for each
2582 * regular expression match within the text.
2583 * @param __m [IN] Policy flags for match rules.
2585 regex_token_iterator(_Bi_iter __a
, _Bi_iter __b
,
2586 const regex_type
& __re
,
2587 initializer_list
<int> __submatches
,
2588 regex_constants::match_flag_type __m
2589 = regex_constants::match_default
)
2590 : _M_position(__a
, __b
, __re
, __m
), _M_subs(__submatches
), _M_n(0)
2591 { _M_init(__a
, __b
); }
2594 * Constructs a %regex_token_iterator...
2595 * @param __a [IN] The start of the text to search.
2596 * @param __b [IN] One-past-the-end of the text to search.
2597 * @param __re [IN] The regular expression to search for.
2598 * @param __submatches [IN] A list of subexpressions to return for each
2599 * regular expression match within the text.
2600 * @param __m [IN] Policy flags for match rules.
2602 template<std::size_t _Nm
>
2603 regex_token_iterator(_Bi_iter __a
, _Bi_iter __b
,
2604 const regex_type
& __re
,
2605 const int (&__submatches
)[_Nm
],
2606 regex_constants::match_flag_type __m
2607 = regex_constants::match_default
)
2608 : _M_position(__a
, __b
, __re
, __m
),
2609 _M_subs(__submatches
, *(&__submatches
+1)), _M_n(0)
2610 { _M_init(__a
, __b
); }
2613 * @brief Copy constructs a %regex_token_iterator.
2614 * @param __rhs [IN] A %regex_token_iterator to copy.
2616 regex_token_iterator(const regex_token_iterator
& __rhs
)
2617 : _M_position(__rhs
._M_position
), _M_subs(__rhs
._M_subs
),
2618 _M_suffix(__rhs
._M_suffix
), _M_n(__rhs
._M_n
), _M_result(__rhs
._M_result
),
2619 _M_has_m1(__rhs
._M_has_m1
)
2621 if (__rhs
._M_result
== &__rhs
._M_suffix
)
2622 _M_result
= &_M_suffix
;
2626 * @brief Assigns a %regex_token_iterator to another.
2627 * @param __rhs [IN] A %regex_token_iterator to copy.
2629 regex_token_iterator
&
2630 operator=(const regex_token_iterator
& __rhs
);
2633 * @brief Compares a %regex_token_iterator to another for equality.
2636 operator==(const regex_token_iterator
& __rhs
) const;
2639 * @brief Compares a %regex_token_iterator to another for inequality.
2642 operator!=(const regex_token_iterator
& __rhs
) const
2643 { return !(*this == __rhs
); }
2646 * @brief Dereferences a %regex_token_iterator.
2650 { return *_M_result
; }
2653 * @brief Selects a %regex_token_iterator member.
2657 { return _M_result
; }
2660 * @brief Increments a %regex_token_iterator.
2662 regex_token_iterator
&
2666 * @brief Postincrements a %regex_token_iterator.
2668 regex_token_iterator
2677 typedef regex_iterator
<_Bi_iter
, _Ch_type
, _Rx_traits
> _Position
;
2680 _M_init(_Bi_iter __a
, _Bi_iter __b
);
2683 _M_current_match() const
2685 if (_M_subs
[_M_n
] == -1)
2686 return (*_M_position
).prefix();
2688 return (*_M_position
)[_M_subs
[_M_n
]];
2692 _M_end_of_seq() const
2693 { return _M_result
== nullptr; }
2695 _Position _M_position
;
2696 std::vector
<int> _M_subs
;
2697 value_type _M_suffix
;
2699 const value_type
* _M_result
;
2701 // Show whether _M_subs contains -1
2705 /** @brief Token iterator for C-style NULL-terminated strings. */
2706 typedef regex_token_iterator
<const char*> cregex_token_iterator
;
2708 /** @brief Token iterator for standard strings. */
2709 typedef regex_token_iterator
<string::const_iterator
> sregex_token_iterator
;
2711 #ifdef _GLIBCXX_USE_WCHAR_T
2712 /** @brief Token iterator for C-style NULL-terminated wide strings. */
2713 typedef regex_token_iterator
<const wchar_t*> wcregex_token_iterator
;
2715 /** @brief Token iterator for standard wide-character strings. */
2716 typedef regex_token_iterator
<wstring::const_iterator
> wsregex_token_iterator
;
2720 _GLIBCXX_END_NAMESPACE_VERSION
2723 #include <bits/regex.tcc>