1 #if defined(PERL_EXT_RE_DEBUG) && !defined(DEBUGGING)
5 #define PERL_NO_GET_CONTEXT
14 extern regexp* my_re_compile (pTHX_ char* exp, char* xend, PMOP* pm);
15 extern I32 my_regexec (pTHX_ regexp* prog, char* stringarg, char* strend,
16 char* strbeg, I32 minend, SV* screamer,
17 void* data, U32 flags);
19 extern char* my_re_intuit_start (pTHX_ regexp *prog, SV *sv, char *strpos,
20 char *strend, U32 flags,
21 struct re_scream_pos_data_s *data);
22 extern SV* my_re_intuit_string (pTHX_ regexp *prog);
24 extern void my_regfree (pTHX_ struct regexp* r);
25 #if defined(USE_ITHREADS)
26 extern void* my_regdupe (pTHX_ const regexp *r, CLONE_PARAMS *param);
29 EXTERN_C const struct regexp_engine my_reg_engine;
33 const struct regexp_engine my_reg_engine = {
39 #if defined(USE_ITHREADS)
44 MODULE = re PACKAGE = re
49 PL_colorset = 0; /* Allow reinspection of ENV. */
50 /* PL_debug |= DEBUG_r_FLAG; */
51 XPUSHs(sv_2mortal(newSViv(PTR2IV(&my_reg_engine))));
65 (sv = (SV*)SvRV(sv)) && /* assign deliberate */
66 SvTYPE(sv) == SVt_PVMG &&
67 (mg = mg_find(sv, PERL_MAGIC_qr))) /* assign deliberate */
85 Checks if a reference is a regex or not. If the parameter is
86 not a ref, or is not the result of a qr// then returns false
87 in scalar context and an empty list in list context.
88 Otherwise in list context it returns the pattern and the
89 modifiers, in scalar context it returns the pattern just as it
90 would if the qr// was stringified normally, regardless as
91 to the class of the variable and any strigification overloads
98 (sv = (SV*)SvRV(sv)) && /* assign deliberate */
99 SvTYPE(sv) == SVt_PVMG &&
100 (mg = mg_find(sv, PERL_MAGIC_qr))) /* assign deliberate */
103 /* Housten, we have a regex! */
105 regexp *re = (regexp *)mg->mg_obj;
110 if ( GIMME_V == G_ARRAY ) {
112 we are in list context so stringify
113 the modifiers that apply. We ignore "negative
114 modifiers" in this scenario.
119 U16 match_flags = (U16)((re->extflags & PMf_COMPILETIME) >> 12);
121 while((ch = *fptr++)) {
122 if(match_flags & 1) {
123 reflags[left++] = ch;
128 pattern = sv_2mortal(newSVpvn(re->precomp,re->prelen));
129 if (re->extflags & RXf_UTF8) SvUTF8_on(pattern);
131 /* return the pattern and the modifiers */
133 XPUSHs(sv_2mortal(newSVpvn(reflags,left)));
136 /* Scalar, so use the string that Perl would return */
138 CALLREG_STRINGIFY(mg,0,0);
140 /* return the pattern in (?msix:..) format */
141 pattern = sv_2mortal(newSVpvn(mg->mg_ptr,mg->mg_len));
142 if (re->extflags & RXf_UTF8)
148 /* It ain't a regexp folks */
149 if ( GIMME_V == G_ARRAY ) {
150 /* return the empty list */
153 /* Because of the (?:..) wrapping involved in a
154 stringified pattern it is impossible to get a
155 result for a real regexp that would evaluate to
156 false. Therefore we can return PL_sv_no to signify
157 that the object is not a regex, this means that one
160 if (regex($might_be_a_regex) eq '(?:foo)') { }
162 and not worry about undefined values.
182 (sv = (SV*)SvRV(sv)) && /* assign deliberate */
183 SvTYPE(sv) == SVt_PVMG &&
184 (mg = mg_find(sv, PERL_MAGIC_qr))) /* assign deliberate */
188 regexp *re = (regexp *)mg->mg_obj;
189 if (re->anchored_substr) {
190 an = newSVsv(re->anchored_substr);
191 } else if (re->anchored_utf8) {
192 an = newSVsv(re->anchored_utf8);
194 if (re->float_substr) {
195 fl = newSVsv(re->float_substr);
196 } else if (re->float_utf8) {
197 fl = newSVsv(re->float_utf8);