1 // class template regex -*- C++ -*-
3 // Copyright (C) 2010-2025 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
38 namespace std
_GLIBCXX_VISIBILITY(default)
40 _GLIBCXX_BEGIN_NAMESPACE_VERSION
41 _GLIBCXX_BEGIN_NAMESPACE_CXX11
42 template<typename
, typename
>
45 template<typename _Bi_iter
, typename _Alloc
>
48 _GLIBCXX_END_NAMESPACE_CXX11
52 enum class _RegexExecutorPolicy
: int { _S_auto
, _S_alternate
};
54 template<typename _BiIter
, typename _Alloc
,
55 typename _CharT
, typename _TraitsT
>
57 __regex_algo_impl(_BiIter __s
, _BiIter __e
,
58 match_results
<_BiIter
, _Alloc
>& __m
,
59 const basic_regex
<_CharT
, _TraitsT
>& __re
,
60 regex_constants::match_flag_type __flags
,
61 _RegexExecutorPolicy __policy
,
64 template<typename
, typename
, typename
, bool>
67 template<typename _Tp
>
68 struct __is_contiguous_iter
: false_type
{ };
70 template<typename _Tp
>
71 struct __is_contiguous_iter
<_Tp
*> : true_type
{ };
73 template<typename _Tp
, typename _Cont
>
74 struct __is_contiguous_iter
<__gnu_cxx::__normal_iterator
<_Tp
*, _Cont
>>
78 _GLIBCXX_BEGIN_NAMESPACE_CXX11
86 * @brief Describes aspects of a regular expression.
88 * A regular expression traits class that satisfies the requirements of
91 * The class %regex is parameterized around a set of related types and
92 * functions used to complete the definition of its semantics. This class
93 * satisfies the requirements of such a traits class.
98 template<typename _Ch_type
>
102 typedef _Ch_type char_type
;
103 typedef std::basic_string
<char_type
> string_type
;
104 typedef std::locale locale_type
;
109 typedef std::ctype_base::mask _BaseType
;
111 unsigned char _M_extended
;
112 static constexpr unsigned char _S_under
= 1 << 0;
113 static constexpr unsigned char _S_valid_mask
= 0x1;
115 constexpr _RegexMask(_BaseType __base
= 0,
116 unsigned char __extended
= 0)
117 : _M_base(__base
), _M_extended(__extended
)
121 operator&(_RegexMask __other
) const
123 return _RegexMask(_M_base
& __other
._M_base
,
124 _M_extended
& __other
._M_extended
);
128 operator|(_RegexMask __other
) const
130 return _RegexMask(_M_base
| __other
._M_base
,
131 _M_extended
| __other
._M_extended
);
135 operator^(_RegexMask __other
) const
137 return _RegexMask(_M_base
^ __other
._M_base
,
138 _M_extended
^ __other
._M_extended
);
143 { return _RegexMask(~_M_base
, ~_M_extended
); }
146 operator&=(_RegexMask __other
)
147 { return *this = (*this) & __other
; }
150 operator|=(_RegexMask __other
)
151 { return *this = (*this) | __other
; }
154 operator^=(_RegexMask __other
)
155 { return *this = (*this) ^ __other
; }
158 operator==(_RegexMask __other
) const
160 return (_M_extended
& _S_valid_mask
)
161 == (__other
._M_extended
& _S_valid_mask
)
162 && _M_base
== __other
._M_base
;
165 #if __cpp_impl_three_way_comparison < 201907L
167 operator!=(_RegexMask __other
) const
168 { return !((*this) == __other
); }
173 typedef _RegexMask char_class_type
;
177 * @brief Constructs a default traits object.
182 * @brief Gives the length of a C-style string starting at @p __p.
184 * @param __p a pointer to the start of a character sequence.
186 * @returns the number of characters between @p *__p and the first
187 * default-initialized value of type @p char_type. In other words, uses
188 * the C-string algorithm for determining the length of a sequence of
192 length(const char_type
* __p
)
193 { return string_type::traits_type::length(__p
); }
196 * @brief Performs the identity translation.
198 * @param __c A character to the locale-specific character set.
203 translate(char_type __c
) const
207 * @brief Translates a character into a case-insensitive equivalent.
209 * @param __c A character to the locale-specific character set.
211 * @returns the locale-specific lower-case equivalent of __c.
212 * @throws std::bad_cast if the imbued locale does not support the ctype
216 translate_nocase(char_type __c
) const
218 typedef std::ctype
<char_type
> __ctype_type
;
219 const __ctype_type
& __fctyp(use_facet
<__ctype_type
>(_M_locale
));
220 return __fctyp
.tolower(__c
);
224 * @brief Gets a sort key for a character sequence.
226 * @param __first beginning of the character sequence.
227 * @param __last one-past-the-end of the character sequence.
229 * Returns a sort key for the character sequence designated by the
230 * iterator range [F1, F2) such that if the character sequence [G1, G2)
231 * sorts before the character sequence [H1, H2) then
232 * v.transform(G1, G2) < v.transform(H1, H2).
234 * What this really does is provide a more efficient way to compare a
235 * string to multiple other strings in locales with fancy collation
236 * rules and equivalence classes.
238 * @returns a locale-specific sort key equivalent to the input range.
240 * @throws std::bad_cast if the current locale does not have a collate
243 template<typename _Fwd_iter
>
245 transform(_Fwd_iter __first
, _Fwd_iter __last
) const
247 typedef std::collate
<char_type
> __collate_type
;
248 const __collate_type
& __fclt(use_facet
<__collate_type
>(_M_locale
));
249 string_type
__s(__first
, __last
);
250 return __fclt
.transform(__s
.data(), __s
.data() + __s
.size());
254 * @brief Gets a sort key for a character sequence, independent of case.
256 * @param __first beginning of the character sequence.
257 * @param __last one-past-the-end of the character sequence.
259 * Effects: if `typeid(use_facet<collate<_Ch_type>>(getloc())) ==
260 * typeid(collate_byname<_Ch_type>)` and the form of the sort key
261 * returned by `collate_byname<_Ch_type>::transform(__first, __last)`
262 * is known and can be converted into a primary sort key
263 * then returns that key, otherwise returns an empty string.
265 * @todo Implement this function correctly.
267 template<typename _Fwd_iter
>
269 transform_primary(_Fwd_iter __first
, _Fwd_iter __last
) const
273 const auto& __fclt
= use_facet
<collate
<char_type
>>(_M_locale
);
274 if (typeid(__fclt
) != typeid(collate
<char_type
>)) // FIXME: PR 118110
277 // TODO : this is not entirely correct.
278 // This function requires extra support from the platform.
279 // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118105
281 const auto& __fctyp(use_facet
<ctype
<char_type
>>(_M_locale
));
282 basic_string
<char_type
> __s(__first
, __last
);
283 const auto __p
= const_cast<char_type
*>(__s
.c_str());
284 const auto __pend
= __p
+ __s
.size();
285 // XXX: should we use tolower here? The regex traits requirements
286 // say that transform_primary ignores case, but the specification
287 // for the std::regex_traits<char> and std::regex_traits<wchar_t>
288 // specializations don't, they seem to suggest just using the
289 // collate::transform function to get a primary sort key.
290 __fctyp
.tolower(__p
, __pend
);
294 __ret
= __fclt
.transform(__p
, __pend
);
296 __catch (const exception
&)
304 * @brief Gets a collation element by name.
306 * @param __first beginning of the collation element name.
307 * @param __last one-past-the-end of the collation element name.
309 * @returns a sequence of one or more characters that represents the
310 * collating element consisting of the character sequence designated by
311 * the iterator range [__first, __last). Returns an empty string if the
312 * character sequence is not a valid collating element.
314 template<typename _Fwd_iter
>
316 lookup_collatename(_Fwd_iter __first
, _Fwd_iter __last
) const;
319 * @brief Maps one or more characters to a named character
322 * @param __first beginning of the character sequence.
323 * @param __last one-past-the-end of the character sequence.
324 * @param __icase ignores the case of the classification name.
326 * @returns an unspecified value that represents the character
327 * classification named by the character sequence designated by
328 * the iterator range [__first, __last). If @p icase is true,
329 * the returned mask identifies the classification regardless of
330 * the case of the characters to be matched (for example,
331 * [[:lower:]] is the same as [[:alpha:]]), otherwise a
332 * case-dependent classification is returned. The value
333 * returned shall be independent of the case of the characters
334 * in the character sequence. If the name is not recognized then
335 * returns a value that compares equal to 0.
337 * At least the following names (or their wide-character equivalent) are
355 template<typename _Fwd_iter
>
357 lookup_classname(_Fwd_iter __first
, _Fwd_iter __last
,
358 bool __icase
= false) const;
361 * @brief Determines if @p c is a member of an identified class.
363 * @param __c a character.
364 * @param __f a class type (as returned from lookup_classname).
366 * @returns true if the character @p __c is a member of the classification
367 * represented by @p __f, false otherwise.
369 * @throws std::bad_cast if the current locale does not have a ctype
373 isctype(_Ch_type __c
, char_class_type __f
) const;
376 * @brief Converts a digit to an int.
378 * @param __ch a character representing a digit.
379 * @param __radix the radix if the numeric conversion (limited to 8, 10,
382 * @returns the value represented by the digit __ch in base radix if the
383 * character __ch is a valid digit in base radix; otherwise returns -1.
386 value(_Ch_type __ch
, int __radix
) const;
389 * @brief Imbues the regex_traits object with a copy of a new locale.
391 * @param __loc A locale.
393 * @returns a copy of the previous locale in use by the regex_traits
396 * @note Calling imbue with a different locale than the one currently in
397 * use invalidates all cached data held by *this.
400 imbue(locale_type __loc
)
402 std::swap(_M_locale
, __loc
);
407 * @brief Gets a copy of the current locale in use by the regex_traits
412 { return _M_locale
; }
415 locale_type _M_locale
;
418 // [7.8] Class basic_regex
420 * @brief A regular expression
422 * Specializations of this class template represent regular expressions
423 * constructed from sequences of character type `_Ch_type`.
424 * Use the `std::regex` typedef for `std::basic_regex<char>`.
426 * A character sequence passed to the constructor will be parsed according
427 * to the chosen grammar, and used to create a state machine representing
428 * the regular expression. The regex object can then be passed to algorithms
429 * such as `std::regex_match` to match sequences of characters.
431 * The `syntax_option_type` flag passed to the constructor selects from
432 * one of the supported regular expression grammars. The default is
433 * `ECMAScript` and the others are `basic`, `extended`, `awk`, `grep`, and
434 * `egrep`, which are variations on POSIX regular expressions.
439 template<typename _Ch_type
, typename _Rx_traits
= regex_traits
<_Ch_type
>>
443 static_assert(is_same
<_Ch_type
, typename
_Rx_traits::char_type
>::value
,
444 "regex traits class must have the same char_type");
447 typedef _Ch_type value_type
;
448 typedef _Rx_traits traits_type
;
449 typedef typename
traits_type::string_type string_type
;
450 typedef regex_constants::syntax_option_type flag_type
;
451 typedef typename
traits_type::locale_type locale_type
;
458 static constexpr flag_type icase
= regex_constants::icase
;
459 static constexpr flag_type nosubs
= regex_constants::nosubs
;
460 static constexpr flag_type optimize
= regex_constants::optimize
;
461 static constexpr flag_type collate
= regex_constants::collate
;
462 static constexpr flag_type ECMAScript
= regex_constants::ECMAScript
;
463 static constexpr flag_type basic
= regex_constants::basic
;
464 static constexpr flag_type extended
= regex_constants::extended
;
465 static constexpr flag_type awk
= regex_constants::awk
;
466 static constexpr flag_type grep
= regex_constants::grep
;
467 static constexpr flag_type egrep
= regex_constants::egrep
;
468 #if __cplusplus >= 201703L || !defined __STRICT_ANSI__
469 static constexpr flag_type multiline
= regex_constants::multiline
;
473 // [7.8.2] construct/copy/destroy
475 * Constructs a basic regular expression that does not match any
476 * character sequence.
478 basic_regex() noexcept
479 : _M_flags(ECMAScript
), _M_loc(), _M_automaton(nullptr)
483 * @brief Constructs a basic regular expression from the
484 * sequence [__p, __p + char_traits<_Ch_type>::length(__p))
485 * interpreted according to the flags in @p __f.
487 * @param __p A pointer to the start of a C-style null-terminated string
488 * containing a regular expression.
489 * @param __f Flags indicating the syntax rules and options.
491 * @throws regex_error if @p __p is not a valid regular expression.
494 basic_regex(const _Ch_type
* __p
, flag_type __f
= ECMAScript
)
495 { _M_compile(__p
, __p
+ _Rx_traits::length(__p
), __f
); }
498 * @brief Constructs a basic regular expression from the sequence
499 * [p, p + len) interpreted according to the flags in @p f.
501 * @param __p A pointer to the start of a string containing a regular
503 * @param __len The length of the string containing the regular
505 * @param __f Flags indicating the syntax rules and options.
507 * @throws regex_error if @p __p is not a valid regular expression.
509 basic_regex(const _Ch_type
* __p
, std::size_t __len
,
510 flag_type __f
= ECMAScript
)
512 __glibcxx_requires_string_len(__p
, __len
);
513 _M_compile(__p
, __p
+ __len
, __f
);
517 * @brief Copy-constructs a basic regular expression.
519 * @param __rhs A @p regex object.
521 basic_regex(const basic_regex
& __rhs
) = default;
524 * @brief Move-constructs a basic regular expression.
526 * @param __rhs A @p regex object.
528 basic_regex(basic_regex
&& __rhs
) noexcept
= default;
531 * @brief Constructs a basic regular expression from the string
532 * @p s interpreted according to the flags in @p f.
534 * @param __s A string containing a regular expression.
535 * @param __f Flags indicating the syntax rules and options.
537 * @throws regex_error if @p __s is not a valid regular expression.
539 template<typename _Ch_traits
, typename _Ch_alloc
>
541 basic_regex(const std::basic_string
<_Ch_type
, _Ch_traits
,
543 flag_type __f
= ECMAScript
)
544 { _M_compile(__s
.data(), __s
.data() + __s
.size(), __f
); }
547 * @brief Constructs a basic regular expression from the range
548 * [first, last) interpreted according to the flags in @p f.
550 * @param __first The start of a range containing a valid regular
552 * @param __last The end of a range containing a valid regular
554 * @param __f The format flags of the regular expression.
556 * @throws regex_error if @p [__first, __last) is not a valid regular
559 template<typename _FwdIter
>
560 basic_regex(_FwdIter __first
, _FwdIter __last
,
561 flag_type __f
= ECMAScript
)
562 { this->assign(__first
, __last
, __f
); }
565 * @brief Constructs a basic regular expression from an initializer list.
567 * @param __l The initializer list.
568 * @param __f The format flags of the regular expression.
570 * @throws regex_error if @p __l is not a valid regular expression.
572 basic_regex(initializer_list
<_Ch_type
> __l
, flag_type __f
= ECMAScript
)
573 { _M_compile(__l
.begin(), __l
.end(), __f
); }
576 * @brief Destroys a basic regular expression.
582 * @brief Assigns one regular expression to another.
585 operator=(const basic_regex
&) = default;
588 * @brief Move-assigns one regular expression to another.
591 operator=(basic_regex
&&) = default;
594 * @brief Replaces a regular expression with a new one constructed from
595 * a C-style null-terminated string.
597 * @param __p A pointer to the start of a null-terminated C-style string
598 * containing a regular expression.
601 operator=(const _Ch_type
* __p
)
602 { return this->assign(__p
); }
605 * @brief Replaces a regular expression with a new one constructed from
606 * an initializer list.
608 * @param __l The initializer list.
610 * @throws regex_error if @p __l is not a valid regular expression.
613 operator=(initializer_list
<_Ch_type
> __l
)
614 { return this->assign(__l
); }
617 * @brief Replaces a regular expression with a new one constructed from
620 * @param __s A pointer to a string containing a regular expression.
622 template<typename _Ch_traits
, typename _Alloc
>
624 operator=(const basic_string
<_Ch_type
, _Ch_traits
, _Alloc
>& __s
)
625 { return this->assign(__s
); }
629 * @brief Assigns one regular expression to another.
631 * @param __rhs Another regular expression object.
634 assign(const basic_regex
& __rhs
) noexcept
635 { return *this = __rhs
; }
638 * @brief Move-assigns one regular expression to another.
640 * @param __rhs Another regular expression object.
643 assign(basic_regex
&& __rhs
) noexcept
644 { return *this = std::move(__rhs
); }
647 * @brief Assigns a new regular expression to a regex object from a
648 * C-style null-terminated string containing a regular expression
651 * @param __p A pointer to a C-style null-terminated string containing
652 * a regular expression pattern.
653 * @param __flags Syntax option flags.
655 * @throws regex_error if __p does not contain a valid regular
656 * expression pattern interpreted according to @p __flags. If
657 * regex_error is thrown, *this remains unchanged.
660 assign(const _Ch_type
* __p
, flag_type __flags
= ECMAScript
)
662 _M_compile(__p
, __p
+ _Rx_traits::length(__p
), __flags
);
667 * @brief Assigns a new regular expression to a regex object from a
668 * C-style string containing a regular expression pattern.
670 * @param __p A pointer to a C-style string containing a
671 * regular expression pattern.
672 * @param __len The length of the regular expression pattern string.
673 * @param __flags Syntax option flags.
675 * @throws regex_error if p does not contain a valid regular
676 * expression pattern interpreted according to @p __flags. If
677 * regex_error is thrown, *this remains unchanged.
679 // _GLIBCXX_RESOLVE_LIB_DEFECTS
680 // 3296. Inconsistent default argument for basic_regex<>::assign
682 assign(const _Ch_type
* __p
, size_t __len
, flag_type __flags
= ECMAScript
)
684 _M_compile(__p
, __p
+ __len
, __flags
);
689 * @brief Assigns a new regular expression to a regex object from a
690 * string containing a regular expression pattern.
692 * @param __s A string containing a regular expression pattern.
693 * @param __flags Syntax option flags.
695 * @throws regex_error if __s does not contain a valid regular
696 * expression pattern interpreted according to @p __flags. If
697 * regex_error is thrown, *this remains unchanged.
699 template<typename _Ch_traits
, typename _Alloc
>
701 assign(const basic_string
<_Ch_type
, _Ch_traits
, _Alloc
>& __s
,
702 flag_type __flags
= ECMAScript
)
704 _M_compile(__s
.data(), __s
.data() + __s
.size(), __flags
);
709 * @brief Assigns a new regular expression to a regex object.
711 * @param __first The start of a range containing a valid regular
713 * @param __last The end of a range containing a valid regular
715 * @param __flags Syntax option flags.
717 * @throws regex_error if p does not contain a valid regular
718 * expression pattern interpreted according to @p __flags. If
719 * regex_error is thrown, the object remains unchanged.
721 template<typename _InputIterator
>
723 assign(_InputIterator __first
, _InputIterator __last
,
724 flag_type __flags
= ECMAScript
)
726 #if __cpp_if_constexpr >= 201606L
727 using _ValT
= typename iterator_traits
<_InputIterator
>::value_type
;
728 if constexpr (__detail::__is_contiguous_iter
<_InputIterator
>::value
729 && is_same_v
<_ValT
, value_type
>)
731 __glibcxx_requires_valid_range(__first
, __last
);
732 if constexpr (is_pointer_v
<_InputIterator
>)
733 _M_compile(__first
, __last
, __flags
);
734 else // __normal_iterator<_T*, C>
735 _M_compile(__first
.base(), __last
.base(), __flags
);
739 this->assign(string_type(__first
, __last
), __flags
);
744 * @brief Assigns a new regular expression to a regex object.
746 * @param __l An initializer list representing a regular expression.
747 * @param __flags Syntax option flags.
749 * @throws regex_error if @p __l does not contain a valid
750 * regular expression pattern interpreted according to @p
751 * __flags. If regex_error is thrown, the object remains
755 assign(initializer_list
<_Ch_type
> __l
, flag_type __flags
= ECMAScript
)
757 _M_compile(__l
.begin(), __l
.end(), __flags
);
761 // [7.8.4] const operations
763 * @brief Gets the number of marked subexpressions within the regular
767 mark_count() const noexcept
770 return _M_automaton
->_M_sub_count() - 1;
775 * @brief Gets the flags used to construct the regular expression
776 * or in the last call to assign().
779 flags() const noexcept
784 * @brief Imbues the regular expression object with the given locale.
786 * @param __loc A locale.
789 imbue(locale_type __loc
)
791 std::swap(__loc
, _M_loc
);
792 _M_automaton
.reset();
797 * @brief Gets the locale currently imbued in the regular expression
801 getloc() const noexcept
806 * @brief Swaps the contents of two regular expression objects.
808 * @param __rhs Another regular expression object.
811 swap(basic_regex
& __rhs
) noexcept
813 std::swap(_M_flags
, __rhs
._M_flags
);
814 std::swap(_M_loc
, __rhs
._M_loc
);
815 std::swap(_M_automaton
, __rhs
._M_automaton
);
818 #ifdef _GLIBCXX_DEBUG
820 _M_dot(std::ostream
& __ostr
)
821 { _M_automaton
->_M_dot(__ostr
); }
825 typedef std::shared_ptr
<const __detail::_NFA
<_Rx_traits
>> _AutomatonPtr
;
828 _M_compile(const _Ch_type
* __first
, const _Ch_type
* __last
,
831 __detail::_Compiler
<_Rx_traits
> __c(__first
, __last
, _M_loc
, __f
);
832 _M_automaton
= __c
._M_get_nfa();
836 template<typename _Bp
, typename _Ap
, typename _Cp
, typename _Rp
>
838 __detail::__regex_algo_impl(_Bp
, _Bp
, match_results
<_Bp
, _Ap
>&,
839 const basic_regex
<_Cp
, _Rp
>&,
840 regex_constants::match_flag_type
,
841 __detail::_RegexExecutorPolicy
, bool);
843 template<typename
, typename
, typename
, bool>
844 friend class __detail::_Executor
;
848 _AutomatonPtr _M_automaton
;
851 #if ! __cpp_inline_variables
852 template<typename _Ch
, typename _Tr
>
853 constexpr regex_constants::syntax_option_type
854 basic_regex
<_Ch
, _Tr
>::icase
;
856 template<typename _Ch
, typename _Tr
>
857 constexpr regex_constants::syntax_option_type
858 basic_regex
<_Ch
, _Tr
>::nosubs
;
860 template<typename _Ch
, typename _Tr
>
861 constexpr regex_constants::syntax_option_type
862 basic_regex
<_Ch
, _Tr
>::optimize
;
864 template<typename _Ch
, typename _Tr
>
865 constexpr regex_constants::syntax_option_type
866 basic_regex
<_Ch
, _Tr
>::collate
;
868 template<typename _Ch
, typename _Tr
>
869 constexpr regex_constants::syntax_option_type
870 basic_regex
<_Ch
, _Tr
>::ECMAScript
;
872 template<typename _Ch
, typename _Tr
>
873 constexpr regex_constants::syntax_option_type
874 basic_regex
<_Ch
, _Tr
>::basic
;
876 template<typename _Ch
, typename _Tr
>
877 constexpr regex_constants::syntax_option_type
878 basic_regex
<_Ch
, _Tr
>::extended
;
880 template<typename _Ch
, typename _Tr
>
881 constexpr regex_constants::syntax_option_type
882 basic_regex
<_Ch
, _Tr
>::awk
;
884 template<typename _Ch
, typename _Tr
>
885 constexpr regex_constants::syntax_option_type
886 basic_regex
<_Ch
, _Tr
>::grep
;
888 template<typename _Ch
, typename _Tr
>
889 constexpr regex_constants::syntax_option_type
890 basic_regex
<_Ch
, _Tr
>::egrep
;
893 #if __cpp_deduction_guides >= 201606
894 template<typename _ForwardIterator
>
895 basic_regex(_ForwardIterator
, _ForwardIterator
,
896 regex_constants::syntax_option_type
= {})
897 -> basic_regex
<typename iterator_traits
<_ForwardIterator
>::value_type
>;
900 /** @brief Standard regular expressions. */
901 typedef basic_regex
<char> regex
;
903 #ifdef _GLIBCXX_USE_WCHAR_T
904 /** @brief Standard wide-character regular expressions. */
905 typedef basic_regex
<wchar_t> wregex
;
909 // [7.8.6] basic_regex swap
911 * @brief Swaps the contents of two regular expression objects.
912 * @param __lhs First regular expression.
913 * @param __rhs Second regular expression.
914 * @relates basic_regex
916 template<typename _Ch_type
, typename _Rx_traits
>
918 swap(basic_regex
<_Ch_type
, _Rx_traits
>& __lhs
,
919 basic_regex
<_Ch_type
, _Rx_traits
>& __rhs
) noexcept
920 { __lhs
.swap(__rhs
); }
923 // C++11 28.9 [re.submatch] Class template sub_match
925 * A sequence of characters matched by a particular marked sub-expression.
927 * An object of this class is essentially a pair of iterators marking a
928 * matched subexpression within a regular expression pattern match. Such
929 * objects can be converted to and compared with std::basic_string objects
930 * of the same character type as the pattern matched by the regular
933 * A `sub_match<Iter>` has a public base class of type `pair<Iter, Iter>`,
934 * so inherits pair's data members named `first` and `second`.
935 * The iterators that make up the pair are the usual half-open interval
936 * referencing the actual original pattern matched.
941 template<typename _BiIter
>
943 /// @cond undocumented
944 : public std::pair
<_BiIter
, _BiIter
>
947 typedef iterator_traits
<_BiIter
> __iter_traits
;
950 typedef typename
__iter_traits::value_type value_type
;
951 typedef typename
__iter_traits::difference_type difference_type
;
952 typedef _BiIter iterator
;
953 typedef basic_string
<value_type
> string_type
;
955 _GLIBCXX_DOXYGEN_ONLY(iterator first
; iterator second
;)
959 constexpr sub_match() noexcept
: matched() { }
961 /// Gets the length of the matching sequence.
963 length() const noexcept
964 { return this->matched
? std::distance(this->first
, this->second
) : 0; }
967 * @brief Gets the matching sequence as a string.
969 * @returns the matching sequence as a string.
971 * This is the implicit conversion operator. It is identical to the
972 * str() member function except that it will want to pop up in
973 * unexpected places and cause a great deal of confusion and cursing
976 operator string_type() const
980 * @brief Gets the matching sequence as a string.
982 * @returns the matching sequence as a string.
988 ? string_type(this->first
, this->second
)
993 * @brief Compares this and another matched sequence.
995 * @param __s Another matched sequence to compare to this one.
997 * @retval negative This matched sequence will collate before `__s`.
998 * @retval zero This matched sequence is equivalent to `__s`.
999 * @retval positive This matched sequence will collate after `__s`.
1002 compare(const sub_match
& __s
) const
1003 { return this->_M_str().compare(__s
._M_str()); }
1007 * @brief Compares this `sub_match` to a string.
1009 * @param __s A string to compare to this `sub_match`.
1011 * @retval negative This matched sequence will collate before `__s`.
1012 * @retval zero This matched sequence is equivalent to `__s`.
1013 * @retval positive This matched sequence will collate after `__s`.
1016 compare(const string_type
& __s
) const
1017 { return this->_M_str().compare(__s
); }
1020 compare(const value_type
* __s
) const
1021 { return this->_M_str().compare(__s
); }
1024 /// @cond undocumented
1025 // Non-standard, used by comparison operators
1027 _M_compare(const value_type
* __s
, size_t __n
) const
1028 { return this->_M_str().compare({__s
, __n
}); }
1031 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1032 // 3204. sub_match::swap only swaps the base class
1033 /// Swap the values of two sub_match objects.
1035 swap(sub_match
& __s
) noexcept(__is_nothrow_swappable
<_BiIter
>::value
)
1037 this->pair
<_BiIter
, _BiIter
>::swap(__s
);
1038 std::swap(matched
, __s
.matched
);
1042 // Simplified basic_string_view for C++11
1043 struct __string_view
1045 using traits_type
= typename
string_type::traits_type
;
1047 __string_view() = default;
1049 __string_view(const value_type
* __s
, size_t __n
) noexcept
1050 : _M_data(__s
), _M_len(__n
) { }
1052 __string_view(const value_type
* __s
) noexcept
1053 : _M_data(__s
), _M_len(traits_type::length(__s
)) { }
1055 __string_view(const string_type
& __s
) noexcept
1056 : _M_data(__s
.data()), _M_len(__s
.length()) { }
1059 compare(__string_view __s
) const noexcept
1061 if (const size_t __n
= std::min(_M_len
, __s
._M_len
))
1062 if (int __ret
= traits_type::compare(_M_data
, __s
._M_data
, __n
))
1064 using __limits
= __gnu_cxx::__int_traits
<int>;
1065 const difference_type __diff
= _M_len
- __s
._M_len
;
1066 if (__diff
> __limits::__max
)
1067 return __limits::__max
;
1068 if (__diff
< __limits::__min
)
1069 return __limits::__min
;
1070 return static_cast<int>(__diff
);
1074 const value_type
* _M_data
= nullptr;
1078 // Create a __string_view over the iterator range.
1079 template<typename _Iter
= _BiIter
>
1080 __enable_if_t
<__detail::__is_contiguous_iter
<_Iter
>::value
,
1082 _M_str() const noexcept
1085 if (size_t __len
= this->second
- this->first
)
1086 return { std::__addressof(*this->first
), __len
};
1090 // Create a temporary string that can be converted to __string_view.
1091 template<typename _Iter
= _BiIter
>
1092 __enable_if_t
<!__detail::__is_contiguous_iter
<_Iter
>::value
,
1099 /** @brief Standard regex submatch over a C-style null-terminated string. */
1100 typedef sub_match
<const char*> csub_match
;
1102 /** @brief Standard regex submatch over a standard string. */
1103 typedef sub_match
<string::const_iterator
> ssub_match
;
1105 #ifdef _GLIBCXX_USE_WCHAR_T
1106 /** @brief Regex submatch over a C-style null-terminated wide string. */
1107 typedef sub_match
<const wchar_t*> wcsub_match
;
1109 /** @brief Regex submatch over a standard wide string. */
1110 typedef sub_match
<wstring::const_iterator
> wssub_match
;
1113 // [7.9.2] sub_match non-member operators
1115 /// @relates sub_match @{
1118 * @brief Tests the equivalence of two regular expression submatches.
1119 * @param __lhs First regular expression submatch.
1120 * @param __rhs Second regular expression submatch.
1121 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1123 template<typename _BiIter
>
1125 operator==(const sub_match
<_BiIter
>& __lhs
, const sub_match
<_BiIter
>& __rhs
)
1126 { return __lhs
.compare(__rhs
) == 0; }
1128 #if __cpp_lib_three_way_comparison
1130 * @brief Three-way comparison of two regular expression submatches.
1131 * @param __lhs First regular expression submatch.
1132 * @param __rhs Second regular expression submatch.
1133 * @returns A value indicating whether `__lhs` is less than, equal to,
1134 * greater than, or incomparable with `__rhs`.
1136 template<typename _BiIter
>
1138 operator<=>(const sub_match
<_BiIter
>& __lhs
,
1139 const sub_match
<_BiIter
>& __rhs
)
1140 noexcept(__detail::__is_contiguous_iter
<_BiIter
>::value
)
1142 using _Tr
= char_traits
<typename iterator_traits
<_BiIter
>::value_type
>;
1143 return __detail::__char_traits_cmp_cat
<_Tr
>(__lhs
.compare(__rhs
));
1147 * @brief Tests the inequivalence 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 is not equivalent to @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 precedes @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 does not succeed @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; }
1180 * @brief Tests the ordering of two regular expression submatches.
1181 * @param __lhs First regular expression submatch.
1182 * @param __rhs Second regular expression submatch.
1183 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1185 template<typename _BiIter
>
1187 operator>=(const sub_match
<_BiIter
>& __lhs
, const sub_match
<_BiIter
>& __rhs
)
1188 { return __lhs
.compare(__rhs
) >= 0; }
1191 * @brief Tests the ordering of two regular expression submatches.
1192 * @param __lhs First regular expression submatch.
1193 * @param __rhs Second regular expression submatch.
1194 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1196 template<typename _BiIter
>
1198 operator>(const sub_match
<_BiIter
>& __lhs
, const sub_match
<_BiIter
>& __rhs
)
1199 { return __lhs
.compare(__rhs
) > 0; }
1200 #endif // three-way comparison
1202 /// @cond undocumented
1204 // Alias for a basic_string that can be compared to a sub_match.
1205 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1206 using __sub_match_string
= basic_string
<
1207 typename iterator_traits
<_Bi_iter
>::value_type
,
1208 _Ch_traits
, _Ch_alloc
>;
1211 #if ! __cpp_lib_three_way_comparison
1213 * @brief Tests the equivalence of a string and a regular expression
1215 * @param __lhs A string.
1216 * @param __rhs A regular expression submatch.
1217 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1219 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1221 operator==(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
1222 const sub_match
<_Bi_iter
>& __rhs
)
1223 { return __rhs
._M_compare(__lhs
.data(), __lhs
.size()) == 0; }
1226 * @brief Tests the inequivalence of a string and a regular expression
1228 * @param __lhs A string.
1229 * @param __rhs A regular expression submatch.
1230 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1232 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1234 operator!=(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
1235 const sub_match
<_Bi_iter
>& __rhs
)
1236 { return !(__lhs
== __rhs
); }
1239 * @brief Tests the ordering of a string and a regular expression submatch.
1240 * @param __lhs A string.
1241 * @param __rhs A regular expression submatch.
1242 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1244 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1246 operator<(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
1247 const sub_match
<_Bi_iter
>& __rhs
)
1248 { return __rhs
._M_compare(__lhs
.data(), __lhs
.size()) > 0; }
1251 * @brief Tests the ordering of a string and a regular expression submatch.
1252 * @param __lhs A string.
1253 * @param __rhs A regular expression submatch.
1254 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1256 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1258 operator>(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
1259 const sub_match
<_Bi_iter
>& __rhs
)
1260 { return __rhs
< __lhs
; }
1263 * @brief Tests the ordering of a string and a regular expression submatch.
1264 * @param __lhs A string.
1265 * @param __rhs A regular expression submatch.
1266 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1268 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1270 operator>=(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
1271 const sub_match
<_Bi_iter
>& __rhs
)
1272 { return !(__lhs
< __rhs
); }
1275 * @brief Tests the ordering of a string and a regular expression submatch.
1276 * @param __lhs A string.
1277 * @param __rhs A regular expression submatch.
1278 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1280 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1282 operator<=(const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __lhs
,
1283 const sub_match
<_Bi_iter
>& __rhs
)
1284 { return !(__rhs
< __lhs
); }
1285 #endif // three-way comparison
1288 * @brief Tests the equivalence of a regular expression submatch and a
1290 * @param __lhs A regular expression submatch.
1291 * @param __rhs A string.
1292 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1294 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1296 operator==(const sub_match
<_Bi_iter
>& __lhs
,
1297 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1298 { return __lhs
._M_compare(__rhs
.data(), __rhs
.size()) == 0; }
1300 #if __cpp_lib_three_way_comparison
1302 * @brief Three-way comparison of a regular expression submatch and a string.
1303 * @param __lhs A regular expression submatch.
1304 * @param __rhs A string.
1305 * @returns A value indicating whether `__lhs` is less than, equal to,
1306 * greater than, or incomparable with `__rhs`.
1308 template<typename _Bi_iter
, typename _Ch_traits
, typename _Alloc
>
1310 operator<=>(const sub_match
<_Bi_iter
>& __lhs
,
1311 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Alloc
>& __rhs
)
1312 noexcept(__detail::__is_contiguous_iter
<_Bi_iter
>::value
)
1314 return __detail::__char_traits_cmp_cat
<_Ch_traits
>(
1315 __lhs
._M_compare(__rhs
.data(), __rhs
.size()));
1319 * @brief Tests the inequivalence of a regular expression submatch and a
1321 * @param __lhs A regular expression submatch.
1322 * @param __rhs A string.
1323 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1325 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1327 operator!=(const sub_match
<_Bi_iter
>& __lhs
,
1328 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1329 { return !(__lhs
== __rhs
); }
1332 * @brief Tests the ordering of a regular expression submatch and a string.
1333 * @param __lhs A regular expression submatch.
1334 * @param __rhs A string.
1335 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1337 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1339 operator<(const sub_match
<_Bi_iter
>& __lhs
,
1340 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1341 { return __lhs
._M_compare(__rhs
.data(), __rhs
.size()) < 0; }
1344 * @brief Tests the ordering of a regular expression submatch and a string.
1345 * @param __lhs A regular expression submatch.
1346 * @param __rhs A string.
1347 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1349 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1351 operator>(const sub_match
<_Bi_iter
>& __lhs
,
1352 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1353 { return __rhs
< __lhs
; }
1356 * @brief Tests the ordering of a regular expression submatch and a string.
1357 * @param __lhs A regular expression submatch.
1358 * @param __rhs A string.
1359 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1361 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1363 operator>=(const sub_match
<_Bi_iter
>& __lhs
,
1364 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1365 { return !(__lhs
< __rhs
); }
1368 * @brief Tests the ordering of a regular expression submatch and a string.
1369 * @param __lhs A regular expression submatch.
1370 * @param __rhs A string.
1371 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1373 template<typename _Bi_iter
, typename _Ch_traits
, typename _Ch_alloc
>
1375 operator<=(const sub_match
<_Bi_iter
>& __lhs
,
1376 const __sub_match_string
<_Bi_iter
, _Ch_traits
, _Ch_alloc
>& __rhs
)
1377 { return !(__rhs
< __lhs
); }
1380 * @brief Tests the equivalence of a C string and a regular expression
1382 * @param __lhs A null-terminated string.
1383 * @param __rhs A regular expression submatch.
1384 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1386 template<typename _Bi_iter
>
1388 operator==(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1389 const sub_match
<_Bi_iter
>& __rhs
)
1390 { return __rhs
.compare(__lhs
) == 0; }
1393 * @brief Tests the inequivalence of a C string and a regular
1394 * expression submatch.
1395 * @param __lhs A null-terminated string.
1396 * @param __rhs A regular expression submatch.
1397 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1399 template<typename _Bi_iter
>
1401 operator!=(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1402 const sub_match
<_Bi_iter
>& __rhs
)
1403 { return !(__lhs
== __rhs
); }
1406 * @brief Tests the ordering of a C string and a regular expression submatch.
1407 * @param __lhs A null-terminated string.
1408 * @param __rhs A regular expression submatch.
1409 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1411 template<typename _Bi_iter
>
1413 operator<(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1414 const sub_match
<_Bi_iter
>& __rhs
)
1415 { return __rhs
.compare(__lhs
) > 0; }
1418 * @brief Tests the ordering of a C string and a regular expression submatch.
1419 * @param __lhs A null-terminated string.
1420 * @param __rhs A regular expression submatch.
1421 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1423 template<typename _Bi_iter
>
1425 operator>(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1426 const sub_match
<_Bi_iter
>& __rhs
)
1427 { return __rhs
< __lhs
; }
1430 * @brief Tests the ordering of a C string and a regular expression submatch.
1431 * @param __lhs A null-terminated string.
1432 * @param __rhs A regular expression submatch.
1433 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1435 template<typename _Bi_iter
>
1437 operator>=(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1438 const sub_match
<_Bi_iter
>& __rhs
)
1439 { return !(__lhs
< __rhs
); }
1442 * @brief Tests the ordering of a C string and a regular expression submatch.
1443 * @param __lhs A null-terminated string.
1444 * @param __rhs A regular expression submatch.
1445 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1447 template<typename _Bi_iter
>
1449 operator<=(typename iterator_traits
<_Bi_iter
>::value_type
const* __lhs
,
1450 const sub_match
<_Bi_iter
>& __rhs
)
1451 { return !(__rhs
< __lhs
); }
1452 #endif // three-way comparison
1455 * @brief Tests the equivalence of a regular expression submatch and a C
1457 * @param __lhs A regular expression submatch.
1458 * @param __rhs A null-terminated string.
1459 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1461 template<typename _Bi_iter
>
1463 operator==(const sub_match
<_Bi_iter
>& __lhs
,
1464 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1465 { return __lhs
.compare(__rhs
) == 0; }
1467 #if __cpp_lib_three_way_comparison
1469 * @brief Three-way comparison of a regular expression submatch and a C
1471 * @param __lhs A regular expression submatch.
1472 * @param __rhs A null-terminated string.
1473 * @returns A value indicating whether `__lhs` is less than, equal to,
1474 * greater than, or incomparable with `__rhs`.
1476 template<typename _Bi_iter
>
1478 operator<=>(const sub_match
<_Bi_iter
>& __lhs
,
1479 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1480 noexcept(__detail::__is_contiguous_iter
<_Bi_iter
>::value
)
1482 using _Tr
= char_traits
<typename iterator_traits
<_Bi_iter
>::value_type
>;
1483 return __detail::__char_traits_cmp_cat
<_Tr
>(__lhs
.compare(__rhs
));
1487 * @brief Tests the inequivalence of a regular expression submatch and a
1489 * @param __lhs A regular expression submatch.
1490 * @param __rhs A null-terminated string.
1491 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1493 template<typename _Bi_iter
>
1495 operator!=(const sub_match
<_Bi_iter
>& __lhs
,
1496 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1497 { return !(__lhs
== __rhs
); }
1500 * @brief Tests the ordering of a regular expression submatch and a C string.
1501 * @param __lhs A regular expression submatch.
1502 * @param __rhs A null-terminated string.
1503 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1505 template<typename _Bi_iter
>
1507 operator<(const sub_match
<_Bi_iter
>& __lhs
,
1508 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1509 { return __lhs
.compare(__rhs
) < 0; }
1512 * @brief Tests the ordering of a regular expression submatch and a C string.
1513 * @param __lhs A regular expression submatch.
1514 * @param __rhs A null-terminated string.
1515 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1517 template<typename _Bi_iter
>
1519 operator>(const sub_match
<_Bi_iter
>& __lhs
,
1520 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1521 { return __rhs
< __lhs
; }
1524 * @brief Tests the ordering of a regular expression submatch and a C string.
1525 * @param __lhs A regular expression submatch.
1526 * @param __rhs A null-terminated string.
1527 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1529 template<typename _Bi_iter
>
1531 operator>=(const sub_match
<_Bi_iter
>& __lhs
,
1532 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1533 { return !(__lhs
< __rhs
); }
1536 * @brief Tests the ordering of a regular expression submatch and a C string.
1537 * @param __lhs A regular expression submatch.
1538 * @param __rhs A null-terminated string.
1539 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1541 template<typename _Bi_iter
>
1543 operator<=(const sub_match
<_Bi_iter
>& __lhs
,
1544 typename iterator_traits
<_Bi_iter
>::value_type
const* __rhs
)
1545 { return !(__rhs
< __lhs
); }
1548 * @brief Tests the equivalence of a character and a regular expression
1550 * @param __lhs A character.
1551 * @param __rhs A regular expression submatch.
1552 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1554 template<typename _Bi_iter
>
1556 operator==(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1557 const sub_match
<_Bi_iter
>& __rhs
)
1558 { return __rhs
._M_compare(std::__addressof(__lhs
), 1) == 0; }
1561 * @brief Tests the inequivalence of a character and a regular expression
1563 * @param __lhs A character.
1564 * @param __rhs A regular expression submatch.
1565 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1567 template<typename _Bi_iter
>
1569 operator!=(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1570 const sub_match
<_Bi_iter
>& __rhs
)
1571 { return !(__lhs
== __rhs
); }
1574 * @brief Tests the ordering of a character and a regular expression
1576 * @param __lhs A character.
1577 * @param __rhs A regular expression submatch.
1578 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1580 template<typename _Bi_iter
>
1582 operator<(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1583 const sub_match
<_Bi_iter
>& __rhs
)
1584 { return __rhs
._M_compare(std::__addressof(__lhs
), 1) > 0; }
1587 * @brief Tests the ordering of a character and a regular expression
1589 * @param __lhs A character.
1590 * @param __rhs A regular expression submatch.
1591 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1593 template<typename _Bi_iter
>
1595 operator>(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1596 const sub_match
<_Bi_iter
>& __rhs
)
1597 { return __rhs
< __lhs
; }
1600 * @brief Tests the ordering of a character and a regular expression
1602 * @param __lhs A character.
1603 * @param __rhs A regular expression submatch.
1604 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1606 template<typename _Bi_iter
>
1608 operator>=(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1609 const sub_match
<_Bi_iter
>& __rhs
)
1610 { return !(__lhs
< __rhs
); }
1613 * @brief Tests the ordering of a character and a regular expression
1615 * @param __lhs A character.
1616 * @param __rhs A regular expression submatch.
1617 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1619 template<typename _Bi_iter
>
1621 operator<=(typename iterator_traits
<_Bi_iter
>::value_type
const& __lhs
,
1622 const sub_match
<_Bi_iter
>& __rhs
)
1623 { return !(__rhs
< __lhs
); }
1624 #endif // three-way comparison
1627 * @brief Tests the equivalence of a regular expression submatch and a
1629 * @param __lhs A regular expression submatch.
1630 * @param __rhs A character.
1631 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1633 template<typename _Bi_iter
>
1635 operator==(const sub_match
<_Bi_iter
>& __lhs
,
1636 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1637 { return __lhs
._M_compare(std::__addressof(__rhs
), 1) == 0; }
1639 #if __cpp_lib_three_way_comparison
1641 * @brief Three-way comparison of a regular expression submatch and a
1643 * @param __lhs A regular expression submatch.
1644 * @param __rhs A character.
1645 * @returns A value indicating whether `__lhs` is less than, equal to,
1646 * greater than, or incomparable with `__rhs`.
1649 template<typename _Bi_iter
>
1651 operator<=>(const sub_match
<_Bi_iter
>& __lhs
,
1652 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1653 noexcept(__detail::__is_contiguous_iter
<_Bi_iter
>::value
)
1655 using _Tr
= char_traits
<typename iterator_traits
<_Bi_iter
>::value_type
>;
1656 return __detail::__char_traits_cmp_cat
<_Tr
>(
1657 __lhs
._M_compare(std::__addressof(__rhs
), 1));
1661 * @brief Tests the inequivalence of a regular expression submatch and a
1663 * @param __lhs A regular expression submatch.
1664 * @param __rhs A character.
1665 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1667 template<typename _Bi_iter
>
1669 operator!=(const sub_match
<_Bi_iter
>& __lhs
,
1670 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1671 { return !(__lhs
== __rhs
); }
1674 * @brief Tests the ordering of a regular expression submatch and a
1676 * @param __lhs A regular expression submatch.
1677 * @param __rhs A character.
1678 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1680 template<typename _Bi_iter
>
1682 operator<(const sub_match
<_Bi_iter
>& __lhs
,
1683 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1684 { return __lhs
._M_compare(std::__addressof(__rhs
), 1) < 0; }
1687 * @brief Tests the ordering of a regular expression submatch and a
1689 * @param __lhs A regular expression submatch.
1690 * @param __rhs A character.
1691 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1693 template<typename _Bi_iter
>
1695 operator>(const sub_match
<_Bi_iter
>& __lhs
,
1696 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1697 { return __rhs
< __lhs
; }
1700 * @brief Tests the ordering of a regular expression submatch and a
1702 * @param __lhs A regular expression submatch.
1703 * @param __rhs A character.
1704 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1706 template<typename _Bi_iter
>
1708 operator>=(const sub_match
<_Bi_iter
>& __lhs
,
1709 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1710 { return !(__lhs
< __rhs
); }
1713 * @brief Tests the ordering of a regular expression submatch and a
1715 * @param __lhs A regular expression submatch.
1716 * @param __rhs A character.
1717 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1719 template<typename _Bi_iter
>
1721 operator<=(const sub_match
<_Bi_iter
>& __lhs
,
1722 typename iterator_traits
<_Bi_iter
>::value_type
const& __rhs
)
1723 { return !(__rhs
< __lhs
); }
1724 #endif // three-way comparison
1727 * @brief Inserts a matched string into an output stream.
1729 * @param __os The output stream.
1730 * @param __m A submatch string.
1732 * @returns the output stream with the submatch string inserted.
1734 template<typename _Ch_type
, typename _Ch_traits
, typename _Bi_iter
>
1736 basic_ostream
<_Ch_type
, _Ch_traits
>&
1737 operator<<(basic_ostream
<_Ch_type
, _Ch_traits
>& __os
,
1738 const sub_match
<_Bi_iter
>& __m
)
1739 { return __os
<< __m
.str(); }
1741 /// @} relates sub_match
1743 // [7.10] Class template match_results
1746 * @brief The results of a match or search operation.
1748 * A collection of character sequences representing the result of a regular
1749 * expression match. Storage for the collection is allocated and freed as
1750 * necessary by the member functions of class template match_results.
1752 * This class satisfies the Sequence requirements, with the exception that
1753 * only the operations defined for a const-qualified Sequence are supported.
1755 * The sub_match object stored at index 0 represents sub-expression 0, i.e.
1756 * the whole match. In this case the %sub_match member matched is always true.
1757 * The sub_match object stored at index n denotes what matched the marked
1758 * sub-expression n within the matched expression. If the sub-expression n
1759 * participated in a regular expression match then the %sub_match member
1760 * matched evaluates to true, and members first and second denote the range
1761 * of characters [first, second) which formed that match. Otherwise matched
1762 * is false, and members first and second point to the end of the sequence
1763 * that was searched.
1768 template<typename _Bi_iter
,
1769 typename _Alloc
= allocator
<sub_match
<_Bi_iter
> > >
1771 : private std::vector
<sub_match
<_Bi_iter
>, _Alloc
>
1775 * The vector base is empty if this does not represent a match (!ready());
1776 * Otherwise if it's a match failure, it contains 3 elements:
1780 * Otherwise it contains n+4 elements where n is the number of marked
1783 * [1] 1st marked subexpression
1785 * [n] nth marked subexpression
1790 typedef std::vector
<sub_match
<_Bi_iter
>, _Alloc
> _Base_type
;
1791 // In debug mode _Base_type is the debug vector, this is the unsafe one:
1792 typedef _GLIBCXX_STD_C::vector
<sub_match
<_Bi_iter
>, _Alloc
> _Unchecked
;
1793 typedef std::iterator_traits
<_Bi_iter
> __iter_traits
;
1794 typedef regex_constants::match_flag_type match_flag_type
;
1798 * @name 28.10 Public Types
1801 typedef sub_match
<_Bi_iter
> value_type
;
1802 typedef const value_type
& const_reference
;
1803 typedef value_type
& reference
;
1804 typedef typename
_Base_type::const_iterator const_iterator
;
1805 typedef const_iterator iterator
;
1806 typedef typename
__iter_traits::difference_type difference_type
;
1807 typedef typename allocator_traits
<_Alloc
>::size_type size_type
;
1808 typedef _Alloc allocator_type
;
1809 typedef typename
__iter_traits::value_type char_type
;
1810 typedef std::basic_string
<char_type
> string_type
;
1815 * @name 28.10.1 Construction, Copying, and Destruction
1820 * @brief Constructs a default %match_results container.
1821 * @post size() returns 0 and str() returns an empty string.
1823 match_results() : match_results(_Alloc()) { }
1826 * @brief Constructs a default %match_results container.
1827 * @post size() returns 0 and str() returns an empty string.
1830 match_results(const _Alloc
& __a
) noexcept
1835 * @brief Copy constructs a %match_results.
1837 match_results(const match_results
&) = default;
1840 * @brief Move constructs a %match_results.
1842 match_results(match_results
&&) noexcept
= default;
1845 * @brief Assigns rhs to *this.
1848 operator=(const match_results
&) = default;
1851 * @brief Move-assigns rhs to *this.
1854 operator=(match_results
&&) = default;
1857 * @brief Destroys a %match_results object.
1859 ~match_results() = default;
1861 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1862 // 2195. Missing constructors for match_results
1864 match_results(const match_results
& __m
, const _Alloc
& __a
)
1865 : _Base_type(__m
, __a
) { }
1867 match_results(match_results
&& __m
, const _Alloc
& __a
)
1868 noexcept(noexcept(_Base_type(std::move(__m
), __a
)))
1869 : _Base_type(std::move(__m
), __a
) { }
1875 * @brief Indicates if the %match_results is ready.
1876 * @retval true The object has a fully-established result state.
1877 * @retval false The object is not ready.
1879 bool ready() const noexcept
{ return !_Unchecked::empty(); }
1882 * @name 28.10.2 Size
1887 * @brief Gets the number of matches and submatches.
1889 * The number of matches for a given regular expression will be either 0
1890 * if there was no match or mark_count() + 1 if a match was successful.
1891 * Some matches may be empty.
1893 * @returns the number of matches found.
1896 size() const noexcept
1897 { return _Unchecked::empty() ? 0 : _Unchecked::size() - 3; }
1900 max_size() const noexcept
1901 { return _Unchecked::max_size() - 3; }
1904 * @brief Indicates if the %match_results contains no results.
1905 * @retval true The %match_results object is empty.
1906 * @retval false The %match_results object is not empty.
1908 _GLIBCXX_NODISCARD
bool
1909 empty() const noexcept
1910 { return _Unchecked::size() <= 3; }
1915 * @name 28.10.4 Element Access
1920 * @brief Gets the length of the indicated submatch.
1921 * @param __sub indicates the submatch.
1922 * @pre ready() == true
1924 * This function returns the length of the indicated submatch, or the
1925 * length of the entire match if @p __sub is zero (the default).
1928 length(size_type __sub
= 0) const
1929 { return (*this)[__sub
].length(); }
1932 * @brief Gets the offset of the beginning of the indicated submatch.
1933 * @param __sub indicates the submatch.
1934 * @pre ready() == true
1936 * This function returns the offset from the beginning of the target
1937 * sequence to the beginning of the submatch, unless the value of @p __sub
1938 * is zero (the default), in which case this function returns the offset
1939 * from the beginning of the target sequence to the beginning of the
1943 position(size_type __sub
= 0) const
1944 { return std::distance(_M_begin
, (*this)[__sub
].first
); }
1947 * @brief Gets the match or submatch converted to a string type.
1948 * @param __sub indicates the submatch.
1949 * @pre ready() == true
1951 * This function gets the submatch (or match, if @p __sub is
1952 * zero) extracted from the target range and converted to the
1953 * associated string type.
1956 str(size_type __sub
= 0) const
1957 { return string_type((*this)[__sub
]); }
1960 * @brief Gets a %sub_match reference for the match or submatch.
1961 * @param __sub indicates the submatch.
1962 * @pre ready() == true
1964 * This function gets a reference to the indicated submatch, or
1965 * the entire match if @p __sub is zero.
1967 * If @p __sub >= size() then this function returns a %sub_match with a
1968 * special value indicating no submatch.
1971 operator[](size_type __sub
) const
1973 __glibcxx_assert( ready() );
1974 return __sub
< size()
1975 ? _Unchecked::operator[](__sub
)
1976 : _M_unmatched_sub();
1980 * @brief Gets a %sub_match representing the match prefix.
1981 * @pre ready() == true
1983 * This function gets a reference to a %sub_match object representing the
1984 * part of the target range between the start of the target range and the
1985 * start of the match.
1990 __glibcxx_assert( ready() );
1991 return !empty() ? _M_prefix() : _M_unmatched_sub();
1995 * @brief Gets a %sub_match representing the match suffix.
1996 * @pre ready() == true
1998 * This function gets a reference to a %sub_match object representing the
1999 * part of the target range between the end of the match and the end of
2005 __glibcxx_assert( ready() );
2006 return !empty() ? _M_suffix() : _M_unmatched_sub();
2010 * @brief Gets an iterator to the start of the %sub_match collection.
2013 begin() const noexcept
2014 { return _Base_type::begin(); }
2017 * @brief Gets an iterator to the start of the %sub_match collection.
2020 cbegin() const noexcept
2021 { return this->begin(); }
2024 * @brief Gets an iterator to one-past-the-end of the collection.
2027 end() const noexcept
2028 { return _Base_type::end() - (_Base_type::empty() ? 0 : 3); }
2031 * @brief Gets an iterator to one-past-the-end of the collection.
2034 cend() const noexcept
2035 { return this->end(); }
2040 * @name 28.10.5 Formatting
2042 * These functions perform formatted substitution of the matched
2043 * character sequences into their target. The format specifiers and
2044 * escape sequences accepted by these functions are determined by
2045 * their @p flags parameter as documented above.
2050 * @pre ready() == true
2052 template<typename _Out_iter
>
2054 format(_Out_iter __out
, const char_type
* __fmt_first
,
2055 const char_type
* __fmt_last
,
2056 match_flag_type __flags
= regex_constants::format_default
) const;
2059 * @pre ready() == true
2061 template<typename _Out_iter
, typename _St
, typename _Sa
>
2063 format(_Out_iter __out
, const basic_string
<char_type
, _St
, _Sa
>& __fmt
,
2064 match_flag_type __flags
= regex_constants::format_default
) const
2066 return format(__out
, __fmt
.data(), __fmt
.data() + __fmt
.size(),
2071 * @pre ready() == true
2073 template<typename _St
, typename _Sa
>
2074 basic_string
<char_type
, _St
, _Sa
>
2075 format(const basic_string
<char_type
, _St
, _Sa
>& __fmt
,
2076 match_flag_type __flags
= regex_constants::format_default
) const
2078 basic_string
<char_type
, _St
, _Sa
> __result
;
2079 format(std::back_inserter(__result
), __fmt
, __flags
);
2084 * @pre ready() == true
2087 format(const char_type
* __fmt
,
2088 match_flag_type __flags
= regex_constants::format_default
) const
2090 string_type __result
;
2091 format(std::back_inserter(__result
),
2093 __fmt
+ char_traits
<char_type
>::length(__fmt
),
2101 * @name 28.10.6 Allocator
2106 * @brief Gets a copy of the allocator.
2109 get_allocator() const noexcept
2110 { return _Base_type::get_allocator(); }
2115 * @name 28.10.7 Swap
2120 * @brief Swaps the contents of two match_results.
2123 swap(match_results
& __that
) noexcept
2126 _Base_type::swap(__that
);
2127 swap(_M_begin
, __that
._M_begin
);
2132 template<typename
, typename
, typename
>
2133 friend class regex_iterator
;
2135 /// @cond undocumented
2137 template<typename
, typename
, typename
, bool>
2138 friend class __detail::_Executor
;
2140 template<typename _Bp
, typename _Ap
, typename _Cp
, typename _Rp
>
2142 __detail::__regex_algo_impl(_Bp
, _Bp
, match_results
<_Bp
, _Ap
>&,
2143 const basic_regex
<_Cp
, _Rp
>&,
2144 regex_constants::match_flag_type
,
2145 __detail::_RegexExecutorPolicy
, bool);
2147 // Reset contents to __size unmatched sub_match objects
2148 // (plus additional objects for prefix, suffix and unmatched sub).
2150 _M_resize(unsigned int __size
)
2151 { _Unchecked::assign(__size
+ 3, sub_match
<_Bi_iter
>{}); }
2153 // Set state to a failed match for the given past-the-end iterator.
2155 _M_establish_failed_match(_Bi_iter __end
)
2157 sub_match
<_Bi_iter
> __sm
;
2158 __sm
.first
= __sm
.second
= __end
;
2159 _Unchecked::assign(3, __sm
);
2163 _M_unmatched_sub() const
2164 { return _Unchecked::operator[](_Unchecked::size() - 3); }
2166 sub_match
<_Bi_iter
>&
2168 { return _Unchecked::operator[](_Unchecked::size() - 3); }
2172 { return _Unchecked::operator[](_Unchecked::size() - 2); }
2174 sub_match
<_Bi_iter
>&
2176 { return _Unchecked::operator[](_Unchecked::size() - 2); }
2180 { return _Unchecked::operator[](_Unchecked::size() - 1); }
2182 sub_match
<_Bi_iter
>&
2184 { return _Unchecked::operator[](_Unchecked::size() - 1); }
2186 _Bi_iter _M_begin
{};
2190 typedef match_results
<const char*> cmatch
;
2191 typedef match_results
<string::const_iterator
> smatch
;
2192 #ifdef _GLIBCXX_USE_WCHAR_T
2193 typedef match_results
<const wchar_t*> wcmatch
;
2194 typedef match_results
<wstring::const_iterator
> wsmatch
;
2197 // match_results comparisons
2200 * @brief Compares two match_results for equality.
2201 * @returns true if the two objects refer to the same match,
2204 * @relates match_results
2206 template<typename _Bi_iter
, typename _Alloc
>
2208 operator==(const match_results
<_Bi_iter
, _Alloc
>& __m1
,
2209 const match_results
<_Bi_iter
, _Alloc
>& __m2
)
2211 if (__m1
.ready() != __m2
.ready())
2213 if (!__m1
.ready()) // both are not ready
2215 if (__m1
.empty() != __m2
.empty())
2217 if (__m1
.empty()) // both are empty
2219 return __m1
.prefix() == __m2
.prefix()
2220 && __m1
.size() == __m2
.size()
2221 && std::equal(__m1
.begin(), __m1
.end(), __m2
.begin())
2222 && __m1
.suffix() == __m2
.suffix();
2225 #if ! __cpp_lib_three_way_comparison
2227 * @brief Compares two match_results for inequality.
2228 * @returns true if the two objects do not refer to the same match,
2231 * @relates match_results
2233 template<typename _Bi_iter
, class _Alloc
>
2235 operator!=(const match_results
<_Bi_iter
, _Alloc
>& __m1
,
2236 const match_results
<_Bi_iter
, _Alloc
>& __m2
)
2237 { return !(__m1
== __m2
); }
2240 // [7.10.6] match_results swap
2242 * @brief Swaps two match results.
2243 * @param __lhs A match result.
2244 * @param __rhs A match result.
2246 * The contents of the two match_results objects are swapped.
2248 * @relates match_results
2250 template<typename _Bi_iter
, typename _Alloc
>
2252 swap(match_results
<_Bi_iter
, _Alloc
>& __lhs
,
2253 match_results
<_Bi_iter
, _Alloc
>& __rhs
) noexcept
2254 { __lhs
.swap(__rhs
); }
2256 _GLIBCXX_END_NAMESPACE_CXX11
2258 // [28.11.2] Function template regex_match
2260 * @name Matching, Searching, and Replacing
2266 * @brief Determines if there is a match between the regular expression @p e
2267 * and all of the character sequence [first, last).
2269 * @param __s Start of the character sequence to match.
2270 * @param __e One-past-the-end of the character sequence to match.
2271 * @param __m The match results.
2272 * @param __re The regular expression.
2273 * @param __flags Controls how the regular expression is matched.
2275 * @retval true A match exists.
2276 * @retval false Otherwise.
2278 * @throws an exception of type regex_error.
2280 template<typename _Bi_iter
, typename _Alloc
,
2281 typename _Ch_type
, typename _Rx_traits
>
2283 regex_match(_Bi_iter __s
,
2285 match_results
<_Bi_iter
, _Alloc
>& __m
,
2286 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2287 regex_constants::match_flag_type __flags
2288 = regex_constants::match_default
)
2290 return __detail::__regex_algo_impl(__s
, __e
, __m
, __re
, __flags
,
2291 __detail::_RegexExecutorPolicy::_S_auto
, true);
2295 * @brief Indicates if there is a match between the regular expression @p e
2296 * and all of the character sequence [first, last).
2298 * @param __first Beginning of the character sequence to match.
2299 * @param __last One-past-the-end of the character sequence to match.
2300 * @param __re The regular expression.
2301 * @param __flags Controls how the regular expression is matched.
2303 * @retval true A match exists.
2304 * @retval false Otherwise.
2306 * @throws an exception of type regex_error.
2308 template<typename _Bi_iter
, typename _Ch_type
, typename _Rx_traits
>
2310 regex_match(_Bi_iter __first
, _Bi_iter __last
,
2311 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2312 regex_constants::match_flag_type __flags
2313 = regex_constants::match_default
)
2315 match_results
<_Bi_iter
> __what
;
2316 return regex_match(__first
, __last
, __what
, __re
, __flags
);
2320 * @brief Determines if there is a match between the regular expression @p e
2321 * and a C-style null-terminated string.
2323 * @param __s The C-style null-terminated string to match.
2324 * @param __m The match results.
2325 * @param __re The regular expression.
2326 * @param __f Controls how the regular expression is matched.
2328 * @retval true A match exists.
2329 * @retval false Otherwise.
2331 * @throws an exception of type regex_error.
2333 template<typename _Ch_type
, typename _Alloc
, typename _Rx_traits
>
2335 regex_match(const _Ch_type
* __s
,
2336 match_results
<const _Ch_type
*, _Alloc
>& __m
,
2337 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2338 regex_constants::match_flag_type __f
2339 = regex_constants::match_default
)
2340 { return regex_match(__s
, __s
+ _Rx_traits::length(__s
), __m
, __re
, __f
); }
2343 * @brief Determines if there is a match between the regular expression @p e
2346 * @param __s The string to match.
2347 * @param __m The match results.
2348 * @param __re The regular expression.
2349 * @param __flags Controls how the regular expression is matched.
2351 * @retval true A match exists.
2352 * @retval false Otherwise.
2354 * @throws an exception of type regex_error.
2356 template<typename _Ch_traits
, typename _Ch_alloc
,
2357 typename _Alloc
, typename _Ch_type
, typename _Rx_traits
>
2359 regex_match(const basic_string
<_Ch_type
, _Ch_traits
, _Ch_alloc
>& __s
,
2360 match_results
<typename basic_string
<_Ch_type
,
2361 _Ch_traits
, _Ch_alloc
>::const_iterator
, _Alloc
>& __m
,
2362 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2363 regex_constants::match_flag_type __flags
2364 = regex_constants::match_default
)
2365 { return regex_match(__s
.begin(), __s
.end(), __m
, __re
, __flags
); }
2367 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2368 // 2329. regex_match() with match_results should forbid temporary strings
2369 /// Prevent unsafe attempts to get match_results from a temporary string.
2370 template<typename _Ch_traits
, typename _Ch_alloc
,
2371 typename _Alloc
, typename _Ch_type
, typename _Rx_traits
>
2373 regex_match(const basic_string
<_Ch_type
, _Ch_traits
, _Ch_alloc
>&&,
2374 match_results
<typename basic_string
<_Ch_type
,
2375 _Ch_traits
, _Ch_alloc
>::const_iterator
, _Alloc
>&,
2376 const basic_regex
<_Ch_type
, _Rx_traits
>&,
2377 regex_constants::match_flag_type
2378 = regex_constants::match_default
) = delete;
2381 * @brief Indicates if there is a match between the regular expression @p e
2382 * and a C-style null-terminated string.
2384 * @param __s The C-style null-terminated string to match.
2385 * @param __re The regular expression.
2386 * @param __f Controls how the regular expression is matched.
2388 * @retval true A match exists.
2389 * @retval false Otherwise.
2391 * @throws an exception of type regex_error.
2393 template<typename _Ch_type
, class _Rx_traits
>
2395 regex_match(const _Ch_type
* __s
,
2396 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2397 regex_constants::match_flag_type __f
2398 = regex_constants::match_default
)
2399 { return regex_match(__s
, __s
+ _Rx_traits::length(__s
), __re
, __f
); }
2402 * @brief Indicates if there is a match between the regular expression @p e
2405 * @param __s [IN] The string to match.
2406 * @param __re [IN] The regular expression.
2407 * @param __flags [IN] Controls how the regular expression is matched.
2409 * @retval true A match exists.
2410 * @retval false Otherwise.
2412 * @throws an exception of type regex_error.
2414 template<typename _Ch_traits
, typename _Str_allocator
,
2415 typename _Ch_type
, typename _Rx_traits
>
2417 regex_match(const basic_string
<_Ch_type
, _Ch_traits
, _Str_allocator
>& __s
,
2418 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2419 regex_constants::match_flag_type __flags
2420 = regex_constants::match_default
)
2421 { return regex_match(__s
.begin(), __s
.end(), __re
, __flags
); }
2423 // [7.11.3] Function template regex_search
2425 * Searches for a regular expression within a range.
2426 * @param __s [IN] The start of the string to search.
2427 * @param __e [IN] One-past-the-end of the string to search.
2428 * @param __m [OUT] The match results.
2429 * @param __re [IN] The regular expression to search for.
2430 * @param __flags [IN] Search policy flags.
2431 * @retval true A match was found within the string.
2432 * @retval false No match was found within the string, the content of %m is
2435 * @throws an exception of type regex_error.
2437 template<typename _Bi_iter
, typename _Alloc
,
2438 typename _Ch_type
, typename _Rx_traits
>
2440 regex_search(_Bi_iter __s
, _Bi_iter __e
,
2441 match_results
<_Bi_iter
, _Alloc
>& __m
,
2442 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2443 regex_constants::match_flag_type __flags
2444 = regex_constants::match_default
)
2446 return __detail::__regex_algo_impl(__s
, __e
, __m
, __re
, __flags
,
2447 __detail::_RegexExecutorPolicy::_S_auto
, false);
2451 * Searches for a regular expression within a range.
2452 * @param __first [IN] The start of the string to search.
2453 * @param __last [IN] One-past-the-end of the string to search.
2454 * @param __re [IN] The regular expression to search for.
2455 * @param __flags [IN] Search policy flags.
2456 * @retval true A match was found within the string.
2457 * @retval false No match was found within the string.
2459 * @throws an exception of type regex_error.
2461 template<typename _Bi_iter
, typename _Ch_type
, typename _Rx_traits
>
2463 regex_search(_Bi_iter __first
, _Bi_iter __last
,
2464 const basic_regex
<_Ch_type
, _Rx_traits
>& __re
,
2465 regex_constants::match_flag_type __flags
2466 = regex_constants::match_default
)
2468 match_results
<_Bi_iter
> __what
;
2469 return regex_search(__first
, __last
, __what
, __re
, __flags
);
2473 * @brief Searches for a regular expression within a C-string.
2474 * @param __s [IN] A C-string to search for the regex.
2475 * @param __m [OUT] The set of regex matches.
2476 * @param __e [IN] The regex to search for in @p s.
2477 * @param __f [IN] The search flags.
2478 * @retval true A match was found within the string.
2479 * @retval false No match was found within the string, the content of %m is
2482 * @throws an exception of type regex_error.
2484 template<typename _Ch_type
, class _Alloc
, class _Rx_traits
>
2486 regex_search(const _Ch_type
* __s
,
2487 match_results
<const _Ch_type
*, _Alloc
>& __m
,
2488 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2489 regex_constants::match_flag_type __f
2490 = regex_constants::match_default
)
2491 { return regex_search(__s
, __s
+ _Rx_traits::length(__s
), __m
, __e
, __f
); }
2494 * @brief Searches for a regular expression within a C-string.
2495 * @param __s [IN] The C-string to search.
2496 * @param __e [IN] The regular expression to search for.
2497 * @param __f [IN] Search policy flags.
2498 * @retval true A match was found within the string.
2499 * @retval false No match was found within the string.
2501 * @throws an exception of type regex_error.
2503 template<typename _Ch_type
, typename _Rx_traits
>
2505 regex_search(const _Ch_type
* __s
,
2506 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2507 regex_constants::match_flag_type __f
2508 = regex_constants::match_default
)
2509 { return regex_search(__s
, __s
+ _Rx_traits::length(__s
), __e
, __f
); }
2512 * @brief Searches for a regular expression within a string.
2513 * @param __s [IN] The string to search.
2514 * @param __e [IN] The regular expression to search for.
2515 * @param __flags [IN] Search policy flags.
2516 * @retval true A match was found within the string.
2517 * @retval false No match was found within the string.
2519 * @throws an exception of type regex_error.
2521 template<typename _Ch_traits
, typename _String_allocator
,
2522 typename _Ch_type
, typename _Rx_traits
>
2524 regex_search(const basic_string
<_Ch_type
, _Ch_traits
,
2525 _String_allocator
>& __s
,
2526 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2527 regex_constants::match_flag_type __flags
2528 = regex_constants::match_default
)
2529 { return regex_search(__s
.begin(), __s
.end(), __e
, __flags
); }
2532 * @brief Searches for a regular expression within a string.
2533 * @param __s [IN] A C++ string to search for the regex.
2534 * @param __m [OUT] The set of regex matches.
2535 * @param __e [IN] The regex to search for in @p s.
2536 * @param __f [IN] The search flags.
2537 * @retval true A match was found within the string.
2538 * @retval false No match was found within the string, the content of %m is
2541 * @throws an exception of type regex_error.
2543 template<typename _Ch_traits
, typename _Ch_alloc
,
2544 typename _Alloc
, typename _Ch_type
,
2545 typename _Rx_traits
>
2547 regex_search(const basic_string
<_Ch_type
, _Ch_traits
, _Ch_alloc
>& __s
,
2548 match_results
<typename basic_string
<_Ch_type
,
2549 _Ch_traits
, _Ch_alloc
>::const_iterator
, _Alloc
>& __m
,
2550 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2551 regex_constants::match_flag_type __f
2552 = regex_constants::match_default
)
2553 { return regex_search(__s
.begin(), __s
.end(), __m
, __e
, __f
); }
2555 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2556 // 2329. regex_search() with match_results should forbid temporary strings
2557 /// Prevent unsafe attempts to get match_results from a temporary string.
2558 template<typename _Ch_traits
, typename _Ch_alloc
,
2559 typename _Alloc
, typename _Ch_type
,
2560 typename _Rx_traits
>
2562 regex_search(const basic_string
<_Ch_type
, _Ch_traits
, _Ch_alloc
>&&,
2563 match_results
<typename basic_string
<_Ch_type
,
2564 _Ch_traits
, _Ch_alloc
>::const_iterator
, _Alloc
>&,
2565 const basic_regex
<_Ch_type
, _Rx_traits
>&,
2566 regex_constants::match_flag_type
2567 = regex_constants::match_default
) = delete;
2569 // std [28.11.4] Function template regex_replace
2571 /// @cond undocumented
2572 template<typename _Out_iter
, typename _Bi_iter
,
2573 typename _Rx_traits
, typename _Ch_type
>
2575 __regex_replace(_Out_iter __out
, _Bi_iter __first
, _Bi_iter __last
,
2576 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2577 const _Ch_type
* __fmt
, size_t __len
,
2578 regex_constants::match_flag_type __flags
);
2582 * @brief Search for a regular expression within a range for multiple times,
2583 and replace the matched parts through filling a format string.
2584 * @param __out [OUT] The output iterator.
2585 * @param __first [IN] The start of the string to search.
2586 * @param __last [IN] One-past-the-end of the string to search.
2587 * @param __e [IN] The regular expression to search for.
2588 * @param __fmt [IN] The format string.
2589 * @param __flags [IN] Search and replace policy flags.
2592 * @throws an exception of type regex_error.
2594 template<typename _Out_iter
, typename _Bi_iter
,
2595 typename _Rx_traits
, typename _Ch_type
,
2596 typename _St
, typename _Sa
>
2598 regex_replace(_Out_iter __out
, _Bi_iter __first
, _Bi_iter __last
,
2599 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2600 const basic_string
<_Ch_type
, _St
, _Sa
>& __fmt
,
2601 regex_constants::match_flag_type __flags
2602 = regex_constants::match_default
)
2604 return std::__regex_replace(__out
, __first
, __last
, __e
, __fmt
.c_str(),
2605 __fmt
.length(), __flags
);
2609 * @brief Search for a regular expression within a range for multiple times,
2610 and replace the matched parts through filling a format C-string.
2611 * @param __out [OUT] The output iterator.
2612 * @param __first [IN] The start of the string to search.
2613 * @param __last [IN] One-past-the-end of the string to search.
2614 * @param __e [IN] The regular expression to search for.
2615 * @param __fmt [IN] The format C-string.
2616 * @param __flags [IN] Search and replace policy flags.
2619 * @throws an exception of type regex_error.
2621 template<typename _Out_iter
, typename _Bi_iter
,
2622 typename _Rx_traits
, typename _Ch_type
>
2624 regex_replace(_Out_iter __out
, _Bi_iter __first
, _Bi_iter __last
,
2625 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2626 const _Ch_type
* __fmt
,
2627 regex_constants::match_flag_type __flags
2628 = regex_constants::match_default
)
2630 return std::__regex_replace(__out
, __first
, __last
, __e
, __fmt
,
2631 char_traits
<_Ch_type
>::length(__fmt
),
2637 * @brief Search for a regular expression within a string for multiple times,
2638 and replace the matched parts through filling a format string.
2639 * @param __s [IN] The string to search and replace.
2640 * @param __e [IN] The regular expression to search for.
2641 * @param __fmt [IN] The format string.
2642 * @param __flags [IN] Search and replace policy flags.
2644 * @returns The string after replacing.
2645 * @throws an exception of type regex_error.
2647 template<typename _Rx_traits
, typename _Ch_type
,
2648 typename _St
, typename _Sa
, typename _Fst
, typename _Fsa
>
2649 inline basic_string
<_Ch_type
, _St
, _Sa
>
2650 regex_replace(const basic_string
<_Ch_type
, _St
, _Sa
>& __s
,
2651 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2652 const basic_string
<_Ch_type
, _Fst
, _Fsa
>& __fmt
,
2653 regex_constants::match_flag_type __flags
2654 = regex_constants::match_default
)
2656 basic_string
<_Ch_type
, _St
, _Sa
> __result
;
2657 regex_replace(std::back_inserter(__result
),
2658 __s
.begin(), __s
.end(), __e
, __fmt
, __flags
);
2663 * @brief Search for a regular expression within a string for multiple times,
2664 and replace the matched parts through filling a format C-string.
2665 * @param __s [IN] The string to search and replace.
2666 * @param __e [IN] The regular expression to search for.
2667 * @param __fmt [IN] The format C-string.
2668 * @param __flags [IN] Search and replace policy flags.
2670 * @returns The string after replacing.
2671 * @throws an exception of type regex_error.
2673 template<typename _Rx_traits
, typename _Ch_type
,
2674 typename _St
, typename _Sa
>
2675 inline basic_string
<_Ch_type
, _St
, _Sa
>
2676 regex_replace(const basic_string
<_Ch_type
, _St
, _Sa
>& __s
,
2677 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2678 const _Ch_type
* __fmt
,
2679 regex_constants::match_flag_type __flags
2680 = regex_constants::match_default
)
2682 basic_string
<_Ch_type
, _St
, _Sa
> __result
;
2683 regex_replace(std::back_inserter(__result
),
2684 __s
.begin(), __s
.end(), __e
, __fmt
, __flags
);
2689 * @brief Search for a regular expression within a C-string for multiple
2690 times, and replace the matched parts through filling a format string.
2691 * @param __s [IN] The C-string to search and replace.
2692 * @param __e [IN] The regular expression to search for.
2693 * @param __fmt [IN] The format string.
2694 * @param __flags [IN] Search and replace policy flags.
2696 * @returns The string after replacing.
2697 * @throws an exception of type regex_error.
2699 template<typename _Rx_traits
, typename _Ch_type
,
2700 typename _St
, typename _Sa
>
2701 inline basic_string
<_Ch_type
>
2702 regex_replace(const _Ch_type
* __s
,
2703 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2704 const basic_string
<_Ch_type
, _St
, _Sa
>& __fmt
,
2705 regex_constants::match_flag_type __flags
2706 = regex_constants::match_default
)
2708 basic_string
<_Ch_type
> __result
;
2709 regex_replace(std::back_inserter(__result
), __s
,
2710 __s
+ char_traits
<_Ch_type
>::length(__s
),
2711 __e
, __fmt
, __flags
);
2716 * @brief Search for a regular expression within a C-string for multiple
2717 times, and replace the matched parts through filling a format C-string.
2718 * @param __s [IN] The C-string to search and replace.
2719 * @param __e [IN] The regular expression to search for.
2720 * @param __fmt [IN] The format C-string.
2721 * @param __flags [IN] Search and replace policy flags.
2723 * @returns The string after replacing.
2724 * @throws an exception of type regex_error.
2726 template<typename _Rx_traits
, typename _Ch_type
>
2727 inline basic_string
<_Ch_type
>
2728 regex_replace(const _Ch_type
* __s
,
2729 const basic_regex
<_Ch_type
, _Rx_traits
>& __e
,
2730 const _Ch_type
* __fmt
,
2731 regex_constants::match_flag_type __flags
2732 = regex_constants::match_default
)
2734 basic_string
<_Ch_type
> __result
;
2735 regex_replace(std::back_inserter(__result
), __s
,
2736 __s
+ char_traits
<_Ch_type
>::length(__s
),
2737 __e
, __fmt
, __flags
);
2743 _GLIBCXX_BEGIN_NAMESPACE_CXX11
2745 // std [28.12] Class template regex_iterator
2747 * An iterator adaptor that will provide repeated calls of regex_search over
2748 * a range until no more matches remain.
2753 template<typename _Bi_iter
,
2754 typename _Ch_type
= typename iterator_traits
<_Bi_iter
>::value_type
,
2755 typename _Rx_traits
= regex_traits
<_Ch_type
> >
2756 class regex_iterator
2759 typedef basic_regex
<_Ch_type
, _Rx_traits
> regex_type
;
2760 typedef match_results
<_Bi_iter
> value_type
;
2761 typedef std::ptrdiff_t difference_type
;
2762 typedef const value_type
* pointer
;
2763 typedef const value_type
& reference
;
2764 typedef std::forward_iterator_tag iterator_category
;
2765 #if __cplusplus > 201703L
2766 typedef std::input_iterator_tag iterator_concept
;
2770 * @brief Provides a singular iterator, useful for indicating
2771 * one-past-the-end of a range.
2773 regex_iterator() = default;
2776 * Constructs a %regex_iterator...
2777 * @param __a [IN] The start of a text range to search.
2778 * @param __b [IN] One-past-the-end of the text range to search.
2779 * @param __re [IN] The regular expression to match.
2780 * @param __m [IN] Policy flags for match rules.
2782 regex_iterator(_Bi_iter __a
, _Bi_iter __b
, const regex_type
& __re
,
2783 regex_constants::match_flag_type __m
2784 = regex_constants::match_default
)
2785 : _M_begin(__a
), _M_end(__b
), _M_pregex(&__re
), _M_flags(__m
), _M_match()
2787 if (!regex_search(_M_begin
, _M_end
, _M_match
, *_M_pregex
, _M_flags
))
2788 *this = regex_iterator();
2791 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2792 // 2332. regex_iterator should forbid temporary regexes
2793 regex_iterator(_Bi_iter
, _Bi_iter
, const regex_type
&&,
2794 regex_constants::match_flag_type
2795 = regex_constants::match_default
) = delete;
2797 /// Copy constructs a %regex_iterator.
2798 regex_iterator(const regex_iterator
&) = default;
2800 /// Copy assigns one %regex_iterator to another.
2802 operator=(const regex_iterator
&) = default;
2804 ~regex_iterator() = default;
2807 * @brief Tests the equivalence of two regex iterators.
2810 operator==(const regex_iterator
&) const noexcept
;
2812 #if __cplusplus >= 202002L
2813 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2814 // 3719. Directory iterators should be usable with default sentinel
2815 bool operator==(default_sentinel_t
) const noexcept
2816 { return _M_pregex
== nullptr; }
2819 #if __cpp_impl_three_way_comparison < 201907L
2821 * @brief Tests the inequivalence of two regex iterators.
2824 operator!=(const regex_iterator
& __rhs
) const noexcept
2825 { return !(*this == __rhs
); }
2829 * @brief Dereferences a %regex_iterator.
2832 operator*() const noexcept
2833 { return _M_match
; }
2836 * @brief Selects a %regex_iterator member.
2839 operator->() const noexcept
2840 { return &_M_match
; }
2843 * @brief Increments a %regex_iterator.
2849 * @brief Postincrements a %regex_iterator.
2860 _Bi_iter _M_begin
{};
2862 const regex_type
* _M_pregex
= nullptr;
2863 regex_constants::match_flag_type _M_flags
{};
2864 match_results
<_Bi_iter
> _M_match
;
2867 typedef regex_iterator
<const char*> cregex_iterator
;
2868 typedef regex_iterator
<string::const_iterator
> sregex_iterator
;
2869 #ifdef _GLIBCXX_USE_WCHAR_T
2870 typedef regex_iterator
<const wchar_t*> wcregex_iterator
;
2871 typedef regex_iterator
<wstring::const_iterator
> wsregex_iterator
;
2874 // [7.12.2] Class template regex_token_iterator
2876 * Iterates over submatches in a range (or @a splits a text string).
2878 * The purpose of this iterator is to enumerate all, or all specified,
2879 * matches of a regular expression within a text range. The dereferenced
2880 * value of an iterator of this class is a std::sub_match object.
2885 template<typename _Bi_iter
,
2886 typename _Ch_type
= typename iterator_traits
<_Bi_iter
>::value_type
,
2887 typename _Rx_traits
= regex_traits
<_Ch_type
> >
2888 class regex_token_iterator
2891 typedef basic_regex
<_Ch_type
, _Rx_traits
> regex_type
;
2892 typedef sub_match
<_Bi_iter
> value_type
;
2893 typedef std::ptrdiff_t difference_type
;
2894 typedef const value_type
* pointer
;
2895 typedef const value_type
& reference
;
2896 typedef std::forward_iterator_tag iterator_category
;
2897 #if __cplusplus > 201703L
2898 typedef std::input_iterator_tag iterator_concept
;
2903 * @brief Default constructs a %regex_token_iterator.
2905 * A default-constructed %regex_token_iterator is a singular iterator
2906 * that will compare equal to the one-past-the-end value for any
2907 * iterator of the same type.
2909 regex_token_iterator()
2910 : _M_position(), _M_subs(), _M_suffix(), _M_n(0), _M_result(nullptr),
2915 * Constructs a %regex_token_iterator...
2916 * @param __a [IN] The start of the text to search.
2917 * @param __b [IN] One-past-the-end of the text to search.
2918 * @param __re [IN] The regular expression to search for.
2919 * @param __submatch [IN] Which submatch to return. There are some
2920 * special values for this parameter:
2921 * - -1 each enumerated subexpression does NOT
2922 * match the regular expression (aka field
2924 * - 0 the entire string matching the
2925 * subexpression is returned for each match
2927 * - >0 enumerates only the indicated
2928 * subexpression from a match within the text.
2929 * @param __m [IN] Policy flags for match rules.
2931 regex_token_iterator(_Bi_iter __a
, _Bi_iter __b
, const regex_type
& __re
,
2933 regex_constants::match_flag_type __m
2934 = regex_constants::match_default
)
2935 : _M_position(__a
, __b
, __re
, __m
), _M_subs(1, __submatch
), _M_n(0)
2936 { _M_init(__a
, __b
); }
2939 * Constructs a %regex_token_iterator...
2940 * @param __a [IN] The start of the text to search.
2941 * @param __b [IN] One-past-the-end of the text to search.
2942 * @param __re [IN] The regular expression to search for.
2943 * @param __submatches [IN] A list of subexpressions to return for each
2944 * regular expression match within the text.
2945 * @param __m [IN] Policy flags for match rules.
2947 regex_token_iterator(_Bi_iter __a
, _Bi_iter __b
,
2948 const regex_type
& __re
,
2949 const std::vector
<int>& __submatches
,
2950 regex_constants::match_flag_type __m
2951 = regex_constants::match_default
)
2952 : _M_position(__a
, __b
, __re
, __m
), _M_subs(__submatches
), _M_n(0)
2953 { _M_init(__a
, __b
); }
2956 * Constructs a %regex_token_iterator...
2957 * @param __a [IN] The start of the text to search.
2958 * @param __b [IN] One-past-the-end of the text to search.
2959 * @param __re [IN] The regular expression to search for.
2960 * @param __submatches [IN] A list of subexpressions to return for each
2961 * regular expression match within the text.
2962 * @param __m [IN] Policy flags for match rules.
2964 regex_token_iterator(_Bi_iter __a
, _Bi_iter __b
,
2965 const regex_type
& __re
,
2966 initializer_list
<int> __submatches
,
2967 regex_constants::match_flag_type __m
2968 = regex_constants::match_default
)
2969 : _M_position(__a
, __b
, __re
, __m
), _M_subs(__submatches
), _M_n(0)
2970 { _M_init(__a
, __b
); }
2973 * Constructs a %regex_token_iterator...
2974 * @param __a [IN] The start of the text to search.
2975 * @param __b [IN] One-past-the-end of the text to search.
2976 * @param __re [IN] The regular expression to search for.
2977 * @param __submatches [IN] A list of subexpressions to return for each
2978 * regular expression match within the text.
2979 * @param __m [IN] Policy flags for match rules.
2981 template<std::size_t _Nm
>
2982 regex_token_iterator(_Bi_iter __a
, _Bi_iter __b
,
2983 const regex_type
& __re
,
2984 const int (&__submatches
)[_Nm
],
2985 regex_constants::match_flag_type __m
2986 = regex_constants::match_default
)
2987 : _M_position(__a
, __b
, __re
, __m
),
2988 _M_subs(__submatches
, __submatches
+ _Nm
), _M_n(0)
2989 { _M_init(__a
, __b
); }
2991 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2992 // 2332. regex_token_iterator should forbid temporary regexes
2993 regex_token_iterator(_Bi_iter
, _Bi_iter
, const regex_type
&&, int = 0,
2994 regex_constants::match_flag_type
=
2995 regex_constants::match_default
) = delete;
2996 regex_token_iterator(_Bi_iter
, _Bi_iter
, const regex_type
&&,
2997 const std::vector
<int>&,
2998 regex_constants::match_flag_type
=
2999 regex_constants::match_default
) = delete;
3000 regex_token_iterator(_Bi_iter
, _Bi_iter
, const regex_type
&&,
3001 initializer_list
<int>,
3002 regex_constants::match_flag_type
=
3003 regex_constants::match_default
) = delete;
3004 template <std::size_t _Nm
>
3005 regex_token_iterator(_Bi_iter
, _Bi_iter
, const regex_type
&&,
3007 regex_constants::match_flag_type
=
3008 regex_constants::match_default
) = delete;
3011 * @brief Copy constructs a %regex_token_iterator.
3012 * @param __rhs [IN] A %regex_token_iterator to copy.
3014 regex_token_iterator(const regex_token_iterator
& __rhs
)
3015 : _M_position(__rhs
._M_position
), _M_subs(__rhs
._M_subs
),
3016 _M_suffix(__rhs
._M_suffix
), _M_n(__rhs
._M_n
), _M_has_m1(__rhs
._M_has_m1
)
3017 { _M_normalize_result(); }
3020 * @brief Assigns a %regex_token_iterator to another.
3021 * @param __rhs [IN] A %regex_token_iterator to copy.
3023 regex_token_iterator
&
3024 operator=(const regex_token_iterator
& __rhs
);
3027 * @brief Compares a %regex_token_iterator to another for equality.
3030 operator==(const regex_token_iterator
& __rhs
) const;
3032 #if __cplusplus >= 202002L
3033 // _GLIBCXX_RESOLVE_LIB_DEFECTS
3034 // 3719. Directory iterators should be usable with default sentinel
3035 bool operator==(default_sentinel_t
) const noexcept
3036 { return _M_end_of_seq(); }
3039 #if __cpp_impl_three_way_comparison < 201907L
3041 * @brief Compares a %regex_token_iterator to another for inequality.
3044 operator!=(const regex_token_iterator
& __rhs
) const
3045 { return !(*this == __rhs
); }
3049 * @brief Dereferences a %regex_token_iterator.
3053 { return *_M_result
; }
3056 * @brief Selects a %regex_token_iterator member.
3060 { return _M_result
; }
3063 * @brief Increments a %regex_token_iterator.
3065 regex_token_iterator
&
3069 * @brief Postincrements a %regex_token_iterator.
3071 regex_token_iterator
3080 typedef regex_iterator
<_Bi_iter
, _Ch_type
, _Rx_traits
> _Position
;
3083 _M_init(_Bi_iter __a
, _Bi_iter __b
);
3086 _M_current_match() const
3088 if (_M_subs
[_M_n
] == -1)
3089 return (*_M_position
).prefix();
3091 return (*_M_position
)[_M_subs
[_M_n
]];
3095 _M_end_of_seq() const noexcept
3096 { return _M_result
== nullptr; }
3100 _M_normalize_result()
3102 if (_M_position
!= _Position())
3103 _M_result
= &_M_current_match();
3105 _M_result
= &_M_suffix
;
3107 _M_result
= nullptr;
3110 _Position _M_position
;
3111 std::vector
<int> _M_subs
;
3112 value_type _M_suffix
;
3114 const value_type
* _M_result
;
3116 // Show whether _M_subs contains -1
3120 /** @brief Token iterator for C-style NULL-terminated strings. */
3121 typedef regex_token_iterator
<const char*> cregex_token_iterator
;
3123 /** @brief Token iterator for standard strings. */
3124 typedef regex_token_iterator
<string::const_iterator
> sregex_token_iterator
;
3126 #ifdef _GLIBCXX_USE_WCHAR_T
3127 /** @brief Token iterator for C-style NULL-terminated wide strings. */
3128 typedef regex_token_iterator
<const wchar_t*> wcregex_token_iterator
;
3130 /** @brief Token iterator for standard wide-character strings. */
3131 typedef regex_token_iterator
<wstring::const_iterator
> wsregex_token_iterator
;
3134 ///@} // group regex
3136 _GLIBCXX_END_NAMESPACE_CXX11
3137 _GLIBCXX_END_NAMESPACE_VERSION
3140 #include <bits/regex.tcc>