This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move Tie::Hash::NamedCapture::{FIRST,NEXT}KEY to NamedCapture.xs
[perl5.git] / ext / Tie-Hash-NamedCapture / NamedCapture.xs
CommitLineData
8cf6f931
NC
1#include "EXTERN.h"
2#include "perl.h"
3#include "XSUB.h"
4
5MODULE = Tie::Hash::NamedCapture PACKAGE = Tie::Hash::NamedCapture
6PROTOTYPES: DISABLE
7
8void
610f2345
NC
9FIRSTKEY(...)
10 ALIAS:
11 Tie::Hash::NamedCapture::NEXTKEY = 1
12 PREINIT:
13 REGEXP *const rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
14 U32 flags;
15 SV *ret;
16 const int expect = ix ? 2 : 1;
17 const U32 action = ix ? RXapif_NEXTKEY : RXapif_FIRSTKEY;
18 PPCODE:
19 if (items != expect)
20 croak_xs_usage(cv, expect == 2 ? "$lastkey" : "");
21
22 if (!rx || !SvROK(ST(0)))
23 XSRETURN_UNDEF;
24
25 flags = (U32)SvUV(SvRV(MUTABLE_SV(ST(0))));
26
27 PUTBACK;
28 ret = RX_ENGINE(rx)->named_buff_iter(aTHX_ (rx),
29 expect >= 2 ? ST(1) : NULL,
30 flags | action);
31 SPAGAIN;
32
33 PUSHs(ret ? sv_2mortal(ret) : &PL_sv_undef);
34
35void
8cf6f931
NC
36flags(...)
37 PPCODE:
38 EXTEND(SP, 2);
39 mPUSHu(RXapif_ONE);
40 mPUSHu(RXapif_ALL);
41