1 #if defined(PERL_EXT_RE_DEBUG) && !defined(DEBUGGING)
5 #define PERL_NO_GET_CONTEXT
14 extern REGEXP* my_re_compile (pTHX_ const SV * const pattern, U32 pm_flags);
15 extern I32 my_regexec (pTHX_ REGEXP * const 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 * const 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 * const prog);
24 extern void my_regfree (pTHX_ REGEXP * const r);
25 extern void my_reg_numbered_buff_get(pTHX_ REGEXP * const rx, const I32 paren,
27 extern SV* my_reg_named_buff_get(pTHX_ REGEXP * const rx, SV * const namesv,
29 extern SV* my_reg_qr_package(pTHX_ REGEXP * const rx);
30 #if defined(USE_ITHREADS)
31 extern void* my_regdupe (pTHX_ REGEXP * const r, CLONE_PARAMS *param);
34 EXTERN_C const struct regexp_engine my_reg_engine;
38 const struct regexp_engine my_reg_engine = {
44 my_reg_numbered_buff_get,
45 my_reg_named_buff_get,
47 #if defined(USE_ITHREADS)
53 get_re_arg( pTHX_ SV *sv, U32 flags, MAGIC **mgp) {
59 (sv = (SV*)SvRV(sv)) && /* assign deliberate */
60 SvTYPE(sv) == SVt_PVMG &&
61 (mg = mg_find(sv, PERL_MAGIC_qr))) /* assign deliberate */
64 return (REGEXP *)mg->mg_obj;
68 return ((flags && PL_curpm) ? PM_GETRE(PL_curpm) : NULL);
71 MODULE = re PACKAGE = re
76 PL_colorset = 0; /* Allow reinspection of ENV. */
77 /* PL_debug |= DEBUG_r_FLAG; */
78 XPUSHs(sv_2mortal(newSViv(PTR2IV(&my_reg_engine))));
91 Checks if a reference is a regex or not. If the parameter is
92 not a ref, or is not the result of a qr// then returns false
93 in scalar context and an empty list in list context.
94 Otherwise in list context it returns the pattern and the
95 modifiers, in scalar context it returns the pattern just as it
96 would if the qr// was stringified normally, regardless as
97 to the class of the variable and any strigification overloads
101 if ( re = get_re_arg( aTHX_ sv, 0, &mg) ) /* assign deliberate */
103 /* Housten, we have a regex! */
109 if ( GIMME_V == G_ARRAY ) {
111 we are in list context so stringify
112 the modifiers that apply. We ignore "negative
113 modifiers" in this scenario.
116 char *fptr = INT_PAT_MODS;
118 U16 match_flags = (U16)((re->extflags & PMf_COMPILETIME) >> 12);
120 while((ch = *fptr++)) {
121 if(match_flags & 1) {
122 reflags[left++] = ch;
127 pattern = sv_2mortal(newSVpvn(re->precomp,re->prelen));
128 if (re->extflags & RXf_UTF8) SvUTF8_on(pattern);
130 /* return the pattern and the modifiers */
132 XPUSHs(sv_2mortal(newSVpvn(reflags,left)));
135 /* Scalar, so use the string that Perl would return */
136 /* return the pattern in (?msix:..) format */
137 pattern = sv_2mortal(newSVpvn(re->wrapped,re->wraplen));
138 if (re->extflags & RXf_UTF8)
144 /* It ain't a regexp folks */
145 if ( GIMME_V == G_ARRAY ) {
146 /* return the empty list */
149 /* Because of the (?:..) wrapping involved in a
150 stringified pattern it is impossible to get a
151 result for a real regexp that would evaluate to
152 false. Therefore we can return PL_sv_no to signify
153 that the object is not a regex, this means that one
156 if (regex($might_be_a_regex) eq '(?:foo)') { }
158 and not worry about undefined values.
175 if ( re = get_re_arg( aTHX_ sv, 0, 0) ) /* assign deliberate */
179 if (re->anchored_substr) {
180 an = newSVsv(re->anchored_substr);
181 } else if (re->anchored_utf8) {
182 an = newSVsv(re->anchored_utf8);
184 if (re->float_substr) {
185 fl = newSVsv(re->float_substr);
186 } else if (re->float_utf8) {
187 fl = newSVsv(re->float_utf8);