@@ -1681,6 +1681,8 @@ enum class _Rx_unwind_ops {
16811681 _Loop_nongreedy,
16821682 _Loop_greedy,
16831683 _Loop_restore_vals,
1684+ _Capture_restore_begin,
1685+ _Capture_restore_end
16841686};
16851687
16861688template <class _BidIt>
@@ -1689,7 +1691,7 @@ public:
16891691 _Rx_unwind_ops _Code;
16901692 int _Loop_idx_sav;
16911693 _Node_base* _Node;
1692- _Tgt_state_t <_BidIt> _Match_state;
1694+ _Bt_state_t <_BidIt> _Match_state;
16931695 size_t _Loop_frame_idx_sav;
16941696};
16951697
@@ -3946,7 +3948,10 @@ bool _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Match_pat(_Node_base* _N
39463948 { // record current position
39473949 _Node_capture* _Node = static_cast<_Node_capture*>(_Nx);
39483950 if (_Node->_Idx != 0U) {
3949- _Tgt_state._Grps[_Node->_Idx]._Begin = _Tgt_state._Cur;
3951+ auto& _Group = _Tgt_state._Grps[_Node->_Idx];
3952+ auto _Frame_idx = _Push_frame(_Rx_unwind_ops::_Capture_restore_begin, _Node);
3953+ _Frames[_Frame_idx]._Match_state._Cur = _Group._Begin;
3954+ _Group._Begin = _Tgt_state._Cur;
39503955 }
39513956 break;
39523957 }
@@ -3956,8 +3961,11 @@ bool _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Match_pat(_Node_base* _N
39563961 _Node_end_group* _Node = static_cast<_Node_end_group*>(_Nx);
39573962 _Node_capture* _Node0 = static_cast<_Node_capture*>(_Node->_Back);
39583963 if (_Node0->_Idx != 0U) { // update capture data
3959- _Tgt_state._Grp_valid[_Node0->_Idx] = true;
3960- _Tgt_state._Grps[_Node0->_Idx]._End = _Tgt_state._Cur;
3964+ auto& _Group = _Tgt_state._Grps[_Node0->_Idx];
3965+ auto _Frame_idx = _Push_frame(_Rx_unwind_ops::_Capture_restore_end, _Node0);
3966+ _Frames[_Frame_idx]._Match_state._Cur = _Group._End;
3967+ _Tgt_state._Grp_valid[_Node0->_Idx] = true;
3968+ _Group._End = _Tgt_state._Cur;
39613969 }
39623970 break;
39633971 }
@@ -4325,6 +4333,20 @@ bool _Matcher3<_BidIt, _Elem, _RxTraits, _It, _Alloc>::_Match_pat(_Node_base* _N
43254333 }
43264334 break;
43274335
4336+ case _Rx_unwind_ops::_Capture_restore_begin:
4337+ { // restore begin of capturing group
4338+ auto _Node = static_cast<_Node_capture*>(_Frame._Node);
4339+ _Tgt_state._Grps[_Node->_Idx]._Begin = _Frame._Match_state._Cur;
4340+ }
4341+ break;
4342+
4343+ case _Rx_unwind_ops::_Capture_restore_end:
4344+ { // restore end of capturing group
4345+ auto _Node = static_cast<_Node_capture*>(_Frame._Node);
4346+ _Tgt_state._Grps[_Node->_Idx]._End = _Frame._Match_state._Cur;
4347+ }
4348+ break;
4349+
43284350 default:
43294351#if _ITERATOR_DEBUG_LEVEL != 0
43304352 _STL_REPORT_ERROR("internal stack of regex matcher corrupted");
0 commit comments