5 * "One Ring to rule them all, One Ring to find them..."
8 /* NOTE: this is derived from Henry Spencer's regexp code, and should not
9 * confused with the original package (see point 3 below). Thanks, Henry!
12 /* Additional note: this code is very heavily munged from Henry's version
13 * in places. In some spots I've traded clarity for efficiency, so don't
14 * blame Henry for some of the lack of readability.
17 /* The names of the functions have been changed from regcomp and
18 * regexec to pregcomp and pregexec in order to avoid conflicts
19 * with the POSIX routines of the same names.
22 #ifdef PERL_EXT_RE_BUILD
23 /* need to replace pregcomp et al, so enable that */
24 # ifndef PERL_IN_XSUB_RE
25 # define PERL_IN_XSUB_RE
27 /* need access to debugger hooks */
28 # if defined(PERL_EXT_RE_DEBUG) && !defined(DEBUGGING)
33 #ifdef PERL_IN_XSUB_RE
34 /* We *really* need to overwrite these symbols: */
35 # define Perl_regexec_flags my_regexec
36 # define Perl_regdump my_regdump
37 # define Perl_regprop my_regprop
38 # define Perl_re_intuit_start my_re_intuit_start
39 /* *These* symbols are masked to allow static link. */
40 # define Perl_pregexec my_pregexec
41 # define Perl_reginitcolors my_reginitcolors
43 # define PERL_NO_GET_CONTEXT
48 * pregcomp and pregexec -- regsub and regerror are not used in perl
50 * Copyright (c) 1986 by University of Toronto.
51 * Written by Henry Spencer. Not derived from licensed software.
53 * Permission is granted to anyone to use this software for any
54 * purpose on any computer system, and to redistribute it freely,
55 * subject to the following restrictions:
57 * 1. The author is not responsible for the consequences of use of
58 * this software, no matter how awful, even if they arise
61 * 2. The origin of this software must not be misrepresented, either
62 * by explicit claim or by omission.
64 * 3. Altered versions must be plainly marked as such, and must not
65 * be misrepresented as being the original software.
67 **** Alterations to Henry's code are...
69 **** Copyright (c) 1991-1999, Larry Wall
71 **** You may distribute under the terms of either the GNU General Public
72 **** License or the Artistic License, as specified in the README file.
74 * Beware that some of this code is subtly aware of the way operator
75 * precedence is structured in regular expressions. Serious changes in
76 * regular-expression syntax might require a total rethink.
79 #define PERL_IN_REGEXEC_C
82 #ifdef PERL_IN_XSUB_RE
83 # if defined(PERL_CAPI) || defined(PERL_OBJECT)
90 #define RF_tainted 1 /* tainted information used? */
91 #define RF_warned 2 /* warned about big count? */
92 #define RF_evaled 4 /* Did an EVAL with setting? */
93 #define RF_utf8 8 /* String contains multibyte chars? */
95 #define UTF (PL_reg_flags & RF_utf8)
97 #define RS_init 1 /* eval environment created */
98 #define RS_set 2 /* replsv value is set */
101 #define STATIC static
108 #define REGINCLASS(p,c) (ANYOF_FLAGS(p) ? reginclass(p,c) : ANYOF_BITMAP_TEST(p,c))
109 #define REGINCLASSUTF8(f,p) (ARG1(f) ? reginclassutf8(f,p) : swash_fetch((SV*)PL_regdata->data[ARG2(f)],p))
111 #define CHR_SVLEN(sv) (UTF ? sv_len_utf8(sv) : SvCUR(sv))
112 #define CHR_DIST(a,b) (UTF ? utf8_distance(a,b) : a - b)
114 #define reghop_c(pos,off) ((char*)reghop((U8*)pos, off))
115 #define reghopmaybe_c(pos,off) ((char*)reghopmaybe((U8*)pos, off))
116 #define HOP(pos,off) (UTF ? reghop((U8*)pos, off) : (U8*)(pos + off))
117 #define HOPMAYBE(pos,off) (UTF ? reghopmaybe((U8*)pos, off) : (U8*)(pos + off))
118 #define HOPc(pos,off) ((char*)HOP(pos,off))
119 #define HOPMAYBEc(pos,off) ((char*)HOPMAYBE(pos,off))
121 static void restore_pos(pTHXo_ void *arg);
125 S_regcppush(pTHX_ I32 parenfloor)
128 int retval = PL_savestack_ix;
129 int i = (PL_regsize - parenfloor) * 4;
133 for (p = PL_regsize; p > parenfloor; p--) {
134 SSPUSHINT(PL_regendp[p]);
135 SSPUSHINT(PL_regstartp[p]);
136 SSPUSHPTR(PL_reg_start_tmp[p]);
139 SSPUSHINT(PL_regsize);
140 SSPUSHINT(*PL_reglastparen);
141 SSPUSHPTR(PL_reginput);
143 SSPUSHINT(SAVEt_REGCONTEXT);
147 /* These are needed since we do not localize EVAL nodes: */
148 # define REGCP_SET DEBUG_r(PerlIO_printf(Perl_debug_log, \
149 " Setting an EVAL scope, savestack=%i\n", \
150 PL_savestack_ix)); lastcp = PL_savestack_ix
152 # define REGCP_UNWIND DEBUG_r(lastcp != PL_savestack_ix ? \
153 PerlIO_printf(Perl_debug_log, \
154 " Clearing an EVAL scope, savestack=%i..%i\n", \
155 lastcp, PL_savestack_ix) : 0); regcpblow(lastcp)
165 assert(i == SAVEt_REGCONTEXT);
167 input = (char *) SSPOPPTR;
168 *PL_reglastparen = SSPOPINT;
169 PL_regsize = SSPOPINT;
170 for (i -= 3; i > 0; i -= 4) {
171 paren = (U32)SSPOPINT;
172 PL_reg_start_tmp[paren] = (char *) SSPOPPTR;
173 PL_regstartp[paren] = SSPOPINT;
175 if (paren <= *PL_reglastparen)
176 PL_regendp[paren] = tmps;
178 PerlIO_printf(Perl_debug_log,
179 " restoring \\%d to %d(%d)..%d%s\n",
180 paren, PL_regstartp[paren],
181 PL_reg_start_tmp[paren] - PL_bostr,
183 (paren > *PL_reglastparen ? "(no)" : ""));
187 if (*PL_reglastparen + 1 <= PL_regnpar) {
188 PerlIO_printf(Perl_debug_log,
189 " restoring \\%d..\\%d to undef\n",
190 *PL_reglastparen + 1, PL_regnpar);
193 for (paren = *PL_reglastparen + 1; paren <= PL_regnpar; paren++) {
194 if (paren > PL_regsize)
195 PL_regstartp[paren] = -1;
196 PL_regendp[paren] = -1;
202 S_regcp_set_to(pTHX_ I32 ss)
205 I32 tmp = PL_savestack_ix;
207 PL_savestack_ix = ss;
209 PL_savestack_ix = tmp;
213 typedef struct re_cc_state
217 struct re_cc_state *prev;
222 #define regcpblow(cp) LEAVE_SCOPE(cp)
225 * pregexec and friends
229 - pregexec - match a regexp against a string
232 Perl_pregexec(pTHX_ register regexp *prog, char *stringarg, register char *strend,
233 char *strbeg, I32 minend, SV *screamer, U32 nosave)
234 /* strend: pointer to null at end of string */
235 /* strbeg: real beginning of string */
236 /* minend: end of match must be >=minend after stringarg. */
237 /* nosave: For optimizations. */
240 regexec_flags(prog, stringarg, strend, strbeg, minend, screamer, NULL,
241 nosave ? 0 : REXEC_COPY_STR);
245 S_cache_re(pTHX_ regexp *prog)
248 PL_regprecomp = prog->precomp; /* Needed for FAIL. */
250 PL_regprogram = prog->program;
252 PL_regnpar = prog->nparens;
253 PL_regdata = prog->data;
258 * Need to implement the following flags for reg_anch:
260 * USE_INTUIT_NOML - Useful to call re_intuit_start() first
262 * INTUIT_AUTORITATIVE_NOML - Can trust a positive answer
263 * INTUIT_AUTORITATIVE_ML
264 * INTUIT_ONCE_NOML - Intuit can match in one location only.
267 * Another flag for this function: SECOND_TIME (so that float substrs
268 * with giant delta may be not rechecked).
271 /* Assumptions: if ANCH_GPOS, then strpos is anchored. XXXX Check GPOS logic */
273 /* If SCREAM, then SvPVX(sv) should be compatible with strpos and strend.
274 Otherwise, only SvCUR(sv) is used to get strbeg. */
276 /* XXXX We assume that strpos is strbeg unless sv. */
278 /* A failure to find a constant substring means that there is no need to make
279 an expensive call to REx engine, thus we celebrate a failure. Similarly,
280 finding a substring too deep into the string means that less calls to
281 regtry() should be needed. */
284 Perl_re_intuit_start(pTHX_ regexp *prog, SV *sv, char *strpos,
285 char *strend, U32 flags, re_scream_pos_data *data)
287 register I32 start_shift;
288 /* Should be nonnegative! */
289 register I32 end_shift;
295 register char *other_last = Nullch;
297 DEBUG_r( if (!PL_colorset) reginitcolors() );
298 DEBUG_r(PerlIO_printf(Perl_debug_log,
299 "%sGuessing start of match, REx%s `%s%.60s%s%s' against `%s%.*s%s%s'...\n",
300 PL_colors[4],PL_colors[5],PL_colors[0],
303 (strlen(prog->precomp) > 60 ? "..." : ""),
305 (strend - strpos > 60 ? 60 : strend - strpos),
306 strpos, PL_colors[1],
307 (strend - strpos > 60 ? "..." : ""))
310 if (prog->minlen > strend - strpos) {
311 DEBUG_r(PerlIO_printf(Perl_debug_log, "String too short...\n"));
314 if (prog->reganch & ROPT_ANCH) { /* Match at beg-of-str or after \n */
315 ml_anch = !( (prog->reganch & ROPT_ANCH_SINGLE)
316 || ( (prog->reganch & ROPT_ANCH_BOL)
317 && !PL_multiline ) ); /* Check after \n? */
319 if ((prog->check_offset_min == prog->check_offset_max) && !ml_anch) {
320 /* Substring at constant offset from beg-of-str... */
323 if ( !(prog->reganch & ROPT_ANCH_GPOS) /* Checked by the caller */
324 && (sv && (strpos + SvCUR(sv) != strend)) ) {
325 DEBUG_r(PerlIO_printf(Perl_debug_log, "Not at start...\n"));
328 PL_regeol = strend; /* Used in HOP() */
329 s = HOPc(strpos, prog->check_offset_min);
330 if (SvTAIL(prog->check_substr)) {
331 slen = SvCUR(prog->check_substr); /* >= 1 */
333 if ( strend - s > slen || strend - s < slen - 1
334 || (strend - s == slen && strend[-1] != '\n')) {
335 DEBUG_r(PerlIO_printf(Perl_debug_log, "String too long...\n"));
338 /* Now should match s[0..slen-2] */
340 if (slen && (*SvPVX(prog->check_substr) != *s
342 && memNE(SvPVX(prog->check_substr), s, slen)))) {
344 DEBUG_r(PerlIO_printf(Perl_debug_log, "String not equal...\n"));
348 else if (*SvPVX(prog->check_substr) != *s
349 || ((slen = SvCUR(prog->check_substr)) > 1
350 && memNE(SvPVX(prog->check_substr), s, slen)))
352 goto success_at_start;
354 /* Match is anchored, but substr is not anchored wrt beg-of-str. */
356 start_shift = prog->check_offset_min; /* okay to underestimate on CC */
357 /* Should be nonnegative! */
358 end_shift = prog->minlen - start_shift -
359 CHR_SVLEN(prog->check_substr) + (SvTAIL(prog->check_substr) != 0);
361 I32 end = prog->check_offset_max + CHR_SVLEN(prog->check_substr)
362 - (SvTAIL(prog->check_substr) != 0);
363 I32 eshift = strend - s - end;
365 if (end_shift < eshift)
369 else { /* Can match at random position */
372 start_shift = prog->check_offset_min; /* okay to underestimate on CC */
373 /* Should be nonnegative! */
374 end_shift = prog->minlen - start_shift -
375 CHR_SVLEN(prog->check_substr) + (SvTAIL(prog->check_substr) != 0);
378 #ifdef DEBUGGING /* 7/99: reports of failure (with the older version) */
380 croak("panic: end_shift");
383 check = prog->check_substr;
385 /* Find a possible match in the region s..strend by looking for
386 the "check" substring in the region corrected by start/end_shift. */
387 if (flags & REXEC_SCREAM) {
388 char *strbeg = SvPVX(sv); /* XXXX Assume PV_force() on SCREAM! */
389 I32 p = -1; /* Internal iterator of scream. */
390 I32 *pp = data ? data->scream_pos : &p;
392 if (PL_screamfirst[BmRARE(check)] >= 0
393 || ( BmRARE(check) == '\n'
394 && (BmPREVIOUS(check) == SvCUR(check) - 1)
396 s = screaminstr(sv, check,
397 start_shift + (s - strbeg), end_shift, pp, 0);
401 *data->scream_olds = s;
404 s = fbm_instr((unsigned char*)s + start_shift,
405 (unsigned char*)strend - end_shift,
406 check, PL_multiline ? FBMrf_MULTILINE : 0);
408 /* Update the count-of-usability, remove useless subpatterns,
411 DEBUG_r(PerlIO_printf(Perl_debug_log, "%s %s substr `%s%.*s%s'%s%s",
412 (s ? "Found" : "Did not find"),
413 ((check == prog->anchored_substr) ? "anchored" : "floating"),
415 SvCUR(check) - (SvTAIL(check)!=0), SvPVX(check),
416 PL_colors[1], (SvTAIL(check) ? "$" : ""),
417 (s ? " at offset " : "...\n") ) );
422 /* Finish the diagnostic message */
423 DEBUG_r(PerlIO_printf(Perl_debug_log, "%ld...\n", (long)(s - strpos)) );
425 /* Got a candidate. Check MBOL anchoring, and the *other* substr.
426 Start with the other substr.
427 XXXX no SCREAM optimization yet - and a very coarse implementation
428 XXXX /ttx+/ results in anchored=`ttx', floating=`x'. floating will
429 *always* match. Probably should be marked during compile...
430 Probably it is right to do no SCREAM here...
433 if (prog->float_substr && prog->anchored_substr) {
434 /* Take into account the anchored substring. */
435 /* XXXX May be hopelessly wrong for UTF... */
437 other_last = strpos - 1;
438 if (check == prog->float_substr) {
439 char *last = s - start_shift, *last1, *last2;
443 t = s - prog->check_offset_max;
444 if (s - strpos > prog->check_offset_max /* signed-corrected t > strpos */
445 && (!(prog->reganch & ROPT_UTF8)
446 || (PL_bostr = strpos, /* Used in regcopmaybe() */
447 (t = reghopmaybe_c(s, -(prog->check_offset_max)))
452 t += prog->anchored_offset;
456 last2 = last1 = strend - prog->minlen;
459 /* XXXX It is not documented what units *_offsets are in. Assume bytes. */
460 /* On end-of-str: see comment below. */
461 s = fbm_instr((unsigned char*)t,
462 (unsigned char*)last1 + prog->anchored_offset
463 + SvCUR(prog->anchored_substr)
464 - (SvTAIL(prog->anchored_substr)!=0),
465 prog->anchored_substr, PL_multiline ? FBMrf_MULTILINE : 0);
466 DEBUG_r(PerlIO_printf(Perl_debug_log, "%s anchored substr `%s%.*s%s'%s",
467 (s ? "Found" : "Contradicts"),
469 SvCUR(prog->anchored_substr)
470 - (SvTAIL(prog->anchored_substr)!=0),
471 SvPVX(prog->anchored_substr),
472 PL_colors[1], (SvTAIL(prog->anchored_substr) ? "$" : "")));
474 if (last1 >= last2) {
475 DEBUG_r(PerlIO_printf(Perl_debug_log,
476 ", giving up...\n"));
479 DEBUG_r(PerlIO_printf(Perl_debug_log,
480 ", trying floating at offset %ld...\n",
481 (long)(s1 + 1 - strpos)));
482 PL_regeol = strend; /* Used in HOP() */
483 other_last = last1 + prog->anchored_offset;
488 DEBUG_r(PerlIO_printf(Perl_debug_log, " at offset %ld...\n",
489 (long)(s - strpos)));
490 t = s - prog->anchored_offset;
498 else { /* Take into account the floating substring. */
503 last1 = last = strend - prog->minlen + prog->float_min_offset;
504 if (last - t > prog->float_max_offset)
505 last = t + prog->float_max_offset;
506 s = t + prog->float_min_offset;
509 /* XXXX It is not documented what units *_offsets are in. Assume bytes. */
510 /* fbm_instr() takes into account exact value of end-of-str
511 if the check is SvTAIL(ed). Since false positives are OK,
512 and end-of-str is not later than strend we are OK. */
513 s = fbm_instr((unsigned char*)s,
514 (unsigned char*)last + SvCUR(prog->float_substr)
515 - (SvTAIL(prog->float_substr)!=0),
516 prog->float_substr, PL_multiline ? FBMrf_MULTILINE : 0);
517 DEBUG_r(PerlIO_printf(Perl_debug_log, "%s floating substr `%s%.*s%s'%s",
518 (s ? "Found" : "Contradicts"),
520 SvCUR(prog->float_substr)
521 - (SvTAIL(prog->float_substr)!=0),
522 SvPVX(prog->float_substr),
523 PL_colors[1], (SvTAIL(prog->float_substr) ? "$" : "")));
526 DEBUG_r(PerlIO_printf(Perl_debug_log,
527 ", giving up...\n"));
530 DEBUG_r(PerlIO_printf(Perl_debug_log,
531 ", trying anchored starting at offset %ld...\n",
532 (long)(s1 + 1 - strpos)));
534 PL_regeol = strend; /* Used in HOP() */
539 DEBUG_r(PerlIO_printf(Perl_debug_log, " at offset %ld...\n",
540 (long)(s - strpos)));
550 t = s - prog->check_offset_max;
552 if (s - strpos > prog->check_offset_max /* signed-corrected t > strpos */
553 && (!(prog->reganch & ROPT_UTF8)
554 || (PL_bostr = strpos, /* Used in regcopmaybe() */
555 ((t = reghopmaybe_c(s, -(prog->check_offset_max)))
558 /* Fixed substring is found far enough so that the match
559 cannot start at strpos. */
561 if (ml_anch && t[-1] != '\n') {
562 find_anchor: /* Eventually fbm_*() should handle this */
563 while (t < strend - prog->minlen) {
565 if (t < s - prog->check_offset_min) {
567 DEBUG_r(PerlIO_printf(Perl_debug_log, "Found /%s^%s/m at offset %ld...\n",
568 PL_colors[0],PL_colors[1], (long)(s - strpos)));
571 DEBUG_r(PerlIO_printf(Perl_debug_log, "Found /%s^%s/m, restarting at offset %ld...\n",
572 PL_colors[0],PL_colors[1], (long)(t + 1 - strpos)));
578 DEBUG_r(PerlIO_printf(Perl_debug_log, "Did not find /%s^%s/m...\n",
579 PL_colors[0],PL_colors[1]));
584 ++BmUSEFUL(prog->check_substr); /* hooray/5 */
588 /* The found string does not prohibit matching at beg-of-str
589 - no optimization of calling REx engine can be performed,
590 unless it was an MBOL and we are not after MBOL. */
592 /* Even in this situation we may use MBOL flag if strpos is offset
593 wrt the start of the string. */
595 && (strpos + SvCUR(sv) != strend) && strpos[-1] != '\n') {
600 if (!(prog->reganch & ROPT_NAUGHTY)
601 && --BmUSEFUL(prog->check_substr) < 0
602 && prog->check_substr == prog->float_substr) { /* boo */
603 /* If flags & SOMETHING - do not do it many times on the same match */
604 SvREFCNT_dec(prog->check_substr);
605 prog->check_substr = Nullsv; /* disable */
606 prog->float_substr = Nullsv; /* clear */
608 prog->reganch &= ~RE_USE_INTUIT;
614 DEBUG_r(PerlIO_printf(Perl_debug_log, "%sGuessed:%s match at offset %ld\n",
615 PL_colors[4], PL_colors[5], (long)(s - strpos)) );
618 fail_finish: /* Substring not found */
619 BmUSEFUL(prog->check_substr) += 5; /* hooray */
621 DEBUG_r(PerlIO_printf(Perl_debug_log, "%sMatch rejected by optimizer%s\n",
622 PL_colors[4],PL_colors[5]));
627 - regexec_flags - match a regexp against a string
630 Perl_regexec_flags(pTHX_ register regexp *prog, char *stringarg, register char *strend,
631 char *strbeg, I32 minend, SV *sv, void *data, U32 flags)
632 /* strend: pointer to null at end of string */
633 /* strbeg: real beginning of string */
634 /* minend: end of match must be >=minend after stringarg. */
635 /* data: May be used for some additional optimizations. */
636 /* nosave: For optimizations. */
641 register char *startpos = stringarg;
643 I32 minlen; /* must match at least this many chars */
644 I32 dontbother = 0; /* how many characters not to try at end */
646 I32 start_shift = 0; /* Offset of the start to find
647 constant substr. */ /* CC */
648 I32 end_shift = 0; /* Same for the end. */ /* CC */
649 I32 scream_pos = -1; /* Internal iterator of scream. */
651 SV* oreplsv = GvSV(PL_replgv);
659 PL_regnarrate = PL_debug & 512;
663 if (prog == NULL || startpos == NULL) {
664 Perl_croak(aTHX_ "NULL regexp parameter");
668 minlen = prog->minlen;
669 if (strend - startpos < minlen) goto phooey;
671 if (startpos == strbeg) /* is ^ valid at stringarg? */
674 PL_regprev = (U32)stringarg[-1];
675 if (!PL_multiline && PL_regprev == '\n')
676 PL_regprev = '\0'; /* force ^ to NOT match */
679 /* Check validity of program. */
680 if (UCHARAT(prog->program) != REG_MAGIC) {
681 Perl_croak(aTHX_ "corrupted regexp program");
688 if (prog->reganch & ROPT_UTF8)
689 PL_reg_flags |= RF_utf8;
691 /* Mark beginning of line for ^ and lookbehind. */
692 PL_regbol = startpos;
696 /* Mark end of line for $ (and such) */
699 /* see how far we have to get to not match where we matched before */
700 PL_regtill = startpos+minend;
702 /* We start without call_cc context. */
705 /* If there is a "must appear" string, look for it. */
708 if (prog->reganch & ROPT_GPOS_SEEN) {
711 if (!(flags & REXEC_IGNOREPOS) && sv && SvTYPE(sv) >= SVt_PVMG
712 && SvMAGIC(sv) && (mg = mg_find(sv, 'g')) && mg->mg_len >= 0)
713 PL_reg_ganch = strbeg + mg->mg_len;
715 PL_reg_ganch = startpos;
716 if (prog->reganch & ROPT_ANCH_GPOS) {
717 if (s > PL_reg_ganch)
723 if (!(flags & REXEC_CHECKED) && prog->check_substr != Nullsv) {
724 re_scream_pos_data d;
726 d.scream_olds = &scream_olds;
727 d.scream_pos = &scream_pos;
728 s = re_intuit_start(prog, sv, s, strend, flags, &d);
730 goto phooey; /* not present */
733 DEBUG_r( if (!PL_colorset) reginitcolors() );
734 DEBUG_r(PerlIO_printf(Perl_debug_log,
735 "%sMatching REx%s `%s%.60s%s%s' against `%s%.*s%s%s'\n",
736 PL_colors[4],PL_colors[5],PL_colors[0],
739 (strlen(prog->precomp) > 60 ? "..." : ""),
741 (strend - startpos > 60 ? 60 : strend - startpos),
742 startpos, PL_colors[1],
743 (strend - startpos > 60 ? "..." : ""))
746 /* Simplest case: anchored match need be tried only once. */
747 /* [unless only anchor is BOL and multiline is set] */
748 if (prog->reganch & (ROPT_ANCH & ~ROPT_ANCH_GPOS)) {
749 if (s == startpos && regtry(prog, startpos))
751 else if (PL_multiline || (prog->reganch & ROPT_IMPLICIT)
752 || (prog->reganch & ROPT_ANCH_MBOL)) /* XXXX SBOL? */
757 dontbother = minlen - 1;
758 end = HOPc(strend, -dontbother) - 1;
759 /* for multiline we only have to try after newlines */
760 if (prog->check_substr) {
766 s = re_intuit_start(prog, sv, s + 1, strend, flags, NULL);
774 if (*s++ == '\n') { /* don't need PL_utf8skip here */
782 } else if (prog->reganch & ROPT_ANCH_GPOS) {
783 if (regtry(prog, PL_reg_ganch))
788 /* Messy cases: unanchored match. */
789 if (prog->anchored_substr && prog->reganch & ROPT_SKIP) {
790 /* we have /x+whatever/ */
791 /* it must be a one character string (XXXX Except UTF?) */
792 char ch = SvPVX(prog->anchored_substr)[0];
796 if (regtry(prog, s)) goto got_it;
798 while (s < strend && *s == ch)
807 if (regtry(prog, s)) goto got_it;
809 while (s < strend && *s == ch)
817 else if (prog->anchored_substr != Nullsv
818 || (prog->float_substr != Nullsv
819 && prog->float_max_offset < strend - s)) {
820 SV *must = prog->anchored_substr
821 ? prog->anchored_substr : prog->float_substr;
823 prog->anchored_substr ? prog->anchored_offset : prog->float_max_offset;
825 prog->anchored_substr ? prog->anchored_offset : prog->float_min_offset;
826 I32 delta = back_max - back_min;
827 char *last = HOPc(strend, /* Cannot start after this */
828 -(I32)(CHR_SVLEN(must)
829 - (SvTAIL(must) != 0) + back_min));
830 char *last1; /* Last position checked before */
835 last1 = s - 1; /* bogus */
837 /* XXXX check_substr already used to find `s', can optimize if
838 check_substr==must. */
840 dontbother = end_shift;
841 strend = HOPc(strend, -dontbother);
842 while ( (s <= last) &&
843 ((flags & REXEC_SCREAM)
844 ? (s = screaminstr(sv, must, HOPc(s, back_min) - strbeg,
845 end_shift, &scream_pos, 0))
846 : (s = fbm_instr((unsigned char*)HOP(s, back_min),
847 (unsigned char*)strend, must,
848 PL_multiline ? FBMrf_MULTILINE : 0))) ) {
849 if (HOPc(s, -back_max) > last1) {
850 last1 = HOPc(s, -back_min);
851 s = HOPc(s, -back_max);
854 char *t = (last1 >= PL_bostr) ? HOPc(last1, 1) : last1 + 1;
856 last1 = HOPc(s, -back_min);
876 else if (c = prog->regstclass) {
877 I32 doevery = (prog->reganch & ROPT_SKIP) == 0;
881 dontbother = minlen - 1;
882 strend = HOPc(strend, -dontbother); /* don't bother with what can't match */
884 /* We know what class it must start with. */
887 cc = (char *) OPERAND(c);
889 if (REGINCLASSUTF8(c, (U8*)s)) {
890 if (tmp && regtry(prog, s))
901 cc = (char *) OPERAND(c);
903 if (REGINCLASS(cc, *s)) {
904 if (tmp && regtry(prog, s))
915 PL_reg_flags |= RF_tainted;
922 tmp = (s != startpos) ? UCHARAT(s - 1) : PL_regprev;
923 tmp = ((OP(c) == BOUND ? isALNUM(tmp) : isALNUM_LC(tmp)) != 0);
925 if (tmp == !(OP(c) == BOUND ? isALNUM(*s) : isALNUM_LC(*s))) {
932 if ((minlen || tmp) && regtry(prog,s))
936 PL_reg_flags |= RF_tainted;
941 strend = reghop_c(strend, -1);
943 tmp = (I32)(s != startpos) ? utf8_to_uv(reghop((U8*)s, -1), 0) : PL_regprev;
944 tmp = ((OP(c) == BOUND ? isALNUM_uni(tmp) : isALNUM_LC_uni(tmp)) != 0);
946 if (tmp == !(OP(c) == BOUND ?
947 swash_fetch(PL_utf8_alnum, (U8*)s) :
948 isALNUM_LC_utf8((U8*)s)))
956 if ((minlen || tmp) && regtry(prog,s))
960 PL_reg_flags |= RF_tainted;
967 tmp = (s != startpos) ? UCHARAT(s - 1) : PL_regprev;
968 tmp = ((OP(c) == NBOUND ? isALNUM(tmp) : isALNUM_LC(tmp)) != 0);
970 if (tmp == !(OP(c) == NBOUND ? isALNUM(*s) : isALNUM_LC(*s)))
972 else if (regtry(prog, s))
976 if ((minlen || !tmp) && regtry(prog,s))
980 PL_reg_flags |= RF_tainted;
985 strend = reghop_c(strend, -1);
987 tmp = (I32)(s != startpos) ? utf8_to_uv(reghop((U8*)s, -1), 0) : PL_regprev;
988 tmp = ((OP(c) == NBOUND ? isALNUM_uni(tmp) : isALNUM_LC_uni(tmp)) != 0);
990 if (tmp == !(OP(c) == NBOUND ?
991 swash_fetch(PL_utf8_alnum, (U8*)s) :
992 isALNUM_LC_utf8((U8*)s)))
994 else if (regtry(prog, s))
998 if ((minlen || !tmp) && regtry(prog,s))
1002 while (s < strend) {
1004 if (tmp && regtry(prog, s))
1015 while (s < strend) {
1016 if (swash_fetch(PL_utf8_alnum, (U8*)s)) {
1017 if (tmp && regtry(prog, s))
1028 PL_reg_flags |= RF_tainted;
1029 while (s < strend) {
1030 if (isALNUM_LC(*s)) {
1031 if (tmp && regtry(prog, s))
1042 PL_reg_flags |= RF_tainted;
1043 while (s < strend) {
1044 if (isALNUM_LC_utf8((U8*)s)) {
1045 if (tmp && regtry(prog, s))
1056 while (s < strend) {
1058 if (tmp && regtry(prog, s))
1069 while (s < strend) {
1070 if (!swash_fetch(PL_utf8_alnum, (U8*)s)) {
1071 if (tmp && regtry(prog, s))
1082 PL_reg_flags |= RF_tainted;
1083 while (s < strend) {
1084 if (!isALNUM_LC(*s)) {
1085 if (tmp && regtry(prog, s))
1096 PL_reg_flags |= RF_tainted;
1097 while (s < strend) {
1098 if (!isALNUM_LC_utf8((U8*)s)) {
1099 if (tmp && regtry(prog, s))
1110 while (s < strend) {
1112 if (tmp && regtry(prog, s))
1123 while (s < strend) {
1124 if (*s == ' ' || swash_fetch(PL_utf8_space,(U8*)s)) {
1125 if (tmp && regtry(prog, s))
1136 PL_reg_flags |= RF_tainted;
1137 while (s < strend) {
1138 if (isSPACE_LC(*s)) {
1139 if (tmp && regtry(prog, s))
1150 PL_reg_flags |= RF_tainted;
1151 while (s < strend) {
1152 if (*s == ' ' || isSPACE_LC_utf8((U8*)s)) {
1153 if (tmp && regtry(prog, s))
1164 while (s < strend) {
1166 if (tmp && regtry(prog, s))
1177 while (s < strend) {
1178 if (!(*s == ' ' || swash_fetch(PL_utf8_space,(U8*)s))) {
1179 if (tmp && regtry(prog, s))
1190 PL_reg_flags |= RF_tainted;
1191 while (s < strend) {
1192 if (!isSPACE_LC(*s)) {
1193 if (tmp && regtry(prog, s))
1204 PL_reg_flags |= RF_tainted;
1205 while (s < strend) {
1206 if (!(*s == ' ' || isSPACE_LC_utf8((U8*)s))) {
1207 if (tmp && regtry(prog, s))
1218 while (s < strend) {
1220 if (tmp && regtry(prog, s))
1231 while (s < strend) {
1232 if (swash_fetch(PL_utf8_digit,(U8*)s)) {
1233 if (tmp && regtry(prog, s))
1244 PL_reg_flags |= RF_tainted;
1245 while (s < strend) {
1246 if (isDIGIT_LC(*s)) {
1247 if (tmp && regtry(prog, s))
1258 PL_reg_flags |= RF_tainted;
1259 while (s < strend) {
1260 if (isDIGIT_LC_utf8((U8*)s)) {
1261 if (tmp && regtry(prog, s))
1272 while (s < strend) {
1274 if (tmp && regtry(prog, s))
1285 while (s < strend) {
1286 if (!swash_fetch(PL_utf8_digit,(U8*)s)) {
1287 if (tmp && regtry(prog, s))
1298 PL_reg_flags |= RF_tainted;
1299 while (s < strend) {
1300 if (!isDIGIT_LC(*s)) {
1301 if (tmp && regtry(prog, s))
1312 PL_reg_flags |= RF_tainted;
1313 while (s < strend) {
1314 if (!isDIGIT_LC_utf8((U8*)s)) {
1315 if (tmp && regtry(prog, s))
1326 while (s < strend) {
1328 if (tmp && regtry(prog, s))
1339 while (s < strend) {
1340 if (swash_fetch(PL_utf8_alnumc, (U8*)s)) {
1341 if (tmp && regtry(prog, s))
1352 PL_reg_flags |= RF_tainted;
1353 while (s < strend) {
1354 if (isALNUMC_LC(*s)) {
1355 if (tmp && regtry(prog, s))
1366 PL_reg_flags |= RF_tainted;
1367 while (s < strend) {
1368 if (isALNUMC_LC_utf8((U8*)s)) {
1369 if (tmp && regtry(prog, s))
1380 while (s < strend) {
1381 if (!isALNUMC(*s)) {
1382 if (tmp && regtry(prog, s))
1393 while (s < strend) {
1394 if (!swash_fetch(PL_utf8_alnumc, (U8*)s)) {
1395 if (tmp && regtry(prog, s))
1406 PL_reg_flags |= RF_tainted;
1407 while (s < strend) {
1408 if (!isALNUMC_LC(*s)) {
1409 if (tmp && regtry(prog, s))
1420 PL_reg_flags |= RF_tainted;
1421 while (s < strend) {
1422 if (!isALNUMC_LC_utf8((U8*)s)) {
1423 if (tmp && regtry(prog, s))
1434 while (s < strend) {
1435 if (isASCII(*(U8*)s)) {
1436 if (tmp && regtry(prog, s))
1447 while (s < strend) {
1448 if (!isASCII(*(U8*)s)) {
1449 if (tmp && regtry(prog, s))
1460 while (s < strend) {
1462 if (tmp && regtry(prog, s))
1473 while (s < strend) {
1474 if (swash_fetch(PL_utf8_cntrl,(U8*)s)) {
1475 if (tmp && regtry(prog, s))
1486 PL_reg_flags |= RF_tainted;
1487 while (s < strend) {
1488 if (isCNTRL_LC(*s)) {
1489 if (tmp && regtry(prog, s))
1500 PL_reg_flags |= RF_tainted;
1501 while (s < strend) {
1502 if (*s == ' ' || isCNTRL_LC_utf8((U8*)s)) {
1503 if (tmp && regtry(prog, s))
1514 while (s < strend) {
1516 if (tmp && regtry(prog, s))
1527 while (s < strend) {
1528 if (!swash_fetch(PL_utf8_cntrl,(U8*)s)) {
1529 if (tmp && regtry(prog, s))
1540 PL_reg_flags |= RF_tainted;
1541 while (s < strend) {
1542 if (!isCNTRL_LC(*s)) {
1543 if (tmp && regtry(prog, s))
1554 PL_reg_flags |= RF_tainted;
1555 while (s < strend) {
1556 if (!isCNTRL_LC_utf8((U8*)s)) {
1557 if (tmp && regtry(prog, s))
1568 while (s < strend) {
1570 if (tmp && regtry(prog, s))
1581 while (s < strend) {
1582 if (swash_fetch(PL_utf8_graph,(U8*)s)) {
1583 if (tmp && regtry(prog, s))
1594 PL_reg_flags |= RF_tainted;
1595 while (s < strend) {
1596 if (isGRAPH_LC(*s)) {
1597 if (tmp && regtry(prog, s))
1608 PL_reg_flags |= RF_tainted;
1609 while (s < strend) {
1610 if (*s == ' ' || isGRAPH_LC_utf8((U8*)s)) {
1611 if (tmp && regtry(prog, s))
1622 while (s < strend) {
1624 if (tmp && regtry(prog, s))
1635 while (s < strend) {
1636 if (!swash_fetch(PL_utf8_graph,(U8*)s)) {
1637 if (tmp && regtry(prog, s))
1648 PL_reg_flags |= RF_tainted;
1649 while (s < strend) {
1650 if (!isGRAPH_LC(*s)) {
1651 if (tmp && regtry(prog, s))
1662 PL_reg_flags |= RF_tainted;
1663 while (s < strend) {
1664 if (!isGRAPH_LC_utf8((U8*)s)) {
1665 if (tmp && regtry(prog, s))
1676 while (s < strend) {
1678 if (tmp && regtry(prog, s))
1689 while (s < strend) {
1690 if (swash_fetch(PL_utf8_lower,(U8*)s)) {
1691 if (tmp && regtry(prog, s))
1702 PL_reg_flags |= RF_tainted;
1703 while (s < strend) {
1704 if (isLOWER_LC(*s)) {
1705 if (tmp && regtry(prog, s))
1716 PL_reg_flags |= RF_tainted;
1717 while (s < strend) {
1718 if (*s == ' ' || isLOWER_LC_utf8((U8*)s)) {
1719 if (tmp && regtry(prog, s))
1730 while (s < strend) {
1732 if (tmp && regtry(prog, s))
1743 while (s < strend) {
1744 if (!swash_fetch(PL_utf8_lower,(U8*)s)) {
1745 if (tmp && regtry(prog, s))
1756 PL_reg_flags |= RF_tainted;
1757 while (s < strend) {
1758 if (!isLOWER_LC(*s)) {
1759 if (tmp && regtry(prog, s))
1770 PL_reg_flags |= RF_tainted;
1771 while (s < strend) {
1772 if (!isLOWER_LC_utf8((U8*)s)) {
1773 if (tmp && regtry(prog, s))
1784 while (s < strend) {
1786 if (tmp && regtry(prog, s))
1797 while (s < strend) {
1798 if (swash_fetch(PL_utf8_print,(U8*)s)) {
1799 if (tmp && regtry(prog, s))
1810 PL_reg_flags |= RF_tainted;
1811 while (s < strend) {
1812 if (isPRINT_LC(*s)) {
1813 if (tmp && regtry(prog, s))
1824 PL_reg_flags |= RF_tainted;
1825 while (s < strend) {
1826 if (*s == ' ' || isPRINT_LC_utf8((U8*)s)) {
1827 if (tmp && regtry(prog, s))
1838 while (s < strend) {
1840 if (tmp && regtry(prog, s))
1851 while (s < strend) {
1852 if (!swash_fetch(PL_utf8_print,(U8*)s)) {
1853 if (tmp && regtry(prog, s))
1864 PL_reg_flags |= RF_tainted;
1865 while (s < strend) {
1866 if (!isPRINT_LC(*s)) {
1867 if (tmp && regtry(prog, s))
1878 PL_reg_flags |= RF_tainted;
1879 while (s < strend) {
1880 if (!isPRINT_LC_utf8((U8*)s)) {
1881 if (tmp && regtry(prog, s))
1892 while (s < strend) {
1894 if (tmp && regtry(prog, s))
1905 while (s < strend) {
1906 if (swash_fetch(PL_utf8_punct,(U8*)s)) {
1907 if (tmp && regtry(prog, s))
1918 PL_reg_flags |= RF_tainted;
1919 while (s < strend) {
1920 if (isPUNCT_LC(*s)) {
1921 if (tmp && regtry(prog, s))
1932 PL_reg_flags |= RF_tainted;
1933 while (s < strend) {
1934 if (*s == ' ' || isPUNCT_LC_utf8((U8*)s)) {
1935 if (tmp && regtry(prog, s))
1946 while (s < strend) {
1948 if (tmp && regtry(prog, s))
1959 while (s < strend) {
1960 if (!swash_fetch(PL_utf8_punct,(U8*)s)) {
1961 if (tmp && regtry(prog, s))
1972 PL_reg_flags |= RF_tainted;
1973 while (s < strend) {
1974 if (!isPUNCT_LC(*s)) {
1975 if (tmp && regtry(prog, s))
1986 PL_reg_flags |= RF_tainted;
1987 while (s < strend) {
1988 if (!isPUNCT_LC_utf8((U8*)s)) {
1989 if (tmp && regtry(prog, s))
2000 while (s < strend) {
2002 if (tmp && regtry(prog, s))
2013 while (s < strend) {
2014 if (swash_fetch(PL_utf8_upper,(U8*)s)) {
2015 if (tmp && regtry(prog, s))
2026 PL_reg_flags |= RF_tainted;
2027 while (s < strend) {
2028 if (isUPPER_LC(*s)) {
2029 if (tmp && regtry(prog, s))
2040 PL_reg_flags |= RF_tainted;
2041 while (s < strend) {
2042 if (*s == ' ' || isUPPER_LC_utf8((U8*)s)) {
2043 if (tmp && regtry(prog, s))
2054 while (s < strend) {
2056 if (tmp && regtry(prog, s))
2067 while (s < strend) {
2068 if (!swash_fetch(PL_utf8_upper,(U8*)s)) {
2069 if (tmp && regtry(prog, s))
2080 PL_reg_flags |= RF_tainted;
2081 while (s < strend) {
2082 if (!isUPPER_LC(*s)) {
2083 if (tmp && regtry(prog, s))
2094 PL_reg_flags |= RF_tainted;
2095 while (s < strend) {
2096 if (!isUPPER_LC_utf8((U8*)s)) {
2097 if (tmp && regtry(prog, s))
2108 while (s < strend) {
2110 if (tmp && regtry(prog, s))
2121 while (s < strend) {
2122 if (!isXDIGIT(*s)) {
2123 if (tmp && regtry(prog, s))
2137 if (prog->float_substr != Nullsv) { /* Trim the end. */
2139 I32 oldpos = scream_pos;
2141 if (flags & REXEC_SCREAM) {
2142 last = screaminstr(sv, prog->float_substr, s - strbeg,
2143 end_shift, &scream_pos, 1); /* last one */
2145 last = scream_olds; /* Only one occurence. */
2149 char *little = SvPV(prog->float_substr, len);
2151 if (SvTAIL(prog->float_substr)) {
2152 if (memEQ(strend - len + 1, little, len - 1))
2153 last = strend - len + 1;
2154 else if (!PL_multiline)
2155 last = memEQ(strend - len, little, len)
2156 ? strend - len : Nullch;
2162 last = rninstr(s, strend, little, little + len);
2164 last = strend; /* matching `$' */
2167 if (last == NULL) goto phooey; /* Should not happen! */
2168 dontbother = strend - last + prog->float_min_offset;
2170 if (minlen && (dontbother < minlen))
2171 dontbother = minlen - 1;
2172 strend -= dontbother; /* this one's always in bytes! */
2173 /* We don't know much -- general case. */
2176 if (regtry(prog, s))
2185 if (regtry(prog, s))
2187 } while (s++ < strend);
2195 RX_MATCH_TAINTED_set(prog, PL_reg_flags & RF_tainted);
2197 if (PL_reg_eval_set) {
2198 /* Preserve the current value of $^R */
2199 if (oreplsv != GvSV(PL_replgv))
2200 sv_setsv(oreplsv, GvSV(PL_replgv));/* So that when GvSV(replgv) is
2201 restored, the value remains
2203 restore_pos(aTHXo_ 0);
2206 /* make sure $`, $&, $', and $digit will work later */
2207 if ( !(flags & REXEC_NOT_FIRST) ) {
2208 if (RX_MATCH_COPIED(prog)) {
2209 Safefree(prog->subbeg);
2210 RX_MATCH_COPIED_off(prog);
2212 if (flags & REXEC_COPY_STR) {
2213 I32 i = PL_regeol - startpos + (stringarg - strbeg);
2215 s = savepvn(strbeg, i);
2218 RX_MATCH_COPIED_on(prog);
2221 prog->subbeg = strbeg;
2222 prog->sublen = PL_regeol - strbeg; /* strend may have been modified */
2229 if (PL_reg_eval_set)
2230 restore_pos(aTHXo_ 0);
2235 - regtry - try match at specific point
2237 STATIC I32 /* 0 failure, 1 success */
2238 S_regtry(pTHX_ regexp *prog, char *startpos)
2246 if ((prog->reganch & ROPT_EVAL_SEEN) && !PL_reg_eval_set) {
2249 PL_reg_eval_set = RS_init;
2251 PerlIO_printf(Perl_debug_log, " setting stack tmpbase at %i\n",
2252 PL_stack_sp - PL_stack_base);
2254 SAVEINT(cxstack[cxstack_ix].blk_oldsp);
2255 cxstack[cxstack_ix].blk_oldsp = PL_stack_sp - PL_stack_base;
2256 /* Otherwise OP_NEXTSTATE will free whatever on stack now. */
2258 /* Apparently this is not needed, judging by wantarray. */
2259 /* SAVEINT(cxstack[cxstack_ix].blk_gimme);
2260 cxstack[cxstack_ix].blk_gimme = G_SCALAR; */
2263 /* Make $_ available to executed code. */
2264 if (PL_reg_sv != DEFSV) {
2265 /* SAVE_DEFSV does *not* suffice here for USE_THREADS */
2270 if (!(SvTYPE(PL_reg_sv) >= SVt_PVMG && SvMAGIC(PL_reg_sv)
2271 && (mg = mg_find(PL_reg_sv, 'g')))) {
2272 /* prepare for quick setting of pos */
2273 sv_magic(PL_reg_sv, (SV*)0, 'g', Nullch, 0);
2274 mg = mg_find(PL_reg_sv, 'g');
2278 PL_reg_oldpos = mg->mg_len;
2279 SAVEDESTRUCTOR(restore_pos, 0);
2282 New(22,PL_reg_curpm, 1, PMOP);
2283 PL_reg_curpm->op_pmregexp = prog;
2284 PL_reg_oldcurpm = PL_curpm;
2285 PL_curpm = PL_reg_curpm;
2286 if (RX_MATCH_COPIED(prog)) {
2287 /* Here is a serious problem: we cannot rewrite subbeg,
2288 since it may be needed if this match fails. Thus
2289 $` inside (?{}) could fail... */
2290 PL_reg_oldsaved = prog->subbeg;
2291 PL_reg_oldsavedlen = prog->sublen;
2292 RX_MATCH_COPIED_off(prog);
2295 PL_reg_oldsaved = Nullch;
2296 prog->subbeg = PL_bostr;
2297 prog->sublen = PL_regeol - PL_bostr; /* strend may have been modified */
2299 prog->startp[0] = startpos - PL_bostr;
2300 PL_reginput = startpos;
2301 PL_regstartp = prog->startp;
2302 PL_regendp = prog->endp;
2303 PL_reglastparen = &prog->lastparen;
2304 prog->lastparen = 0;
2306 DEBUG_r(PL_reg_starttry = startpos);
2307 if (PL_reg_start_tmpl <= prog->nparens) {
2308 PL_reg_start_tmpl = prog->nparens*3/2 + 3;
2309 if(PL_reg_start_tmp)
2310 Renew(PL_reg_start_tmp, PL_reg_start_tmpl, char*);
2312 New(22,PL_reg_start_tmp, PL_reg_start_tmpl, char*);
2315 /* XXXX What this code is doing here?!!! There should be no need
2316 to do this again and again, PL_reglastparen should take care of
2320 if (prog->nparens) {
2321 for (i = prog->nparens; i >= 1; i--) {
2327 if (regmatch(prog->program + 1)) {
2328 prog->endp[0] = PL_reginput - PL_bostr;
2336 - regmatch - main matching routine
2338 * Conceptually the strategy is simple: check to see whether the current
2339 * node matches, call self recursively to see whether the rest matches,
2340 * and then act accordingly. In practice we make some effort to avoid
2341 * recursion, in particular by going through "ordinary" nodes (that don't
2342 * need to know whether the rest of the match failed) by a loop instead of
2345 /* [lwall] I've hoisted the register declarations to the outer block in order to
2346 * maybe save a little bit of pushing and popping on the stack. It also takes
2347 * advantage of machines that use a register save mask on subroutine entry.
2349 STATIC I32 /* 0 failure, 1 success */
2350 S_regmatch(pTHX_ regnode *prog)
2353 register regnode *scan; /* Current node. */
2354 regnode *next; /* Next node. */
2355 regnode *inner; /* Next node in internal branch. */
2356 register I32 nextchr; /* renamed nextchr - nextchar colides with
2357 function of same name */
2358 register I32 n; /* no or next */
2359 register I32 ln; /* len or last */
2360 register char *s; /* operand or save */
2361 register char *locinput = PL_reginput;
2362 register I32 c1, c2, paren; /* case fold search, parenth */
2363 int minmod = 0, sw = 0, logical = 0;
2368 /* Note that nextchr is a byte even in UTF */
2369 nextchr = UCHARAT(locinput);
2371 while (scan != NULL) {
2372 #define sayNO_L (logical ? (logical = 0, sw = 0, goto cont) : sayNO)
2374 # define sayYES goto yes
2375 # define sayNO goto no
2376 # define saySAME(x) if (x) goto yes; else goto no
2377 # define REPORT_CODE_OFF 24
2379 # define sayYES return 1
2380 # define sayNO return 0
2381 # define saySAME(x) return x
2384 SV *prop = sv_newmortal();
2385 int docolor = *PL_colors[0];
2386 int taill = (docolor ? 10 : 7); /* 3 chars for "> <" */
2387 int l = (PL_regeol - locinput > taill ? taill : PL_regeol - locinput);
2388 /* The part of the string before starttry has one color
2389 (pref0_len chars), between starttry and current
2390 position another one (pref_len - pref0_len chars),
2391 after the current position the third one.
2392 We assume that pref0_len <= pref_len, otherwise we
2393 decrease pref0_len. */
2394 int pref_len = (locinput - PL_bostr > (5 + taill) - l
2395 ? (5 + taill) - l : locinput - PL_bostr);
2396 int pref0_len = pref_len - (locinput - PL_reg_starttry);
2398 if (l + pref_len < (5 + taill) && l < PL_regeol - locinput)
2399 l = ( PL_regeol - locinput > (5 + taill) - pref_len
2400 ? (5 + taill) - pref_len : PL_regeol - locinput);
2403 if (pref0_len > pref_len)
2404 pref0_len = pref_len;
2405 regprop(prop, scan);
2406 PerlIO_printf(Perl_debug_log,
2407 "%4i <%s%.*s%s%s%.*s%s%s%s%.*s%s>%*s|%3d:%*s%s\n",
2408 locinput - PL_bostr,
2409 PL_colors[4], pref0_len,
2410 locinput - pref_len, PL_colors[5],
2411 PL_colors[2], pref_len - pref0_len,
2412 locinput - pref_len + pref0_len, PL_colors[3],
2413 (docolor ? "" : "> <"),
2414 PL_colors[0], l, locinput, PL_colors[1],
2415 15 - l - pref_len + 1,
2417 scan - PL_regprogram, PL_regindent*2, "",
2421 next = scan + NEXT_OFF(scan);
2427 if (locinput == PL_bostr
2428 ? PL_regprev == '\n'
2430 (nextchr || locinput < PL_regeol) && locinput[-1] == '\n') )
2432 /* regtill = regbol; */
2437 if (locinput == PL_bostr
2438 ? PL_regprev == '\n'
2439 : ((nextchr || locinput < PL_regeol) && locinput[-1] == '\n') )
2445 if (locinput == PL_regbol && PL_regprev == '\n')
2449 if (locinput == PL_reg_ganch)
2459 if ((nextchr || locinput < PL_regeol) && nextchr != '\n')
2464 if ((nextchr || locinput < PL_regeol) && nextchr != '\n')
2466 if (PL_regeol - locinput > 1)
2470 if (PL_regeol != locinput)
2474 if (nextchr & 0x80) {
2475 locinput += PL_utf8skip[nextchr];
2476 if (locinput > PL_regeol)
2478 nextchr = UCHARAT(locinput);
2481 if (!nextchr && locinput >= PL_regeol)
2483 nextchr = UCHARAT(++locinput);
2486 if (!nextchr && locinput >= PL_regeol)
2488 nextchr = UCHARAT(++locinput);
2491 if (nextchr & 0x80) {
2492 locinput += PL_utf8skip[nextchr];
2493 if (locinput > PL_regeol)
2495 nextchr = UCHARAT(locinput);
2498 if (!nextchr && locinput >= PL_regeol || nextchr == '\n')
2500 nextchr = UCHARAT(++locinput);
2503 if (!nextchr && locinput >= PL_regeol || nextchr == '\n')
2505 nextchr = UCHARAT(++locinput);
2508 s = (char *) OPERAND(scan);
2510 /* Inline the first character, for speed. */
2511 if (UCHARAT(s) != nextchr)
2513 if (PL_regeol - locinput < ln)
2515 if (ln > 1 && memNE(s, locinput, ln))
2518 nextchr = UCHARAT(locinput);
2521 PL_reg_flags |= RF_tainted;
2524 s = (char *) OPERAND(scan);
2530 c1 = OP(scan) == EXACTF;
2534 if (utf8_to_uv((U8*)s, 0) != (c1 ?
2535 toLOWER_utf8((U8*)l) :
2536 toLOWER_LC_utf8((U8*)l)))
2544 nextchr = UCHARAT(locinput);
2548 /* Inline the first character, for speed. */
2549 if (UCHARAT(s) != nextchr &&
2550 UCHARAT(s) != ((OP(scan) == EXACTF)
2551 ? PL_fold : PL_fold_locale)[nextchr])
2553 if (PL_regeol - locinput < ln)
2555 if (ln > 1 && (OP(scan) == EXACTF
2556 ? ibcmp(s, locinput, ln)
2557 : ibcmp_locale(s, locinput, ln)))
2560 nextchr = UCHARAT(locinput);
2563 s = (char *) OPERAND(scan);
2564 if (!REGINCLASSUTF8(scan, (U8*)locinput))
2566 if (locinput >= PL_regeol)
2568 locinput += PL_utf8skip[nextchr];
2569 nextchr = UCHARAT(locinput);
2572 s = (char *) OPERAND(scan);
2574 nextchr = UCHARAT(locinput);
2575 if (!REGINCLASS(s, nextchr))
2577 if (!nextchr && locinput >= PL_regeol)
2579 nextchr = UCHARAT(++locinput);
2582 PL_reg_flags |= RF_tainted;
2587 if (!(OP(scan) == ALNUM
2588 ? isALNUM(nextchr) : isALNUM_LC(nextchr)))
2590 nextchr = UCHARAT(++locinput);
2593 PL_reg_flags |= RF_tainted;
2598 if (nextchr & 0x80) {
2599 if (!(OP(scan) == ALNUMUTF8
2600 ? swash_fetch(PL_utf8_alnum, (U8*)locinput)
2601 : isALNUM_LC_utf8((U8*)locinput)))
2605 locinput += PL_utf8skip[nextchr];
2606 nextchr = UCHARAT(locinput);
2609 if (!(OP(scan) == ALNUMUTF8
2610 ? isALNUM(nextchr) : isALNUM_LC(nextchr)))
2612 nextchr = UCHARAT(++locinput);
2615 PL_reg_flags |= RF_tainted;
2618 if (!nextchr && locinput >= PL_regeol)
2620 if (OP(scan) == NALNUM
2621 ? isALNUM(nextchr) : isALNUM_LC(nextchr))
2623 nextchr = UCHARAT(++locinput);
2626 PL_reg_flags |= RF_tainted;
2629 if (!nextchr && locinput >= PL_regeol)
2631 if (nextchr & 0x80) {
2632 if (OP(scan) == NALNUMUTF8
2633 ? swash_fetch(PL_utf8_alnum, (U8*)locinput)
2634 : isALNUM_LC_utf8((U8*)locinput))
2638 locinput += PL_utf8skip[nextchr];
2639 nextchr = UCHARAT(locinput);
2642 if (OP(scan) == NALNUMUTF8
2643 ? isALNUM(nextchr) : isALNUM_LC(nextchr))
2645 nextchr = UCHARAT(++locinput);
2649 PL_reg_flags |= RF_tainted;
2653 /* was last char in word? */
2654 ln = (locinput != PL_regbol) ? UCHARAT(locinput - 1) : PL_regprev;
2655 if (OP(scan) == BOUND || OP(scan) == NBOUND) {
2657 n = isALNUM(nextchr);
2660 ln = isALNUM_LC(ln);
2661 n = isALNUM_LC(nextchr);
2663 if (((!ln) == (!n)) == (OP(scan) == BOUND || OP(scan) == BOUNDL))
2668 PL_reg_flags |= RF_tainted;
2672 /* was last char in word? */
2673 ln = (locinput != PL_regbol)
2674 ? utf8_to_uv(reghop((U8*)locinput, -1), 0) : PL_regprev;
2675 if (OP(scan) == BOUNDUTF8 || OP(scan) == NBOUNDUTF8) {
2676 ln = isALNUM_uni(ln);
2677 n = swash_fetch(PL_utf8_alnum, (U8*)locinput);
2680 ln = isALNUM_LC_uni(ln);
2681 n = isALNUM_LC_utf8((U8*)locinput);
2683 if (((!ln) == (!n)) == (OP(scan) == BOUNDUTF8 || OP(scan) == BOUNDLUTF8))
2687 PL_reg_flags |= RF_tainted;
2690 if (!nextchr && locinput >= PL_regeol)
2692 if (!(OP(scan) == SPACE
2693 ? isSPACE(nextchr) : isSPACE_LC(nextchr)))
2695 nextchr = UCHARAT(++locinput);
2698 PL_reg_flags |= RF_tainted;
2701 if (!nextchr && locinput >= PL_regeol)
2703 if (nextchr & 0x80) {
2704 if (!(OP(scan) == SPACEUTF8
2705 ? swash_fetch(PL_utf8_space,(U8*)locinput)
2706 : isSPACE_LC_utf8((U8*)locinput)))
2710 locinput += PL_utf8skip[nextchr];
2711 nextchr = UCHARAT(locinput);
2714 if (!(OP(scan) == SPACEUTF8
2715 ? isSPACE(nextchr) : isSPACE_LC(nextchr)))
2717 nextchr = UCHARAT(++locinput);
2720 PL_reg_flags |= RF_tainted;
2725 if (OP(scan) == SPACE
2726 ? isSPACE(nextchr) : isSPACE_LC(nextchr))
2728 nextchr = UCHARAT(++locinput);
2731 PL_reg_flags |= RF_tainted;
2736 if (nextchr & 0x80) {
2737 if (OP(scan) == NSPACEUTF8
2738 ? swash_fetch(PL_utf8_space,(U8*)locinput)
2739 : isSPACE_LC_utf8((U8*)locinput))
2743 locinput += PL_utf8skip[nextchr];
2744 nextchr = UCHARAT(locinput);
2747 if (OP(scan) == NSPACEUTF8
2748 ? isSPACE(nextchr) : isSPACE_LC(nextchr))
2750 nextchr = UCHARAT(++locinput);
2753 PL_reg_flags |= RF_tainted;
2756 if (!nextchr && locinput >= PL_regeol)
2758 if (!(OP(scan) == DIGIT
2759 ? isDIGIT(nextchr) : isDIGIT_LC(nextchr)))
2761 nextchr = UCHARAT(++locinput);
2764 PL_reg_flags |= RF_tainted;
2769 if (nextchr & 0x80) {
2770 if (OP(scan) == NDIGITUTF8
2771 ? swash_fetch(PL_utf8_digit,(U8*)locinput)
2772 : isDIGIT_LC_utf8((U8*)locinput))
2776 locinput += PL_utf8skip[nextchr];
2777 nextchr = UCHARAT(locinput);
2780 if (!isDIGIT(nextchr))
2782 nextchr = UCHARAT(++locinput);
2785 PL_reg_flags |= RF_tainted;
2790 if (OP(scan) == DIGIT
2791 ? isDIGIT(nextchr) : isDIGIT_LC(nextchr))
2793 nextchr = UCHARAT(++locinput);
2796 PL_reg_flags |= RF_tainted;
2799 if (!nextchr && locinput >= PL_regeol)
2801 if (nextchr & 0x80) {
2802 if (swash_fetch(PL_utf8_digit,(U8*)locinput))
2804 locinput += PL_utf8skip[nextchr];
2805 nextchr = UCHARAT(locinput);
2808 if (isDIGIT(nextchr))
2810 nextchr = UCHARAT(++locinput);
2813 PL_reg_flags |= RF_tainted;
2818 if (!(OP(scan) == ALNUMC
2819 ? isALNUMC(nextchr) : isALNUMC_LC(nextchr)))
2821 nextchr = UCHARAT(++locinput);
2824 PL_reg_flags |= RF_tainted;
2829 if (nextchr & 0x80) {
2830 if (!(OP(scan) == ALNUMCUTF8
2831 ? swash_fetch(PL_utf8_alnumc, (U8*)locinput)
2832 : isALNUMC_LC_utf8((U8*)locinput)))
2836 locinput += PL_utf8skip[nextchr];
2837 nextchr = UCHARAT(locinput);
2840 if (!(OP(scan) == ALNUMCUTF8
2841 ? isALNUMC(nextchr) : isALNUMC_LC(nextchr)))
2843 nextchr = UCHARAT(++locinput);
2846 PL_reg_flags |= RF_tainted;
2851 if (OP(scan) == ALNUMC
2852 ? isALNUMC(nextchr) : isALNUMC_LC(nextchr))
2854 nextchr = UCHARAT(++locinput);
2857 PL_reg_flags |= RF_tainted;
2860 if (!nextchr && locinput >= PL_regeol)
2862 if (nextchr & 0x80) {
2863 if (swash_fetch(PL_utf8_alnumc,(U8*)locinput))
2865 locinput += PL_utf8skip[nextchr];
2866 nextchr = UCHARAT(locinput);
2869 if (isALNUMC(nextchr))
2871 nextchr = UCHARAT(++locinput);
2874 PL_reg_flags |= RF_tainted;
2879 if (!(OP(scan) == ALPHA
2880 ? isALPHA(nextchr) : isALPHA_LC(nextchr)))
2882 nextchr = UCHARAT(++locinput);
2885 PL_reg_flags |= RF_tainted;
2890 if (nextchr & 0x80) {
2891 if (!(OP(scan) == ALPHAUTF8
2892 ? swash_fetch(PL_utf8_alpha, (U8*)locinput)
2893 : isALPHA_LC_utf8((U8*)locinput)))
2897 locinput += PL_utf8skip[nextchr];
2898 nextchr = UCHARAT(locinput);
2901 if (!(OP(scan) == ALPHAUTF8
2902 ? isALPHA(nextchr) : isALPHA_LC(nextchr)))
2904 nextchr = UCHARAT(++locinput);
2907 PL_reg_flags |= RF_tainted;
2912 if (OP(scan) == ALPHA
2913 ? isALPHA(nextchr) : isALPHA_LC(nextchr))
2915 nextchr = UCHARAT(++locinput);
2918 PL_reg_flags |= RF_tainted;
2921 if (!nextchr && locinput >= PL_regeol)
2923 if (nextchr & 0x80) {
2924 if (swash_fetch(PL_utf8_alpha,(U8*)locinput))
2926 locinput += PL_utf8skip[nextchr];
2927 nextchr = UCHARAT(locinput);
2930 if (isALPHA(nextchr))
2932 nextchr = UCHARAT(++locinput);
2935 if (!nextchr && locinput >= PL_regeol)
2937 if (!isASCII(nextchr))
2939 nextchr = UCHARAT(++locinput);
2942 if (!nextchr && locinput >= PL_regeol)
2944 if (isASCII(nextchr))
2946 nextchr = UCHARAT(++locinput);
2949 PL_reg_flags |= RF_tainted;
2954 if (!(OP(scan) == CNTRL
2955 ? isCNTRL(nextchr) : isCNTRL_LC(nextchr)))
2957 nextchr = UCHARAT(++locinput);
2960 PL_reg_flags |= RF_tainted;
2965 if (nextchr & 0x80) {
2966 if (!(OP(scan) == CNTRLUTF8
2967 ? swash_fetch(PL_utf8_cntrl, (U8*)locinput)
2968 : isCNTRL_LC_utf8((U8*)locinput)))
2972 locinput += PL_utf8skip[nextchr];
2973 nextchr = UCHARAT(locinput);
2976 if (!(OP(scan) == CNTRLUTF8
2977 ? isCNTRL(nextchr) : isCNTRL_LC(nextchr)))
2979 nextchr = UCHARAT(++locinput);
2982 PL_reg_flags |= RF_tainted;
2987 if (OP(scan) == CNTRL
2988 ? isCNTRL(nextchr) : isCNTRL_LC(nextchr))
2990 nextchr = UCHARAT(++locinput);
2993 PL_reg_flags |= RF_tainted;
2996 if (!nextchr && locinput >= PL_regeol)
2998 if (nextchr & 0x80) {
2999 if (swash_fetch(PL_utf8_cntrl,(U8*)locinput))
3001 locinput += PL_utf8skip[nextchr];
3002 nextchr = UCHARAT(locinput);
3005 if (isCNTRL(nextchr))
3007 nextchr = UCHARAT(++locinput);
3010 PL_reg_flags |= RF_tainted;
3015 if (!(OP(scan) == GRAPH
3016 ? isGRAPH(nextchr) : isGRAPH_LC(nextchr)))
3018 nextchr = UCHARAT(++locinput);
3021 PL_reg_flags |= RF_tainted;
3026 if (nextchr & 0x80) {
3027 if (!(OP(scan) == GRAPHUTF8
3028 ? swash_fetch(PL_utf8_graph, (U8*)locinput)
3029 : isGRAPH_LC_utf8((U8*)locinput)))
3033 locinput += PL_utf8skip[nextchr];
3034 nextchr = UCHARAT(locinput);
3037 if (!(OP(scan) == GRAPHUTF8
3038 ? isGRAPH(nextchr) : isGRAPH_LC(nextchr)))
3040 nextchr = UCHARAT(++locinput);
3043 PL_reg_flags |= RF_tainted;
3048 if (OP(scan) == GRAPH
3049 ? isGRAPH(nextchr) : isGRAPH_LC(nextchr))
3051 nextchr = UCHARAT(++locinput);
3054 PL_reg_flags |= RF_tainted;
3057 if (!nextchr && locinput >= PL_regeol)
3059 if (nextchr & 0x80) {
3060 if (swash_fetch(PL_utf8_graph,(U8*)locinput))
3062 locinput += PL_utf8skip[nextchr];
3063 nextchr = UCHARAT(locinput);
3066 if (isGRAPH(nextchr))
3068 nextchr = UCHARAT(++locinput);
3071 PL_reg_flags |= RF_tainted;
3076 if (!(OP(scan) == LOWER
3077 ? isLOWER(nextchr) : isLOWER_LC(nextchr)))
3079 nextchr = UCHARAT(++locinput);
3082 PL_reg_flags |= RF_tainted;
3087 if (nextchr & 0x80) {
3088 if (!(OP(scan) == LOWERUTF8
3089 ? swash_fetch(PL_utf8_lower, (U8*)locinput)
3090 : isLOWER_LC_utf8((U8*)locinput)))
3094 locinput += PL_utf8skip[nextchr];
3095 nextchr = UCHARAT(locinput);
3098 if (!(OP(scan) == LOWERUTF8
3099 ? isLOWER(nextchr) : isLOWER_LC(nextchr)))
3101 nextchr = UCHARAT(++locinput);
3104 PL_reg_flags |= RF_tainted;
3109 if (OP(scan) == LOWER
3110 ? isLOWER(nextchr) : isLOWER_LC(nextchr))
3112 nextchr = UCHARAT(++locinput);
3115 PL_reg_flags |= RF_tainted;
3118 if (!nextchr && locinput >= PL_regeol)
3120 if (nextchr & 0x80) {
3121 if (swash_fetch(PL_utf8_lower,(U8*)locinput))
3123 locinput += PL_utf8skip[nextchr];
3124 nextchr = UCHARAT(locinput);
3127 if (isLOWER(nextchr))
3129 nextchr = UCHARAT(++locinput);
3132 PL_reg_flags |= RF_tainted;
3137 if (!(OP(scan) == PRINT
3138 ? isPRINT(nextchr) : isPRINT_LC(nextchr)))
3140 nextchr = UCHARAT(++locinput);
3143 PL_reg_flags |= RF_tainted;
3148 if (nextchr & 0x80) {
3149 if (!(OP(scan) == PRINTUTF8
3150 ? swash_fetch(PL_utf8_print, (U8*)locinput)
3151 : isPRINT_LC_utf8((U8*)locinput)))
3155 locinput += PL_utf8skip[nextchr];
3156 nextchr = UCHARAT(locinput);
3159 if (!(OP(scan) == PRINTUTF8
3160 ? isPRINT(nextchr) : isPRINT_LC(nextchr)))
3162 nextchr = UCHARAT(++locinput);
3165 PL_reg_flags |= RF_tainted;
3170 if (OP(scan) == PRINT
3171 ? isPRINT(nextchr) : isPRINT_LC(nextchr))
3173 nextchr = UCHARAT(++locinput);
3176 PL_reg_flags |= RF_tainted;
3179 if (!nextchr && locinput >= PL_regeol)
3181 if (nextchr & 0x80) {
3182 if (swash_fetch(PL_utf8_print,(U8*)locinput))
3184 locinput += PL_utf8skip[nextchr];
3185 nextchr = UCHARAT(locinput);
3188 if (isPRINT(nextchr))
3190 nextchr = UCHARAT(++locinput);
3193 PL_reg_flags |= RF_tainted;
3198 if (!(OP(scan) == PUNCT
3199 ? isPUNCT(nextchr) : isPUNCT_LC(nextchr)))
3201 nextchr = UCHARAT(++locinput);
3204 PL_reg_flags |= RF_tainted;
3209 if (nextchr & 0x80) {
3210 if (!(OP(scan) == PUNCTUTF8
3211 ? swash_fetch(PL_utf8_punct, (U8*)locinput)
3212 : isPUNCT_LC_utf8((U8*)locinput)))
3216 locinput += PL_utf8skip[nextchr];
3217 nextchr = UCHARAT(locinput);
3220 if (!(OP(scan) == PUNCTUTF8
3221 ? isPUNCT(nextchr) : isPUNCT_LC(nextchr)))
3223 nextchr = UCHARAT(++locinput);
3226 PL_reg_flags |= RF_tainted;
3231 if (OP(scan) == PUNCT
3232 ? isPUNCT(nextchr) : isPUNCT_LC(nextchr))
3234 nextchr = UCHARAT(++locinput);
3237 PL_reg_flags |= RF_tainted;
3240 if (!nextchr && locinput >= PL_regeol)
3242 if (nextchr & 0x80) {
3243 if (swash_fetch(PL_utf8_punct,(U8*)locinput))
3245 locinput += PL_utf8skip[nextchr];
3246 nextchr = UCHARAT(locinput);
3249 if (isPUNCT(nextchr))
3251 nextchr = UCHARAT(++locinput);
3254 PL_reg_flags |= RF_tainted;
3259 if (!(OP(scan) == UPPER
3260 ? isUPPER(nextchr) : isUPPER_LC(nextchr)))
3262 nextchr = UCHARAT(++locinput);
3265 PL_reg_flags |= RF_tainted;
3270 if (nextchr & 0x80) {
3271 if (!(OP(scan) == UPPERUTF8
3272 ? swash_fetch(PL_utf8_upper, (U8*)locinput)
3273 : isUPPER_LC_utf8((U8*)locinput)))
3277 locinput += PL_utf8skip[nextchr];
3278 nextchr = UCHARAT(locinput);
3281 if (!(OP(scan) == UPPERUTF8
3282 ? isUPPER(nextchr) : isUPPER_LC(nextchr)))
3284 nextchr = UCHARAT(++locinput);
3287 PL_reg_flags |= RF_tainted;
3292 if (OP(scan) == UPPER
3293 ? isUPPER(nextchr) : isUPPER_LC(nextchr))
3295 nextchr = UCHARAT(++locinput);
3298 PL_reg_flags |= RF_tainted;
3301 if (!nextchr && locinput >= PL_regeol)
3303 if (nextchr & 0x80) {
3304 if (swash_fetch(PL_utf8_upper,(U8*)locinput))
3306 locinput += PL_utf8skip[nextchr];
3307 nextchr = UCHARAT(locinput);
3310 if (isUPPER(nextchr))
3312 nextchr = UCHARAT(++locinput);
3315 if (!nextchr && locinput >= PL_regeol)
3317 if (!isXDIGIT(nextchr))
3319 nextchr = UCHARAT(++locinput);
3322 if (!nextchr && locinput >= PL_regeol)
3324 if (isXDIGIT(nextchr))
3326 nextchr = UCHARAT(++locinput);
3329 if (locinput >= PL_regeol || swash_fetch(PL_utf8_mark,(U8*)locinput))
3331 locinput += PL_utf8skip[nextchr];
3332 while (locinput < PL_regeol && swash_fetch(PL_utf8_mark,(U8*)locinput))
3333 locinput += UTF8SKIP(locinput);
3334 if (locinput > PL_regeol)
3336 nextchr = UCHARAT(locinput);
3339 PL_reg_flags |= RF_tainted;
3343 n = ARG(scan); /* which paren pair */
3344 ln = PL_regstartp[n];
3345 PL_reg_leftiter = PL_reg_maxiter; /* Void cache */
3346 if (*PL_reglastparen < n || ln == -1)
3347 sayNO; /* Do not match unless seen CLOSEn. */
3348 if (ln == PL_regendp[n])
3352 if (UTF && OP(scan) != REF) { /* REF can do byte comparison */
3354 char *e = PL_bostr + PL_regendp[n];
3356 * Note that we can't do the "other character" lookup trick as
3357 * in the 8-bit case (no pun intended) because in Unicode we
3358 * have to map both upper and title case to lower case.
3360 if (OP(scan) == REFF) {
3364 if (toLOWER_utf8((U8*)s) != toLOWER_utf8((U8*)l))
3374 if (toLOWER_LC_utf8((U8*)s) != toLOWER_LC_utf8((U8*)l))
3381 nextchr = UCHARAT(locinput);
3385 /* Inline the first character, for speed. */
3386 if (UCHARAT(s) != nextchr &&
3388 (UCHARAT(s) != ((OP(scan) == REFF
3389 ? PL_fold : PL_fold_locale)[nextchr]))))
3391 ln = PL_regendp[n] - ln;
3392 if (locinput + ln > PL_regeol)
3394 if (ln > 1 && (OP(scan) == REF
3395 ? memNE(s, locinput, ln)
3397 ? ibcmp(s, locinput, ln)
3398 : ibcmp_locale(s, locinput, ln))))
3401 nextchr = UCHARAT(locinput);
3412 OP_4tree *oop = PL_op;
3413 COP *ocurcop = PL_curcop;
3414 SV **ocurpad = PL_curpad;
3418 PL_op = (OP_4tree*)PL_regdata->data[n];
3419 DEBUG_r( PerlIO_printf(Perl_debug_log, " re_eval 0x%x\n", PL_op) );
3420 PL_curpad = AvARRAY((AV*)PL_regdata->data[n + 2]);
3421 PL_regendp[0] = PL_reg_magic->mg_len = locinput - PL_bostr;
3423 CALLRUNOPS(aTHX); /* Scalar context. */
3429 PL_curpad = ocurpad;
3430 PL_curcop = ocurcop;
3432 if (logical == 2) { /* Postponed subexpression. */
3434 MAGIC *mg = Null(MAGIC*);
3437 CHECKPOINT cp, lastcp;
3439 if(SvROK(ret) || SvRMAGICAL(ret)) {
3440 SV *sv = SvROK(ret) ? SvRV(ret) : ret;
3443 mg = mg_find(sv, 'r');
3446 re = (regexp *)mg->mg_obj;
3447 (void)ReREFCNT_inc(re);
3451 char *t = SvPV(ret, len);
3453 char *oprecomp = PL_regprecomp;
3454 I32 osize = PL_regsize;
3455 I32 onpar = PL_regnpar;
3458 re = CALLREGCOMP(aTHX_ t, t + len, &pm);
3460 & (SVs_TEMP | SVs_PADTMP | SVf_READONLY)))
3461 sv_magic(ret,(SV*)ReREFCNT_inc(re),'r',0,0);
3462 PL_regprecomp = oprecomp;
3467 PerlIO_printf(Perl_debug_log,
3468 "Entering embedded `%s%.60s%s%s'\n",
3472 (strlen(re->precomp) > 60 ? "..." : ""))
3475 state.prev = PL_reg_call_cc;
3476 state.cc = PL_regcc;
3477 state.re = PL_reg_re;
3483 cp = regcppush(0); /* Save *all* the positions. */
3486 state.ss = PL_savestack_ix;
3487 *PL_reglastparen = 0;
3488 PL_reg_call_cc = &state;
3489 PL_reginput = locinput;
3491 /* XXXX This is too dramatic a measure... */
3494 if (regmatch(re->program + 1)) {
3500 PerlIO_printf(Perl_debug_log,
3502 REPORT_CODE_OFF+PL_regindent*2, "")
3507 PL_reg_call_cc = state.prev;
3508 PL_regcc = state.cc;
3509 PL_reg_re = state.re;
3510 cache_re(PL_reg_re);
3512 /* XXXX This is too dramatic a measure... */
3521 sv_setsv(save_scalar(PL_replgv), ret);
3525 n = ARG(scan); /* which paren pair */
3526 PL_reg_start_tmp[n] = locinput;
3531 n = ARG(scan); /* which paren pair */
3532 PL_regstartp[n] = PL_reg_start_tmp[n] - PL_bostr;
3533 PL_regendp[n] = locinput - PL_bostr;
3534 if (n > *PL_reglastparen)
3535 *PL_reglastparen = n;
3538 n = ARG(scan); /* which paren pair */
3539 sw = (*PL_reglastparen >= n && PL_regendp[n] != -1);
3542 PL_reg_leftiter = PL_reg_maxiter; /* Void cache */
3544 next = NEXTOPER(NEXTOPER(scan));
3546 next = scan + ARG(scan);
3547 if (OP(next) == IFTHEN) /* Fake one. */
3548 next = NEXTOPER(NEXTOPER(next));
3552 logical = scan->flags;
3556 CHECKPOINT cp = PL_savestack_ix;
3558 if (OP(PREVOPER(next)) == NOTHING) /* LONGJMP */
3560 cc.oldcc = PL_regcc;
3562 cc.parenfloor = *PL_reglastparen;
3564 cc.min = ARG1(scan);
3565 cc.max = ARG2(scan);
3566 cc.scan = NEXTOPER(scan) + EXTRA_STEP_2ARGS;
3570 PL_reginput = locinput;
3571 n = regmatch(PREVOPER(next)); /* start on the WHILEM */
3573 PL_regcc = cc.oldcc;
3579 * This is really hard to understand, because after we match
3580 * what we're trying to match, we must make sure the rest of
3581 * the REx is going to match for sure, and to do that we have
3582 * to go back UP the parse tree by recursing ever deeper. And
3583 * if it fails, we have to reset our parent's current state
3584 * that we can try again after backing off.
3587 CHECKPOINT cp, lastcp;
3588 CURCUR* cc = PL_regcc;
3589 char *lastloc = cc->lastloc; /* Detection of 0-len. */
3591 n = cc->cur + 1; /* how many we know we matched */
3592 PL_reginput = locinput;
3595 PerlIO_printf(Perl_debug_log,
3596 "%*s %ld out of %ld..%ld cc=%lx\n",
3597 REPORT_CODE_OFF+PL_regindent*2, "",
3598 (long)n, (long)cc->min,
3599 (long)cc->max, (long)cc)
3602 /* If degenerate scan matches "", assume scan done. */
3604 if (locinput == cc->lastloc && n >= cc->min) {
3605 PL_regcc = cc->oldcc;
3608 PerlIO_printf(Perl_debug_log,
3609 "%*s empty match detected, try continuation...\n",
3610 REPORT_CODE_OFF+PL_regindent*2, "")
3612 if (regmatch(cc->next))
3615 PerlIO_printf(Perl_debug_log,
3617 REPORT_CODE_OFF+PL_regindent*2, "")
3624 /* First just match a string of min scans. */
3628 cc->lastloc = locinput;
3629 if (regmatch(cc->scan))
3632 cc->lastloc = lastloc;
3634 PerlIO_printf(Perl_debug_log,
3636 REPORT_CODE_OFF+PL_regindent*2, "")
3642 /* Check whether we already were at this position.
3643 Postpone detection until we know the match is not
3644 *that* much linear. */
3645 if (!PL_reg_maxiter) {
3646 PL_reg_maxiter = (PL_regeol - PL_bostr + 1) * (scan->flags>>4);
3647 PL_reg_leftiter = PL_reg_maxiter;
3649 if (PL_reg_leftiter-- == 0) {
3650 I32 size = (PL_reg_maxiter + 7)/8;
3651 if (PL_reg_poscache) {
3652 if (PL_reg_poscache_size < size) {
3653 Renew(PL_reg_poscache, size, char);
3654 PL_reg_poscache_size = size;
3656 Zero(PL_reg_poscache, size, char);
3659 PL_reg_poscache_size = size;
3660 Newz(29, PL_reg_poscache, size, char);
3663 PerlIO_printf(Perl_debug_log,
3664 "%sDetected a super-linear match, switching on caching%s...\n",
3665 PL_colors[4], PL_colors[5])
3668 if (PL_reg_leftiter < 0) {
3669 I32 o = locinput - PL_bostr, b;
3671 o = (scan->flags & 0xf) - 1 + o * (scan->flags>>4);
3674 if (PL_reg_poscache[o] & (1<<b)) {
3676 PerlIO_printf(Perl_debug_log,
3677 "%*s already tried at this position...\n",
3678 REPORT_CODE_OFF+PL_regindent*2, "")
3682 PL_reg_poscache[o] |= (1<<b);
3686 /* Prefer next over scan for minimal matching. */
3689 PL_regcc = cc->oldcc;
3691 cp = regcppush(cc->parenfloor);
3693 if (regmatch(cc->next)) {
3695 sayYES; /* All done. */
3702 if (n >= cc->max) { /* Maximum greed exceeded? */
3703 if (ckWARN(WARN_UNSAFE) && n >= REG_INFTY
3704 && !(PL_reg_flags & RF_warned)) {
3705 PL_reg_flags |= RF_warned;
3706 Perl_warner(aTHX_ WARN_UNSAFE, "%s limit (%d) exceeded",
3707 "Complex regular subexpression recursion",
3714 PerlIO_printf(Perl_debug_log,
3715 "%*s trying longer...\n",
3716 REPORT_CODE_OFF+PL_regindent*2, "")
3718 /* Try scanning more and see if it helps. */
3719 PL_reginput = locinput;
3721 cc->lastloc = locinput;
3722 cp = regcppush(cc->parenfloor);
3724 if (regmatch(cc->scan)) {
3729 PerlIO_printf(Perl_debug_log,
3731 REPORT_CODE_OFF+PL_regindent*2, "")
3736 cc->lastloc = lastloc;
3740 /* Prefer scan over next for maximal matching. */
3742 if (n < cc->max) { /* More greed allowed? */
3743 cp = regcppush(cc->parenfloor);
3745 cc->lastloc = locinput;
3747 if (regmatch(cc->scan)) {
3752 regcppop(); /* Restore some previous $<digit>s? */
3753 PL_reginput = locinput;
3755 PerlIO_printf(Perl_debug_log,
3756 "%*s failed, try continuation...\n",
3757 REPORT_CODE_OFF+PL_regindent*2, "")
3760 if (ckWARN(WARN_UNSAFE) && n >= REG_INFTY
3761 && !(PL_reg_flags & RF_warned)) {
3762 PL_reg_flags |= RF_warned;
3763 Perl_warner(aTHX_ WARN_UNSAFE, "%s limit (%d) exceeded",
3764 "Complex regular subexpression recursion",
3768 /* Failed deeper matches of scan, so see if this one works. */
3769 PL_regcc = cc->oldcc;
3771 if (regmatch(cc->next))
3774 PerlIO_printf(Perl_debug_log, "%*s failed...\n",
3775 REPORT_CODE_OFF+PL_regindent*2, "")
3780 cc->lastloc = lastloc;
3785 next = scan + ARG(scan);
3788 inner = NEXTOPER(NEXTOPER(scan));
3791 inner = NEXTOPER(scan);
3796 if (OP(next) != c1) /* No choice. */
3797 next = inner; /* Avoid recursion. */
3799 int lastparen = *PL_reglastparen;
3803 PL_reginput = locinput;
3804 if (regmatch(inner))
3807 for (n = *PL_reglastparen; n > lastparen; n--)
3809 *PL_reglastparen = n;
3812 if (n = (c1 == BRANCH ? NEXT_OFF(next) : ARG(next)))
3816 inner = NEXTOPER(scan);
3817 if (c1 == BRANCHJ) {
3818 inner = NEXTOPER(inner);
3820 } while (scan != NULL && OP(scan) == c1);
3834 /* We suppose that the next guy does not need
3835 backtracking: in particular, it is of constant length,
3836 and has no parenths to influence future backrefs. */
3837 ln = ARG1(scan); /* min to match */
3838 n = ARG2(scan); /* max to match */
3839 paren = scan->flags;
3841 if (paren > PL_regsize)
3843 if (paren > *PL_reglastparen)
3844 *PL_reglastparen = paren;
3846 scan = NEXTOPER(scan) + NODE_STEP_REGNODE;
3848 scan += NEXT_OFF(scan); /* Skip former OPEN. */
3849 PL_reginput = locinput;
3852 if (ln && regrepeat_hard(scan, ln, &l) < ln)
3854 if (ln && l == 0 && n >= ln
3855 /* In fact, this is tricky. If paren, then the
3856 fact that we did/didnot match may influence
3857 future execution. */
3858 && !(paren && ln == 0))
3860 locinput = PL_reginput;
3861 if (PL_regkind[(U8)OP(next)] == EXACT) {
3862 c1 = UCHARAT(OPERAND(next) + 1);
3863 if (OP(next) == EXACTF)
3865 else if (OP(next) == EXACTFL)
3866 c2 = PL_fold_locale[c1];
3873 /* This may be improved if l == 0. */
3874 while (n >= ln || (n == REG_INFTY && ln > 0 && l)) { /* ln overflow ? */
3875 /* If it could work, try it. */
3877 UCHARAT(PL_reginput) == c1 ||
3878 UCHARAT(PL_reginput) == c2)
3882 PL_regstartp[paren] =
3883 HOPc(PL_reginput, -l) - PL_bostr;
3884 PL_regendp[paren] = PL_reginput - PL_bostr;
3887 PL_regendp[paren] = -1;
3893 /* Couldn't or didn't -- move forward. */
3894 PL_reginput = locinput;
3895 if (regrepeat_hard(scan, 1, &l)) {
3897 locinput = PL_reginput;
3904 n = regrepeat_hard(scan, n, &l);
3905 if (n != 0 && l == 0
3906 /* In fact, this is tricky. If paren, then the
3907 fact that we did/didnot match may influence
3908 future execution. */
3909 && !(paren && ln == 0))
3911 locinput = PL_reginput;
3913 PerlIO_printf(Perl_debug_log,
3914 "%*s matched %ld times, len=%ld...\n",
3915 REPORT_CODE_OFF+PL_regindent*2, "", n, l)
3918 if (PL_regkind[(U8)OP(next)] == EXACT) {
3919 c1 = UCHARAT(OPERAND(next) + 1);
3920 if (OP(next) == EXACTF)
3922 else if (OP(next) == EXACTFL)
3923 c2 = PL_fold_locale[c1];
3932 /* If it could work, try it. */
3934 UCHARAT(PL_reginput) == c1 ||
3935 UCHARAT(PL_reginput) == c2)
3938 PerlIO_printf(Perl_debug_log,
3939 "%*s trying tail with n=%ld...\n",
3940 REPORT_CODE_OFF+PL_regindent*2, "", n)
3944 PL_regstartp[paren] = HOPc(PL_reginput, -l) - PL_bostr;
3945 PL_regendp[paren] = PL_reginput - PL_bostr;
3948 PL_regendp[paren] = -1;
3954 /* Couldn't or didn't -- back up. */
3956 locinput = HOPc(locinput, -l);
3957 PL_reginput = locinput;
3964 paren = scan->flags; /* Which paren to set */
3965 if (paren > PL_regsize)
3967 if (paren > *PL_reglastparen)
3968 *PL_reglastparen = paren;
3969 ln = ARG1(scan); /* min to match */
3970 n = ARG2(scan); /* max to match */
3971 scan = regnext(NEXTOPER(scan) + NODE_STEP_REGNODE);
3975 ln = ARG1(scan); /* min to match */
3976 n = ARG2(scan); /* max to match */
3977 scan = NEXTOPER(scan) + NODE_STEP_REGNODE;
3982 scan = NEXTOPER(scan);
3988 scan = NEXTOPER(scan);
3992 * Lookahead to avoid useless match attempts
3993 * when we know what character comes next.
3995 if (PL_regkind[(U8)OP(next)] == EXACT) {
3996 c1 = UCHARAT(OPERAND(next) + 1);
3997 if (OP(next) == EXACTF)
3999 else if (OP(next) == EXACTFL)
4000 c2 = PL_fold_locale[c1];
4006 PL_reginput = locinput;
4010 if (ln && regrepeat(scan, ln) < ln)
4012 locinput = PL_reginput;
4015 char *e = locinput + n - ln; /* Should not check after this */
4016 char *old = locinput;
4018 if (e >= PL_regeol || (n == REG_INFTY))
4021 /* Find place 'next' could work */
4023 while (locinput <= e && *locinput != c1)
4026 while (locinput <= e
4033 /* PL_reginput == old now */
4034 if (locinput != old) {
4035 ln = 1; /* Did some */
4036 if (regrepeat(scan, locinput - old) <
4040 /* PL_reginput == locinput now */
4043 PL_regstartp[paren] = HOPc(locinput, -1) - PL_bostr;
4044 PL_regendp[paren] = locinput - PL_bostr;
4047 PL_regendp[paren] = -1;
4051 PL_reginput = locinput; /* Could be reset... */
4053 /* Couldn't or didn't -- move forward. */
4058 while (n >= ln || (n == REG_INFTY && ln > 0)) { /* ln overflow ? */
4059 /* If it could work, try it. */
4061 UCHARAT(PL_reginput) == c1 ||
4062 UCHARAT(PL_reginput) == c2)
4066 PL_regstartp[paren] = HOPc(PL_reginput, -1) - PL_bostr;
4067 PL_regendp[paren] = PL_reginput - PL_bostr;
4070 PL_regendp[paren] = -1;
4076 /* Couldn't or didn't -- move forward. */
4077 PL_reginput = locinput;
4078 if (regrepeat(scan, 1)) {
4080 locinput = PL_reginput;
4088 n = regrepeat(scan, n);
4089 locinput = PL_reginput;
4090 if (ln < n && PL_regkind[(U8)OP(next)] == EOL &&
4091 (!PL_multiline || OP(next) == SEOL))
4092 ln = n; /* why back off? */
4096 /* If it could work, try it. */
4098 UCHARAT(PL_reginput) == c1 ||
4099 UCHARAT(PL_reginput) == c2)
4103 PL_regstartp[paren] = HOPc(PL_reginput, -1) - PL_bostr;
4104 PL_regendp[paren] = PL_reginput - PL_bostr;
4107 PL_regendp[paren] = -1;
4113 /* Couldn't or didn't -- back up. */
4115 PL_reginput = locinput = HOPc(locinput, -1);
4120 /* If it could work, try it. */
4122 UCHARAT(PL_reginput) == c1 ||
4123 UCHARAT(PL_reginput) == c2)
4129 /* Couldn't or didn't -- back up. */
4131 PL_reginput = locinput = HOPc(locinput, -1);
4138 if (PL_reg_call_cc) {
4139 re_cc_state *cur_call_cc = PL_reg_call_cc;
4140 CURCUR *cctmp = PL_regcc;
4141 regexp *re = PL_reg_re;
4142 CHECKPOINT cp, lastcp;
4144 cp = regcppush(0); /* Save *all* the positions. */
4146 regcp_set_to(PL_reg_call_cc->ss); /* Restore parens of
4148 PL_reginput = locinput; /* Make position available to
4150 cache_re(PL_reg_call_cc->re);
4151 PL_regcc = PL_reg_call_cc->cc;
4152 PL_reg_call_cc = PL_reg_call_cc->prev;
4153 if (regmatch(cur_call_cc->node)) {
4154 PL_reg_call_cc = cur_call_cc;
4160 PL_reg_call_cc = cur_call_cc;
4166 PerlIO_printf(Perl_debug_log,
4167 "%*s continuation failed...\n",
4168 REPORT_CODE_OFF+PL_regindent*2, "")
4172 if (locinput < PL_regtill)
4173 sayNO; /* Cannot match: too short. */
4176 PL_reginput = locinput; /* put where regtry can find it */
4177 sayYES; /* Success! */
4180 PL_reginput = locinput;
4185 if (UTF) { /* XXXX This is absolutely
4186 broken, we read before
4188 s = HOPMAYBEc(locinput, -scan->flags);
4194 if (locinput < PL_bostr + scan->flags)
4196 PL_reginput = locinput - scan->flags;
4201 PL_reginput = locinput;
4206 if (UTF) { /* XXXX This is absolutely
4207 broken, we read before
4209 s = HOPMAYBEc(locinput, -scan->flags);
4210 if (!s || s < PL_bostr)
4215 if (locinput < PL_bostr + scan->flags)
4217 PL_reginput = locinput - scan->flags;
4222 PL_reginput = locinput;
4225 inner = NEXTOPER(NEXTOPER(scan));
4226 if (regmatch(inner) != n) {
4241 if (OP(scan) == SUSPEND) {
4242 locinput = PL_reginput;
4243 nextchr = UCHARAT(locinput);
4248 next = scan + ARG(scan);
4253 PerlIO_printf(PerlIO_stderr(), "%lx %d\n",
4254 (unsigned long)scan, OP(scan));
4255 Perl_croak(aTHX_ "regexp memory corruption");
4261 * We get here only if there's trouble -- normally "case END" is
4262 * the terminating point.
4264 Perl_croak(aTHX_ "corrupted regexp pointers");
4282 - regrepeat - repeatedly match something simple, report how many
4285 * [This routine now assumes that it will only match on things of length 1.
4286 * That was true before, but now we assume scan - reginput is the count,
4287 * rather than incrementing count on every character. [Er, except utf8.]]
4290 S_regrepeat(pTHX_ regnode *p, I32 max)
4293 register char *scan;
4294 register char *opnd;
4296 register char *loceol = PL_regeol;
4297 register I32 hardcount = 0;
4300 if (max != REG_INFTY && max < loceol - scan)
4301 loceol = scan + max;
4302 opnd = (char *) OPERAND(p);
4305 while (scan < loceol && *scan != '\n')
4313 while (scan < loceol && *scan != '\n') {
4314 scan += UTF8SKIP(scan);
4320 while (scan < loceol) {
4321 scan += UTF8SKIP(scan);
4325 case EXACT: /* length of string is 1 */
4326 c = UCHARAT(++opnd);
4327 while (scan < loceol && UCHARAT(scan) == c)
4330 case EXACTF: /* length of string is 1 */
4331 c = UCHARAT(++opnd);
4332 while (scan < loceol &&
4333 (UCHARAT(scan) == c || UCHARAT(scan) == PL_fold[c]))
4336 case EXACTFL: /* length of string is 1 */
4337 PL_reg_flags |= RF_tainted;
4338 c = UCHARAT(++opnd);
4339 while (scan < loceol &&
4340 (UCHARAT(scan) == c || UCHARAT(scan) == PL_fold_locale[c]))
4345 while (scan < loceol && REGINCLASSUTF8(p, (U8*)scan)) {
4346 scan += UTF8SKIP(scan);
4351 while (scan < loceol && REGINCLASS(opnd, *scan))
4355 while (scan < loceol && isALNUM(*scan))
4360 while (scan < loceol && swash_fetch(PL_utf8_alnum, (U8*)scan)) {
4361 scan += UTF8SKIP(scan);
4366 PL_reg_flags |= RF_tainted;
4367 while (scan < loceol && isALNUM_LC(*scan))
4371 PL_reg_flags |= RF_tainted;
4373 while (scan < loceol && isALNUM_LC_utf8((U8*)scan)) {
4374 scan += UTF8SKIP(scan);
4380 while (scan < loceol && !isALNUM(*scan))
4385 while (scan < loceol && !swash_fetch(PL_utf8_alnum, (U8*)scan)) {
4386 scan += UTF8SKIP(scan);
4391 PL_reg_flags |= RF_tainted;
4392 while (scan < loceol && !isALNUM_LC(*scan))
4396 PL_reg_flags |= RF_tainted;
4398 while (scan < loceol && !isALNUM_LC_utf8((U8*)scan)) {
4399 scan += UTF8SKIP(scan);
4404 while (scan < loceol && isSPACE(*scan))
4409 while (scan < loceol && (*scan == ' ' || swash_fetch(PL_utf8_space,(U8*)scan))) {
4410 scan += UTF8SKIP(scan);
4415 PL_reg_flags |= RF_tainted;
4416 while (scan < loceol && isSPACE_LC(*scan))
4420 PL_reg_flags |= RF_tainted;
4422 while (scan < loceol && (*scan == ' ' || isSPACE_LC_utf8((U8*)scan))) {
4423 scan += UTF8SKIP(scan);
4428 while (scan < loceol && !isSPACE(*scan))
4433 while (scan < loceol && !(*scan == ' ' || swash_fetch(PL_utf8_space,(U8*)scan))) {
4434 scan += UTF8SKIP(scan);
4439 PL_reg_flags |= RF_tainted;
4440 while (scan < loceol && !isSPACE_LC(*scan))
4444 PL_reg_flags |= RF_tainted;
4446 while (scan < loceol && !(*scan == ' ' || isSPACE_LC_utf8((U8*)scan))) {
4447 scan += UTF8SKIP(scan);
4452 while (scan < loceol && isDIGIT(*scan))
4457 while (scan < loceol && swash_fetch(PL_utf8_digit,(U8*)scan)) {
4458 scan += UTF8SKIP(scan);
4464 while (scan < loceol && !isDIGIT(*scan))
4469 while (scan < loceol && !swash_fetch(PL_utf8_digit,(U8*)scan)) {
4470 scan += UTF8SKIP(scan);
4474 default: /* Called on something of 0 width. */
4475 break; /* So match right here or not at all. */
4481 c = scan - PL_reginput;
4486 SV *prop = sv_newmortal();
4489 PerlIO_printf(Perl_debug_log,
4490 "%*s %s can match %ld times out of %ld...\n",
4491 REPORT_CODE_OFF+1, "", SvPVX(prop),c,max);
4498 - regrepeat_hard - repeatedly match something, report total lenth and length
4500 * The repeater is supposed to have constant length.
4504 S_regrepeat_hard(pTHX_ regnode *p, I32 max, I32 *lp)
4507 register char *scan;
4508 register char *start;
4509 register char *loceol = PL_regeol;
4511 I32 count = 0, res = 1;
4516 start = PL_reginput;
4518 while (PL_reginput < loceol && (scan = PL_reginput, res = regmatch(p))) {
4521 while (start < PL_reginput) {
4523 start += UTF8SKIP(start);
4534 while (PL_reginput < loceol && (scan = PL_reginput, res = regmatch(p))) {
4536 *lp = l = PL_reginput - start;
4537 if (max != REG_INFTY && l*max < loceol - scan)
4538 loceol = scan + l*max;
4551 - reginclass - determine if a character falls into a character class
4555 S_reginclass(pTHX_ register char *p, register I32 c)
4558 char flags = ANYOF_FLAGS(p);
4562 if (ANYOF_BITMAP_TEST(p, c))
4564 else if (flags & ANYOF_FOLD) {
4566 if (flags & ANYOF_LOCALE) {
4567 PL_reg_flags |= RF_tainted;
4568 cf = PL_fold_locale[c];
4572 if (ANYOF_BITMAP_TEST(p, cf))
4576 if (!match && (flags & ANYOF_CLASS)) {
4577 PL_reg_flags |= RF_tainted;
4579 (ANYOF_CLASS_TEST(p, ANYOF_ALNUM) && isALNUM_LC(c)) ||
4580 (ANYOF_CLASS_TEST(p, ANYOF_NALNUM) && !isALNUM_LC(c)) ||
4581 (ANYOF_CLASS_TEST(p, ANYOF_SPACE) && isSPACE_LC(c)) ||
4582 (ANYOF_CLASS_TEST(p, ANYOF_NSPACE) && !isSPACE_LC(c)) ||
4583 (ANYOF_CLASS_TEST(p, ANYOF_DIGIT) && isDIGIT_LC(c)) ||
4584 (ANYOF_CLASS_TEST(p, ANYOF_NDIGIT) && !isDIGIT_LC(c)) ||
4585 (ANYOF_CLASS_TEST(p, ANYOF_ALNUMC) && isALNUMC_LC(c)) ||
4586 (ANYOF_CLASS_TEST(p, ANYOF_NALNUMC) && !isALNUMC_LC(c)) ||
4587 (ANYOF_CLASS_TEST(p, ANYOF_ALPHA) && isALPHA_LC(c)) ||
4588 (ANYOF_CLASS_TEST(p, ANYOF_NALPHA) && !isALPHA_LC(c)) ||
4589 (ANYOF_CLASS_TEST(p, ANYOF_ASCII) && isASCII(c)) ||
4590 (ANYOF_CLASS_TEST(p, ANYOF_NASCII) && !isASCII(c)) ||
4591 (ANYOF_CLASS_TEST(p, ANYOF_CNTRL) && isCNTRL_LC(c)) ||
4592 (ANYOF_CLASS_TEST(p, ANYOF_NCNTRL) && !isCNTRL_LC(c)) ||
4593 (ANYOF_CLASS_TEST(p, ANYOF_GRAPH) && isGRAPH_LC(c)) ||
4594 (ANYOF_CLASS_TEST(p, ANYOF_NGRAPH) && !isGRAPH_LC(c)) ||
4595 (ANYOF_CLASS_TEST(p, ANYOF_LOWER) && isLOWER_LC(c)) ||
4596 (ANYOF_CLASS_TEST(p, ANYOF_NLOWER) && !isLOWER_LC(c)) ||
4597 (ANYOF_CLASS_TEST(p, ANYOF_PRINT) && isPRINT_LC(c)) ||
4598 (ANYOF_CLASS_TEST(p, ANYOF_NPRINT) && !isPRINT_LC(c)) ||
4599 (ANYOF_CLASS_TEST(p, ANYOF_PUNCT) && isPUNCT_LC(c)) ||
4600 (ANYOF_CLASS_TEST(p, ANYOF_NPUNCT) && !isPUNCT_LC(c)) ||
4601 (ANYOF_CLASS_TEST(p, ANYOF_UPPER) && isUPPER_LC(c)) ||
4602 (ANYOF_CLASS_TEST(p, ANYOF_NUPPER) && !isUPPER_LC(c)) ||
4603 (ANYOF_CLASS_TEST(p, ANYOF_XDIGIT) && isXDIGIT(c)) ||
4604 (ANYOF_CLASS_TEST(p, ANYOF_NXDIGIT) && !isXDIGIT(c))
4605 ) /* How's that for a conditional? */
4611 return (flags & ANYOF_INVERT) ? !match : match;
4615 S_reginclassutf8(pTHX_ regnode *f, U8 *p)
4618 char flags = ARG1(f);
4620 SV *sv = (SV*)PL_regdata->data[ARG2(f)];
4622 if (swash_fetch(sv, p))
4624 else if (flags & ANYOF_FOLD) {
4627 if (flags & ANYOF_LOCALE) {
4628 PL_reg_flags |= RF_tainted;
4629 uv_to_utf8(tmpbuf, toLOWER_LC_utf8(p));
4632 uv_to_utf8(tmpbuf, toLOWER_utf8(p));
4633 if (swash_fetch(sv, tmpbuf))
4637 /* UTF8 combined with ANYOF_CLASS is ill-defined. */
4639 return (flags & ANYOF_INVERT) ? !match : match;
4643 S_reghop(pTHX_ U8 *s, I32 off)
4647 while (off-- && s < (U8*)PL_regeol)
4652 if (s > (U8*)PL_bostr) {
4655 while (s > (U8*)PL_bostr && (*s & 0xc0) == 0x80)
4657 } /* XXX could check well-formedness here */
4665 S_reghopmaybe(pTHX_ U8* s, I32 off)
4669 while (off-- && s < (U8*)PL_regeol)
4676 if (s > (U8*)PL_bostr) {
4679 while (s > (U8*)PL_bostr && (*s & 0xc0) == 0x80)
4681 } /* XXX could check well-formedness here */
4698 restore_pos(pTHXo_ void *arg)
4701 if (PL_reg_eval_set) {
4702 if (PL_reg_oldsaved) {
4703 PL_reg_re->subbeg = PL_reg_oldsaved;
4704 PL_reg_re->sublen = PL_reg_oldsavedlen;
4705 RX_MATCH_COPIED_on(PL_reg_re);
4707 PL_reg_magic->mg_len = PL_reg_oldpos;
4708 PL_reg_eval_set = 0;
4709 PL_curpm = PL_reg_oldcurpm;