1 // class template regex -*- C++ -*-
3 // Copyright (C) 2010-2024 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 #if __cplusplus >= 202002L
32 # include <bits/iterator_concepts.h> // std::default_sentinel_t
35 namespace std
_GLIBCXX_VISIBILITY(default)
37 _GLIBCXX_BEGIN_NAMESPACE_VERSION
38 _GLIBCXX_BEGIN_NAMESPACE_CXX11
39 template<typename
, typename
>
42 template<typename _Bi_iter
, typename _Alloc
>
45 _GLIBCXX_END_NAMESPACE_CXX11
49 enum class _RegexExecutorPolicy
: int { _S_auto
, _S_alternate
};
51 template<typename _BiIter
, typename _Alloc
,
52 typename _CharT
, typename _TraitsT
>
54 __regex_algo_impl(_BiIter __s
, _BiIter __e
,
55 match_results
<_BiIter
, _Alloc
>& __m
,
56 const basic_regex
<_CharT
, _TraitsT
>& __re
,
57 regex_constants::match_flag_type __flags
,
58 _RegexExecutorPolicy __policy
,
61 template<typename
, typename
, typename
, bool>
64 template<typename _Tp
>
65 struct __is_contiguous_iter
: false_type
{ };
67 template<typename _Tp
>
68 struct __is_contiguous_iter
<_Tp
*> : true_type
{ };
70 template<typename _Tp
, typename _Cont
>
71 struct __is_contiguous_iter
<__gnu_cxx::__normal_iterator
<_Tp
*, _Cont
>>
75 _GLIBCXX_BEGIN_NAMESPACE_CXX11
83 * @brief Describes aspects of a regular expression.
85 * A regular expression traits class that satisfies the requirements of
88 * The class %regex is parameterized around a set of related types and
89 * functions used to complete the definition of its semantics. This class
90 * satisfies the requirements of such a traits class.
95 template<typename _Ch_type
>
99 typedef _Ch_type char_type
;
100 typedef std::basic_string
<char_type
> string_type
;
101 typedef std::locale locale_type
;
106 typedef std::ctype_base::mask _BaseType
;
108 unsigned char _M_extended
;
109 static constexpr unsigned char _S_under
= 1 << 0;
110 static constexpr unsigned char _S_valid_mask
= 0x1;
112 constexpr _RegexMask(_BaseType __base
= 0,
113 unsigned char __extended
= 0)
114 : _M_base(__base
), _M_extended(__extended
)
118 operator&(_RegexMask __other
) const
120 return _RegexMask(_M_base
& __other
._M_base
,
121 _M_extended
& __other
._M_extended
);
125 operator|(_RegexMask __other
) const
127 return _RegexMask(_M_base
| __other
._M_base
,
128 _M_extended
| __other
._M_extended
);
132 operator^(_RegexMask __other
) const
134 return _RegexMask(_M_base
^ __other
._M_base
,
135 _M_extended
^ __other
._M_extended
);
140 { return _RegexMask(~_M_base
, ~_M_extended
); }
143 operator&=(_RegexMask __other
)
144 { return *this = (*this) & __other
; }
147 operator|=(_RegexMask __other
)
148 { return *this = (*this) | __other
; }
151 operator^=(_RegexMask __other
)
152 { return *this = (*this) ^ __other
; }
155 operator==(_RegexMask __other
) const
157 return (_M_extended
& _S_valid_mask
)
158 == (__other
._M_extended
& _S_valid_mask
)
159 && _M_base
== __other
._M_base
;
162 #if __cpp_impl_three_way_comparison < 201907L
164 operator!=(_RegexMask __other
) const
165 { return !((*this) == __other
); }
170 typedef _RegexMask char_class_type
;
174 * @brief Constructs a default traits object.
179 * @brief Gives the length of a C-style string starting at @p __p.
181 * @param __p a pointer to the start of a character sequence.
183 * @returns the number of characters between @p *__p and the first
184 * default-initialized value of type @p char_type. In other words, uses
185 * the C-string algorithm for determining the length of a sequence of
189 length(const char_type
* __p
)
190 { return string_type::traits_type::length(__p
); }
193 * @brief Performs the identity translation.
195 * @param __c A character to the locale-specific character set.
200 translate(char_type __c
) const
204 * @brief Translates a character into a case-insensitive equivalent.
206 * @param __c A character to the locale-specific character set.
208 * @returns the locale-specific lower-case equivalent of __c.
209 * @throws std::bad_cast if the imbued locale does not support the ctype
213 translate_nocase(char_type __c
) const
215 typedef std::ctype
<char_type
> __ctype_type
;
216 const __ctype_type
& __fctyp(use_facet
<__ctype_type
>(_M_locale
));
217 return __fctyp
.tolower(__c
);
221 * @brief Gets a sort key for a character sequence.
223 * @param __first beginning of the character sequence.
224 * @param __last one-past-the-end of the character sequence.
226 * Returns a sort key for the character sequence designated by the
227 * iterator range [F1, F2) such that if the character sequence [G1, G2)
228 * sorts before the character sequence [H1, H2) then
229 * v.transform(G1, G2) < v.transform(H1, H2).
231 * What this really does is provide a more efficient way to compare a
232 * string to multiple other strings in locales with fancy collation
233 * rules and equivalence classes.
235 * @returns a locale-specific sort key equivalent to the input range.
237 * @throws std::bad_cast if the current locale does not have a collate
240 template<typename _Fwd_iter
>
242 transform(_Fwd_iter __first
, _Fwd_iter __last
) const
244 typedef std::collate
<char_type
> __collate_type
;
245 const __collate_type
& __fclt(use_facet
<__collate_type
>(_M_locale
));
246 string_type
__s(__first
, __last
);
247 return __fclt
.transform(__s
.data(), __s
.data() + __s
.size());
251 * @brief Gets a sort key for a character sequence, independent of case.
253 * @param __first beginning of the character sequence.
254 * @param __last one-past-the-end of the character sequence.
256 * Effects: if typeid(use_facet<collate<_Ch_type> >) ==
257 * typeid(collate_byname<_Ch_type>) and the form of the sort key
258 * returned by collate_byname<_Ch_type>::transform(__first, __last)
259 * is known and can be converted into a primary sort key
260 * then returns that key, otherwise returns an empty string.
262 * @todo Implement this function correctly.
264 template<typename _Fwd_iter
>
266 transform_primary(_Fwd_iter __first
, _Fwd_iter __last
) const
268 // TODO : this is not entirely correct.
269 // This function requires extra support from the platform.
271 // Read http://gcc.gnu.org/ml/libstdc++/2013-09/msg00117.html and
272 // http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2003/n1429.htm
274 typedef std::ctype
<char_type
> __ctype_type
;
275 const __ctype_type
& __fctyp(use_facet
<__ctype_type
>(_M_locale
));
276 _GLIBCXX_STD_C::vector
<char_type
> __s(__first
, __last
);
277 __fctyp
.tolower(__s
.data(), __s
.data() + __s
.size());
278 return this->transform(__s
.data(), __s
.data() + __s
.size());
282 * @brief Gets a collation element by name.
284 * @param __first beginning of the collation element name.
285 * @param __last one-past-the-end of the collation element name.
287 * @returns a sequence of one or more characters that represents the
288 * collating element consisting of the character sequence designated by
289 * the iterator range [__first, __last). Returns an empty string if the
290 * character sequence is not a valid collating element.
292 template<typename _Fwd_iter
>
294 lookup_collatename(_Fwd_iter __first
, _Fwd_iter __last
) const;
297 * @brief Maps one or more characters to a named character
300 * @param __first beginning of the character sequence.
301 * @param __last one-past-the-end of the character sequence.
302 * @param __icase ignores the case of the classification name.
304 * @returns an unspecified value that represents the character
305 * classification named by the character sequence designated by
306 * the iterator range [__first, __last). If @p icase is true,
307 * the returned mask identifies the classification regardless of
308 * the case of the characters to be matched (for example,
309 * [[:lower:]] is the same as [[:alpha:]]), otherwise a
310 * case-dependent classification is returned. The value
311 * returned shall be independent of the case of the characters
312 * in the character sequence. If the name is not recognized then
313 * returns a value that compares equal to 0.
315 * At least the following names (or their wide-character equivalent) are
333 template<typename _Fwd_iter
>
335 lookup_classname(_Fwd_iter __first
, _Fwd_iter __last
,
336 bool __icase
= false) const;
339 * @brief Determines if @p c is a member of an identified class.
341 * @param __c a character.
342 * @param __f a class type (as returned from lookup_classname).
344 * @returns true if the character @p __c is a member of the classification
345 * represented by @p __f, false otherwise.
347 * @throws std::bad_cast if the current locale does not have a ctype
351 isctype(_Ch_type __c
, char_class_type __f
) const;
354 * @brief Converts a digit to an int.
356 * @param __ch a character representing a digit.
357 * @param __radix the radix if the numeric conversion (limited to 8, 10,
360 * @returns the value represented by the digit __ch in base radix if the
361 * character __ch is a valid digit in base radix; otherwise returns -1.
364 value(_Ch_type __ch
, int __radix
) const;
367 * @brief Imbues the regex_traits object with a copy of a new locale.
369 * @param __loc A locale.
371 * @returns a copy of the previous locale in use by the regex_traits
374 * @note Calling imbue with a different locale than the one currently in
375 * use invalidates all cached data held by *this.
378 imbue(locale_type __loc
)
380 std::swap(_M_locale
, __loc
);
385 * @brief Gets a copy of the current locale in use by the regex_traits
390 { return _M_locale
; }
393 locale_type _M_locale
;
396 // [7.8] Class basic_regex
398 * @brief A regular expression
400 * Specializations of this class template represent regular expressions
401 * constructed from sequences of character type `_Ch_type`.
402 * Use the `std::regex` typedef for `std::basic_regex<char>`.
404 * A character sequence passed to the constructor will be parsed according
405 * to the chosen grammar, and used to create a state machine representing
406 * the regular expression. The regex object can then be passed to algorithms
407 * such as `std::regex_match` to match sequences of characters.
409 * The `syntax_option_type` flag passed to the constructor selects from
410 * one of the supported regular expression grammars. The default is
411 * `ECMAScript` and the others are `basic`, `extended`, `awk`, `grep`, and
412 * `egrep`, which are variations on POSIX regular expressions.
417 template<typename _Ch_type
, typename _Rx_traits
= regex_traits
<_Ch_type
>>
421 static_assert(is_same
<_Ch_type
, typename
_Rx_traits::char_type
>::value
,
422 "regex traits class must have the same char_type");
425 typedef _Ch_type value_type
;
426 typedef _Rx_traits traits_type
;
427 typedef typename
traits_type::string_type string_type
;
428 typedef regex_constants::syntax_option_type flag_type
;
429 typedef typename
traits_type::locale_type locale_type
;
436 static constexpr flag_type icase
= regex_constants::icase
;
437 static constexpr flag_type nosubs
= regex_constants::nosubs
;
438 static constexpr flag_type optimize
= regex_constants::optimize
;
439 static constexpr flag_type collate
= regex_constants::collate
;
440 static constexpr flag_type ECMAScript
= regex_constants::ECMAScript
;
441 static constexpr flag_type basic
= regex_constants::basic
;
442 static constexpr flag_type extended
= regex_constants::extended
;
443 static constexpr flag_type awk
= regex_constants::awk
;
444 static constexpr flag_type grep
= regex_constants::grep
;
445 static constexpr flag_type egrep
= regex_constants::egrep
;
446 #if __cplusplus >= 201703L || !defined __STRICT_ANSI__
447 static constexpr flag_type multiline
= regex_constants::multiline
;
451 // [7.8.2] construct/copy/destroy
453 * Constructs a basic regular expression that does not match any
454 * character sequence.
456 basic_regex() noexcept
457 : _M_flags(ECMAScript
), _M_loc(), _M_automaton(nullptr)
461 * @brief Constructs a basic regular expression from the
462 * sequence [__p, __p + char_traits<_Ch_type>::length(__p))
463 * interpreted according to the flags in @p __f.
465 * @param __p A pointer to the start of a C-style null-terminated string
466 * containing a regular expression.
467 * @param __f Flags indicating the syntax rules and options.
469 * @throws regex_error if @p __p is not a valid regular expression.
472 basic_regex(const _Ch_type
* __p
, flag_type __f
= ECMAScript
)
473 { _M_compile(__p
, __p
+ _Rx_traits::length(__p
), __f
); }
476 * @brief Constructs a basic regular expression from the sequence
477 * [p, p + len) interpreted according to the flags in @p f.
479 * @param __p A pointer to the start of a string containing a regular
481 * @param __len The length of the string containing the regular
483 * @param __f Flags indicating the syntax rules and options.
485 * @throws regex_error if @p __p is not a valid regular expression.
487 basic_regex(const _Ch_type
* __p
, std::size_t __len
,
488 flag_type __f
= ECMAScript
)
490 __glibcxx_requires_string_len(__p
, __len
);
491 _M_compile(__p
, __p
+ __len
, __f
);
495 * @brief Copy-constructs a basic regular expression.
497 * @param __rhs A @p regex object.
499 basic_regex(const basic_regex
& __rhs
) = default;
502 * @brief Move-constructs a basic regular expression.
504 * @param __rhs A @p regex object.
506 basic_regex(basic_regex
&& __rhs
) noexcept
= default;
509 * @brief Constructs a basic regular expression from the string
510 * @p s interpreted according to the flags in @p f.
512 * @param __s A string containing a regular expression.
513 * @param __f Flags indicating the syntax rules and options.
515 * @throws regex_error if @p __s is not a valid regular expression.
517 template<typename _Ch_traits
, typename _Ch_alloc
>
519 basic_regex(const std::basic_string
<_Ch_type
, _Ch_traits
,
521 flag_type __f
= ECMAScript
)
522 { _M_compile(__s
.data(), __s
.data() + __s
.size(), __f
); }
525 * @brief Constructs a basic regular expression from the range
526 * [first, last) interpreted according to the flags in @p f.
528 * @param __first The start of a range containing a valid regular
530 * @param __last The end of a range containing a valid regular
532 * @param __f The format flags of the regular expression.
534 * @throws regex_error if @p [__first, __last) is not a valid regular
537 template<typename _FwdIter
>
538 basic_regex(_FwdIter __first
, _FwdIter __last
,
539 flag_type __f
= ECMAScript
)
540 { this->assign(__first
, __last
, __f
); }
543 * @brief Constructs a basic regular expression from an initializer list.
545 * @param __l The initializer list.
546 * @param __f The format flags of the regular expression.
548 * @throws regex_error if @p __l is not a valid regular expression.
550 basic_regex(initializer_list
<_Ch_type
> __l
, flag_type __f
= ECMAScript
)
551 { _M_compile(__l
.begin(), __l
.end(), __f
); }
554 * @brief Destroys a basic regular expression.
560 * @brief Assigns one regular expression to another.
563 operator=(const basic_regex
&) = default;
566 * @brief Move-assigns one regular expression to another.
569 operator=(basic_regex
&&) = default;
572 * @brief Replaces a regular expression with a new one constructed from
573 * a C-style null-terminated string.
575 * @param __p A pointer to the start of a null-terminated C-style string
576 * containing a regular expression.
579 operator=(const _Ch_type
* __p
)
580 { return this->assign(__p
); }
583 * @brief Replaces a regular expression with a new one constructed from
584 * an initializer list.
586 * @param __l The initializer list.
588 * @throws regex_error if @p __l is not a valid regular expression.
591 operator=(initializer_list
<_Ch_type
> __l
)
592 { return this->assign(__l
); }
595 * @brief Replaces a regular expression with a new one constructed from
598 * @param __s A pointer to a string containing a regular expression.
600 template<typename _Ch_traits
, typename _Alloc
>
602 operator=(const basic_string
<_Ch_type
, _Ch_traits
, _Alloc
>& __s
)
603 { return this->assign(__s
); }
607 * @brief Assigns one regular expression to another.
609 * @param __rhs Another regular expression object.
612 assign(const basic_regex
& __rhs
) noexcept
613 { return *this = __rhs
; }
616 * @brief Move-assigns one regular expression to another.
618 * @param __rhs Another regular expression object.
621 assign(basic_regex
&& __rhs
) noexcept
622 { return *this = std::move(__rhs
); }
625 * @brief Assigns a new regular expression to a regex object from a
626 * C-style null-terminated string containing a regular expression
629 * @param __p A pointer to a C-style null-terminated string containing
630 * a regular expression pattern.
631 * @param __flags Syntax option flags.
633 * @throws regex_error if __p does not contain a valid regular
634 * expression pattern interpreted according to @p __flags. If
635 * regex_error is thrown, *this remains unchanged.
638 assign(const _Ch_type
* __p
, flag_type __flags
= ECMAScript
)
640 _M_compile(__p
, __p
+ _Rx_traits::length(__p
), __flags
);
645 * @brief Assigns a new regular expression to a regex object from a
646 * C-style string containing a regular expression pattern.
648 * @param __p A pointer to a C-style string containing a
649 * regular expression pattern.
650 * @param __len The length of the regular expression pattern string.
651 * @param __flags Syntax option flags.
653 * @throws regex_error if p does not contain a valid regular
654 * expression pattern interpreted according to @p __flags. If
655 * regex_error is thrown, *this remains unchanged.
657 // _GLIBCXX_RESOLVE_LIB_DEFECTS
658 // 3296. Inconsistent default argument for basic_regex<>::assign
660 assign(const _Ch_type
* __p
, size_t __len
, flag_type __flags
= ECMAScript
)
662 _M_compile(__p
, __p
+ __len
, __flags
);
667 * @brief Assigns a new regular expression to a regex object from a
668 * string containing a regular expression pattern.
670 * @param __s A string containing a regular expression pattern.
671 * @param __flags Syntax option flags.
673 * @throws regex_error if __s does not contain a valid regular
674 * expression pattern interpreted according to @p __flags. If
675 * regex_error is thrown, *this remains unchanged.
677 template<typename _Ch_traits
, typename _Alloc
>
679 assign(const basic_string
<_Ch_type
, _Ch_traits
, _Alloc
>& __s
,
680 flag_type __flags
= ECMAScript
)
682 _M_compile(__s
.data(), __s
.data() + __s
.size(), __flags
);
687 * @brief Assigns a new regular expression to a regex object.
689 * @param __first The start of a range containing a valid regular
691 * @param __last The end of a range containing a valid regular
693 * @param __flags Syntax option flags.
695 * @throws regex_error if p does not contain a valid regular
696 * expression pattern interpreted according to @p __flags. If
697 * regex_error is thrown, the object remains unchanged.
699 template<typename _InputIterator
>
701 assign(_InputIterator __first
, _InputIterator __last
,
702 flag_type __flags
= ECMAScript
)
704 #if __cpp_if_constexpr >= 201606L
705 using _ValT
= typename iterator_traits
<_InputIterator
>::value_type
;
706 if constexpr (__detail::__is_contiguous_iter
<_InputIterator
>::value
707 && is_same_v
<_ValT
, value_type
>)
709 __glibcxx_requires_valid_range(__first
, __last
);
710 if constexpr (is_pointer_v
<_InputIterator
>)
711 _M_compile(__first
, __last
, __flags
);
712 else // __normal_iterator<_T*, C>
713 _M_compile(__first
.base(), __last
.base(), __flags
);
717 this->assign(string_type(__first
, __last
), __flags
);
722 * @brief Assigns a new regular expression to a regex object.
724 * @param __l An initializer list representing a regular expression.
725 * @param __flags Syntax option flags.
727 * @throws regex_error if @p __l does not contain a valid
728 * regular expression pattern interpreted according to @p
729 * __flags. If regex_error is thrown, the object remains
733 assign(initializer_list
<_Ch_type
> __l
, flag_type __flags
= ECMAScript
)
735 _M_compile(__l
.begin(), __l
.end(), __flags
);
739 // [7.8.4] const operations
741 * @brief Gets the number of marked subexpressions within the regular
745 mark_count() const noexcept
748 return _M_automaton
->_M_sub_count() - 1;
753 * @brief Gets the flags used to construct the regular expression
754 * or in the last call to assign().
757 flags() const noexcept
762 * @brief Imbues the regular expression object with the given locale.
764 * @param __loc A locale.
767 imbue(locale_type __loc
)
769 std::swap(__loc
, _M_loc
);
770 _M_automaton
.reset();
775 * @brief Gets the locale currently imbued in the regular expression
779 getloc() const noexcept
784 * @brief Swaps the contents of two regular expression objects.
786 * @param __rhs Another regular expression object.
789 swap(basic_regex
& __rhs
) noexcept
791 std::swap(_M_flags
, __rhs
._M_flags
);
792 std::swap(_M_loc
, __rhs
._M_loc
);
793 std::swap(_M_automaton
, __rhs
._M_automaton
);
796 #ifdef _GLIBCXX_DEBUG
798 _M_dot(std::ostream
& __ostr
)
799 { _M_automaton
->_M_dot(__ostr
); }
803 typedef std::shared_ptr
<const __detail::_NFA
<_Rx_traits
>> _AutomatonPtr
;
806 _M_compile(const _Ch_type
* __first
, const _Ch_type
* __last
,
809 __detail::_Compiler
<_Rx_traits
> __c(__first
, __last
, _M_loc
, __f
);
810 _M_automaton
= __c
._M_get_nfa();
814 template<typename _Bp
, typename _Ap
, typename _Cp
, typename _Rp
>
816 __detail::__regex_algo_impl(_Bp
, _Bp
, match_results
<_Bp
, _Ap
>&,
817 const basic_regex
<_Cp
, _Rp
>&,
818 regex_constants::match_flag_type
,
819 __detail::_RegexExecutorPolicy
, bool);
821 template<typename
, typename
, typename
, bool>
822 friend class __detail::_Executor
;
826 _AutomatonPtr _M_automaton
;
829 #if ! __cpp_inline_variables
830 template<typename _Ch
, typename _Tr
>
831 constexpr regex_constants::syntax_option_type
832 basic_regex
<_Ch
, _Tr
>::icase
;
834 template<typename _Ch
, typename _Tr
>
835 constexpr regex_constants::syntax_option_type
836 basic_regex
<_Ch
, _Tr
>::nosubs
;
838 template<typename _Ch
, typename _Tr
>
839 constexpr regex_constants::syntax_option_type
840 basic_regex
<_Ch
, _Tr
>::optimize
;
842 template<typename _Ch
, typename _Tr
>
843 constexpr regex_constants::syntax_option_type
844 basic_regex
<_Ch
, _Tr
>::collate
;
846 template<typename _Ch
, typename _Tr
>
847 constexpr regex_constants::syntax_option_type
848 basic_regex
<_Ch
, _Tr
>::ECMAScript
;
850 template<typename _Ch
, typename _Tr
>
851 constexpr regex_constants::syntax_option_type
852 basic_regex
<_Ch
, _Tr
>::basic
;
854 template<typename _Ch
, typename _Tr
>
855 constexpr regex_constants::syntax_option_type
856 basic_regex
<_Ch
, _Tr
>::extended
;
858 template<typename _Ch
, typename _Tr
>
859 constexpr regex_constants::syntax_option_type
860 basic_regex
<_Ch
, _Tr
>::awk
;
862 template<typename _Ch
, typename _Tr
>
863 constexpr regex_constants::syntax_option_type
864 basic_regex
<_Ch
, _Tr
>::grep
;
866 template<typename _Ch
, typename _Tr
>
867 constexpr regex_constants::syntax_option_type
868 basic_regex
<_Ch
, _Tr
>::egrep
;
871 #if __cpp_deduction_guides >= 201606
872 template<typename _ForwardIterator
>
873 basic_regex(_ForwardIterator
, _ForwardIterator
,
874 regex_constants::syntax_option_type
= {})
875 -> basic_regex
<typename iterator_traits
<_ForwardIterator
>::value_type
>;
878 /** @brief Standard regular expressions. */
879 typedef basic_regex
<char> regex
;
881 #ifdef _GLIBCXX_USE_WCHAR_T
882 /** @brief Standard wide-character regular expressions. */
883 typedef basic_regex
<wchar_t> wregex
;
887 // [7.8.6] basic_regex swap
889 * @brief Swaps the contents of two regular expression objects.
890 * @param __lhs First regular expression.
891 * @param __rhs Second regular expression.
892 * @relates basic_regex
894 template<typename _Ch_type
, typename _Rx_traits
>
896 swap(basic_regex
<_Ch_type
, _Rx_traits
>& __lhs
,
897 basic_regex
<_Ch_type
, _Rx_traits
>& __rhs
) noexcept
898 { __lhs
.swap(__rhs
); }
901 // C++11 28.9 [re.submatch] Class template sub_match
903 * A sequence of characters matched by a particular marked sub-expression.
905 * An object of this class is essentially a pair of iterators marking a
906 * matched subexpression within a regular expression pattern match. Such
907 * objects can be converted to and compared with std::basic_string objects
908 * of the same character type as the pattern matched by the regular
911 * A `sub_match<Iter>` has a public base class of type `pair<Iter, Iter>`,
912 * so inherits pair's data members named `first` and `second`.
913 * The iterators that make up the pair are the usual half-open interval
914 * referencing the actual original pattern matched.
919 template<typename _BiIter
>
921 /// @cond undocumented
922 : public std::pair
<_BiIter
, _BiIter
>
925 typedef iterator_traits
<_BiIter
> __iter_traits
;
928 typedef typename
__iter_traits::value_type value_type
;
929 typedef typename
__iter_traits::difference_type difference_type
;
930 typedef _BiIter iterator
;
931 typedef basic_string
<value_type
> string_type
;
933 _GLIBCXX_DOXYGEN_ONLY(iterator first
; iterator second
;)
937 constexpr sub_match() noexcept
: matched() { }
939 /// Gets the length of the matching sequence.
941 length() const noexcept
942 { return this->matched
? std::distance(this->first
, this->second
) : 0; }
945 * @brief Gets the matching sequence as a string.
947 * @returns the matching sequence as a string.
949 * This is the implicit conversion operator. It is identical to the
950 * str() member function except that it will want to pop up in
951 * unexpected places and cause a great deal of confusion and cursing
954 operator string_type() const
958 * @brief Gets the matching sequence as a string.
960 * @returns the matching sequence as a string.
966 ? string_type(this->first
, this->second
)
971 * @brief Compares this and another matched sequence.
973 * @param __s Another matched sequence to compare to this one.
975 * @retval negative This matched sequence will collate before `__s`.
976 * @retval zero This matched sequence is equivalent to `__s`.
977 * @retval positive This matched sequence will collate after `__s`.
980 compare(const sub_match
& __s
) const
981 { return this->_M_str().compare(__s
._M_str()); }
985 * @brief Compares this `sub_match` to a string.
987 * @param __s A string to compare to this `sub_match`.
989 * @retval negative This matched sequence will collate before `__s`.
990 * @retval zero This matched sequence is equivalent to `__s`.
991 * @retval positive This matched sequence will collate after `__s`.
994 compare(const string_type
& __s
) const
995 { return this->_M_str().compare(__s
); }
998 compare(const value_type
* __s
) const
999 { return this->_M_str().compare(__s
); }
1002 /// @cond undocumented
1003 // Non-standard, used by comparison operators
1005 _M_compare(const value_type
* __s
, size_t __n
) const
1006 { return this->_M_str().compare({__s
, __n
}); }
1009 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1010 // 3204. sub_match::swap only swaps the base class
1011 /// Swap the values of two sub_match objects.
1013 swap(sub_match
& __s
) noexcept(__is_nothrow_swappable
<_BiIter
>::value
)
1015 this->pair
<_BiIter
, _BiIter
>::swap(__s
);
1016 std::swap(matched
, __s
.matched
);
1020 // Simplified basic_string_view for C++11
1021 struct __string_view
1023 using traits_type
= typename
string_type::traits_type
;
1025 __string_view() = default;
1027 __string_view(const value_type
* __s
, size_t __n
) noexcept
1028 : _M_data(__s
), _M_len(__n
) { }
1030 __string_view(const value_type
* __s
) noexcept
1031 : _M_data(__s
), _M_len(traits_type::length(__s
)) { }
1033 __string_view(const string_type
& __s
) noexcept
1034 : _M_data(__s
.data()), _M_len(__s
.length()) { }
1037 compare(__string_view __s
) const noexcept
1039 if (const size_t __n
= std::min(_M_len
, __s
._M_len
))
1040 if (int __ret
= traits_type::compare(_M_data
, __s
._M_data
, __n
))
1042 using __limits
= __gnu_cxx::__int_traits
<int>;
1043 const difference_type __diff
= _M_len
- __s
._M_len
;
1044 if (__diff
> __limits::__max
)
1045 return __limits::__max
;
1046 if (__diff
< __limits::__min
)
1047 return __limits::__min
;
1048 return static_cast<int>(__diff
);
1052 const value_type
* _M_data
= nullptr;
1056 // Create a __string_view over the iterator range.
1057 template<typename _Iter
= _BiIter
>
1058 __enable_if_t
<__detail::__is_contiguous_iter
<_Iter
>::value
,
1060 _M_str() const noexcept
1063 if (size_t __len
= this->second
- this->first
)
1064 return { std::__addressof(*this->first
), __len
};
1068 // Create a temporary string that can be converted to __string_view.
1069 template<typename _Iter
= _BiIter
>
1070 __enable_if_t
<!__detail::__is_contiguous_iter
<_Iter
>::value
,
1077 /** @brief Standard regex submatch over a C-style null-terminated string. */
1078 typedef sub_match
<const char*> csub_match
;
1080 /** @brief Standard regex submatch over a standard string. */
1081 typedef sub_match
<string::const_iterator
> ssub_match
;
1083 #ifdef _GLIBCXX_USE_WCHAR_T
1084 /** @brief Regex submatch over a C-style null-terminated wide string. */
1085 typedef sub_match
<const wchar_t*> wcsub_match
;
1087 /** @brief Regex submatch over a standard wide string. */
1088 typedef sub_match
<wstring::const_iterator
> wssub_match
;
1091 // [7.9.2] sub_match non-member operators
1093 /// @relates sub_match @{
1096 * @brief Tests the equivalence of two regular expression submatches.
1097 * @param __lhs First regular expression submatch.
1098 * @param __rhs Second regular expression submatch.
1099 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1101 template<typename _BiIter
>
1103 operator==(const sub_match
<_BiIter
>& __lhs
, const sub_match
<_BiIter
>& __rhs
)
1104 { return __lhs
.compare(__rhs
) == 0; }
1106 #if __cpp_lib_three_way_comparison
1108 * @brief Three-way comparison of two regular expression submatches.
1109 * @param __lhs First regular expression submatch.
1110 * @param __rhs Second regular expression submatch.
1111 * @returns A value indicating whether `__lhs` is less than, equal to,
1112 * greater than, or incomparable with `__rhs`.
1114 template<typename _BiIter
>
1116 operator<=>(const sub_match
<_BiIter
>& __lhs
,
1117 const sub_match
<_BiIter
>& __rhs
)
1118 noexcept(__detail::__is_contiguous_iter
<_BiIter
>::value
)
1120 using _Tr
= char_traits
<typename iterator_traits
<_BiIter
>::value_type
>;
1121 return __detail::__char_traits_cmp_cat
<_Tr
>(__lhs
.compare(__rhs
));
1125 * @brief Tests the inequivalence of two regular expression submatches.
1126 * @param __lhs First regular expression submatch.
1127 * @param __rhs Second regular expression submatch.
1128 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1130 template<typename _BiIter
>
1132 operator!=(const sub_match
<_BiIter
>& __lhs
, const sub_match
<_BiIter
>& __rhs
)
1133 { return __lhs
.compare(__rhs
) != 0; }
1136 * @brief Tests the ordering of two regular expression submatches.
1137 * @param __lhs First regular expression submatch.
1138 * @param __rhs Second regular expression submatch.
1139 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1141 template<typename _BiIter
>
1143 operator<(const sub_match
<_BiIter
>& __lhs
, const sub_match
<_BiIter
>& __rhs
)
1144 { return __lhs
.compare(__rhs
) < 0; }
1147 * @brief Tests the ordering of two regular expression submatches.
1148 * @param __lhs First regular expression submatch.
1149 * @param __rhs Second regular expression submatch.
1150 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1152 template<typename _BiIter
>
1154 operator<=(const sub_match
<_BiIter
>& __lhs
, const sub_match
<_BiIter
>& __rhs
)
1155 { return __lhs
.compare(__rhs
) <= 0; }
1158 * @brief Tests the ordering of two regular expression submatches.
1159 * @param __lhs First regular expression submatch.
1160 * @param __rhs Second regular expression submatch.
1161 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1163 template<typename _BiIter
>
1165 operator>=(const sub_match
<_BiIter
>& __lhs
, const sub_match
<_BiIter
>& __rhs
)
1166 { return __lhs
.compare(__rhs
) >= 0; }
1169 * @brief Tests the ordering of two regular expression submatches.
1170 * @param __lhs First regular expression submatch.
1171 * @param __rhs Second regular expression submatch.
1172 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1174 template<typename _BiIter
>
1176 operator>(const sub_match
<_BiIter
>& __lhs
, const sub_match
<_BiIter
>& __rhs
)
1177 { return __lhs
.compare(__rhs
) > 0; }
1178 #endif // three-way comparison
1180 /// @cond undocumented
1182 // Alias for a basic_string that can be compared to a sub_match.
1183 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1184 using __sub_match_string
= basic_string
<
1185 typename iterator_traits
<_Bi_iter
>::value_type
,
1186 _Ch_traits
, _Ch_alloc
>;
1189 #if ! __cpp_lib_three_way_comparison
1191 * @brief Tests the equivalence of a string and a regular expression
1193 * @param __lhs A string.
1194 * @param __rhs A regular expression submatch.
1195 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1197 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1199 operator==(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
1200 const sub_match
<_Bi_iter
>& __rhs
)
1201 { return __rhs
._M_compare(__lhs
.data(), __lhs
.size()) == 0; }
1204 * @brief Tests the inequivalence of a string and a regular expression
1206 * @param __lhs A string.
1207 * @param __rhs A regular expression submatch.
1208 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1210 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1212 operator!=(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
1213 const sub_match
<_Bi_iter
>& __rhs
)
1214 { return !(__lhs
== __rhs
); }
1217 * @brief Tests the ordering of a string and a regular expression submatch.
1218 * @param __lhs A string.
1219 * @param __rhs A regular expression submatch.
1220 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1222 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1224 operator<(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
1225 const sub_match
<_Bi_iter
>& __rhs
)
1226 { return __rhs
._M_compare(__lhs
.data(), __lhs
.size()) > 0; }
1229 * @brief Tests the ordering of a string and a regular expression submatch.
1230 * @param __lhs A string.
1231 * @param __rhs A regular expression submatch.
1232 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1234 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1236 operator>(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
1237 const sub_match
<_Bi_iter
>& __rhs
)
1238 { return __rhs
< __lhs
; }
1241 * @brief Tests the ordering of a string and a regular expression submatch.
1242 * @param __lhs A string.
1243 * @param __rhs A regular expression submatch.
1244 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1246 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1248 operator>=(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
1249 const sub_match
<_Bi_iter
>& __rhs
)
1250 { return !(__lhs
< __rhs
); }
1253 * @brief Tests the ordering of a string and a regular expression submatch.
1254 * @param __lhs A string.
1255 * @param __rhs A regular expression submatch.
1256 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1258 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1260 operator<=(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
1261 const sub_match
<_Bi_iter
>& __rhs
)
1262 { return !(__rhs
< __lhs
); }
1263 #endif // three-way comparison
1266 * @brief Tests the equivalence of a regular expression submatch and a
1268 * @param __lhs A regular expression submatch.
1269 * @param __rhs A string.
1270 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1272 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1274 operator==(const sub_match
<_Bi_iter
>& __lhs
,
1275 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1276 { return __lhs
._M_compare(__rhs
.data(), __rhs
.size()) == 0; }
1278 #if __cpp_lib_three_way_comparison
1280 * @brief Three-way comparison of a regular expression submatch and a string.
1281 * @param __lhs A regular expression submatch.
1282 * @param __rhs A string.
1283 * @returns A value indicating whether `__lhs` is less than, equal to,
1284 * greater than, or incomparable with `__rhs`.
1286 template<typename _Bi_iter
, typename _Ch_traits
, typename _Alloc
>
1288 operator<=>(const sub_match
<_Bi_iter
>& __lhs
,
1289 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Alloc
>& __rhs
)
1290 noexcept(__detail::__is_contiguous_iter
<_Bi_iter
>::value
)
1292 return __detail::__char_traits_cmp_cat
<_Ch_traits
>(
1293 __lhs
._M_compare(__rhs
.data(), __rhs
.size()));
1297 * @brief Tests the inequivalence of a regular expression submatch and a
1299 * @param __lhs A regular expression submatch.
1300 * @param __rhs A string.
1301 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1303 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1305 operator!=(const sub_match
<_Bi_iter
>& __lhs
,
1306 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1307 { return !(__lhs
== __rhs
); }
1310 * @brief Tests the ordering of a regular expression submatch and a string.
1311 * @param __lhs A regular expression submatch.
1312 * @param __rhs A string.
1313 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1315 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1317 operator<(const sub_match
<_Bi_iter
>& __lhs
,
1318 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1319 { return __lhs
._M_compare(__rhs
.data(), __rhs
.size()) < 0; }
1322 * @brief Tests the ordering of a regular expression submatch and a string.
1323 * @param __lhs A regular expression submatch.
1324 * @param __rhs A string.
1325 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1327 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1329 operator>(const sub_match
<_Bi_iter
>& __lhs
,
1330 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1331 { return __rhs
< __lhs
; }
1334 * @brief Tests the ordering of a regular expression submatch and a string.
1335 * @param __lhs A regular expression submatch.
1336 * @param __rhs A string.
1337 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1339 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1341 operator>=(const sub_match
<_Bi_iter
>& __lhs
,
1342 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1343 { return !(__lhs
< __rhs
); }
1346 * @brief Tests the ordering of a regular expression submatch and a string.
1347 * @param __lhs A regular expression submatch.
1348 * @param __rhs A string.
1349 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1351 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1353 operator<=(const sub_match
<_Bi_iter
>& __lhs
,
1354 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1355 { return !(__rhs
< __lhs
); }
1358 * @brief Tests the equivalence of a C string and a regular expression
1360 * @param __lhs A null-terminated string.
1361 * @param __rhs A regular expression submatch.
1362 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1364 template<typename _Bi_iter
>
1366 operator==(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1367 const sub_match
<_Bi_iter
>& __rhs
)
1368 { return __rhs
.compare(__lhs
) == 0; }
1371 * @brief Tests the inequivalence of a C string and a regular
1372 * expression submatch.
1373 * @param __lhs A null-terminated string.
1374 * @param __rhs A regular expression submatch.
1375 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1377 template<typename _Bi_iter
>
1379 operator!=(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1380 const sub_match
<_Bi_iter
>& __rhs
)
1381 { return !(__lhs
== __rhs
); }
1384 * @brief Tests the ordering of a C string and a regular expression submatch.
1385 * @param __lhs A null-terminated string.
1386 * @param __rhs A regular expression submatch.
1387 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1389 template<typename _Bi_iter
>
1391 operator<(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1392 const sub_match
<_Bi_iter
>& __rhs
)
1393 { return __rhs
.compare(__lhs
) > 0; }
1396 * @brief Tests the ordering of a C string and a regular expression submatch.
1397 * @param __lhs A null-terminated string.
1398 * @param __rhs A regular expression submatch.
1399 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1401 template<typename _Bi_iter
>
1403 operator>(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1404 const sub_match
<_Bi_iter
>& __rhs
)
1405 { return __rhs
< __lhs
; }
1408 * @brief Tests the ordering of a C string and a regular expression submatch.
1409 * @param __lhs A null-terminated string.
1410 * @param __rhs A regular expression submatch.
1411 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1413 template<typename _Bi_iter
>
1415 operator>=(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1416 const sub_match
<_Bi_iter
>& __rhs
)
1417 { return !(__lhs
< __rhs
); }
1420 * @brief Tests the ordering of a C string and a regular expression submatch.
1421 * @param __lhs A null-terminated string.
1422 * @param __rhs A regular expression submatch.
1423 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1425 template<typename _Bi_iter
>
1427 operator<=(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1428 const sub_match
<_Bi_iter
>& __rhs
)
1429 { return !(__rhs
< __lhs
); }
1430 #endif // three-way comparison
1433 * @brief Tests the equivalence of a regular expression submatch and a C
1435 * @param __lhs A regular expression submatch.
1436 * @param __rhs A null-terminated string.
1437 * @returns true if @a __lhs is equivalent to @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
.compare(__rhs
) == 0; }
1445 #if __cpp_lib_three_way_comparison
1447 * @brief Three-way comparison of a regular expression submatch and a C
1449 * @param __lhs A regular expression submatch.
1450 * @param __rhs A null-terminated string.
1451 * @returns A value indicating whether `__lhs` is less than, equal to,
1452 * greater than, or incomparable with `__rhs`.
1454 template<typename _Bi_iter
>
1456 operator<=>(const sub_match
<_Bi_iter
>& __lhs
,
1457 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1458 noexcept(__detail::__is_contiguous_iter
<_Bi_iter
>::value
)
1460 using _Tr
= char_traits
<typename iterator_traits
<_Bi_iter
>::value_type
>;
1461 return __detail::__char_traits_cmp_cat
<_Tr
>(__lhs
.compare(__rhs
));
1465 * @brief Tests the inequivalence of a regular expression submatch and a
1467 * @param __lhs A regular expression submatch.
1468 * @param __rhs A null-terminated string.
1469 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1471 template<typename _Bi_iter
>
1473 operator!=(const sub_match
<_Bi_iter
>& __lhs
,
1474 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1475 { return !(__lhs
== __rhs
); }
1478 * @brief Tests the ordering of a regular expression submatch and a C string.
1479 * @param __lhs A regular expression submatch.
1480 * @param __rhs A null-terminated string.
1481 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1483 template<typename _Bi_iter
>
1485 operator<(const sub_match
<_Bi_iter
>& __lhs
,
1486 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1487 { return __lhs
.compare(__rhs
) < 0; }
1490 * @brief Tests the ordering of a regular expression submatch and a C string.
1491 * @param __lhs A regular expression submatch.
1492 * @param __rhs A null-terminated string.
1493 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1495 template<typename _Bi_iter
>
1497 operator>(const sub_match
<_Bi_iter
>& __lhs
,
1498 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1499 { return __rhs
< __lhs
; }
1502 * @brief Tests the ordering of a regular expression submatch and a C string.
1503 * @param __lhs A regular expression submatch.
1504 * @param __rhs A null-terminated string.
1505 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1507 template<typename _Bi_iter
>
1509 operator>=(const sub_match
<_Bi_iter
>& __lhs
,
1510 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1511 { return !(__lhs
< __rhs
); }
1514 * @brief Tests the ordering of a regular expression submatch and a C string.
1515 * @param __lhs A regular expression submatch.
1516 * @param __rhs A null-terminated string.
1517 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1519 template<typename _Bi_iter
>
1521 operator<=(const sub_match
<_Bi_iter
>& __lhs
,
1522 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1523 { return !(__rhs
< __lhs
); }
1526 * @brief Tests the equivalence of a character and a regular expression
1528 * @param __lhs A character.
1529 * @param __rhs A regular expression submatch.
1530 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1532 template<typename _Bi_iter
>
1534 operator==(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1535 const sub_match
<_Bi_iter
>& __rhs
)
1536 { return __rhs
._M_compare(std::__addressof(__lhs
), 1) == 0; }
1539 * @brief Tests the inequivalence of a character and a regular expression
1541 * @param __lhs A character.
1542 * @param __rhs A regular expression submatch.
1543 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1545 template<typename _Bi_iter
>
1547 operator!=(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1548 const sub_match
<_Bi_iter
>& __rhs
)
1549 { return !(__lhs
== __rhs
); }
1552 * @brief Tests the ordering of a character and a regular expression
1554 * @param __lhs A character.
1555 * @param __rhs A regular expression submatch.
1556 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1558 template<typename _Bi_iter
>
1560 operator<(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1561 const sub_match
<_Bi_iter
>& __rhs
)
1562 { return __rhs
._M_compare(std::__addressof(__lhs
), 1) > 0; }
1565 * @brief Tests the ordering of a character and a regular expression
1567 * @param __lhs A character.
1568 * @param __rhs A regular expression submatch.
1569 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1571 template<typename _Bi_iter
>
1573 operator>(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1574 const sub_match
<_Bi_iter
>& __rhs
)
1575 { return __rhs
< __lhs
; }
1578 * @brief Tests the ordering of a character and a regular expression
1580 * @param __lhs A character.
1581 * @param __rhs A regular expression submatch.
1582 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1584 template<typename _Bi_iter
>
1586 operator>=(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1587 const sub_match
<_Bi_iter
>& __rhs
)
1588 { return !(__lhs
< __rhs
); }
1591 * @brief Tests the ordering of a character and a regular expression
1593 * @param __lhs A character.
1594 * @param __rhs A regular expression submatch.
1595 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1597 template<typename _Bi_iter
>
1599 operator<=(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1600 const sub_match
<_Bi_iter
>& __rhs
)
1601 { return !(__rhs
< __lhs
); }
1602 #endif // three-way comparison
1605 * @brief Tests the equivalence of a regular expression submatch and a
1607 * @param __lhs A regular expression submatch.
1608 * @param __rhs A character.
1609 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1611 template<typename _Bi_iter
>
1613 operator==(const sub_match
<_Bi_iter
>& __lhs
,
1614 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1615 { return __lhs
._M_compare(std::__addressof(__rhs
), 1) == 0; }
1617 #if __cpp_lib_three_way_comparison
1619 * @brief Three-way comparison of a regular expression submatch and a
1621 * @param __lhs A regular expression submatch.
1622 * @param __rhs A character.
1623 * @returns A value indicating whether `__lhs` is less than, equal to,
1624 * greater than, or incomparable with `__rhs`.
1627 template<typename _Bi_iter
>
1629 operator<=>(const sub_match
<_Bi_iter
>& __lhs
,
1630 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1631 noexcept(__detail::__is_contiguous_iter
<_Bi_iter
>::value
)
1633 using _Tr
= char_traits
<typename iterator_traits
<_Bi_iter
>::value_type
>;
1634 return __detail::__char_traits_cmp_cat
<_Tr
>(
1635 __lhs
._M_compare(std::__addressof(__rhs
), 1));
1639 * @brief Tests the inequivalence of a regular expression submatch and a
1641 * @param __lhs A regular expression submatch.
1642 * @param __rhs A character.
1643 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1645 template<typename _Bi_iter
>
1647 operator!=(const sub_match
<_Bi_iter
>& __lhs
,
1648 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1649 { return !(__lhs
== __rhs
); }
1652 * @brief Tests the ordering of a regular expression submatch and a
1654 * @param __lhs A regular expression submatch.
1655 * @param __rhs A character.
1656 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1658 template<typename _Bi_iter
>
1660 operator<(const sub_match
<_Bi_iter
>& __lhs
,
1661 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1662 { return __lhs
._M_compare(std::__addressof(__rhs
), 1) < 0; }
1665 * @brief Tests the ordering of a regular expression submatch and a
1667 * @param __lhs A regular expression submatch.
1668 * @param __rhs A character.
1669 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1671 template<typename _Bi_iter
>
1673 operator>(const sub_match
<_Bi_iter
>& __lhs
,
1674 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1675 { return __rhs
< __lhs
; }
1678 * @brief Tests the ordering of a regular expression submatch and a
1680 * @param __lhs A regular expression submatch.
1681 * @param __rhs A character.
1682 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1684 template<typename _Bi_iter
>
1686 operator>=(const sub_match
<_Bi_iter
>& __lhs
,
1687 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1688 { return !(__lhs
< __rhs
); }
1691 * @brief Tests the ordering of a regular expression submatch and a
1693 * @param __lhs A regular expression submatch.
1694 * @param __rhs A character.
1695 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1697 template<typename _Bi_iter
>
1699 operator<=(const sub_match
<_Bi_iter
>& __lhs
,
1700 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1701 { return !(__rhs
< __lhs
); }
1702 #endif // three-way comparison
1705 * @brief Inserts a matched string into an output stream.
1707 * @param __os The output stream.
1708 * @param __m A submatch string.
1710 * @returns the output stream with the submatch string inserted.
1712 template<typename _Ch_type
, typename _Ch_traits
, typename _Bi_iter
>
1714 basic_ostream
<_Ch_type
, _Ch_traits
>&
1715 operator<<(basic_ostream
<_Ch_type
, _Ch_traits
>& __os
,
1716 const sub_match
<_Bi_iter
>& __m
)
1717 { return __os
<< __m
.str(); }
1719 /// @} relates sub_match
1721 // [7.10] Class template match_results
1724 * @brief The results of a match or search operation.
1726 * A collection of character sequences representing the result of a regular
1727 * expression match. Storage for the collection is allocated and freed as
1728 * necessary by the member functions of class template match_results.
1730 * This class satisfies the Sequence requirements, with the exception that
1731 * only the operations defined for a const-qualified Sequence are supported.
1733 * The sub_match object stored at index 0 represents sub-expression 0, i.e.
1734 * the whole match. In this case the %sub_match member matched is always true.
1735 * The sub_match object stored at index n denotes what matched the marked
1736 * sub-expression n within the matched expression. If the sub-expression n
1737 * participated in a regular expression match then the %sub_match member
1738 * matched evaluates to true, and members first and second denote the range
1739 * of characters [first, second) which formed that match. Otherwise matched
1740 * is false, and members first and second point to the end of the sequence
1741 * that was searched.
1746 template<typename _Bi_iter
,
1747 typename _Alloc
= allocator
<sub_match
<_Bi_iter
> > >
1749 : private std::vector
<sub_match
<_Bi_iter
>, _Alloc
>
1753 * The vector base is empty if this does not represent a match (!ready());
1754 * Otherwise if it's a match failure, it contains 3 elements:
1758 * Otherwise it contains n+4 elements where n is the number of marked
1761 * [1] 1st marked subexpression
1763 * [n] nth marked subexpression
1768 typedef std::vector
<sub_match
<_Bi_iter
>, _Alloc
> _Base_type
;
1769 // In debug mode _Base_type is the debug vector, this is the unsafe one:
1770 typedef _GLIBCXX_STD_C::vector
<sub_match
<_Bi_iter
>, _Alloc
> _Unchecked
;
1771 typedef std::iterator_traits
<_Bi_iter
> __iter_traits
;
1772 typedef regex_constants::match_flag_type match_flag_type
;
1776 * @name 28.10 Public Types
1779 typedef sub_match
<_Bi_iter
> value_type
;
1780 typedef const value_type
& const_reference
;
1781 typedef value_type
& reference
;
1782 typedef typename
_Base_type::const_iterator const_iterator
;
1783 typedef const_iterator iterator
;
1784 typedef typename
__iter_traits::difference_type difference_type
;
1785 typedef typename allocator_traits
<_Alloc
>::size_type size_type
;
1786 typedef _Alloc allocator_type
;
1787 typedef typename
__iter_traits::value_type char_type
;
1788 typedef std::basic_string
<char_type
> string_type
;
1793 * @name 28.10.1 Construction, Copying, and Destruction
1798 * @brief Constructs a default %match_results container.
1799 * @post size() returns 0 and str() returns an empty string.
1801 match_results() : match_results(_Alloc()) { }
1804 * @brief Constructs a default %match_results container.
1805 * @post size() returns 0 and str() returns an empty string.
1808 match_results(const _Alloc
& __a
) noexcept
1813 * @brief Copy constructs a %match_results.
1815 match_results(const match_results
&) = default;
1818 * @brief Move constructs a %match_results.
1820 match_results(match_results
&&) noexcept
= default;
1823 * @brief Assigns rhs to *this.
1826 operator=(const match_results
&) = default;
1829 * @brief Move-assigns rhs to *this.
1832 operator=(match_results
&&) = default;
1835 * @brief Destroys a %match_results object.
1837 ~match_results() = default;
1839 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1840 // 2195. Missing constructors for match_results
1842 match_results(const match_results
& __m
, const _Alloc
& __a
)
1843 : _Base_type(__m
, __a
) { }
1845 match_results(match_results
&& __m
, const _Alloc
& __a
)
1846 noexcept(noexcept(_Base_type(std::move(__m
), __a
)))
1847 : _Base_type(std::move(__m
), __a
) { }
1853 * @brief Indicates if the %match_results is ready.
1854 * @retval true The object has a fully-established result state.
1855 * @retval false The object is not ready.
1857 bool ready() const noexcept
{ return !_Unchecked::empty(); }
1860 * @name 28.10.2 Size
1865 * @brief Gets the number of matches and submatches.
1867 * The number of matches for a given regular expression will be either 0
1868 * if there was no match or mark_count() + 1 if a match was successful.
1869 * Some matches may be empty.
1871 * @returns the number of matches found.
1874 size() const noexcept
1875 { return _Unchecked::empty() ? 0 : _Unchecked::size() - 3; }
1878 max_size() const noexcept
1879 { return _Unchecked::max_size() - 3; }
1882 * @brief Indicates if the %match_results contains no results.
1883 * @retval true The %match_results object is empty.
1884 * @retval false The %match_results object is not empty.
1886 _GLIBCXX_NODISCARD
bool
1887 empty() const noexcept
1888 { return _Unchecked::size() <= 3; }
1893 * @name 28.10.4 Element Access
1898 * @brief Gets the length of the indicated submatch.
1899 * @param __sub indicates the submatch.
1900 * @pre ready() == true
1902 * This function returns the length of the indicated submatch, or the
1903 * length of the entire match if @p __sub is zero (the default).
1906 length(size_type __sub
= 0) const
1907 { return (*this)[__sub
].length(); }
1910 * @brief Gets the offset of the beginning of the indicated submatch.
1911 * @param __sub indicates the submatch.
1912 * @pre ready() == true
1914 * This function returns the offset from the beginning of the target
1915 * sequence to the beginning of the submatch, unless the value of @p __sub
1916 * is zero (the default), in which case this function returns the offset
1917 * from the beginning of the target sequence to the beginning of the
1921 position(size_type __sub
= 0) const
1922 { return std::distance(_M_begin
, (*this)[__sub
].first
); }
1925 * @brief Gets the match or submatch converted to a string type.
1926 * @param __sub indicates the submatch.
1927 * @pre ready() == true
1929 * This function gets the submatch (or match, if @p __sub is
1930 * zero) extracted from the target range and converted to the
1931 * associated string type.
1934 str(size_type __sub
= 0) const
1935 { return string_type((*this)[__sub
]); }
1938 * @brief Gets a %sub_match reference for the match or submatch.
1939 * @param __sub indicates the submatch.
1940 * @pre ready() == true
1942 * This function gets a reference to the indicated submatch, or
1943 * the entire match if @p __sub is zero.
1945 * If @p __sub >= size() then this function returns a %sub_match with a
1946 * special value indicating no submatch.
1949 operator[](size_type __sub
) const
1951 __glibcxx_assert( ready() );
1952 return __sub
< size()
1953 ? _Unchecked::operator[](__sub
)
1954 : _M_unmatched_sub();
1958 * @brief Gets a %sub_match representing the match prefix.
1959 * @pre ready() == true
1961 * This function gets a reference to a %sub_match object representing the
1962 * part of the target range between the start of the target range and the
1963 * start of the match.
1968 __glibcxx_assert( ready() );
1969 return !empty() ? _M_prefix() : _M_unmatched_sub();
1973 * @brief Gets a %sub_match representing the match suffix.
1974 * @pre ready() == true
1976 * This function gets a reference to a %sub_match object representing the
1977 * part of the target range between the end of the match and the end of
1983 __glibcxx_assert( ready() );
1984 return !empty() ? _M_suffix() : _M_unmatched_sub();
1988 * @brief Gets an iterator to the start of the %sub_match collection.
1991 begin() const noexcept
1992 { return _Base_type::begin(); }
1995 * @brief Gets an iterator to the start of the %sub_match collection.
1998 cbegin() const noexcept
1999 { return this->begin(); }
2002 * @brief Gets an iterator to one-past-the-end of the collection.
2005 end() const noexcept
2006 { return _Base_type::end() - (_Base_type::empty() ? 0 : 3); }
2009 * @brief Gets an iterator to one-past-the-end of the collection.
2012 cend() const noexcept
2013 { return this->end(); }
2018 * @name 28.10.5 Formatting
2020 * These functions perform formatted substitution of the matched
2021 * character sequences into their target. The format specifiers and
2022 * escape sequences accepted by these functions are determined by
2023 * their @p flags parameter as documented above.
2028 * @pre ready() == true
2030 template<typename _Out_iter
>
2032 format(_Out_iter __out
, const char_type
* __fmt_first
,
2033 const char_type
* __fmt_last
,
2034 match_flag_type __flags
= regex_constants::format_default
) const;
2037 * @pre ready() == true
2039 template<typename _Out_iter
, typename _St
, typename _Sa
>
2041 format(_Out_iter __out
, const basic_string
<char_type
, _St
, _Sa
>& __fmt
,
2042 match_flag_type __flags
= regex_constants::format_default
) const
2044 return format(__out
, __fmt
.data(), __fmt
.data() + __fmt
.size(),
2049 * @pre ready() == true
2051 template<typename _St
, typename _Sa
>
2052 basic_string
<char_type
, _St
, _Sa
>
2053 format(const basic_string
<char_type
, _St
, _Sa
>& __fmt
,
2054 match_flag_type __flags
= regex_constants::format_default
) const
2056 basic_string
<char_type
, _St
, _Sa
> __result
;
2057 format(std::back_inserter(__result
), __fmt
, __flags
);
2062 * @pre ready() == true
2065 format(const char_type
* __fmt
,
2066 match_flag_type __flags
= regex_constants::format_default
) const
2068 string_type __result
;
2069 format(std::back_inserter(__result
),
2071 __fmt
+ char_traits
<char_type
>::length(__fmt
),
2079 * @name 28.10.6 Allocator
2084 * @brief Gets a copy of the allocator.
2087 get_allocator() const noexcept
2088 { return _Base_type::get_allocator(); }
2093 * @name 28.10.7 Swap
2098 * @brief Swaps the contents of two match_results.
2101 swap(match_results
& __that
) noexcept
2104 _Base_type::swap(__that
);
2105 swap(_M_begin
, __that
._M_begin
);
2110 template<typename
, typename
, typename
>
2111 friend class regex_iterator
;
2113 /// @cond undocumented
2115 template<typename
, typename
, typename
, bool>
2116 friend class __detail::_Executor
;
2118 template<typename _Bp
, typename _Ap
, typename _Cp
, typename _Rp
>
2120 __detail::__regex_algo_impl(_Bp
, _Bp
, match_results
<_Bp
, _Ap
>&,
2121 const basic_regex
<_Cp
, _Rp
>&,
2122 regex_constants::match_flag_type
,
2123 __detail::_RegexExecutorPolicy
, bool);
2125 // Reset contents to __size unmatched sub_match objects
2126 // (plus additional objects for prefix, suffix and unmatched sub).
2128 _M_resize(unsigned int __size
)
2129 { _Unchecked::assign(__size
+ 3, sub_match
<_Bi_iter
>{}); }
2131 // Set state to a failed match for the given past-the-end iterator.
2133 _M_establish_failed_match(_Bi_iter __end
)
2135 sub_match
<_Bi_iter
> __sm
;
2136 __sm
.first
= __sm
.second
= __end
;
2137 _Unchecked::assign(3, __sm
);
2141 _M_unmatched_sub() const
2142 { return _Unchecked::operator[](_Unchecked::size() - 3); }
2144 sub_match
<_Bi_iter
>&
2146 { return _Unchecked::operator[](_Unchecked::size() - 3); }
2150 { return _Unchecked::operator[](_Unchecked::size() - 2); }
2152 sub_match
<_Bi_iter
>&
2154 { return _Unchecked::operator[](_Unchecked::size() - 2); }
2158 { return _Unchecked::operator[](_Unchecked::size() - 1); }
2160 sub_match
<_Bi_iter
>&
2162 { return _Unchecked::operator[](_Unchecked::size() - 1); }
2164 _Bi_iter _M_begin
{};
2168 typedef match_results
<const char*> cmatch
;
2169 typedef match_results
<string::const_iterator
> smatch
;
2170 #ifdef _GLIBCXX_USE_WCHAR_T
2171 typedef match_results
<const wchar_t*> wcmatch
;
2172 typedef match_results
<wstring::const_iterator
> wsmatch
;
2175 // match_results comparisons
2178 * @brief Compares two match_results for equality.
2179 * @returns true if the two objects refer to the same match,
2182 * @relates match_results
2184 template<typename _Bi_iter
, typename _Alloc
>
2186 operator==(const match_results
<_Bi_iter
, _Alloc
>& __m1
,
2187 const match_results
<_Bi_iter
, _Alloc
>& __m2
)
2189 if (__m1
.ready() != __m2
.ready())
2191 if (!__m1
.ready()) // both are not ready
2193 if (__m1
.empty() != __m2
.empty())
2195 if (__m1
.empty()) // both are empty
2197 return __m1
.prefix() == __m2
.prefix()
2198 && __m1
.size() == __m2
.size()
2199 && std::equal(__m1
.begin(), __m1
.end(), __m2
.begin())
2200 && __m1
.suffix() == __m2
.suffix();
2203 #if ! __cpp_lib_three_way_comparison
2205 * @brief Compares two match_results for inequality.
2206 * @returns true if the two objects do not refer to the same match,
2209 * @relates match_results
2211 template<typename _Bi_iter
, class _Alloc
>
2213 operator!=(const match_results
<_Bi_iter
, _Alloc
>& __m1
,
2214 const match_results
<_Bi_iter
, _Alloc
>& __m2
)
2215 { return !(__m1
== __m2
); }
2218 // [7.10.6] match_results swap
2220 * @brief Swaps two match results.
2221 * @param __lhs A match result.
2222 * @param __rhs A match result.
2224 * The contents of the two match_results objects are swapped.
2226 * @relates match_results
2228 template<typename _Bi_iter
, typename _Alloc
>
2230 swap(match_results
<_Bi_iter
, _Alloc
>& __lhs
,
2231 match_results
<_Bi_iter
, _Alloc
>& __rhs
) noexcept
2232 { __lhs
.swap(__rhs
); }
2234 _GLIBCXX_END_NAMESPACE_CXX11
2236 // [28.11.2] Function template regex_match
2238 * @name Matching, Searching, and Replacing
2244 * @brief Determines if there is a match between the regular expression @p e
2245 * and all of the character sequence [first, last).
2247 * @param __s Start of the character sequence to match.
2248 * @param __e One-past-the-end of the character sequence to match.
2249 * @param __m The match results.
2250 * @param __re The regular expression.
2251 * @param __flags Controls how the regular expression is matched.
2253 * @retval true A match exists.
2254 * @retval false Otherwise.
2256 * @throws an exception of type regex_error.
2258 template<typename _Bi_iter
, typename _Alloc
,
2259 typename _Ch_type
, typename _Rx_traits
>
2261 regex_match(_Bi_iter __s
,
2263 match_results
<_Bi_iter
, _Alloc
>& __m
,
2264 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2265 regex_constants::match_flag_type __flags
2266 = regex_constants::match_default
)
2268 return __detail::__regex_algo_impl(__s
, __e
, __m
, __re
, __flags
,
2269 __detail::_RegexExecutorPolicy::_S_auto
, true);
2273 * @brief Indicates if there is a match between the regular expression @p e
2274 * and all of the character sequence [first, last).
2276 * @param __first Beginning of the character sequence to match.
2277 * @param __last One-past-the-end of the character sequence to match.
2278 * @param __re The regular expression.
2279 * @param __flags Controls how the regular expression is matched.
2281 * @retval true A match exists.
2282 * @retval false Otherwise.
2284 * @throws an exception of type regex_error.
2286 template<typename _Bi_iter
, typename _Ch_type
, typename _Rx_traits
>
2288 regex_match(_Bi_iter __first
, _Bi_iter __last
,
2289 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2290 regex_constants::match_flag_type __flags
2291 = regex_constants::match_default
)
2293 match_results
<_Bi_iter
> __what
;
2294 return regex_match(__first
, __last
, __what
, __re
, __flags
);
2298 * @brief Determines if there is a match between the regular expression @p e
2299 * and a C-style null-terminated string.
2301 * @param __s The C-style null-terminated string to match.
2302 * @param __m The match results.
2303 * @param __re The regular expression.
2304 * @param __f Controls how the regular expression is matched.
2306 * @retval true A match exists.
2307 * @retval false Otherwise.
2309 * @throws an exception of type regex_error.
2311 template<typename _Ch_type
, typename _Alloc
, typename _Rx_traits
>
2313 regex_match(const _Ch_type
* __s
,
2314 match_results
<const _Ch_type
*, _Alloc
>& __m
,
2315 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2316 regex_constants::match_flag_type __f
2317 = regex_constants::match_default
)
2318 { return regex_match(__s
, __s
+ _Rx_traits::length(__s
), __m
, __re
, __f
); }
2321 * @brief Determines if there is a match between the regular expression @p e
2324 * @param __s The string to match.
2325 * @param __m The match results.
2326 * @param __re The regular expression.
2327 * @param __flags Controls how the regular expression is matched.
2329 * @retval true A match exists.
2330 * @retval false Otherwise.
2332 * @throws an exception of type regex_error.
2334 template<typename _Ch_traits
, typename _Ch_alloc
,
2335 typename _Alloc
, typename _Ch_type
, typename _Rx_traits
>
2337 regex_match(const basic_string
<_Ch_type
, _Ch_traits
, _Ch_alloc
>& __s
,
2338 match_results
<typename basic_string
<_Ch_type
,
2339 _Ch_traits
, _Ch_alloc
>::const_iterator
, _Alloc
>& __m
,
2340 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2341 regex_constants::match_flag_type __flags
2342 = regex_constants::match_default
)
2343 { return regex_match(__s
.begin(), __s
.end(), __m
, __re
, __flags
); }
2345 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2346 // 2329. regex_match() with match_results should forbid temporary strings
2347 /// Prevent unsafe attempts to get match_results from a temporary string.
2348 template<typename _Ch_traits
, typename _Ch_alloc
,
2349 typename _Alloc
, typename _Ch_type
, typename _Rx_traits
>
2351 regex_match(const basic_string
<_Ch_type
, _Ch_traits
, _Ch_alloc
>&&,
2352 match_results
<typename basic_string
<_Ch_type
,
2353 _Ch_traits
, _Ch_alloc
>::const_iterator
, _Alloc
>&,
2354 const basic_regex
<_Ch_type
, _Rx_traits
>&,
2355 regex_constants::match_flag_type
2356 = regex_constants::match_default
) = delete;
2359 * @brief Indicates if there is a match between the regular expression @p e
2360 * and a C-style null-terminated string.
2362 * @param __s The C-style null-terminated string to match.
2363 * @param __re The regular expression.
2364 * @param __f Controls how the regular expression is matched.
2366 * @retval true A match exists.
2367 * @retval false Otherwise.
2369 * @throws an exception of type regex_error.
2371 template<typename _Ch_type
, class _Rx_traits
>
2373 regex_match(const _Ch_type
* __s
,
2374 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2375 regex_constants::match_flag_type __f
2376 = regex_constants::match_default
)
2377 { return regex_match(__s
, __s
+ _Rx_traits::length(__s
), __re
, __f
); }
2380 * @brief Indicates if there is a match between the regular expression @p e
2383 * @param __s [IN] The string to match.
2384 * @param __re [IN] The regular expression.
2385 * @param __flags [IN] Controls how the regular expression is matched.
2387 * @retval true A match exists.
2388 * @retval false Otherwise.
2390 * @throws an exception of type regex_error.
2392 template<typename _Ch_traits
, typename _Str_allocator
,
2393 typename _Ch_type
, typename _Rx_traits
>
2395 regex_match(const basic_string
<_Ch_type
, _Ch_traits
, _Str_allocator
>& __s
,
2396 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2397 regex_constants::match_flag_type __flags
2398 = regex_constants::match_default
)
2399 { return regex_match(__s
.begin(), __s
.end(), __re
, __flags
); }
2401 // [7.11.3] Function template regex_search
2403 * Searches for a regular expression within a range.
2404 * @param __s [IN] The start of the string to search.
2405 * @param __e [IN] One-past-the-end of the string to search.
2406 * @param __m [OUT] The match results.
2407 * @param __re [IN] The regular expression to search for.
2408 * @param __flags [IN] Search policy flags.
2409 * @retval true A match was found within the string.
2410 * @retval false No match was found within the string, the content of %m is
2413 * @throws an exception of type regex_error.
2415 template<typename _Bi_iter
, typename _Alloc
,
2416 typename _Ch_type
, typename _Rx_traits
>
2418 regex_search(_Bi_iter __s
, _Bi_iter __e
,
2419 match_results
<_Bi_iter
, _Alloc
>& __m
,
2420 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2421 regex_constants::match_flag_type __flags
2422 = regex_constants::match_default
)
2424 return __detail::__regex_algo_impl(__s
, __e
, __m
, __re
, __flags
,
2425 __detail::_RegexExecutorPolicy::_S_auto
, false);
2429 * Searches for a regular expression within a range.
2430 * @param __first [IN] The start of the string to search.
2431 * @param __last [IN] One-past-the-end of the string to search.
2432 * @param __re [IN] The regular expression to search for.
2433 * @param __flags [IN] Search policy flags.
2434 * @retval true A match was found within the string.
2435 * @retval false No match was found within the string.
2437 * @throws an exception of type regex_error.
2439 template<typename _Bi_iter
, typename _Ch_type
, typename _Rx_traits
>
2441 regex_search(_Bi_iter __first
, _Bi_iter __last
,
2442 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2443 regex_constants::match_flag_type __flags
2444 = regex_constants::match_default
)
2446 match_results
<_Bi_iter
> __what
;
2447 return regex_search(__first
, __last
, __what
, __re
, __flags
);
2451 * @brief Searches for a regular expression within a C-string.
2452 * @param __s [IN] A C-string to search for the regex.
2453 * @param __m [OUT] The set of regex matches.
2454 * @param __e [IN] The regex to search for in @p s.
2455 * @param __f [IN] The search flags.
2456 * @retval true A match was found within the string.
2457 * @retval false No match was found within the string, the content of %m is
2460 * @throws an exception of type regex_error.
2462 template<typename _Ch_type
, class _Alloc
, class _Rx_traits
>
2464 regex_search(const _Ch_type
* __s
,
2465 match_results
<const _Ch_type
*, _Alloc
>& __m
,
2466 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2467 regex_constants::match_flag_type __f
2468 = regex_constants::match_default
)
2469 { return regex_search(__s
, __s
+ _Rx_traits::length(__s
), __m
, __e
, __f
); }
2472 * @brief Searches for a regular expression within a C-string.
2473 * @param __s [IN] The C-string to search.
2474 * @param __e [IN] The regular expression to search for.
2475 * @param __f [IN] Search policy flags.
2476 * @retval true A match was found within the string.
2477 * @retval false No match was found within the string.
2479 * @throws an exception of type regex_error.
2481 template<typename _Ch_type
, typename _Rx_traits
>
2483 regex_search(const _Ch_type
* __s
,
2484 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2485 regex_constants::match_flag_type __f
2486 = regex_constants::match_default
)
2487 { return regex_search(__s
, __s
+ _Rx_traits::length(__s
), __e
, __f
); }
2490 * @brief Searches for a regular expression within a string.
2491 * @param __s [IN] The string to search.
2492 * @param __e [IN] The regular expression to search for.
2493 * @param __flags [IN] Search policy flags.
2494 * @retval true A match was found within the string.
2495 * @retval false No match was found within the string.
2497 * @throws an exception of type regex_error.
2499 template<typename _Ch_traits
, typename _String_allocator
,
2500 typename _Ch_type
, typename _Rx_traits
>
2502 regex_search(const basic_string
<_Ch_type
, _Ch_traits
,
2503 _String_allocator
>& __s
,
2504 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2505 regex_constants::match_flag_type __flags
2506 = regex_constants::match_default
)
2507 { return regex_search(__s
.begin(), __s
.end(), __e
, __flags
); }
2510 * @brief Searches for a regular expression within a string.
2511 * @param __s [IN] A C++ string to search for the regex.
2512 * @param __m [OUT] The set of regex matches.
2513 * @param __e [IN] The regex to search for in @p s.
2514 * @param __f [IN] The search flags.
2515 * @retval true A match was found within the string.
2516 * @retval false No match was found within the string, the content of %m is
2519 * @throws an exception of type regex_error.
2521 template<typename _Ch_traits
, typename _Ch_alloc
,
2522 typename _Alloc
, typename _Ch_type
,
2523 typename _Rx_traits
>
2525 regex_search(const basic_string
<_Ch_type
, _Ch_traits
, _Ch_alloc
>& __s
,
2526 match_results
<typename basic_string
<_Ch_type
,
2527 _Ch_traits
, _Ch_alloc
>::const_iterator
, _Alloc
>& __m
,
2528 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2529 regex_constants::match_flag_type __f
2530 = regex_constants::match_default
)
2531 { return regex_search(__s
.begin(), __s
.end(), __m
, __e
, __f
); }
2533 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2534 // 2329. regex_search() with match_results should forbid temporary strings
2535 /// Prevent unsafe attempts to get match_results from a temporary string.
2536 template<typename _Ch_traits
, typename _Ch_alloc
,
2537 typename _Alloc
, typename _Ch_type
,
2538 typename _Rx_traits
>
2540 regex_search(const basic_string
<_Ch_type
, _Ch_traits
, _Ch_alloc
>&&,
2541 match_results
<typename basic_string
<_Ch_type
,
2542 _Ch_traits
, _Ch_alloc
>::const_iterator
, _Alloc
>&,
2543 const basic_regex
<_Ch_type
, _Rx_traits
>&,
2544 regex_constants::match_flag_type
2545 = regex_constants::match_default
) = delete;
2547 // std [28.11.4] Function template regex_replace
2549 /// @cond undocumented
2550 template<typename _Out_iter
, typename _Bi_iter
,
2551 typename _Rx_traits
, typename _Ch_type
>
2553 __regex_replace(_Out_iter __out
, _Bi_iter __first
, _Bi_iter __last
,
2554 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2555 const _Ch_type
* __fmt
, size_t __len
,
2556 regex_constants::match_flag_type __flags
);
2560 * @brief Search for a regular expression within a range for multiple times,
2561 and replace the matched parts through filling a format string.
2562 * @param __out [OUT] The output iterator.
2563 * @param __first [IN] The start of the string to search.
2564 * @param __last [IN] One-past-the-end of the string to search.
2565 * @param __e [IN] The regular expression to search for.
2566 * @param __fmt [IN] The format string.
2567 * @param __flags [IN] Search and replace policy flags.
2570 * @throws an exception of type regex_error.
2572 template<typename _Out_iter
, typename _Bi_iter
,
2573 typename _Rx_traits
, typename _Ch_type
,
2574 typename _St
, typename _Sa
>
2576 regex_replace(_Out_iter __out
, _Bi_iter __first
, _Bi_iter __last
,
2577 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2578 const basic_string
<_Ch_type
, _St
, _Sa
>& __fmt
,
2579 regex_constants::match_flag_type __flags
2580 = regex_constants::match_default
)
2582 return std::__regex_replace(__out
, __first
, __last
, __e
, __fmt
.c_str(),
2583 __fmt
.length(), __flags
);
2587 * @brief Search for a regular expression within a range for multiple times,
2588 and replace the matched parts through filling a format C-string.
2589 * @param __out [OUT] The output iterator.
2590 * @param __first [IN] The start of the string to search.
2591 * @param __last [IN] One-past-the-end of the string to search.
2592 * @param __e [IN] The regular expression to search for.
2593 * @param __fmt [IN] The format C-string.
2594 * @param __flags [IN] Search and replace policy flags.
2597 * @throws an exception of type regex_error.
2599 template<typename _Out_iter
, typename _Bi_iter
,
2600 typename _Rx_traits
, typename _Ch_type
>
2602 regex_replace(_Out_iter __out
, _Bi_iter __first
, _Bi_iter __last
,
2603 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2604 const _Ch_type
* __fmt
,
2605 regex_constants::match_flag_type __flags
2606 = regex_constants::match_default
)
2608 return std::__regex_replace(__out
, __first
, __last
, __e
, __fmt
,
2609 char_traits
<_Ch_type
>::length(__fmt
),
2615 * @brief Search for a regular expression within a string for multiple times,
2616 and replace the matched parts through filling a format string.
2617 * @param __s [IN] The string to search and replace.
2618 * @param __e [IN] The regular expression to search for.
2619 * @param __fmt [IN] The format string.
2620 * @param __flags [IN] Search and replace policy flags.
2622 * @returns The string after replacing.
2623 * @throws an exception of type regex_error.
2625 template<typename _Rx_traits
, typename _Ch_type
,
2626 typename _St
, typename _Sa
, typename _Fst
, typename _Fsa
>
2627 inline basic_string
<_Ch_type
, _St
, _Sa
>
2628 regex_replace(const basic_string
<_Ch_type
, _St
, _Sa
>& __s
,
2629 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2630 const basic_string
<_Ch_type
, _Fst
, _Fsa
>& __fmt
,
2631 regex_constants::match_flag_type __flags
2632 = regex_constants::match_default
)
2634 basic_string
<_Ch_type
, _St
, _Sa
> __result
;
2635 regex_replace(std::back_inserter(__result
),
2636 __s
.begin(), __s
.end(), __e
, __fmt
, __flags
);
2641 * @brief Search for a regular expression within a string for multiple times,
2642 and replace the matched parts through filling a format C-string.
2643 * @param __s [IN] The string to search and replace.
2644 * @param __e [IN] The regular expression to search for.
2645 * @param __fmt [IN] The format C-string.
2646 * @param __flags [IN] Search and replace policy flags.
2648 * @returns The string after replacing.
2649 * @throws an exception of type regex_error.
2651 template<typename _Rx_traits
, typename _Ch_type
,
2652 typename _St
, typename _Sa
>
2653 inline basic_string
<_Ch_type
, _St
, _Sa
>
2654 regex_replace(const basic_string
<_Ch_type
, _St
, _Sa
>& __s
,
2655 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2656 const _Ch_type
* __fmt
,
2657 regex_constants::match_flag_type __flags
2658 = regex_constants::match_default
)
2660 basic_string
<_Ch_type
, _St
, _Sa
> __result
;
2661 regex_replace(std::back_inserter(__result
),
2662 __s
.begin(), __s
.end(), __e
, __fmt
, __flags
);
2667 * @brief Search for a regular expression within a C-string for multiple
2668 times, and replace the matched parts through filling a format string.
2669 * @param __s [IN] The C-string to search and replace.
2670 * @param __e [IN] The regular expression to search for.
2671 * @param __fmt [IN] The format string.
2672 * @param __flags [IN] Search and replace policy flags.
2674 * @returns The string after replacing.
2675 * @throws an exception of type regex_error.
2677 template<typename _Rx_traits
, typename _Ch_type
,
2678 typename _St
, typename _Sa
>
2679 inline basic_string
<_Ch_type
>
2680 regex_replace(const _Ch_type
* __s
,
2681 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2682 const basic_string
<_Ch_type
, _St
, _Sa
>& __fmt
,
2683 regex_constants::match_flag_type __flags
2684 = regex_constants::match_default
)
2686 basic_string
<_Ch_type
> __result
;
2687 regex_replace(std::back_inserter(__result
), __s
,
2688 __s
+ char_traits
<_Ch_type
>::length(__s
),
2689 __e
, __fmt
, __flags
);
2694 * @brief Search for a regular expression within a C-string for multiple
2695 times, and replace the matched parts through filling a format C-string.
2696 * @param __s [IN] The C-string to search and replace.
2697 * @param __e [IN] The regular expression to search for.
2698 * @param __fmt [IN] The format C-string.
2699 * @param __flags [IN] Search and replace policy flags.
2701 * @returns The string after replacing.
2702 * @throws an exception of type regex_error.
2704 template<typename _Rx_traits
, typename _Ch_type
>
2705 inline basic_string
<_Ch_type
>
2706 regex_replace(const _Ch_type
* __s
,
2707 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2708 const _Ch_type
* __fmt
,
2709 regex_constants::match_flag_type __flags
2710 = regex_constants::match_default
)
2712 basic_string
<_Ch_type
> __result
;
2713 regex_replace(std::back_inserter(__result
), __s
,
2714 __s
+ char_traits
<_Ch_type
>::length(__s
),
2715 __e
, __fmt
, __flags
);
2721 _GLIBCXX_BEGIN_NAMESPACE_CXX11
2723 // std [28.12] Class template regex_iterator
2725 * An iterator adaptor that will provide repeated calls of regex_search over
2726 * a range until no more matches remain.
2731 template<typename _Bi_iter
,
2732 typename _Ch_type
= typename iterator_traits
<_Bi_iter
>::value_type
,
2733 typename _Rx_traits
= regex_traits
<_Ch_type
> >
2734 class regex_iterator
2737 typedef basic_regex
<_Ch_type
, _Rx_traits
> regex_type
;
2738 typedef match_results
<_Bi_iter
> value_type
;
2739 typedef std::ptrdiff_t difference_type
;
2740 typedef const value_type
* pointer
;
2741 typedef const value_type
& reference
;
2742 typedef std::forward_iterator_tag iterator_category
;
2743 #if __cplusplus > 201703L
2744 typedef std::input_iterator_tag iterator_concept
;
2748 * @brief Provides a singular iterator, useful for indicating
2749 * one-past-the-end of a range.
2751 regex_iterator() = default;
2754 * Constructs a %regex_iterator...
2755 * @param __a [IN] The start of a text range to search.
2756 * @param __b [IN] One-past-the-end of the text range to search.
2757 * @param __re [IN] The regular expression to match.
2758 * @param __m [IN] Policy flags for match rules.
2760 regex_iterator(_Bi_iter __a
, _Bi_iter __b
, const regex_type
& __re
,
2761 regex_constants::match_flag_type __m
2762 = regex_constants::match_default
)
2763 : _M_begin(__a
), _M_end(__b
), _M_pregex(&__re
), _M_flags(__m
), _M_match()
2765 if (!regex_search(_M_begin
, _M_end
, _M_match
, *_M_pregex
, _M_flags
))
2766 *this = regex_iterator();
2769 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2770 // 2332. regex_iterator should forbid temporary regexes
2771 regex_iterator(_Bi_iter
, _Bi_iter
, const regex_type
&&,
2772 regex_constants::match_flag_type
2773 = regex_constants::match_default
) = delete;
2775 /// Copy constructs a %regex_iterator.
2776 regex_iterator(const regex_iterator
&) = default;
2778 /// Copy assigns one %regex_iterator to another.
2780 operator=(const regex_iterator
&) = default;
2782 ~regex_iterator() = default;
2785 * @brief Tests the equivalence of two regex iterators.
2788 operator==(const regex_iterator
&) const noexcept
;
2790 #if __cplusplus >= 202002L
2791 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2792 // 3719. Directory iterators should be usable with default sentinel
2793 bool operator==(default_sentinel_t
) const noexcept
2794 { return _M_pregex
== nullptr; }
2797 #if __cpp_impl_three_way_comparison < 201907L
2799 * @brief Tests the inequivalence of two regex iterators.
2802 operator!=(const regex_iterator
& __rhs
) const noexcept
2803 { return !(*this == __rhs
); }
2807 * @brief Dereferences a %regex_iterator.
2810 operator*() const noexcept
2811 { return _M_match
; }
2814 * @brief Selects a %regex_iterator member.
2817 operator->() const noexcept
2818 { return &_M_match
; }
2821 * @brief Increments a %regex_iterator.
2827 * @brief Postincrements a %regex_iterator.
2838 _Bi_iter _M_begin
{};
2840 const regex_type
* _M_pregex
= nullptr;
2841 regex_constants::match_flag_type _M_flags
{};
2842 match_results
<_Bi_iter
> _M_match
;
2845 typedef regex_iterator
<const char*> cregex_iterator
;
2846 typedef regex_iterator
<string::const_iterator
> sregex_iterator
;
2847 #ifdef _GLIBCXX_USE_WCHAR_T
2848 typedef regex_iterator
<const wchar_t*> wcregex_iterator
;
2849 typedef regex_iterator
<wstring::const_iterator
> wsregex_iterator
;
2852 // [7.12.2] Class template regex_token_iterator
2854 * Iterates over submatches in a range (or @a splits a text string).
2856 * The purpose of this iterator is to enumerate all, or all specified,
2857 * matches of a regular expression within a text range. The dereferenced
2858 * value of an iterator of this class is a std::sub_match object.
2863 template<typename _Bi_iter
,
2864 typename _Ch_type
= typename iterator_traits
<_Bi_iter
>::value_type
,
2865 typename _Rx_traits
= regex_traits
<_Ch_type
> >
2866 class regex_token_iterator
2869 typedef basic_regex
<_Ch_type
, _Rx_traits
> regex_type
;
2870 typedef sub_match
<_Bi_iter
> value_type
;
2871 typedef std::ptrdiff_t difference_type
;
2872 typedef const value_type
* pointer
;
2873 typedef const value_type
& reference
;
2874 typedef std::forward_iterator_tag iterator_category
;
2875 #if __cplusplus > 201703L
2876 typedef std::input_iterator_tag iterator_concept
;
2881 * @brief Default constructs a %regex_token_iterator.
2883 * A default-constructed %regex_token_iterator is a singular iterator
2884 * that will compare equal to the one-past-the-end value for any
2885 * iterator of the same type.
2887 regex_token_iterator()
2888 : _M_position(), _M_subs(), _M_suffix(), _M_n(0), _M_result(nullptr),
2893 * Constructs a %regex_token_iterator...
2894 * @param __a [IN] The start of the text to search.
2895 * @param __b [IN] One-past-the-end of the text to search.
2896 * @param __re [IN] The regular expression to search for.
2897 * @param __submatch [IN] Which submatch to return. There are some
2898 * special values for this parameter:
2899 * - -1 each enumerated subexpression does NOT
2900 * match the regular expression (aka field
2902 * - 0 the entire string matching the
2903 * subexpression is returned for each match
2905 * - >0 enumerates only the indicated
2906 * subexpression from a match within the text.
2907 * @param __m [IN] Policy flags for match rules.
2909 regex_token_iterator(_Bi_iter __a
, _Bi_iter __b
, const regex_type
& __re
,
2911 regex_constants::match_flag_type __m
2912 = regex_constants::match_default
)
2913 : _M_position(__a
, __b
, __re
, __m
), _M_subs(1, __submatch
), _M_n(0)
2914 { _M_init(__a
, __b
); }
2917 * Constructs a %regex_token_iterator...
2918 * @param __a [IN] The start of the text to search.
2919 * @param __b [IN] One-past-the-end of the text to search.
2920 * @param __re [IN] The regular expression to search for.
2921 * @param __submatches [IN] A list of subexpressions to return for each
2922 * regular expression match within the text.
2923 * @param __m [IN] Policy flags for match rules.
2925 regex_token_iterator(_Bi_iter __a
, _Bi_iter __b
,
2926 const regex_type
& __re
,
2927 const std::vector
<int>& __submatches
,
2928 regex_constants::match_flag_type __m
2929 = regex_constants::match_default
)
2930 : _M_position(__a
, __b
, __re
, __m
), _M_subs(__submatches
), _M_n(0)
2931 { _M_init(__a
, __b
); }
2934 * Constructs a %regex_token_iterator...
2935 * @param __a [IN] The start of the text to search.
2936 * @param __b [IN] One-past-the-end of the text to search.
2937 * @param __re [IN] The regular expression to search for.
2938 * @param __submatches [IN] A list of subexpressions to return for each
2939 * regular expression match within the text.
2940 * @param __m [IN] Policy flags for match rules.
2942 regex_token_iterator(_Bi_iter __a
, _Bi_iter __b
,
2943 const regex_type
& __re
,
2944 initializer_list
<int> __submatches
,
2945 regex_constants::match_flag_type __m
2946 = regex_constants::match_default
)
2947 : _M_position(__a
, __b
, __re
, __m
), _M_subs(__submatches
), _M_n(0)
2948 { _M_init(__a
, __b
); }
2951 * Constructs a %regex_token_iterator...
2952 * @param __a [IN] The start of the text to search.
2953 * @param __b [IN] One-past-the-end of the text to search.
2954 * @param __re [IN] The regular expression to search for.
2955 * @param __submatches [IN] A list of subexpressions to return for each
2956 * regular expression match within the text.
2957 * @param __m [IN] Policy flags for match rules.
2959 template<std::size_t _Nm
>
2960 regex_token_iterator(_Bi_iter __a
, _Bi_iter __b
,
2961 const regex_type
& __re
,
2962 const int (&__submatches
)[_Nm
],
2963 regex_constants::match_flag_type __m
2964 = regex_constants::match_default
)
2965 : _M_position(__a
, __b
, __re
, __m
),
2966 _M_subs(__submatches
, __submatches
+ _Nm
), _M_n(0)
2967 { _M_init(__a
, __b
); }
2969 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2970 // 2332. regex_token_iterator should forbid temporary regexes
2971 regex_token_iterator(_Bi_iter
, _Bi_iter
, const regex_type
&&, int = 0,
2972 regex_constants::match_flag_type
=
2973 regex_constants::match_default
) = delete;
2974 regex_token_iterator(_Bi_iter
, _Bi_iter
, const regex_type
&&,
2975 const std::vector
<int>&,
2976 regex_constants::match_flag_type
=
2977 regex_constants::match_default
) = delete;
2978 regex_token_iterator(_Bi_iter
, _Bi_iter
, const regex_type
&&,
2979 initializer_list
<int>,
2980 regex_constants::match_flag_type
=
2981 regex_constants::match_default
) = delete;
2982 template <std::size_t _Nm
>
2983 regex_token_iterator(_Bi_iter
, _Bi_iter
, const regex_type
&&,
2985 regex_constants::match_flag_type
=
2986 regex_constants::match_default
) = delete;
2989 * @brief Copy constructs a %regex_token_iterator.
2990 * @param __rhs [IN] A %regex_token_iterator to copy.
2992 regex_token_iterator(const regex_token_iterator
& __rhs
)
2993 : _M_position(__rhs
._M_position
), _M_subs(__rhs
._M_subs
),
2994 _M_suffix(__rhs
._M_suffix
), _M_n(__rhs
._M_n
), _M_has_m1(__rhs
._M_has_m1
)
2995 { _M_normalize_result(); }
2998 * @brief Assigns a %regex_token_iterator to another.
2999 * @param __rhs [IN] A %regex_token_iterator to copy.
3001 regex_token_iterator
&
3002 operator=(const regex_token_iterator
& __rhs
);
3005 * @brief Compares a %regex_token_iterator to another for equality.
3008 operator==(const regex_token_iterator
& __rhs
) const;
3010 #if __cplusplus >= 202002L
3011 // _GLIBCXX_RESOLVE_LIB_DEFECTS
3012 // 3719. Directory iterators should be usable with default sentinel
3013 bool operator==(default_sentinel_t
) const noexcept
3014 { return _M_end_of_seq(); }
3017 #if __cpp_impl_three_way_comparison < 201907L
3019 * @brief Compares a %regex_token_iterator to another for inequality.
3022 operator!=(const regex_token_iterator
& __rhs
) const
3023 { return !(*this == __rhs
); }
3027 * @brief Dereferences a %regex_token_iterator.
3031 { return *_M_result
; }
3034 * @brief Selects a %regex_token_iterator member.
3038 { return _M_result
; }
3041 * @brief Increments a %regex_token_iterator.
3043 regex_token_iterator
&
3047 * @brief Postincrements a %regex_token_iterator.
3049 regex_token_iterator
3058 typedef regex_iterator
<_Bi_iter
, _Ch_type
, _Rx_traits
> _Position
;
3061 _M_init(_Bi_iter __a
, _Bi_iter __b
);
3064 _M_current_match() const
3066 if (_M_subs
[_M_n
] == -1)
3067 return (*_M_position
).prefix();
3069 return (*_M_position
)[_M_subs
[_M_n
]];
3073 _M_end_of_seq() const noexcept
3074 { return _M_result
== nullptr; }
3078 _M_normalize_result()
3080 if (_M_position
!= _Position())
3081 _M_result
= &_M_current_match();
3083 _M_result
= &_M_suffix
;
3085 _M_result
= nullptr;
3088 _Position _M_position
;
3089 std::vector
<int> _M_subs
;
3090 value_type _M_suffix
;
3092 const value_type
* _M_result
;
3094 // Show whether _M_subs contains -1
3098 /** @brief Token iterator for C-style NULL-terminated strings. */
3099 typedef regex_token_iterator
<const char*> cregex_token_iterator
;
3101 /** @brief Token iterator for standard strings. */
3102 typedef regex_token_iterator
<string::const_iterator
> sregex_token_iterator
;
3104 #ifdef _GLIBCXX_USE_WCHAR_T
3105 /** @brief Token iterator for C-style NULL-terminated wide strings. */
3106 typedef regex_token_iterator
<const wchar_t*> wcregex_token_iterator
;
3108 /** @brief Token iterator for standard wide-character strings. */
3109 typedef regex_token_iterator
<wstring::const_iterator
> wsregex_token_iterator
;
3112 ///@} // group regex
3114 _GLIBCXX_END_NAMESPACE_CXX11
3115 _GLIBCXX_END_NAMESPACE_VERSION
3118 #include <bits/regex.tcc>