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 I32 my_regexec (pTHX_ regexp* prog, char* stringarg, char* strend,
16 char* strbeg, I32 minend, SV* screamer,
17 void* data, U32 flags);
18 extern void my_regfree (pTHX_ struct regexp* r);
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);
23 extern char* my_reg_stringify (pTHX_ MAGIC *mg, STRLEN *lp, U32 *flags, I32 *haseval);
25 #if defined(USE_ITHREADS)
26 extern regexp* 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 = {
40 #if defined(USE_ITHREADS)
45 MODULE = re PACKAGE = re
50 PL_colorset = 0; /* Allow reinspection of ENV. */
51 /* PL_debug |= DEBUG_r_FLAG; */
52 XPUSHs(sv_2mortal(newSViv(PTR2IV(&my_reg_engine))));
66 (sv = (SV*)SvRV(sv)) && /* assign deliberate */
67 SvTYPE(sv) == SVt_PVMG &&
68 (mg = mg_find(sv, PERL_MAGIC_qr))) /* assign deliberate */
86 Checks if a reference is a regex or not. If the parameter is
87 not a ref, or is not the result of a qr// then returns false
88 in scalar context and an empty list in list context.
89 Otherwise in list context it returns the pattern and the
90 modifiers, in scalar context it returns the pattern just as it
91 would if the qr// was stringified normally, regardless as
92 to the class of the variable and any strigification overloads
99 (sv = (SV*)SvRV(sv)) && /* assign deliberate */
100 SvTYPE(sv) == SVt_PVMG &&
101 (mg = mg_find(sv, PERL_MAGIC_qr))) /* assign deliberate */
104 /* Housten, we have a regex! */
106 regexp *re = (regexp *)mg->mg_obj;
111 if ( GIMME_V == G_ARRAY ) {
113 we are in list context so stringify
114 the modifiers that apply. We ignore "negative
115 modifiers" in this scenario.
120 U16 match_flags = (U16)((re->extflags & PMf_COMPILETIME) >> 12);
122 while((ch = *fptr++)) {
123 if(match_flags & 1) {
124 reflags[left++] = ch;
129 pattern = sv_2mortal(newSVpvn(re->precomp,re->prelen));
130 if (re->extflags & RXf_UTF8) SvUTF8_on(pattern);
132 /* return the pattern and the modifiers */
134 XPUSHs(sv_2mortal(newSVpvn(reflags,left)));
137 /* Scalar, so use the string that Perl would return */
139 CALLREG_STRINGIFY(mg,0,0);
141 /* return the pattern in (?msix:..) format */
142 pattern = sv_2mortal(newSVpvn(mg->mg_ptr,mg->mg_len));
143 if (re->extflags & RXf_UTF8)
149 /* It ain't a regexp folks */
150 if ( GIMME_V == G_ARRAY ) {
151 /* return the empty list */
154 /* Because of the (?:..) wrapping involved in a
155 stringified pattern it is impossible to get a
156 result for a real regexp that would evaluate to
157 false. Therefore we can return PL_sv_no to signify
158 that the object is not a regex, this means that one
161 if (regex($might_be_a_regex) eq '(?:foo)') { }
163 and not worry about undefined values.
183 (sv = (SV*)SvRV(sv)) && /* assign deliberate */
184 SvTYPE(sv) == SVt_PVMG &&
185 (mg = mg_find(sv, PERL_MAGIC_qr))) /* assign deliberate */
189 regexp *re = (regexp *)mg->mg_obj;
190 if (re->anchored_substr) {
191 an = newSVsv(re->anchored_substr);
192 } else if (re->anchored_utf8) {
193 an = newSVsv(re->anchored_utf8);
195 if (re->float_substr) {
196 fl = newSVsv(re->float_substr);
197 } else if (re->float_utf8) {
198 fl = newSVsv(re->float_utf8);