-static void
-S_named_capture_common(pTHX_ CV *const cv, const bool fatal, const int expect,
- const bool discard, const U32 action)
-{
- dVAR;
- dXSARGS;
- REGEXP * rx;
- U32 flags;
- SV * ret;
-
- if (items != expect)
- croak_xs_usage(cv, expect == 2 ? "$key"
- : (expect == 3 ? "$key, $value" : ""));
-
- rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
-
- if (!rx || !SvROK(ST(0))) {
- if (fatal)
- Perl_croak_no_modify(aTHX);
- else
- XSRETURN_UNDEF;
- }
-
- SP -= items;
- PUTBACK;
-
- flags = (U32)SvUV(SvRV(MUTABLE_SV(ST(0))));
- ret = RX_ENGINE(rx)->named_buff(aTHX_ (rx), expect >= 2 ? ST(1) : NULL,
- expect >= 3 ? ST(2) : NULL, flags | action);
-
- if (discard) {
- /* Called with G_DISCARD, so our return stack state is thrown away.
- Hence if we were returned anything, free it immediately. */
- SvREFCNT_dec(ret);
- XSRETURN_EMPTY;
- }
-
- SPAGAIN;
- PUSHs(ret ? sv_2mortal(ret) : &PL_sv_undef);
- XSRETURN(1);
-}
-
-XS(XS_Tie_Hash_NamedCapture_FETCH)
-{
- S_named_capture_common(aTHX_ cv, FALSE, 2, FALSE, RXapif_FETCH);
-}
-
-XS(XS_Tie_Hash_NamedCapture_STORE)
-{
- S_named_capture_common(aTHX_ cv, TRUE, 3, TRUE, RXapif_STORE);
-}
-
-XS(XS_Tie_Hash_NamedCapture_DELETE)
-{
- S_named_capture_common(aTHX_ cv, TRUE, 2, FALSE, RXapif_DELETE);
-}
-
-XS(XS_Tie_Hash_NamedCapture_CLEAR)
-{
- S_named_capture_common(aTHX_ cv, TRUE, 1, TRUE, RXapif_CLEAR);
-}
-
-XS(XS_Tie_Hash_NamedCapture_EXISTS)
-{
- S_named_capture_common(aTHX_ cv, FALSE, 2, FALSE, RXapif_EXISTS);
-}
-
-XS(XS_Tie_Hash_NamedCapture_FIRSTK)
-{
- dVAR;
- dXSARGS;
- REGEXP * rx;
- U32 flags;
- SV * ret;
-
- if (items != 1)
- croak_xs_usage(cv, "");
-
- rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
-
- if (!rx || !SvROK(ST(0)))
- XSRETURN_UNDEF;
-
- SP -= items;
- PUTBACK;
-
- flags = (U32)SvUV(SvRV(MUTABLE_SV(ST(0))));
- ret = RX_ENGINE(rx)->named_buff_iter(aTHX_ (rx), NULL, flags | RXapif_FIRSTKEY);
-
- SPAGAIN;
- PUSHs(ret ? sv_2mortal(ret) : &PL_sv_undef);
- XSRETURN(1);
-}
-
-XS(XS_Tie_Hash_NamedCapture_NEXTK)
-{
- dVAR;
- dXSARGS;
- REGEXP * rx;
- U32 flags;
- SV * ret;
-
- if (items != 2)
- croak_xs_usage(cv, "$lastkey");
-
- rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
-
- if (!rx || !SvROK(ST(0)))
- XSRETURN_UNDEF;
-
- SP -= items;
- PUTBACK;
-
- flags = (U32)SvUV(SvRV(MUTABLE_SV(ST(0))));
- ret = RX_ENGINE(rx)->named_buff_iter(aTHX_ (rx), ST(1), flags | RXapif_NEXTKEY);
-
- SPAGAIN;
- PUSHs(ret ? sv_2mortal(ret) : &PL_sv_undef);
- XSRETURN(1);
-}
-
-XS(XS_Tie_Hash_NamedCapture_SCALAR)
-{
- S_named_capture_common(aTHX_ cv, FALSE, 1, FALSE, RXapif_SCALAR);
-}
-
-XS(XS_Tie_Hash_NamedCapture_flags)
-{
- dVAR;
- dXSARGS;
-
- if (items != 0)
- croak_xs_usage(cv, "");
-
- mXPUSHu(RXapif_ONE);
- mXPUSHu(RXapif_ALL);
- PUTBACK;
- return;
-}
-