Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 49 additions & 52 deletions stl/inc/regex
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -4095,7 +4095,7 @@ _BidIt _Lookup_coll2(_Elem _First_ch, _BidIt _First, const _BidIt _Last, const _
}

template <class _BidIt, class _Elem, class _RxTraits, class _It, class _Alloc>
_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;
Expand All @@ -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<const _Node_class<_Elem, _RxTraits>*>(_Nx);
if (_Node->_Coll
&& (_Resx = _STD _Lookup_coll2(_Ch, _First, _End, _Node->_Coll, _Traits, _Sflags))
!= _First) { // check for collation element
Expand Down Expand Up @@ -4851,17 +4851,17 @@ bool _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Match_pat(_Node_base* _N
}

template <class _BidIt, class _Elem, class _RxTraits, class _It, class _Alloc>
_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<char>(_Meta_cr), static_cast<char>(_Meta_nl)};
static constexpr wchar_t _Line_terminators_wchar_t[] = {static_cast<wchar_t>(_Meta_cr),
static_cast<wchar_t>(_Meta_nl), static_cast<wchar_t>(_Meta_ls), static_cast<wchar_t>(_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;
Expand All @@ -4870,61 +4870,58 @@ _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;
}

case _N_eol:
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
}

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<const _Node_str<_Elem>*>(_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<const _Node_class<_Elem, _RxTraits>*>(_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;
Expand All @@ -4950,41 +4947,41 @@ _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<const _Node_if*>(_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<const _Node_rep*>(_Nx);
if (_Node->_Min == 0) {
return _First_arg;
return _First;
}
break;
}

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<const _Node_assert*>(_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;
}
}
}
Expand All @@ -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:
Expand All @@ -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 <class _FwdIt, class _Elem, class _RxTraits>
Expand Down