1 #if defined(PERL_EXT_RE_DEBUG) && !defined(DEBUGGING)
5 #define PERL_NO_GET_CONTEXT
14 extern regexp* my_regcomp (pTHX_ char* exp, char* xend, PMOP* pm);
15 extern regexp* my_re_compile(pTHX_ char *exp, char *xend, PMOP *pm);
16 extern I32 my_regexec (pTHX_ regexp* prog, char* stringarg, char* strend,
17 char* strbeg, I32 minend, SV* screamer,
18 void* data, U32 flags);
20 extern char* my_re_intuit_start (pTHX_ regexp *prog, SV *sv, char *strpos,
21 char *strend, U32 flags,
22 struct re_scream_pos_data_s *data);
23 extern SV* my_re_intuit_string (pTHX_ regexp *prog);
25 extern void my_regfree (pTHX_ struct regexp* r);
26 #if defined(USE_ITHREADS)
27 extern regexp* my_regdupe (pTHX_ const regexp *r, CLONE_PARAMS *param);
30 EXTERN_C const struct regexp_engine my_reg_engine;
34 const struct regexp_engine my_reg_engine = {
41 #if defined(USE_ITHREADS)
46 MODULE = re PACKAGE = re
51 PL_colorset = 0; /* Allow reinspection of ENV. */
52 /* PL_debug |= DEBUG_r_FLAG; */
53 XPUSHs(sv_2mortal(newSViv(PTR2IV(&my_reg_engine))));
67 (sv = (SV*)SvRV(sv)) && /* assign deliberate */
68 SvTYPE(sv) == SVt_PVMG &&
69 (mg = mg_find(sv, PERL_MAGIC_qr))) /* assign deliberate */
87 Checks if a reference is a regex or not. If the parameter is
88 not a ref, or is not the result of a qr// then returns false
89 in scalar context and an empty list in list context.
90 Otherwise in list context it returns the pattern and the
91 modifiers, in scalar context it returns the pattern just as it
92 would if the qr// was stringified normally, regardless as
93 to the class of the variable and any strigification overloads
100 (sv = (SV*)SvRV(sv)) && /* assign deliberate */
101 SvTYPE(sv) == SVt_PVMG &&
102 (mg = mg_find(sv, PERL_MAGIC_qr))) /* assign deliberate */
105 /* Housten, we have a regex! */
107 regexp *re = (regexp *)mg->mg_obj;
112 if ( GIMME_V == G_ARRAY ) {
114 we are in list context so stringify
115 the modifiers that apply. We ignore "negative
116 modifiers" in this scenario.
121 U16 match_flags = (U16)((re->extflags & PMf_COMPILETIME) >> 12);
123 while((ch = *fptr++)) {
124 if(match_flags & 1) {
125 reflags[left++] = ch;
130 pattern = sv_2mortal(newSVpvn(re->precomp,re->prelen));
131 if (re->extflags & RXf_UTF8) SvUTF8_on(pattern);
133 /* return the pattern and the modifiers */
135 XPUSHs(sv_2mortal(newSVpvn(reflags,left)));
138 /* Scalar, so use the string that Perl would return */
140 CALLREG_STRINGIFY(mg,0,0);
142 /* return the pattern in (?msix:..) format */
143 pattern = sv_2mortal(newSVpvn(mg->mg_ptr,mg->mg_len));
144 if (re->extflags & RXf_UTF8)
150 /* It ain't a regexp folks */
151 if ( GIMME_V == G_ARRAY ) {
152 /* return the empty list */
155 /* Because of the (?:..) wrapping involved in a
156 stringified pattern it is impossible to get a
157 result for a real regexp that would evaluate to
158 false. Therefore we can return PL_sv_no to signify
159 that the object is not a regex, this means that one
162 if (regex($might_be_a_regex) eq '(?:foo)') { }
164 and not worry about undefined values.
184 (sv = (SV*)SvRV(sv)) && /* assign deliberate */
185 SvTYPE(sv) == SVt_PVMG &&
186 (mg = mg_find(sv, PERL_MAGIC_qr))) /* assign deliberate */
190 regexp *re = (regexp *)mg->mg_obj;
191 if (re->anchored_substr) {
192 an = newSVsv(re->anchored_substr);
193 } else if (re->anchored_utf8) {
194 an = newSVsv(re->anchored_utf8);
196 if (re->float_substr) {
197 fl = newSVsv(re->float_substr);
198 } else if (re->float_utf8) {
199 fl = newSVsv(re->float_utf8);