diff --git a/stl/inc/regex b/stl/inc/regex index 163c263b43..79fa577afb 100644 --- a/stl/inc/regex +++ b/stl/inc/regex @@ -2190,7 +2190,7 @@ public: return true; } - _BidIt _Skip(_BidIt, _BidIt, _Node_base* = nullptr, unsigned int _Recursion_depth = 0U); + _It _Skip(_It _First, _It _Last, const _Node_base* _Node_arg = nullptr, unsigned int _Recursion_depth = 0U); private: _Tgt_state_type _Tgt_state; @@ -2210,7 +2210,7 @@ private: void _Prepare_rep(_Node_rep*); bool _Find_first_inner_capture_group(_Node_base*, _Loop_vals_type*); void _Reset_capture_groups(unsigned int _First); - _It _Do_class(_Node_base*, _It); + _It _Do_class(const _Node_base*, _It); bool _Match_pat(_Node_base*); bool _Better_match(); bool _Is_wbound() const; @@ -4095,7 +4095,7 @@ _BidIt _Lookup_coll2(_Elem _First_ch, _BidIt _First, const _BidIt _Last, const _ } template -_It _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Do_class(_Node_base* _Nx, _It _First) { +_It _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Do_class(const _Node_base* const _Nx, _It _First) { // apply bracket expression bool _Found; _Elem _Ch = *_First; @@ -4109,7 +4109,7 @@ _It _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Do_class(_Node_base* _Nx, _It _Res0 = _First; ++_Res0; _It _Resx; - _Node_class<_Elem, _RxTraits>* _Node = static_cast<_Node_class<_Elem, _RxTraits>*>(_Nx); + const auto _Node = static_cast*>(_Nx); if (_Node->_Coll && (_Resx = _STD _Lookup_coll2(_Ch, _First, _End, _Node->_Coll, _Traits, _Sflags)) != _First) { // check for collation element @@ -4851,17 +4851,17 @@ bool _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Match_pat(_Node_base* _N } template -_BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( - _BidIt _First_arg, _BidIt _Last, _Node_base* _Node_arg, unsigned int _Recursion_depth) { +_It _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( + _It _First, const _It _Last, const _Node_base* const _Node_arg, const unsigned int _Recursion_depth) { // skip until possible match - // assumes --_First_arg is valid + // assumes --_First is valid static constexpr char _Line_terminators_char[] = {static_cast(_Meta_cr), static_cast(_Meta_nl)}; static constexpr wchar_t _Line_terminators_wchar_t[] = {static_cast(_Meta_cr), static_cast(_Meta_nl), static_cast(_Meta_ls), static_cast(_Meta_ps)}; constexpr unsigned int _Max_recursion_depth = 50U; - _Node_base* _Nx = _Node_arg ? _Node_arg : _Start; + const _Node_base* _Nx = _Node_arg ? _Node_arg : _Start; - while (_First_arg != _Last && _Nx) { // check current node + while (_First != _Last && _Nx) { // check current node switch (_Nx->_Kind) { // handle current node's type case _N_nop: break; @@ -4870,25 +4870,24 @@ _BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( if (_Sflags & regex_constants::multiline) { // multiline mode: check for embedded line terminator // return iterator to character just after the newline; for input like "\nabc" - // matching "^abc", _First_arg could be pointing at 'a', so we need to check - // --_First_arg for '\n' - if (!_STD _Is_ecmascript_line_terminator(*_STD _Prev_iter(_First_arg))) { + // matching "^abc", _First could be pointing at 'a', so we need to check --_First for '\n' + if (!_STD _Is_ecmascript_line_terminator(*_STD _Prev_iter(_First))) { if constexpr (sizeof(_Elem) == 1) { - _First_arg = _STD find_first_of( - _First_arg, _Last, _Line_terminators_char, _STD end(_Line_terminators_char)); + _First = + _STD find_first_of(_First, _Last, _Line_terminators_char, _STD end(_Line_terminators_char)); } else { - _First_arg = _STD find_first_of( - _First_arg, _Last, _Line_terminators_wchar_t, _STD end(_Line_terminators_wchar_t)); + _First = _STD find_first_of( + _First, _Last, _Line_terminators_wchar_t, _STD end(_Line_terminators_wchar_t)); } - if (_First_arg != _Last) { - ++_First_arg; + if (_First != _Last) { + ++_First; } } - return _First_arg; + return _First; } else { - // non-multiline mode: never matches because --_First_arg is valid + // non-multiline mode: never matches because --_First is valid return _Last; } @@ -4896,11 +4895,10 @@ _BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( if (_Sflags & regex_constants::multiline) { // multiline mode: matches at next line terminator or end of input if constexpr (sizeof(_Elem) == 1) { - return _STD find_first_of( - _First_arg, _Last, _Line_terminators_char, _STD end(_Line_terminators_char)); + return _STD find_first_of(_First, _Last, _Line_terminators_char, _STD end(_Line_terminators_char)); } else { return _STD find_first_of( - _First_arg, _Last, _Line_terminators_wchar_t, _STD end(_Line_terminators_wchar_t)); + _First, _Last, _Line_terminators_wchar_t, _STD end(_Line_terminators_wchar_t)); } } else { return _Last; // non-multiline mode: matches at end of input or not at all @@ -4908,23 +4906,22 @@ _BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( case _N_str: { // check for string match - _Node_str<_Elem>* _Node = static_cast<_Node_str<_Elem>*>(_Nx); - auto _Str = _Node->_Data._Str(); - return _STD _Search_translate_left( - _First_arg, _Last, _Str, _Str + _Node->_Data._Size(), _Traits, _Sflags); + const auto _Node = static_cast*>(_Nx); + const auto _Str = _Node->_Data._Str(); + return _STD _Search_translate_left(_First, _Last, _Str, _Str + _Node->_Data._Size(), _Traits, _Sflags); } case _N_class: { // check for string match - _Node_class<_Elem, _RxTraits>* _Node = static_cast<_Node_class<_Elem, _RxTraits>*>(_Nx); + const auto _Node = static_cast*>(_Nx); - for (; _First_arg != _Last; ++_First_arg) { // look for starting match - if (_Do_class(_Node, _First_arg) != _First_arg) { - return _First_arg; + for (; _First != _Last; ++_First) { // look for starting match + if (_Do_class(_Node, _First) != _First) { + return _First; } } } - return _First_arg; + return _First; case _N_group: break; @@ -4950,19 +4947,19 @@ _BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( // TRANSITION, ABI: After GH-5539, the parser no longer generates single-branch _N_if nodes. // But we have to retain this special handling to avoid performance regression // when an old parser gets mixed with a new matcher. - _Node_if* _Node = static_cast<_Node_if*>(_Nx); + const auto _Node = static_cast(_Nx); if (_Node->_Child) { - return _First_arg; + return _First; } break; } case _N_rep: { - _Node_rep* _Node = static_cast<_Node_rep*>(_Nx); + const auto _Node = static_cast(_Nx); if (_Node->_Min == 0) { - return _First_arg; + return _First; } break; } @@ -4970,21 +4967,21 @@ _BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( case _N_assert: { if (_Recursion_depth >= _Max_recursion_depth) { - return _First_arg; + return _First; } - _Node_assert* _Node = static_cast<_Node_assert*>(_Nx); - _First_arg = _Skip(_First_arg, _Last, _Node->_Child, _Recursion_depth + 1U); + const auto _Node = static_cast(_Nx); + _First = _Skip(_First, _Last, _Node->_Child, _Recursion_depth + 1U); _BidIt _Next; for (;;) { - _Next = _Skip(_First_arg, _Last, _Node->_Next, _Recursion_depth + 1U); - if (_Next == _First_arg) { - return _First_arg; + _Next = _Skip(_First, _Last, _Node->_Next, _Recursion_depth + 1U); + if (_Next == _First) { + return _First; } - _First_arg = _Skip(_Next, _Last, _Node->_Child, _Recursion_depth + 1U); - if (_Next == _First_arg) { - return _First_arg; + _First = _Skip(_Next, _Last, _Node->_Child, _Recursion_depth + 1U); + if (_Next == _First) { + return _First; } } } @@ -4995,16 +4992,16 @@ _BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( case _N_wbound: { - bool _Negated = (_Nx->_Flags & _Fl_negate) != 0; - bool _Prev_word = _STD _Is_word(*_STD _Prev_iter(_First_arg)); - for (; _First_arg != _Last; ++_First_arg) { - bool _Next_word = _STD _Is_word(*_First_arg); + const bool _Negated = (_Nx->_Flags & _Fl_negate) != 0; + bool _Prev_word = _STD _Is_word(*_STD _Prev_iter(_First)); + for (; _First != _Last; ++_First) { + const bool _Next_word = _STD _Is_word(*_First); if (_Negated == (_Next_word == _Prev_word)) { break; } _Prev_word = _Next_word; } - return _First_arg; + return _First; } case _N_begin: @@ -5017,13 +5014,13 @@ _BidIt _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Skip( case _N_back: case _N_end_rep: default: - return _First_arg; + return _First; } if (_Nx) { _Nx = _Nx->_Next; } } - return _First_arg; + return _First; } template