38 namespace std _GLIBCXX_VISIBILITY(default)
42 _GLIBCXX_BEGIN_NAMESPACE_VERSION
50 template<
typename _BiIter,
typename _Alloc,
51 typename _CharT,
typename _TraitsT,
52 _RegexExecutorPolicy __policy,
55 __regex_algo_impl(_BiIter __s,
57 match_results<_BiIter, _Alloc>& __m,
58 const basic_regex<_CharT, _TraitsT>& __re,
61 if (__re._M_automaton ==
nullptr)
64 typename match_results<_BiIter, _Alloc>::_Base_type& __res = __m;
66 __m._M_resize(__re._M_automaton->_M_sub_count());
67 for (
auto& __it : __res)
74 if (!__re._M_automaton->_M_has_backref
76 #ifndef _GLIBCXX_REGEX_USE_THOMPSON_NFA 77 && __policy == _RegexExecutorPolicy::_S_alternate
81 _Executor<_BiIter, _Alloc, _TraitsT, false>
82 __executor(__s, __e, __m, __re, __flags);
84 __ret = __executor._M_match();
86 __ret = __executor._M_search();
90 _Executor<_BiIter, _Alloc, _TraitsT, true>
91 __executor(__s, __e, __m, __re, __flags);
93 __ret = __executor._M_match();
95 __ret = __executor._M_search();
99 for (
auto& __it : __res)
101 __it.first = __it.second = __e;
102 auto& __pre = __m._M_prefix();
103 auto& __suf = __m._M_suffix();
106 __pre.matched =
false;
109 __suf.matched =
false;
116 __pre.second = __res[0].first;
117 __pre.matched = (__pre.first != __pre.second);
118 __suf.first = __res[0].second;
120 __suf.matched = (__suf.first != __suf.second);
126 for (
auto& __it : __res)
128 __it.matched =
false;
129 __it.first = __it.second = __e;
135 _GLIBCXX_END_NAMESPACE_VERSION
138 _GLIBCXX_BEGIN_NAMESPACE_VERSION
140 template<
typename _Ch_type>
141 template<
typename _Fwd_iter>
142 typename regex_traits<_Ch_type>::string_type
147 const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale));
149 static const char* __collatenames[] =
242 "left-square-bracket",
244 "right-square-bracket",
274 "left-curly-bracket",
276 "right-curly-bracket",
282 for (; __first != __last; ++__first)
283 __s += __fctyp.narrow(*__first, 0);
285 for (
const auto& __it : __collatenames)
288 static_cast<char>(&__it - __collatenames)));
296 template<
typename _Ch_type>
297 template<
typename _Fwd_iter>
298 typename regex_traits<_Ch_type>::char_class_type
303 const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale));
308 {
"d", ctype_base::digit},
309 {
"w", {ctype_base::alnum, _RegexMask::_S_under}},
310 {
"s", ctype_base::space},
311 {
"alnum", ctype_base::alnum},
312 {
"alpha", ctype_base::alpha},
313 {
"blank", ctype_base::blank},
314 {
"cntrl", ctype_base::cntrl},
315 {
"digit", ctype_base::digit},
316 {
"graph", ctype_base::graph},
317 {
"lower", ctype_base::lower},
318 {
"print", ctype_base::print},
319 {
"punct", ctype_base::punct},
320 {
"space", ctype_base::space},
321 {
"upper", ctype_base::upper},
322 {
"xdigit", ctype_base::xdigit},
326 for (; __first != __last; ++__first)
327 __s += __fctyp.narrow(__fctyp.tolower(*__first), 0);
329 for (
const auto& __it : __classnames)
330 if (__s == __it.first)
334 & (ctype_base::lower | ctype_base::upper)) != 0))
335 return ctype_base::alpha;
341 template<
typename _Ch_type>
344 isctype(_Ch_type __c, char_class_type __f)
const 347 const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale));
349 return __fctyp.is(__f._M_base, __c)
351 || ((__f._M_extended & _RegexMask::_S_under)
352 && __c == __fctyp.widen(
'_'));
355 template<
typename _Ch_type>
358 value(_Ch_type __ch,
int __radix)
const 364 else if (__radix == 16)
367 return __is.
fail() ? -1 : __v;
370 template<
typename _Bi_iter,
typename _Alloc>
371 template<
typename _Out_iter>
374 const match_results<_Bi_iter, _Alloc>::char_type* __fmt_first,
375 const match_results<_Bi_iter, _Alloc>::char_type* __fmt_last,
378 _GLIBCXX_DEBUG_ASSERT( ready() );
382 __fctyp(use_facet<__ctype_type>(__traits.
getloc()));
384 auto __output = [&](
size_t __idx)
386 auto& __sub = (*this)[__idx];
388 __out = std::copy(__sub.first, __sub.second, __out);
393 for (; __fmt_first != __fmt_last;)
394 if (*__fmt_first ==
'&')
399 else if (*__fmt_first ==
'\\')
401 if (++__fmt_first != __fmt_last
402 && __fctyp.is(__ctype_type::digit, *__fmt_first))
403 __output(__traits.
value(*__fmt_first++, 10));
408 *__out++ = *__fmt_first++;
414 auto __next = std::find(__fmt_first, __fmt_last,
'$');
415 if (__next == __fmt_last)
418 __out = std::copy(__fmt_first, __next, __out);
420 auto __eat = [&](
char __ch) ->
bool 430 if (++__next == __fmt_last)
438 auto& __sub = _M_prefix();
440 __out = std::copy(__sub.first, __sub.second, __out);
442 else if (__eat(
'\''))
444 auto& __sub = _M_suffix();
446 __out = std::copy(__sub.first, __sub.second, __out);
448 else if (__fctyp.is(__ctype_type::digit, *__next))
450 long __num = __traits.
value(*__next, 10);
451 if (++__next != __fmt_last
452 && __fctyp.is(__ctype_type::digit, *__next))
455 __num += __traits.
value(*__next++, 10);
457 if (0 <= __num && __num < this->size())
462 __fmt_first = __next;
464 __out = std::copy(__fmt_first, __fmt_last, __out);
469 template<
typename _Out_iter,
typename _Bi_iter,
470 typename _Rx_traits,
typename _Ch_type>
474 const _Ch_type* __fmt,
478 _IterT __i(__first, __last, __e, __flags);
483 __out = std::copy(__first, __last, __out);
489 for (; __i != __end; ++__i)
492 __out = std::copy(__i->prefix().first, __i->prefix().second,
494 __out = __i->format(__out, __fmt, __fmt + __len, __flags);
495 __last = __i->suffix();
500 __out = std::copy(__last.
first, __last.
second, __out);
505 template<
typename _Bi_iter,
512 return (_M_match.empty() && __rhs._M_match.
empty())
513 || (_M_begin == __rhs._M_begin
514 && _M_end == __rhs._M_end
515 && _M_pregex == __rhs._M_pregex
516 && _M_flags == __rhs._M_flags
517 && _M_match[0] == __rhs._M_match[0]);
520 template<
typename _Bi_iter,
533 if (_M_match[0].matched)
535 auto __start = _M_match[0].second;
536 auto __prefix_first = _M_match[0].second;
537 if (_M_match[0].first == _M_match[0].second)
539 if (__start == _M_end)
551 _GLIBCXX_DEBUG_ASSERT(_M_match[0].matched);
552 auto& __prefix = _M_match._M_prefix();
553 __prefix.first = __prefix_first;
554 __prefix.matched = __prefix.first != __prefix.second;
556 _M_match._M_begin = _M_begin;
564 if (
regex_search(__start, _M_end, _M_match, *_M_pregex, _M_flags))
566 _GLIBCXX_DEBUG_ASSERT(_M_match[0].matched);
567 auto& __prefix = _M_match._M_prefix();
568 __prefix.first = __prefix_first;
569 __prefix.matched = __prefix.first != __prefix.second;
571 _M_match._M_begin = _M_begin;
579 template<
typename _Bi_iter,
586 _M_position = __rhs._M_position;
587 _M_subs = __rhs._M_subs;
589 _M_suffix = __rhs._M_suffix;
590 _M_has_m1 = __rhs._M_has_m1;
591 _M_normalize_result();
595 template<
typename _Bi_iter,
602 if (_M_end_of_seq() && __rhs._M_end_of_seq())
604 if (_M_suffix.matched && __rhs._M_suffix.matched
605 && _M_suffix == __rhs._M_suffix)
607 if (_M_end_of_seq() || _M_suffix.matched
608 || __rhs._M_end_of_seq() || __rhs._M_suffix.matched)
610 return _M_position == __rhs._M_position
611 && _M_n == __rhs._M_n
612 && _M_subs == __rhs._M_subs;
615 template<
typename _Bi_iter,
622 _Position __prev = _M_position;
623 if (_M_suffix.matched)
625 else if (_M_n + 1 < _M_subs.size())
628 _M_result = &_M_current_match();
634 if (_M_position != _Position())
635 _M_result = &_M_current_match();
636 else if (_M_has_m1 && __prev->suffix().length() != 0)
638 _M_suffix.matched =
true;
639 _M_suffix.first = __prev->suffix().first;
640 _M_suffix.second = __prev->suffix().second;
641 _M_result = &_M_suffix;
649 template<
typename _Bi_iter,
654 _M_init(_Bi_iter __a, _Bi_iter __b)
657 for (
auto __it : _M_subs)
663 if (_M_position != _Position())
664 _M_result = &_M_current_match();
667 _M_suffix.matched =
true;
668 _M_suffix.first = __a;
669 _M_suffix.second = __b;
670 _M_result = &_M_suffix;
676 _GLIBCXX_END_NAMESPACE_VERSION
ios_base & hex(ios_base &__base)
Calls base.setf(ios_base::hex, ios_base::basefield).
constexpr match_flag_type match_prev_avail
bool empty() const
Indicates if the match_results contains no results.
Basis for explicit traits specializations.
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.
regex_token_iterator & operator++()
Increments a regex_token_iterator.
bool fail() const
Fast error checking.
regex_token_iterator & operator=(const regex_token_iterator &__rhs)
Assigns a regex_token_iterator to another.
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.
locale_type getloc() const
Gets a copy of the current locale in use by the regex_traits object.
_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
Managing sequences of characters and character-like objects.
constexpr match_flag_type format_no_copy
bool isctype(_Ch_type __c, char_class_type __f) const
Determines if c is a member of an identified class.
ios_base & oct(ios_base &__base)
Calls base.setf(ios_base::oct, ios_base::basefield).
constexpr match_flag_type format_sed
Describes aspects of a regular expression.
bool operator==(const regex_token_iterator &__rhs) const
Compares a regex_token_iterator to another for equality.
_Out_iter regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last, const basic_regex< _Ch_type, _Rx_traits > &__e, const basic_string< _Ch_type, _St, _Sa > &__fmt, regex_constants::match_flag_type __flags=regex_constants::match_default)
Search for a regular expression within a range for multiple times, and replace the matched parts thro...
Controlling input for std::string.
regex_iterator & operator++()
Increments a regex_iterator.
bool operator==(const regex_iterator &__rhs) const
Tests the equivalence of two regex iterators.
Primary class template ctype facet.This template class defines classification and conversion function...
match_flag_type
This is a bitmask type indicating regex matching rules.
_T2 second
first is a copy of the first object
constexpr syntax_option_type ECMAScript
Struct holding two objects of arbitrary type.
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)
_T1 first
second_type is the second bound type
ISO C++ entities toplevel namespace is std.
constexpr match_flag_type format_first_only
constexpr match_flag_type match_not_null
constexpr match_flag_type match_continuous