diff options
author | Nicholas Clark <nick@ccl4.org> | 2010-10-14 10:24:45 +0100 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2010-10-14 14:34:27 +0100 |
commit | 015db559459b868f19c1cf27c13a231443eab9b7 (patch) | |
tree | dc6fadb2f9f709bc530ac5694ba7de40e6f72f52 /universal.c | |
parent | 606c5d14753b06846c2cc98166e8bc2dc8cb27fd (diff) | |
download | perl-015db559459b868f19c1cf27c13a231443eab9b7.tar.gz |
Merge XS_Tie_Hash_NamedCapture_SCALAR into S_named_capture_common.
Diffstat (limited to 'universal.c')
-rw-r--r-- | universal.c | 37 |
1 files changed, 8 insertions, 29 deletions
diff --git a/universal.c b/universal.c index cbdca0d780..f543a85e3c 100644 --- a/universal.c +++ b/universal.c @@ -1255,7 +1255,7 @@ XS(XS_re_regexp_pattern) } static void -S_named_capture_common(pTHX_ CV *const cv, const U32 action) +S_named_capture_common(pTHX_ CV *const cv, const int expect, const U32 action) { dVAR; dXSARGS; @@ -1263,8 +1263,8 @@ S_named_capture_common(pTHX_ CV *const cv, const U32 action) U32 flags; SV * ret; - if (items != 2) - croak_xs_usage(cv, "$key"); + if (items != expect) + croak_xs_usage(cv, expect == 2 ? "$key" : ""); rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL; @@ -1275,7 +1275,8 @@ S_named_capture_common(pTHX_ CV *const cv, const U32 action) PUTBACK; flags = (U32)SvUV(SvRV(MUTABLE_SV(ST(0)))); - ret = RX_ENGINE(rx)->named_buff(aTHX_ (rx), ST(1), NULL, flags | action); + ret = RX_ENGINE(rx)->named_buff(aTHX_ (rx), expect >= 2 ? ST(1) : NULL, + NULL, flags | action); SPAGAIN; PUSHs(ret ? sv_2mortal(ret) : &PL_sv_undef); @@ -1284,7 +1285,7 @@ S_named_capture_common(pTHX_ CV *const cv, const U32 action) XS(XS_Tie_Hash_NamedCapture_FETCH) { - S_named_capture_common(aTHX_ cv, RXapif_FETCH); + S_named_capture_common(aTHX_ cv, 2, RXapif_FETCH); } XS(XS_Tie_Hash_NamedCapture_STORE) @@ -1376,7 +1377,7 @@ XS(XS_Tie_Hash_NamedCapture_CLEAR) XS(XS_Tie_Hash_NamedCapture_EXISTS) { - S_named_capture_common(aTHX_ cv, RXapif_EXISTS); + S_named_capture_common(aTHX_ cv, 2, RXapif_EXISTS); } XS(XS_Tie_Hash_NamedCapture_FIRSTK) @@ -1435,29 +1436,7 @@ XS(XS_Tie_Hash_NamedCapture_NEXTK) XS(XS_Tie_Hash_NamedCapture_SCALAR) { - 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(aTHX_ (rx), NULL, NULL, flags | RXapif_SCALAR); - - SPAGAIN; - PUSHs(ret ? sv_2mortal(ret) : &PL_sv_undef); - XSRETURN(1); + S_named_capture_common(aTHX_ cv, 1, RXapif_SCALAR); } XS(XS_Tie_Hash_NamedCapture_flags) |