31namespace std _GLIBCXX_VISIBILITY(default)
33_GLIBCXX_BEGIN_NAMESPACE_VERSION
45 template<
typename _BiIter,
typename _Alloc,
46 typename _CharT,
typename _TraitsT>
48 __regex_algo_impl(_BiIter __s,
50 match_results<_BiIter, _Alloc>& __m,
51 const basic_regex<_CharT, _TraitsT>& __re,
53 _RegexExecutorPolicy __policy,
56 if (__re._M_automaton ==
nullptr)
59 typename match_results<_BiIter, _Alloc>::_Unchecked& __res = __m;
61 __m._M_resize(__re._M_automaton->_M_sub_count());
65 || (__policy == _RegexExecutorPolicy::_S_alternate
66 && !__re._M_automaton->_M_has_backref))
69 __executor(__s, __e, __res, __re, __flags);
71 __ret = __executor._M_match();
73 __ret = __executor._M_search();
78 __executor(__s, __e, __res, __re, __flags);
80 __ret = __executor._M_match();
82 __ret = __executor._M_search();
86 for (
auto& __it : __res)
88 __it.first = __it.second = __e;
89 auto& __pre = __m._M_prefix();
90 auto& __suf = __m._M_suffix();
93 __pre.matched =
false;
96 __suf.matched =
false;
103 __pre.second = __res[0].first;
104 __pre.matched = (__pre.first != __pre.second);
105 __suf.first = __res[0].second;
107 __suf.matched = (__suf.first != __suf.second);
112 __m._M_establish_failed_match(__e);
119 template<
typename _Ch_type>
120 template<
typename _Fwd_iter>
121 typename regex_traits<_Ch_type>::string_type
128 static const char* __collatenames[] =
221 "left-square-bracket",
223 "right-square-bracket",
253 "left-curly-bracket",
255 "right-curly-bracket",
261 for (; __first != __last; ++__first)
262 __s += __fctyp.narrow(*__first, 0);
264 for (
const auto& __it : __collatenames)
266 return string_type(1, __fctyp.widen(
267 static_cast<char>(&__it - __collatenames)));
272 return string_type();
275 template<
typename _Ch_type>
276 template<
typename _Fwd_iter>
277 typename regex_traits<_Ch_type>::char_class_type
287 {
"d", ctype_base::digit},
288 {
"w", {ctype_base::alnum, _RegexMask::_S_under}},
289 {
"s", ctype_base::space},
290 {
"alnum", ctype_base::alnum},
291 {
"alpha", ctype_base::alpha},
292 {
"blank", ctype_base::blank},
293 {
"cntrl", ctype_base::cntrl},
294 {
"digit", ctype_base::digit},
295 {
"graph", ctype_base::graph},
296 {
"lower", ctype_base::lower},
297 {
"print", ctype_base::print},
298 {
"punct", ctype_base::punct},
299 {
"space", ctype_base::space},
300 {
"upper", ctype_base::upper},
301 {
"xdigit", ctype_base::xdigit},
305 for (; __first != __last; ++__first)
306 __s += __fctyp.narrow(__fctyp.tolower(*__first), 0);
308 for (
const auto& __it : __classnames)
309 if (__s == __it.first)
313 & (ctype_base::lower | ctype_base::upper)) != 0))
314 return ctype_base::alpha;
320 template<
typename _Ch_type>
323 isctype(_Ch_type __c, char_class_type __f)
const
328 return __fctyp.is(__f._M_base, __c)
330 || ((__f._M_extended & _RegexMask::_S_under)
331 && __c == __fctyp.widen(
'_'));
334#pragma GCC diagnostic push
335#pragma GCC diagnostic ignored "-Wc++17-extensions"
336 template<
typename _Ch_type>
339 value(_Ch_type __ch,
int __radix)
const
341 if constexpr (
sizeof(_Ch_type) > 1)
344 const char __c = __ctyp.narrow(__ch,
'\0');
349 const char __c =
static_cast<char>(__ch);
350 const char __max_digit = __radix == 8 ?
'7' :
'9';
351 if (
'0' <= __c && __c <= __max_digit)
380#pragma GCC diagnostic pop
382 template<
typename _Bi_iter,
typename _Alloc>
383 template<
typename _Out_iter>
387 const match_results<_Bi_iter, _Alloc>::char_type* __fmt_first,
388 const match_results<_Bi_iter, _Alloc>::char_type* __fmt_last,
389 match_flag_type __flags)
const
391 __glibcxx_assert( ready() );
397 auto __output = [&](
size_t __idx)
399 auto& __sub = (*this)[__idx];
401 __out = std::copy(__sub.first, __sub.second, __out);
406 bool __escaping =
false;
407 for (; __fmt_first != __fmt_last; __fmt_first++)
412 if (__fctyp.is(__ctype_type::digit, *__fmt_first))
413 __output(__traits.
value(*__fmt_first, 10));
415 *__out++ = *__fmt_first;
418 if (*__fmt_first ==
'\\')
423 if (*__fmt_first ==
'&')
428 *__out++ = *__fmt_first;
437 auto __next = std::find(__fmt_first, __fmt_last,
'$');
438 if (__next == __fmt_last)
441 __out = std::copy(__fmt_first, __next, __out);
443 auto __eat = [&](
char __ch) ->
bool
453 if (++__next == __fmt_last)
461 auto& __sub = _M_prefix();
463 __out = std::copy(__sub.first, __sub.second, __out);
465 else if (__eat(
'\''))
467 auto& __sub = _M_suffix();
469 __out = std::copy(__sub.first, __sub.second, __out);
471 else if (__fctyp.is(__ctype_type::digit, *__next))
473 long __num = __traits.
value(*__next, 10);
474 if (++__next != __fmt_last
475 && __fctyp.is(__ctype_type::digit, *__next))
478 __num += __traits.
value(*__next++, 10);
480 if (0 <= __num &&
size_t(__num) < this->
size())
485 __fmt_first = __next;
487 __out = std::copy(__fmt_first, __fmt_last, __out);
492 template<
typename _Out_iter,
typename _Bi_iter,
493 typename _Rx_traits,
typename _Ch_type>
495 __regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
497 const _Ch_type* __fmt,
size_t __len,
501 _IterT __i(__first, __last, __e, __flags);
506 __out = std::copy(__first, __last, __out);
511 for (; __i != __end; ++__i)
514 __out = std::copy(__i->prefix().first, __i->prefix().second,
516 __out = __i->format(__out, __fmt, __fmt + __len, __flags);
517 __last = __i->suffix();
522 __out = std::copy(__last.first, __last.second, __out);
527 template<
typename _Bi_iter,
534 if (_M_pregex ==
nullptr && __rhs._M_pregex ==
nullptr)
536 return _M_pregex == __rhs._M_pregex
537 && _M_begin == __rhs._M_begin
538 && _M_end == __rhs._M_end
539 && _M_flags == __rhs._M_flags
540 && _M_match[0] == __rhs._M_match[0];
543 template<
typename _Bi_iter,
556 if (_M_match[0].matched)
558 auto __start = _M_match[0].second;
559 auto __prefix_first = _M_match[0].second;
560 if (_M_match[0].first == _M_match[0].second)
562 if (__start == _M_end)
574 __glibcxx_assert(_M_match[0].matched);
575 auto& __prefix = _M_match._M_prefix();
576 __prefix.first = __prefix_first;
577 __prefix.matched = __prefix.first != __prefix.second;
579 _M_match._M_begin = _M_begin;
587 if (
regex_search(__start, _M_end, _M_match, *_M_pregex, _M_flags))
589 __glibcxx_assert(_M_match[0].matched);
590 auto& __prefix = _M_match._M_prefix();
591 __prefix.first = __prefix_first;
592 __prefix.matched = __prefix.first != __prefix.second;
594 _M_match._M_begin = _M_begin;
602 template<
typename _Bi_iter,
609 _M_position = __rhs._M_position;
610 _M_subs = __rhs._M_subs;
612 _M_suffix = __rhs._M_suffix;
613 _M_has_m1 = __rhs._M_has_m1;
614 _M_normalize_result();
618 template<
typename _Bi_iter,
625 if (_M_end_of_seq() && __rhs._M_end_of_seq())
627 if (_M_suffix.matched && __rhs._M_suffix.matched
628 && _M_suffix == __rhs._M_suffix)
630 if (_M_end_of_seq() || _M_suffix.matched
631 || __rhs._M_end_of_seq() || __rhs._M_suffix.matched)
633 return _M_position == __rhs._M_position
634 && _M_n == __rhs._M_n
635 && _M_subs == __rhs._M_subs;
638 template<
typename _Bi_iter,
645 _Position __prev = _M_position;
646 if (_M_suffix.matched)
648 else if (_M_n + 1 < _M_subs.size())
651 _M_result = &_M_current_match();
657 if (_M_position != _Position())
658 _M_result = &_M_current_match();
659 else if (_M_has_m1 && __prev->suffix().length() != 0)
661 _M_suffix.matched =
true;
662 _M_suffix.first = __prev->suffix().first;
663 _M_suffix.second = __prev->suffix().second;
664 _M_result = &_M_suffix;
672 template<
typename _Bi_iter,
677 _M_init(_Bi_iter __a, _Bi_iter __b)
680 for (
auto __it : _M_subs)
686 if (_M_position != _Position())
687 _M_result = &_M_current_match();
690 _M_suffix.matched =
true;
691 _M_suffix.first = __a;
692 _M_suffix.second = __b;
693 _M_result = &_M_suffix;
699_GLIBCXX_END_NAMESPACE_VERSION
const _Facet & use_facet(const locale &__loc)
Return a facet.
bool regex_search(_Bi_iter __s, _Bi_iter __e, match_results< _Bi_iter, _Alloc > &__m, const basic_regex< _Ch_type, _Rx_traits > &__re, regex_constants::match_flag_type __flags=regex_constants::match_default)
ISO C++ entities toplevel namespace is std.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
Implementation details not part of the namespace std interface.
constexpr syntax_option_type __polynomial
constexpr match_flag_type format_first_only
constexpr match_flag_type match_continuous
match_flag_type
This is a bitmask type indicating regex matching rules.
constexpr match_flag_type match_prev_avail
constexpr match_flag_type format_sed
constexpr match_flag_type match_not_null
constexpr match_flag_type format_no_copy
Primary class template ctype facet.
_Out_iter format(_Out_iter __out, const char_type *__fmt_first, const char_type *__fmt_last, match_flag_type __flags=regex_constants::format_default) const
Takes a regex and an input string and does the matching.
Describes aspects of a regular expression.
regex_traits()
Constructs a default traits object.
int value(_Ch_type __ch, int __radix) const
Converts a digit to an int.
string_type lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const
Gets a collation element by name.
locale_type getloc() const
Gets a copy of the current locale in use by the regex_traits object.
bool isctype(_Ch_type __c, char_class_type __f) const
Determines if c is a member of an identified class.
char_class_type lookup_classname(_Fwd_iter __first, _Fwd_iter __last, bool __icase=false) const
Maps one or more characters to a named character classification.
regex_iterator()=default
Provides a singular iterator, useful for indicating one-past-the-end of a range.
bool operator==(const regex_iterator &) const noexcept
Tests the equivalence of two regex iterators.
regex_iterator & operator++()
Increments a regex_iterator.
bool operator==(const regex_token_iterator &__rhs) const
Compares a regex_token_iterator to another for equality.
regex_token_iterator & operator=(const regex_token_iterator &__rhs)
Assigns a regex_token_iterator to another.
regex_token_iterator & operator++()
Increments a regex_token_iterator.
regex_token_iterator()
Default constructs a regex_token_iterator.
Struct holding two objects of arbitrary type.