31 namespace std _GLIBCXX_VISIBILITY(default)
33 _GLIBCXX_BEGIN_NAMESPACE_VERSION
45 template<
typename _BiIter,
typename _Alloc,
46 typename _CharT,
typename _TraitsT,
47 _RegexExecutorPolicy __policy,
50 __regex_algo_impl(_BiIter __s,
52 match_results<_BiIter, _Alloc>& __m,
53 const basic_regex<_CharT, _TraitsT>& __re,
56 if (__re._M_automaton ==
nullptr)
59 typename match_results<_BiIter, _Alloc>::_Base_type& __res = __m;
61 __m._M_resize(__re._M_automaton->_M_sub_count());
65 || (__policy == _RegexExecutorPolicy::_S_alternate
66 && !__re._M_automaton->_M_has_backref))
68 _Executor<_BiIter, _Alloc, _TraitsT, false>
69 __executor(__s, __e, __m, __re, __flags);
71 __ret = __executor._M_match();
73 __ret = __executor._M_search();
77 _Executor<_BiIter, _Alloc, _TraitsT, true>
78 __executor(__s, __e, __m, __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);
121 template<
typename _Ch_type>
122 template<
typename _Fwd_iter>
123 typename regex_traits<_Ch_type>::string_type
128 const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale));
130 static const char* __collatenames[] =
223 "left-square-bracket",
225 "right-square-bracket",
255 "left-curly-bracket",
257 "right-curly-bracket",
263 for (; __first != __last; ++__first)
264 __s += __fctyp.narrow(*__first, 0);
266 for (
const auto& __it : __collatenames)
268 return string_type(1, __fctyp.widen(
269 static_cast<char>(&__it - __collatenames)));
274 return string_type();
277 template<
typename _Ch_type>
278 template<
typename _Fwd_iter>
279 typename regex_traits<_Ch_type>::char_class_type
284 const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale));
287 static const pair<const char*, char_class_type> __classnames[] =
289 {
"d", ctype_base::digit},
290 {
"w", {ctype_base::alnum, _RegexMask::_S_under}},
291 {
"s", ctype_base::space},
292 {
"alnum", ctype_base::alnum},
293 {
"alpha", ctype_base::alpha},
294 {
"blank", ctype_base::blank},
295 {
"cntrl", ctype_base::cntrl},
296 {
"digit", ctype_base::digit},
297 {
"graph", ctype_base::graph},
298 {
"lower", ctype_base::lower},
299 {
"print", ctype_base::print},
300 {
"punct", ctype_base::punct},
301 {
"space", ctype_base::space},
302 {
"upper", ctype_base::upper},
303 {
"xdigit", ctype_base::xdigit},
307 for (; __first != __last; ++__first)
308 __s += __fctyp.narrow(__fctyp.tolower(*__first), 0);
310 for (
const auto& __it : __classnames)
311 if (__s == __it.first)
315 & (ctype_base::lower | ctype_base::upper)) != 0))
316 return ctype_base::alpha;
322 template<
typename _Ch_type>
325 isctype(_Ch_type __c, char_class_type __f)
const
328 const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale));
330 return __fctyp.is(__f._M_base, __c)
332 || ((__f._M_extended & _RegexMask::_S_under)
333 && __c == __fctyp.widen(
'_'));
336 template<
typename _Ch_type>
339 value(_Ch_type __ch,
int __radix)
const
345 else if (__radix == 16)
348 return __is.fail() ? -1 : __v;
351 template<
typename _Bi_iter,
typename _Alloc>
352 template<
typename _Out_iter>
356 const match_results<_Bi_iter, _Alloc>::char_type* __fmt_first,
357 const match_results<_Bi_iter, _Alloc>::char_type* __fmt_last,
360 __glibcxx_assert( ready() );
361 regex_traits<char_type> __traits;
364 __fctyp(use_facet<__ctype_type>(__traits.getloc()));
366 auto __output = [&](
size_t __idx)
368 auto& __sub = (*this)[__idx];
370 __out = std::copy(__sub.first, __sub.second, __out);
375 bool __escaping =
false;
376 for (; __fmt_first != __fmt_last; __fmt_first++)
381 if (__fctyp.is(__ctype_type::digit, *__fmt_first))
382 __output(__traits.value(*__fmt_first, 10));
384 *__out++ = *__fmt_first;
387 if (*__fmt_first ==
'\\')
392 if (*__fmt_first ==
'&')
397 *__out++ = *__fmt_first;
406 auto __next = std::find(__fmt_first, __fmt_last,
'$');
407 if (__next == __fmt_last)
410 __out = std::copy(__fmt_first, __next, __out);
412 auto __eat = [&](
char __ch) ->
bool
422 if (++__next == __fmt_last)
430 auto& __sub = _M_prefix();
432 __out = std::copy(__sub.first, __sub.second, __out);
434 else if (__eat(
'\''))
436 auto& __sub = _M_suffix();
438 __out = std::copy(__sub.first, __sub.second, __out);
440 else if (__fctyp.is(__ctype_type::digit, *__next))
442 long __num = __traits.value(*__next, 10);
443 if (++__next != __fmt_last
444 && __fctyp.is(__ctype_type::digit, *__next))
447 __num += __traits.value(*__next++, 10);
449 if (0 <= __num && __num < this->size())
454 __fmt_first = __next;
456 __out = std::copy(__fmt_first, __fmt_last, __out);
461 template<
typename _Out_iter,
typename _Bi_iter,
462 typename _Rx_traits,
typename _Ch_type>
464 regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
465 const basic_regex<_Ch_type, _Rx_traits>& __e,
466 const _Ch_type* __fmt,
469 typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> _IterT;
470 _IterT __i(__first, __last, __e, __flags);
475 __out = std::copy(__first, __last, __out);
479 sub_match<_Bi_iter> __last;
480 auto __len = char_traits<_Ch_type>::length(__fmt);
481 for (; __i != __end; ++__i)
484 __out = std::copy(__i->prefix().first, __i->prefix().second,
486 __out = __i->format(__out, __fmt, __fmt + __len, __flags);
487 __last = __i->suffix();
492 __out = std::copy(__last.first, __last.second, __out);
497 template<
typename _Bi_iter,
502 operator==(
const regex_iterator& __rhs)
const noexcept
504 if (_M_pregex ==
nullptr && __rhs._M_pregex ==
nullptr)
506 return _M_pregex == __rhs._M_pregex
507 && _M_begin == __rhs._M_begin
508 && _M_end == __rhs._M_end
509 && _M_flags == __rhs._M_flags
510 && _M_match[0] == __rhs._M_match[0];
513 template<
typename _Bi_iter,
516 regex_iterator<_Bi_iter, _Ch_type, _Rx_traits>&
526 if (_M_match[0].matched)
528 auto __start = _M_match[0].second;
529 auto __prefix_first = _M_match[0].second;
530 if (_M_match[0].first == _M_match[0].second)
532 if (__start == _M_end)
544 __glibcxx_assert(_M_match[0].matched);
545 auto& __prefix = _M_match._M_prefix();
546 __prefix.first = __prefix_first;
547 __prefix.matched = __prefix.first != __prefix.second;
549 _M_match._M_begin = _M_begin;
557 if (
regex_search(__start, _M_end, _M_match, *_M_pregex, _M_flags))
559 __glibcxx_assert(_M_match[0].matched);
560 auto& __prefix = _M_match._M_prefix();
561 __prefix.first = __prefix_first;
562 __prefix.matched = __prefix.first != __prefix.second;
564 _M_match._M_begin = _M_begin;
572 template<
typename _Bi_iter,
575 regex_token_iterator<_Bi_iter, _Ch_type, _Rx_traits>&
577 operator=(
const regex_token_iterator& __rhs)
579 _M_position = __rhs._M_position;
580 _M_subs = __rhs._M_subs;
582 _M_suffix = __rhs._M_suffix;
583 _M_has_m1 = __rhs._M_has_m1;
584 _M_normalize_result();
588 template<
typename _Bi_iter,
593 operator==(
const regex_token_iterator& __rhs)
const
595 if (_M_end_of_seq() && __rhs._M_end_of_seq())
597 if (_M_suffix.matched && __rhs._M_suffix.matched
598 && _M_suffix == __rhs._M_suffix)
600 if (_M_end_of_seq() || _M_suffix.matched
601 || __rhs._M_end_of_seq() || __rhs._M_suffix.matched)
603 return _M_position == __rhs._M_position
604 && _M_n == __rhs._M_n
605 && _M_subs == __rhs._M_subs;
608 template<
typename _Bi_iter,
611 regex_token_iterator<_Bi_iter, _Ch_type, _Rx_traits>&
615 _Position __prev = _M_position;
616 if (_M_suffix.matched)
617 *
this = regex_token_iterator();
618 else if (_M_n + 1 < _M_subs.size())
621 _M_result = &_M_current_match();
627 if (_M_position != _Position())
628 _M_result = &_M_current_match();
629 else if (_M_has_m1 && __prev->suffix().length() != 0)
631 _M_suffix.matched =
true;
632 _M_suffix.first = __prev->suffix().first;
633 _M_suffix.second = __prev->suffix().second;
634 _M_result = &_M_suffix;
637 *
this = regex_token_iterator();
642 template<
typename _Bi_iter,
646 regex_token_iterator<_Bi_iter, _Ch_type, _Rx_traits>::
647 _M_init(_Bi_iter __a, _Bi_iter __b)
650 for (
auto __it : _M_subs)
656 if (_M_position != _Position())
657 _M_result = &_M_current_match();
660 _M_suffix.matched =
true;
661 _M_suffix.first = __a;
662 _M_suffix.second = __b;
663 _M_result = &_M_suffix;
671 _GLIBCXX_END_NAMESPACE_VERSION
_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...
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.
ios_base & oct(ios_base &__base)
Calls base.setf(ios_base::oct, ios_base::basefield).
ios_base & hex(ios_base &__base)
Calls base.setf(ios_base::hex, ios_base::basefield).
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
Controlling input for std::string.
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
string_type lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const
Gets a collation element by name.
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.
int value(_Ch_type __ch, int __radix) const
Converts a digit to an int.
bool isctype(_Ch_type __c, char_class_type __f) const
Determines if c is a member of an identified class.
regex_iterator & operator++()
Increments a regex_iterator.
bool operator==(const regex_iterator &) const noexcept
Tests the equivalence of two regex iterators.
bool operator==(const regex_token_iterator &__rhs) const
Compares a regex_token_iterator to another for equality.
regex_token_iterator & operator++()
Increments a regex_token_iterator.
regex_token_iterator & operator=(const regex_token_iterator &__rhs)
Assigns a regex_token_iterator to another.