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 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. */
279 Perl_re_intuit_start(pTHX_ regexp *prog, SV *sv, char *strpos,
280 char *strend, U32 flags, re_scream_pos_data *data)
283 /* Should be nonnegative! */
289 DEBUG_r( if (!PL_colorset) reginitcolors() );
290 DEBUG_r(PerlIO_printf(Perl_debug_log,
291 "%sGuessing start of match:%s `%s%.60s%s%s' against `%s%.*s%s%s'\n",
292 PL_colors[4],PL_colors[5],PL_colors[0],
295 (strlen(prog->precomp) > 60 ? "..." : ""),
297 (strend - strpos > 60 ? 60 : strend - strpos),
298 strpos, PL_colors[1],
299 (strend - strpos > 60 ? "..." : ""))
302 if (prog->minlen > strend - strpos)
305 /* XXXX Move further down? */
306 start_shift = prog->check_offset_min; /* okay to underestimate on CC */
307 /* Should be nonnegative! */
308 end_shift = prog->minlen - start_shift -
309 CHR_SVLEN(prog->check_substr) + (SvTAIL(prog->check_substr) != 0);
311 if (prog->reganch & ROPT_ANCH) {
312 ml_anch = !( (prog->reganch & ROPT_ANCH_SINGLE)
313 || ( (prog->reganch & ROPT_ANCH_BOL)
314 && !PL_multiline ) );
316 if ((prog->check_offset_min == prog->check_offset_max) && !ml_anch) {
320 if ( !(prog->reganch & ROPT_ANCH_GPOS) /* Checked by the caller */
321 && (sv && (strpos + SvCUR(sv) != strend)) )
324 PL_regeol = strend; /* Used in HOP() */
325 s = (char*)HOP((U8*)strpos, prog->check_offset_min);
326 if (SvTAIL(prog->check_substr)) {
327 slen = SvCUR(prog->check_substr); /* >= 1 */
329 if ( strend - s > slen || strend - s < slen - 1 ) {
333 if ( strend - s == slen && strend[-1] != '\n') {
337 /* Now should match s[0..slen-2] */
339 if (slen && (*SvPVX(prog->check_substr) != *s
341 && memNE(SvPVX(prog->check_substr), s, slen))))
344 else if (*SvPVX(prog->check_substr) != *s
345 || ((slen = SvCUR(prog->check_substr)) > 1
346 && memNE(SvPVX(prog->check_substr), s, slen)))
353 if (!ml_anch && (s + prog->check_offset_max < strend - prog->minlen))
354 end_shift += strend - s - prog->minlen - prog->check_offset_max;
363 end_shift = 0; /* can happen when strend == strpos */
364 if (flags & REXEC_SCREAM) {
365 SV *c = prog->check_substr;
366 char *strbeg = SvPVX(sv); /* XXXX Assume PV_force() on SCREAM! */
367 I32 p = -1; /* Internal iterator of scream. */
368 I32 *pp = data ? data->scream_pos : &p;
370 if (PL_screamfirst[BmRARE(c)] >= 0
371 || ( BmRARE(c) == '\n'
372 && (BmPREVIOUS(c) == SvCUR(c) - 1)
374 s = screaminstr(sv, prog->check_substr,
375 start_shift + (strpos - strbeg), end_shift, pp, 0);
379 *data->scream_olds = s;
382 s = fbm_instr((unsigned char*)s + start_shift,
383 (unsigned char*)strend - end_shift,
384 prog->check_substr, PL_multiline ? FBMrf_MULTILINE : 0);
386 /* Update the count-of-usability, remove useless subpatterns,
390 ++BmUSEFUL(prog->check_substr); /* hooray */
391 goto fail; /* not present */
393 else if (s - strpos > prog->check_offset_max &&
394 ((prog->reganch & ROPT_UTF8)
395 ? ((t = reghopmaybe_c(s, -(prog->check_offset_max)))
397 : (t = s - prog->check_offset_max) != 0) ) {
398 if (ml_anch && t[-1] != '\n') {
400 while (t < strend - end_shift - prog->minlen) {
402 if (t < s - prog->check_offset_min) {
416 ++BmUSEFUL(prog->check_substr); /* hooray/2 */
420 && (strpos + SvCUR(sv) != strend) && strpos[-1] != '\n') {
424 if (!(prog->reganch & ROPT_NAUGHTY)
425 && --BmUSEFUL(prog->check_substr) < 0
426 && prog->check_substr == prog->float_substr) { /* boo */
427 /* If flags & SOMETHING - do not do it many times on the same match */
428 SvREFCNT_dec(prog->check_substr);
429 prog->check_substr = Nullsv; /* disable */
430 prog->float_substr = Nullsv; /* clear */
432 prog->reganch &= ~RE_USE_INTUIT;
438 DEBUG_r(PerlIO_printf(Perl_debug_log, "%sFound%s at offset %ld\n",
439 PL_colors[4],PL_colors[5], (long)(s - strpos)) );
442 DEBUG_r(PerlIO_printf(Perl_debug_log, "%sNot found...%s\n",
443 PL_colors[4],PL_colors[5]));
448 - regexec_flags - match a regexp against a string
451 Perl_regexec_flags(pTHX_ register regexp *prog, char *stringarg, register char *strend,
452 char *strbeg, I32 minend, SV *sv, void *data, U32 flags)
453 /* strend: pointer to null at end of string */
454 /* strbeg: real beginning of string */
455 /* minend: end of match must be >=minend after stringarg. */
456 /* data: May be used for some additional optimizations. */
457 /* nosave: For optimizations. */
462 register char *startpos = stringarg;
464 I32 minlen; /* must match at least this many chars */
465 I32 dontbother = 0; /* how many characters not to try at end */
467 I32 start_shift = 0; /* Offset of the start to find
468 constant substr. */ /* CC */
469 I32 end_shift = 0; /* Same for the end. */ /* CC */
470 I32 scream_pos = -1; /* Internal iterator of scream. */
472 SV* oreplsv = GvSV(PL_replgv);
480 PL_regnarrate = PL_debug & 512;
484 if (prog == NULL || startpos == NULL) {
485 Perl_croak(aTHX_ "NULL regexp parameter");
489 minlen = prog->minlen;
490 if (strend - startpos < minlen) goto phooey;
492 if (startpos == strbeg) /* is ^ valid at stringarg? */
495 PL_regprev = (U32)stringarg[-1];
496 if (!PL_multiline && PL_regprev == '\n')
497 PL_regprev = '\0'; /* force ^ to NOT match */
500 /* Check validity of program. */
501 if (UCHARAT(prog->program) != REG_MAGIC) {
502 Perl_croak(aTHX_ "corrupted regexp program");
508 if (prog->reganch & ROPT_UTF8)
509 PL_reg_flags |= RF_utf8;
511 /* Mark beginning of line for ^ and lookbehind. */
512 PL_regbol = startpos;
516 /* Mark end of line for $ (and such) */
519 /* see how far we have to get to not match where we matched before */
520 PL_regtill = startpos+minend;
522 /* We start without call_cc context. */
525 /* If there is a "must appear" string, look for it. */
528 if (prog->reganch & ROPT_GPOS_SEEN) {
531 if (!(flags & REXEC_IGNOREPOS) && sv && SvTYPE(sv) >= SVt_PVMG
532 && SvMAGIC(sv) && (mg = mg_find(sv, 'g')) && mg->mg_len >= 0)
533 PL_reg_ganch = strbeg + mg->mg_len;
535 PL_reg_ganch = startpos;
536 if (prog->reganch & ROPT_ANCH_GPOS) {
537 if (s > PL_reg_ganch)
543 if (!(flags & REXEC_CHECKED) && prog->check_substr != Nullsv) {
544 re_scream_pos_data d;
546 d.scream_olds = &scream_olds;
547 d.scream_pos = &scream_pos;
548 s = re_intuit_start(prog, sv, s, strend, flags, &d);
550 goto phooey; /* not present */
553 DEBUG_r( if (!PL_colorset) reginitcolors() );
554 DEBUG_r(PerlIO_printf(Perl_debug_log,
555 "%sMatching%s `%s%.60s%s%s' against `%s%.*s%s%s'\n",
556 PL_colors[4],PL_colors[5],PL_colors[0],
559 (strlen(prog->precomp) > 60 ? "..." : ""),
561 (strend - startpos > 60 ? 60 : strend - startpos),
562 startpos, PL_colors[1],
563 (strend - startpos > 60 ? "..." : ""))
566 /* Simplest case: anchored match need be tried only once. */
567 /* [unless only anchor is BOL and multiline is set] */
568 if (prog->reganch & (ROPT_ANCH & ~ROPT_ANCH_GPOS)) {
569 if (s == startpos && regtry(prog, startpos))
571 else if (PL_multiline || (prog->reganch & ROPT_IMPLICIT)
572 || (prog->reganch & ROPT_ANCH_MBOL)) /* XXXX SBOL? */
577 dontbother = minlen - 1;
578 end = HOPc(strend, -dontbother) - 1;
579 /* for multiline we only have to try after newlines */
580 if (prog->check_substr) {
586 s = re_intuit_start(prog, sv, s + 1, strend, flags, NULL);
594 if (*s++ == '\n') { /* don't need PL_utf8skip here */
602 } else if (prog->reganch & ROPT_ANCH_GPOS) {
603 if (regtry(prog, PL_reg_ganch))
608 /* Messy cases: unanchored match. */
609 if (prog->anchored_substr && prog->reganch & ROPT_SKIP) {
610 /* we have /x+whatever/ */
611 /* it must be a one character string (XXXX Except UTF?) */
612 char ch = SvPVX(prog->anchored_substr)[0];
616 if (regtry(prog, s)) goto got_it;
618 while (s < strend && *s == ch)
627 if (regtry(prog, s)) goto got_it;
629 while (s < strend && *s == ch)
637 else if (prog->anchored_substr != Nullsv
638 || (prog->float_substr != Nullsv
639 && prog->float_max_offset < strend - s)) {
640 SV *must = prog->anchored_substr
641 ? prog->anchored_substr : prog->float_substr;
643 prog->anchored_substr ? prog->anchored_offset : prog->float_max_offset;
645 prog->anchored_substr ? prog->anchored_offset : prog->float_min_offset;
646 I32 delta = back_max - back_min;
647 char *last = HOPc(strend, /* Cannot start after this */
648 -(I32)(CHR_SVLEN(must)
649 - (SvTAIL(must) != 0) + back_min));
650 char *last1; /* Last position checked before */
655 last1 = s - 1; /* bogus */
657 /* XXXX check_substr already used to find `s', can optimize if
658 check_substr==must. */
660 dontbother = end_shift;
661 strend = HOPc(strend, -dontbother);
662 while ( (s <= last) &&
663 ((flags & REXEC_SCREAM)
664 ? (s = screaminstr(sv, must, HOPc(s, back_min) - strbeg,
665 end_shift, &scream_pos, 0))
666 : (s = fbm_instr((unsigned char*)HOP(s, back_min),
667 (unsigned char*)strend, must,
668 PL_multiline ? FBMrf_MULTILINE : 0))) ) {
669 if (HOPc(s, -back_max) > last1) {
670 last1 = HOPc(s, -back_min);
671 s = HOPc(s, -back_max);
674 char *t = (last1 >= PL_bostr) ? HOPc(last1, 1) : last1 + 1;
676 last1 = HOPc(s, -back_min);
696 else if (c = prog->regstclass) {
697 I32 doevery = (prog->reganch & ROPT_SKIP) == 0;
701 dontbother = minlen - 1;
702 strend = HOPc(strend, -dontbother); /* don't bother with what can't match */
704 /* We know what class it must start with. */
707 cc = (char *) OPERAND(c);
709 if (REGINCLASSUTF8(c, (U8*)s)) {
710 if (tmp && regtry(prog, s))
721 cc = (char *) OPERAND(c);
723 if (REGINCLASS(cc, *s)) {
724 if (tmp && regtry(prog, s))
735 PL_reg_flags |= RF_tainted;
742 tmp = (s != startpos) ? UCHARAT(s - 1) : PL_regprev;
743 tmp = ((OP(c) == BOUND ? isALNUM(tmp) : isALNUM_LC(tmp)) != 0);
745 if (tmp == !(OP(c) == BOUND ? isALNUM(*s) : isALNUM_LC(*s))) {
752 if ((minlen || tmp) && regtry(prog,s))
756 PL_reg_flags |= RF_tainted;
761 strend = reghop_c(strend, -1);
763 tmp = (I32)(s != startpos) ? utf8_to_uv(reghop((U8*)s, -1), 0) : PL_regprev;
764 tmp = ((OP(c) == BOUND ? isALNUM_uni(tmp) : isALNUM_LC_uni(tmp)) != 0);
766 if (tmp == !(OP(c) == BOUND ?
767 swash_fetch(PL_utf8_alnum, (U8*)s) :
768 isALNUM_LC_utf8((U8*)s)))
776 if ((minlen || tmp) && regtry(prog,s))
780 PL_reg_flags |= RF_tainted;
787 tmp = (s != startpos) ? UCHARAT(s - 1) : PL_regprev;
788 tmp = ((OP(c) == NBOUND ? isALNUM(tmp) : isALNUM_LC(tmp)) != 0);
790 if (tmp == !(OP(c) == NBOUND ? isALNUM(*s) : isALNUM_LC(*s)))
792 else if (regtry(prog, s))
796 if ((minlen || !tmp) && regtry(prog,s))
800 PL_reg_flags |= RF_tainted;
805 strend = reghop_c(strend, -1);
807 tmp = (I32)(s != startpos) ? utf8_to_uv(reghop((U8*)s, -1), 0) : PL_regprev;
808 tmp = ((OP(c) == NBOUND ? isALNUM_uni(tmp) : isALNUM_LC_uni(tmp)) != 0);
810 if (tmp == !(OP(c) == NBOUND ?
811 swash_fetch(PL_utf8_alnum, (U8*)s) :
812 isALNUM_LC_utf8((U8*)s)))
814 else if (regtry(prog, s))
818 if ((minlen || !tmp) && regtry(prog,s))
824 if (tmp && regtry(prog, s))
836 if (swash_fetch(PL_utf8_alnum, (U8*)s)) {
837 if (tmp && regtry(prog, s))
848 PL_reg_flags |= RF_tainted;
850 if (isALNUM_LC(*s)) {
851 if (tmp && regtry(prog, s))
862 PL_reg_flags |= RF_tainted;
864 if (isALNUM_LC_utf8((U8*)s)) {
865 if (tmp && regtry(prog, s))
878 if (tmp && regtry(prog, s))
890 if (!swash_fetch(PL_utf8_alnum, (U8*)s)) {
891 if (tmp && regtry(prog, s))
902 PL_reg_flags |= RF_tainted;
904 if (!isALNUM_LC(*s)) {
905 if (tmp && regtry(prog, s))
916 PL_reg_flags |= RF_tainted;
918 if (!isALNUM_LC_utf8((U8*)s)) {
919 if (tmp && regtry(prog, s))
932 if (tmp && regtry(prog, s))
944 if (*s == ' ' || swash_fetch(PL_utf8_space,(U8*)s)) {
945 if (tmp && regtry(prog, s))
956 PL_reg_flags |= RF_tainted;
958 if (isSPACE_LC(*s)) {
959 if (tmp && regtry(prog, s))
970 PL_reg_flags |= RF_tainted;
972 if (*s == ' ' || isSPACE_LC_utf8((U8*)s)) {
973 if (tmp && regtry(prog, s))
986 if (tmp && regtry(prog, s))
998 if (!(*s == ' ' || swash_fetch(PL_utf8_space,(U8*)s))) {
999 if (tmp && regtry(prog, s))
1010 PL_reg_flags |= RF_tainted;
1011 while (s < strend) {
1012 if (!isSPACE_LC(*s)) {
1013 if (tmp && regtry(prog, s))
1024 PL_reg_flags |= RF_tainted;
1025 while (s < strend) {
1026 if (!(*s == ' ' || isSPACE_LC_utf8((U8*)s))) {
1027 if (tmp && regtry(prog, s))
1038 while (s < strend) {
1040 if (tmp && regtry(prog, s))
1051 while (s < strend) {
1052 if (swash_fetch(PL_utf8_digit,(U8*)s)) {
1053 if (tmp && regtry(prog, s))
1064 PL_reg_flags |= RF_tainted;
1065 while (s < strend) {
1066 if (isDIGIT_LC(*s)) {
1067 if (tmp && regtry(prog, s))
1078 PL_reg_flags |= RF_tainted;
1079 while (s < strend) {
1080 if (isDIGIT_LC_utf8((U8*)s)) {
1081 if (tmp && regtry(prog, s))
1092 while (s < strend) {
1094 if (tmp && regtry(prog, s))
1105 while (s < strend) {
1106 if (!swash_fetch(PL_utf8_digit,(U8*)s)) {
1107 if (tmp && regtry(prog, s))
1118 PL_reg_flags |= RF_tainted;
1119 while (s < strend) {
1120 if (!isDIGIT_LC(*s)) {
1121 if (tmp && regtry(prog, s))
1132 PL_reg_flags |= RF_tainted;
1133 while (s < strend) {
1134 if (!isDIGIT_LC_utf8((U8*)s)) {
1135 if (tmp && regtry(prog, s))
1149 if (prog->float_substr != Nullsv) { /* Trim the end. */
1151 I32 oldpos = scream_pos;
1153 if (flags & REXEC_SCREAM) {
1154 last = screaminstr(sv, prog->float_substr, s - strbeg,
1155 end_shift, &scream_pos, 1); /* last one */
1157 last = scream_olds; /* Only one occurence. */
1161 char *little = SvPV(prog->float_substr, len);
1163 if (SvTAIL(prog->float_substr)) {
1164 if (memEQ(strend - len + 1, little, len - 1))
1165 last = strend - len + 1;
1166 else if (!PL_multiline)
1167 last = memEQ(strend - len, little, len)
1168 ? strend - len : Nullch;
1174 last = rninstr(s, strend, little, little + len);
1176 last = strend; /* matching `$' */
1179 if (last == NULL) goto phooey; /* Should not happen! */
1180 dontbother = strend - last + prog->float_min_offset;
1182 if (minlen && (dontbother < minlen))
1183 dontbother = minlen - 1;
1184 strend -= dontbother; /* this one's always in bytes! */
1185 /* We don't know much -- general case. */
1188 if (regtry(prog, s))
1197 if (regtry(prog, s))
1199 } while (s++ < strend);
1207 RX_MATCH_TAINTED_set(prog, PL_reg_flags & RF_tainted);
1209 if (PL_reg_eval_set) {
1210 /* Preserve the current value of $^R */
1211 if (oreplsv != GvSV(PL_replgv))
1212 sv_setsv(oreplsv, GvSV(PL_replgv));/* So that when GvSV(replgv) is
1213 restored, the value remains
1215 restore_pos(aTHXo_ 0);
1218 /* make sure $`, $&, $', and $digit will work later */
1219 if ( !(flags & REXEC_NOT_FIRST) ) {
1220 if (RX_MATCH_COPIED(prog)) {
1221 Safefree(prog->subbeg);
1222 RX_MATCH_COPIED_off(prog);
1224 if (flags & REXEC_COPY_STR) {
1225 I32 i = PL_regeol - startpos + (stringarg - strbeg);
1227 s = savepvn(strbeg, i);
1230 RX_MATCH_COPIED_on(prog);
1233 prog->subbeg = strbeg;
1234 prog->sublen = PL_regeol - strbeg; /* strend may have been modified */
1241 if (PL_reg_eval_set)
1242 restore_pos(aTHXo_ 0);
1247 - regtry - try match at specific point
1249 STATIC I32 /* 0 failure, 1 success */
1250 S_regtry(pTHX_ regexp *prog, char *startpos)
1258 if ((prog->reganch & ROPT_EVAL_SEEN) && !PL_reg_eval_set) {
1261 PL_reg_eval_set = RS_init;
1263 PerlIO_printf(Perl_debug_log, " setting stack tmpbase at %i\n",
1264 PL_stack_sp - PL_stack_base);
1266 SAVEINT(cxstack[cxstack_ix].blk_oldsp);
1267 cxstack[cxstack_ix].blk_oldsp = PL_stack_sp - PL_stack_base;
1268 /* Otherwise OP_NEXTSTATE will free whatever on stack now. */
1270 /* Apparently this is not needed, judging by wantarray. */
1271 /* SAVEINT(cxstack[cxstack_ix].blk_gimme);
1272 cxstack[cxstack_ix].blk_gimme = G_SCALAR; */
1275 /* Make $_ available to executed code. */
1276 if (PL_reg_sv != DEFSV) {
1277 /* SAVE_DEFSV does *not* suffice here for USE_THREADS */
1282 if (!(SvTYPE(PL_reg_sv) >= SVt_PVMG && SvMAGIC(PL_reg_sv)
1283 && (mg = mg_find(PL_reg_sv, 'g')))) {
1284 /* prepare for quick setting of pos */
1285 sv_magic(PL_reg_sv, (SV*)0, 'g', Nullch, 0);
1286 mg = mg_find(PL_reg_sv, 'g');
1290 PL_reg_oldpos = mg->mg_len;
1291 SAVEDESTRUCTOR(restore_pos, 0);
1294 New(22,PL_reg_curpm, 1, PMOP);
1295 PL_reg_curpm->op_pmregexp = prog;
1296 PL_reg_oldcurpm = PL_curpm;
1297 PL_curpm = PL_reg_curpm;
1298 if (RX_MATCH_COPIED(prog)) {
1299 /* Here is a serious problem: we cannot rewrite subbeg,
1300 since it may be needed if this match fails. Thus
1301 $` inside (?{}) could fail... */
1302 PL_reg_oldsaved = prog->subbeg;
1303 PL_reg_oldsavedlen = prog->sublen;
1304 RX_MATCH_COPIED_off(prog);
1307 PL_reg_oldsaved = Nullch;
1308 prog->subbeg = PL_bostr;
1309 prog->sublen = PL_regeol - PL_bostr; /* strend may have been modified */
1311 prog->startp[0] = startpos - PL_bostr;
1312 PL_reginput = startpos;
1313 PL_regstartp = prog->startp;
1314 PL_regendp = prog->endp;
1315 PL_reglastparen = &prog->lastparen;
1316 prog->lastparen = 0;
1318 DEBUG_r(PL_reg_starttry = startpos);
1319 if (PL_reg_start_tmpl <= prog->nparens) {
1320 PL_reg_start_tmpl = prog->nparens*3/2 + 3;
1321 if(PL_reg_start_tmp)
1322 Renew(PL_reg_start_tmp, PL_reg_start_tmpl, char*);
1324 New(22,PL_reg_start_tmp, PL_reg_start_tmpl, char*);
1327 /* XXXX What this code is doing here?!!! There should be no need
1328 to do this again and again, PL_reglastparen should take care of
1332 if (prog->nparens) {
1333 for (i = prog->nparens; i >= 1; i--) {
1339 if (regmatch(prog->program + 1)) {
1340 prog->endp[0] = PL_reginput - PL_bostr;
1348 - regmatch - main matching routine
1350 * Conceptually the strategy is simple: check to see whether the current
1351 * node matches, call self recursively to see whether the rest matches,
1352 * and then act accordingly. In practice we make some effort to avoid
1353 * recursion, in particular by going through "ordinary" nodes (that don't
1354 * need to know whether the rest of the match failed) by a loop instead of
1357 /* [lwall] I've hoisted the register declarations to the outer block in order to
1358 * maybe save a little bit of pushing and popping on the stack. It also takes
1359 * advantage of machines that use a register save mask on subroutine entry.
1361 STATIC I32 /* 0 failure, 1 success */
1362 S_regmatch(pTHX_ regnode *prog)
1365 register regnode *scan; /* Current node. */
1366 regnode *next; /* Next node. */
1367 regnode *inner; /* Next node in internal branch. */
1368 register I32 nextchr; /* renamed nextchr - nextchar colides with
1369 function of same name */
1370 register I32 n; /* no or next */
1371 register I32 ln; /* len or last */
1372 register char *s; /* operand or save */
1373 register char *locinput = PL_reginput;
1374 register I32 c1, c2, paren; /* case fold search, parenth */
1375 int minmod = 0, sw = 0, logical = 0;
1380 /* Note that nextchr is a byte even in UTF */
1381 nextchr = UCHARAT(locinput);
1383 while (scan != NULL) {
1384 #define sayNO_L (logical ? (logical = 0, sw = 0, goto cont) : sayNO)
1386 # define sayYES goto yes
1387 # define sayNO goto no
1388 # define saySAME(x) if (x) goto yes; else goto no
1389 # define REPORT_CODE_OFF 24
1391 # define sayYES return 1
1392 # define sayNO return 0
1393 # define saySAME(x) return x
1396 SV *prop = sv_newmortal();
1397 int docolor = *PL_colors[0];
1398 int taill = (docolor ? 10 : 7); /* 3 chars for "> <" */
1399 int l = (PL_regeol - locinput > taill ? taill : PL_regeol - locinput);
1400 /* The part of the string before starttry has one color
1401 (pref0_len chars), between starttry and current
1402 position another one (pref_len - pref0_len chars),
1403 after the current position the third one.
1404 We assume that pref0_len <= pref_len, otherwise we
1405 decrease pref0_len. */
1406 int pref_len = (locinput - PL_bostr > (5 + taill) - l
1407 ? (5 + taill) - l : locinput - PL_bostr);
1408 int pref0_len = pref_len - (locinput - PL_reg_starttry);
1410 if (l + pref_len < (5 + taill) && l < PL_regeol - locinput)
1411 l = ( PL_regeol - locinput > (5 + taill) - pref_len
1412 ? (5 + taill) - pref_len : PL_regeol - locinput);
1415 if (pref0_len > pref_len)
1416 pref0_len = pref_len;
1417 regprop(prop, scan);
1418 PerlIO_printf(Perl_debug_log,
1419 "%4i <%s%.*s%s%s%.*s%s%s%s%.*s%s>%*s|%3d:%*s%s\n",
1420 locinput - PL_bostr,
1421 PL_colors[4], pref0_len,
1422 locinput - pref_len, PL_colors[5],
1423 PL_colors[2], pref_len - pref0_len,
1424 locinput - pref_len + pref0_len, PL_colors[3],
1425 (docolor ? "" : "> <"),
1426 PL_colors[0], l, locinput, PL_colors[1],
1427 15 - l - pref_len + 1,
1429 scan - PL_regprogram, PL_regindent*2, "",
1433 next = scan + NEXT_OFF(scan);
1439 if (locinput == PL_bostr
1440 ? PL_regprev == '\n'
1442 (nextchr || locinput < PL_regeol) && locinput[-1] == '\n') )
1444 /* regtill = regbol; */
1449 if (locinput == PL_bostr
1450 ? PL_regprev == '\n'
1451 : ((nextchr || locinput < PL_regeol) && locinput[-1] == '\n') )
1457 if (locinput == PL_regbol && PL_regprev == '\n')
1461 if (locinput == PL_reg_ganch)
1471 if ((nextchr || locinput < PL_regeol) && nextchr != '\n')
1476 if ((nextchr || locinput < PL_regeol) && nextchr != '\n')
1478 if (PL_regeol - locinput > 1)
1482 if (PL_regeol != locinput)
1486 if (nextchr & 0x80) {
1487 locinput += PL_utf8skip[nextchr];
1488 if (locinput > PL_regeol)
1490 nextchr = UCHARAT(locinput);
1493 if (!nextchr && locinput >= PL_regeol)
1495 nextchr = UCHARAT(++locinput);
1498 if (!nextchr && locinput >= PL_regeol)
1500 nextchr = UCHARAT(++locinput);
1503 if (nextchr & 0x80) {
1504 locinput += PL_utf8skip[nextchr];
1505 if (locinput > PL_regeol)
1507 nextchr = UCHARAT(locinput);
1510 if (!nextchr && locinput >= PL_regeol || nextchr == '\n')
1512 nextchr = UCHARAT(++locinput);
1515 if (!nextchr && locinput >= PL_regeol || nextchr == '\n')
1517 nextchr = UCHARAT(++locinput);
1520 s = (char *) OPERAND(scan);
1522 /* Inline the first character, for speed. */
1523 if (UCHARAT(s) != nextchr)
1525 if (PL_regeol - locinput < ln)
1527 if (ln > 1 && memNE(s, locinput, ln))
1530 nextchr = UCHARAT(locinput);
1533 PL_reg_flags |= RF_tainted;
1536 s = (char *) OPERAND(scan);
1542 c1 = OP(scan) == EXACTF;
1546 if (utf8_to_uv((U8*)s, 0) != (c1 ?
1547 toLOWER_utf8((U8*)l) :
1548 toLOWER_LC_utf8((U8*)l)))
1556 nextchr = UCHARAT(locinput);
1560 /* Inline the first character, for speed. */
1561 if (UCHARAT(s) != nextchr &&
1562 UCHARAT(s) != ((OP(scan) == EXACTF)
1563 ? PL_fold : PL_fold_locale)[nextchr])
1565 if (PL_regeol - locinput < ln)
1567 if (ln > 1 && (OP(scan) == EXACTF
1568 ? ibcmp(s, locinput, ln)
1569 : ibcmp_locale(s, locinput, ln)))
1572 nextchr = UCHARAT(locinput);
1575 s = (char *) OPERAND(scan);
1576 if (!REGINCLASSUTF8(scan, (U8*)locinput))
1578 if (locinput >= PL_regeol)
1580 locinput += PL_utf8skip[nextchr];
1581 nextchr = UCHARAT(locinput);
1584 s = (char *) OPERAND(scan);
1586 nextchr = UCHARAT(locinput);
1587 if (!REGINCLASS(s, nextchr))
1589 if (!nextchr && locinput >= PL_regeol)
1591 nextchr = UCHARAT(++locinput);
1594 PL_reg_flags |= RF_tainted;
1599 if (!(OP(scan) == ALNUM
1600 ? isALNUM(nextchr) : isALNUM_LC(nextchr)))
1602 nextchr = UCHARAT(++locinput);
1605 PL_reg_flags |= RF_tainted;
1610 if (nextchr & 0x80) {
1611 if (!(OP(scan) == ALNUMUTF8
1612 ? swash_fetch(PL_utf8_alnum, (U8*)locinput)
1613 : isALNUM_LC_utf8((U8*)locinput)))
1617 locinput += PL_utf8skip[nextchr];
1618 nextchr = UCHARAT(locinput);
1621 if (!(OP(scan) == ALNUMUTF8
1622 ? isALNUM(nextchr) : isALNUM_LC(nextchr)))
1624 nextchr = UCHARAT(++locinput);
1627 PL_reg_flags |= RF_tainted;
1630 if (!nextchr && locinput >= PL_regeol)
1632 if (OP(scan) == NALNUM
1633 ? isALNUM(nextchr) : isALNUM_LC(nextchr))
1635 nextchr = UCHARAT(++locinput);
1638 PL_reg_flags |= RF_tainted;
1641 if (!nextchr && locinput >= PL_regeol)
1643 if (nextchr & 0x80) {
1644 if (OP(scan) == NALNUMUTF8
1645 ? swash_fetch(PL_utf8_alnum, (U8*)locinput)
1646 : isALNUM_LC_utf8((U8*)locinput))
1650 locinput += PL_utf8skip[nextchr];
1651 nextchr = UCHARAT(locinput);
1654 if (OP(scan) == NALNUMUTF8
1655 ? isALNUM(nextchr) : isALNUM_LC(nextchr))
1657 nextchr = UCHARAT(++locinput);
1661 PL_reg_flags |= RF_tainted;
1665 /* was last char in word? */
1666 ln = (locinput != PL_regbol) ? UCHARAT(locinput - 1) : PL_regprev;
1667 if (OP(scan) == BOUND || OP(scan) == NBOUND) {
1669 n = isALNUM(nextchr);
1672 ln = isALNUM_LC(ln);
1673 n = isALNUM_LC(nextchr);
1675 if (((!ln) == (!n)) == (OP(scan) == BOUND || OP(scan) == BOUNDL))
1680 PL_reg_flags |= RF_tainted;
1684 /* was last char in word? */
1685 ln = (locinput != PL_regbol)
1686 ? utf8_to_uv(reghop((U8*)locinput, -1), 0) : PL_regprev;
1687 if (OP(scan) == BOUNDUTF8 || OP(scan) == NBOUNDUTF8) {
1688 ln = isALNUM_uni(ln);
1689 n = swash_fetch(PL_utf8_alnum, (U8*)locinput);
1692 ln = isALNUM_LC_uni(ln);
1693 n = isALNUM_LC_utf8((U8*)locinput);
1695 if (((!ln) == (!n)) == (OP(scan) == BOUNDUTF8 || OP(scan) == BOUNDLUTF8))
1699 PL_reg_flags |= RF_tainted;
1702 if (!nextchr && locinput >= PL_regeol)
1704 if (!(OP(scan) == SPACE
1705 ? isSPACE(nextchr) : isSPACE_LC(nextchr)))
1707 nextchr = UCHARAT(++locinput);
1710 PL_reg_flags |= RF_tainted;
1713 if (!nextchr && locinput >= PL_regeol)
1715 if (nextchr & 0x80) {
1716 if (!(OP(scan) == SPACEUTF8
1717 ? swash_fetch(PL_utf8_space,(U8*)locinput)
1718 : isSPACE_LC_utf8((U8*)locinput)))
1722 locinput += PL_utf8skip[nextchr];
1723 nextchr = UCHARAT(locinput);
1726 if (!(OP(scan) == SPACEUTF8
1727 ? isSPACE(nextchr) : isSPACE_LC(nextchr)))
1729 nextchr = UCHARAT(++locinput);
1732 PL_reg_flags |= RF_tainted;
1737 if (OP(scan) == SPACE
1738 ? isSPACE(nextchr) : isSPACE_LC(nextchr))
1740 nextchr = UCHARAT(++locinput);
1743 PL_reg_flags |= RF_tainted;
1748 if (nextchr & 0x80) {
1749 if (OP(scan) == NSPACEUTF8
1750 ? swash_fetch(PL_utf8_space,(U8*)locinput)
1751 : isSPACE_LC_utf8((U8*)locinput))
1755 locinput += PL_utf8skip[nextchr];
1756 nextchr = UCHARAT(locinput);
1759 if (OP(scan) == NSPACEUTF8
1760 ? isSPACE(nextchr) : isSPACE_LC(nextchr))
1762 nextchr = UCHARAT(++locinput);
1765 PL_reg_flags |= RF_tainted;
1768 if (!nextchr && locinput >= PL_regeol)
1770 if (!(OP(scan) == DIGIT
1771 ? isDIGIT(nextchr) : isDIGIT_LC(nextchr)))
1773 nextchr = UCHARAT(++locinput);
1776 PL_reg_flags |= RF_tainted;
1781 if (nextchr & 0x80) {
1782 if (OP(scan) == NDIGITUTF8
1783 ? swash_fetch(PL_utf8_digit,(U8*)locinput)
1784 : isDIGIT_LC_utf8((U8*)locinput))
1788 locinput += PL_utf8skip[nextchr];
1789 nextchr = UCHARAT(locinput);
1792 if (!isDIGIT(nextchr))
1794 nextchr = UCHARAT(++locinput);
1797 PL_reg_flags |= RF_tainted;
1802 if (OP(scan) == DIGIT
1803 ? isDIGIT(nextchr) : isDIGIT_LC(nextchr))
1805 nextchr = UCHARAT(++locinput);
1808 PL_reg_flags |= RF_tainted;
1811 if (!nextchr && locinput >= PL_regeol)
1813 if (nextchr & 0x80) {
1814 if (swash_fetch(PL_utf8_digit,(U8*)locinput))
1816 locinput += PL_utf8skip[nextchr];
1817 nextchr = UCHARAT(locinput);
1820 if (isDIGIT(nextchr))
1822 nextchr = UCHARAT(++locinput);
1825 if (locinput >= PL_regeol || swash_fetch(PL_utf8_mark,(U8*)locinput))
1827 locinput += PL_utf8skip[nextchr];
1828 while (locinput < PL_regeol && swash_fetch(PL_utf8_mark,(U8*)locinput))
1829 locinput += UTF8SKIP(locinput);
1830 if (locinput > PL_regeol)
1832 nextchr = UCHARAT(locinput);
1835 PL_reg_flags |= RF_tainted;
1839 n = ARG(scan); /* which paren pair */
1840 ln = PL_regstartp[n];
1841 if (*PL_reglastparen < n || ln == -1)
1842 sayNO; /* Do not match unless seen CLOSEn. */
1843 if (ln == PL_regendp[n])
1847 if (UTF && OP(scan) != REF) { /* REF can do byte comparison */
1849 char *e = PL_bostr + PL_regendp[n];
1851 * Note that we can't do the "other character" lookup trick as
1852 * in the 8-bit case (no pun intended) because in Unicode we
1853 * have to map both upper and title case to lower case.
1855 if (OP(scan) == REFF) {
1859 if (toLOWER_utf8((U8*)s) != toLOWER_utf8((U8*)l))
1869 if (toLOWER_LC_utf8((U8*)s) != toLOWER_LC_utf8((U8*)l))
1876 nextchr = UCHARAT(locinput);
1880 /* Inline the first character, for speed. */
1881 if (UCHARAT(s) != nextchr &&
1883 (UCHARAT(s) != ((OP(scan) == REFF
1884 ? PL_fold : PL_fold_locale)[nextchr]))))
1886 ln = PL_regendp[n] - ln;
1887 if (locinput + ln > PL_regeol)
1889 if (ln > 1 && (OP(scan) == REF
1890 ? memNE(s, locinput, ln)
1892 ? ibcmp(s, locinput, ln)
1893 : ibcmp_locale(s, locinput, ln))))
1896 nextchr = UCHARAT(locinput);
1907 OP_4tree *oop = PL_op;
1908 COP *ocurcop = PL_curcop;
1909 SV **ocurpad = PL_curpad;
1913 PL_op = (OP_4tree*)PL_regdata->data[n];
1914 DEBUG_r( PerlIO_printf(Perl_debug_log, " re_eval 0x%x\n", PL_op) );
1915 PL_curpad = AvARRAY((AV*)PL_regdata->data[n + 2]);
1916 PL_regendp[0] = PL_reg_magic->mg_len = locinput - PL_bostr;
1918 CALLRUNOPS(aTHX); /* Scalar context. */
1924 PL_curpad = ocurpad;
1925 PL_curcop = ocurcop;
1927 if (logical == 2) { /* Postponed subexpression. */
1929 MAGIC *mg = Null(MAGIC*);
1932 CHECKPOINT cp, lastcp;
1934 if(SvROK(ret) || SvRMAGICAL(ret)) {
1935 SV *sv = SvROK(ret) ? SvRV(ret) : ret;
1938 mg = mg_find(sv, 'r');
1941 re = (regexp *)mg->mg_obj;
1942 (void)ReREFCNT_inc(re);
1946 char *t = SvPV(ret, len);
1948 char *oprecomp = PL_regprecomp;
1949 I32 osize = PL_regsize;
1950 I32 onpar = PL_regnpar;
1953 re = CALLREGCOMP(aTHX_ t, t + len, &pm);
1955 & (SVs_TEMP | SVs_PADTMP | SVf_READONLY)))
1956 sv_magic(ret,(SV*)ReREFCNT_inc(re),'r',0,0);
1957 PL_regprecomp = oprecomp;
1962 PerlIO_printf(Perl_debug_log,
1963 "Entering embedded `%s%.60s%s%s'\n",
1967 (strlen(re->precomp) > 60 ? "..." : ""))
1970 state.prev = PL_reg_call_cc;
1971 state.cc = PL_regcc;
1972 state.re = PL_reg_re;
1978 cp = regcppush(0); /* Save *all* the positions. */
1981 state.ss = PL_savestack_ix;
1982 *PL_reglastparen = 0;
1983 PL_reg_call_cc = &state;
1984 PL_reginput = locinput;
1985 if (regmatch(re->program + 1)) {
1991 PerlIO_printf(Perl_debug_log,
1993 REPORT_CODE_OFF+PL_regindent*2, "")
1998 PL_reg_call_cc = state.prev;
1999 PL_regcc = state.cc;
2000 PL_reg_re = state.re;
2001 cache_re(PL_reg_re);
2008 sv_setsv(save_scalar(PL_replgv), ret);
2012 n = ARG(scan); /* which paren pair */
2013 PL_reg_start_tmp[n] = locinput;
2018 n = ARG(scan); /* which paren pair */
2019 PL_regstartp[n] = PL_reg_start_tmp[n] - PL_bostr;
2020 PL_regendp[n] = locinput - PL_bostr;
2021 if (n > *PL_reglastparen)
2022 *PL_reglastparen = n;
2025 n = ARG(scan); /* which paren pair */
2026 sw = (*PL_reglastparen >= n && PL_regendp[n] != -1);
2030 next = NEXTOPER(NEXTOPER(scan));
2032 next = scan + ARG(scan);
2033 if (OP(next) == IFTHEN) /* Fake one. */
2034 next = NEXTOPER(NEXTOPER(next));
2038 logical = scan->flags;
2042 CHECKPOINT cp = PL_savestack_ix;
2044 if (OP(PREVOPER(next)) == NOTHING) /* LONGJMP */
2046 cc.oldcc = PL_regcc;
2048 cc.parenfloor = *PL_reglastparen;
2050 cc.min = ARG1(scan);
2051 cc.max = ARG2(scan);
2052 cc.scan = NEXTOPER(scan) + EXTRA_STEP_2ARGS;
2056 PL_reginput = locinput;
2057 n = regmatch(PREVOPER(next)); /* start on the WHILEM */
2059 PL_regcc = cc.oldcc;
2065 * This is really hard to understand, because after we match
2066 * what we're trying to match, we must make sure the rest of
2067 * the RE is going to match for sure, and to do that we have
2068 * to go back UP the parse tree by recursing ever deeper. And
2069 * if it fails, we have to reset our parent's current state
2070 * that we can try again after backing off.
2073 CHECKPOINT cp, lastcp;
2074 CURCUR* cc = PL_regcc;
2075 char *lastloc = cc->lastloc; /* Detection of 0-len. */
2077 n = cc->cur + 1; /* how many we know we matched */
2078 PL_reginput = locinput;
2081 PerlIO_printf(Perl_debug_log,
2082 "%*s %ld out of %ld..%ld cc=%lx\n",
2083 REPORT_CODE_OFF+PL_regindent*2, "",
2084 (long)n, (long)cc->min,
2085 (long)cc->max, (long)cc)
2088 /* If degenerate scan matches "", assume scan done. */
2090 if (locinput == cc->lastloc && n >= cc->min) {
2091 PL_regcc = cc->oldcc;
2094 PerlIO_printf(Perl_debug_log,
2095 "%*s empty match detected, try continuation...\n",
2096 REPORT_CODE_OFF+PL_regindent*2, "")
2098 if (regmatch(cc->next))
2101 PerlIO_printf(Perl_debug_log,
2103 REPORT_CODE_OFF+PL_regindent*2, "")
2110 /* First just match a string of min scans. */
2114 cc->lastloc = locinput;
2115 if (regmatch(cc->scan))
2118 cc->lastloc = lastloc;
2120 PerlIO_printf(Perl_debug_log,
2122 REPORT_CODE_OFF+PL_regindent*2, "")
2127 /* Prefer next over scan for minimal matching. */
2130 PL_regcc = cc->oldcc;
2132 cp = regcppush(cc->parenfloor);
2134 if (regmatch(cc->next)) {
2136 sayYES; /* All done. */
2143 if (n >= cc->max) { /* Maximum greed exceeded? */
2144 if (ckWARN(WARN_UNSAFE) && n >= REG_INFTY
2145 && !(PL_reg_flags & RF_warned)) {
2146 PL_reg_flags |= RF_warned;
2147 Perl_warner(aTHX_ WARN_UNSAFE, "%s limit (%d) exceeded",
2148 "Complex regular subexpression recursion",
2155 PerlIO_printf(Perl_debug_log,
2156 "%*s trying longer...\n",
2157 REPORT_CODE_OFF+PL_regindent*2, "")
2159 /* Try scanning more and see if it helps. */
2160 PL_reginput = locinput;
2162 cc->lastloc = locinput;
2163 cp = regcppush(cc->parenfloor);
2165 if (regmatch(cc->scan)) {
2170 PerlIO_printf(Perl_debug_log,
2172 REPORT_CODE_OFF+PL_regindent*2, "")
2177 cc->lastloc = lastloc;
2181 /* Prefer scan over next for maximal matching. */
2183 if (n < cc->max) { /* More greed allowed? */
2184 cp = regcppush(cc->parenfloor);
2186 cc->lastloc = locinput;
2188 if (regmatch(cc->scan)) {
2193 regcppop(); /* Restore some previous $<digit>s? */
2194 PL_reginput = locinput;
2196 PerlIO_printf(Perl_debug_log,
2197 "%*s failed, try continuation...\n",
2198 REPORT_CODE_OFF+PL_regindent*2, "")
2201 if (ckWARN(WARN_UNSAFE) && n >= REG_INFTY
2202 && !(PL_reg_flags & RF_warned)) {
2203 PL_reg_flags |= RF_warned;
2204 Perl_warner(aTHX_ WARN_UNSAFE, "%s limit (%d) exceeded",
2205 "Complex regular subexpression recursion",
2209 /* Failed deeper matches of scan, so see if this one works. */
2210 PL_regcc = cc->oldcc;
2212 if (regmatch(cc->next))
2215 PerlIO_printf(Perl_debug_log, "%*s failed...\n",
2216 REPORT_CODE_OFF+PL_regindent*2, "")
2221 cc->lastloc = lastloc;
2226 next = scan + ARG(scan);
2229 inner = NEXTOPER(NEXTOPER(scan));
2232 inner = NEXTOPER(scan);
2237 if (OP(next) != c1) /* No choice. */
2238 next = inner; /* Avoid recursion. */
2240 int lastparen = *PL_reglastparen;
2244 PL_reginput = locinput;
2245 if (regmatch(inner))
2248 for (n = *PL_reglastparen; n > lastparen; n--)
2250 *PL_reglastparen = n;
2253 if (n = (c1 == BRANCH ? NEXT_OFF(next) : ARG(next)))
2257 inner = NEXTOPER(scan);
2258 if (c1 == BRANCHJ) {
2259 inner = NEXTOPER(inner);
2261 } while (scan != NULL && OP(scan) == c1);
2275 /* We suppose that the next guy does not need
2276 backtracking: in particular, it is of constant length,
2277 and has no parenths to influence future backrefs. */
2278 ln = ARG1(scan); /* min to match */
2279 n = ARG2(scan); /* max to match */
2280 paren = scan->flags;
2282 if (paren > PL_regsize)
2284 if (paren > *PL_reglastparen)
2285 *PL_reglastparen = paren;
2287 scan = NEXTOPER(scan) + NODE_STEP_REGNODE;
2289 scan += NEXT_OFF(scan); /* Skip former OPEN. */
2290 PL_reginput = locinput;
2293 if (ln && regrepeat_hard(scan, ln, &l) < ln)
2295 if (ln && l == 0 && n >= ln
2296 /* In fact, this is tricky. If paren, then the
2297 fact that we did/didnot match may influence
2298 future execution. */
2299 && !(paren && ln == 0))
2301 locinput = PL_reginput;
2302 if (PL_regkind[(U8)OP(next)] == EXACT) {
2303 c1 = UCHARAT(OPERAND(next) + 1);
2304 if (OP(next) == EXACTF)
2306 else if (OP(next) == EXACTFL)
2307 c2 = PL_fold_locale[c1];
2314 /* This may be improved if l == 0. */
2315 while (n >= ln || (n == REG_INFTY && ln > 0 && l)) { /* ln overflow ? */
2316 /* If it could work, try it. */
2318 UCHARAT(PL_reginput) == c1 ||
2319 UCHARAT(PL_reginput) == c2)
2323 PL_regstartp[paren] =
2324 HOPc(PL_reginput, -l) - PL_bostr;
2325 PL_regendp[paren] = PL_reginput - PL_bostr;
2328 PL_regendp[paren] = -1;
2334 /* Couldn't or didn't -- move forward. */
2335 PL_reginput = locinput;
2336 if (regrepeat_hard(scan, 1, &l)) {
2338 locinput = PL_reginput;
2345 n = regrepeat_hard(scan, n, &l);
2346 if (n != 0 && l == 0
2347 /* In fact, this is tricky. If paren, then the
2348 fact that we did/didnot match may influence
2349 future execution. */
2350 && !(paren && ln == 0))
2352 locinput = PL_reginput;
2354 PerlIO_printf(Perl_debug_log,
2355 "%*s matched %ld times, len=%ld...\n",
2356 REPORT_CODE_OFF+PL_regindent*2, "", n, l)
2359 if (PL_regkind[(U8)OP(next)] == EXACT) {
2360 c1 = UCHARAT(OPERAND(next) + 1);
2361 if (OP(next) == EXACTF)
2363 else if (OP(next) == EXACTFL)
2364 c2 = PL_fold_locale[c1];
2373 /* If it could work, try it. */
2375 UCHARAT(PL_reginput) == c1 ||
2376 UCHARAT(PL_reginput) == c2)
2379 PerlIO_printf(Perl_debug_log,
2380 "%*s trying tail with n=%ld...\n",
2381 REPORT_CODE_OFF+PL_regindent*2, "", n)
2385 PL_regstartp[paren] = HOPc(PL_reginput, -l) - PL_bostr;
2386 PL_regendp[paren] = PL_reginput - PL_bostr;
2389 PL_regendp[paren] = -1;
2395 /* Couldn't or didn't -- back up. */
2397 locinput = HOPc(locinput, -l);
2398 PL_reginput = locinput;
2405 paren = scan->flags; /* Which paren to set */
2406 if (paren > PL_regsize)
2408 if (paren > *PL_reglastparen)
2409 *PL_reglastparen = paren;
2410 ln = ARG1(scan); /* min to match */
2411 n = ARG2(scan); /* max to match */
2412 scan = regnext(NEXTOPER(scan) + NODE_STEP_REGNODE);
2416 ln = ARG1(scan); /* min to match */
2417 n = ARG2(scan); /* max to match */
2418 scan = NEXTOPER(scan) + NODE_STEP_REGNODE;
2423 scan = NEXTOPER(scan);
2429 scan = NEXTOPER(scan);
2433 * Lookahead to avoid useless match attempts
2434 * when we know what character comes next.
2436 if (PL_regkind[(U8)OP(next)] == EXACT) {
2437 c1 = UCHARAT(OPERAND(next) + 1);
2438 if (OP(next) == EXACTF)
2440 else if (OP(next) == EXACTFL)
2441 c2 = PL_fold_locale[c1];
2447 PL_reginput = locinput;
2451 if (ln && regrepeat(scan, ln) < ln)
2453 locinput = PL_reginput;
2456 char *e = locinput + n - ln; /* Should not check after this */
2457 char *old = locinput;
2459 if (e >= PL_regeol || (n == REG_INFTY))
2462 /* Find place 'next' could work */
2464 while (locinput <= e && *locinput != c1)
2467 while (locinput <= e
2474 /* PL_reginput == old now */
2475 if (locinput != old) {
2476 ln = 1; /* Did some */
2477 if (regrepeat(scan, locinput - old) <
2481 /* PL_reginput == locinput now */
2484 PL_regstartp[paren] = HOPc(locinput, -1) - PL_bostr;
2485 PL_regendp[paren] = locinput - PL_bostr;
2488 PL_regendp[paren] = -1;
2492 PL_reginput = locinput; /* Could be reset... */
2494 /* Couldn't or didn't -- move forward. */
2499 while (n >= ln || (n == REG_INFTY && ln > 0)) { /* ln overflow ? */
2500 /* If it could work, try it. */
2502 UCHARAT(PL_reginput) == c1 ||
2503 UCHARAT(PL_reginput) == c2)
2507 PL_regstartp[paren] = HOPc(PL_reginput, -1) - PL_bostr;
2508 PL_regendp[paren] = PL_reginput - PL_bostr;
2511 PL_regendp[paren] = -1;
2517 /* Couldn't or didn't -- move forward. */
2518 PL_reginput = locinput;
2519 if (regrepeat(scan, 1)) {
2521 locinput = PL_reginput;
2529 n = regrepeat(scan, n);
2530 locinput = PL_reginput;
2531 if (ln < n && PL_regkind[(U8)OP(next)] == EOL &&
2532 (!PL_multiline || OP(next) == SEOL))
2533 ln = n; /* why back off? */
2537 /* If it could work, try it. */
2539 UCHARAT(PL_reginput) == c1 ||
2540 UCHARAT(PL_reginput) == c2)
2544 PL_regstartp[paren] = HOPc(PL_reginput, -1) - PL_bostr;
2545 PL_regendp[paren] = PL_reginput - PL_bostr;
2548 PL_regendp[paren] = -1;
2554 /* Couldn't or didn't -- back up. */
2556 PL_reginput = locinput = HOPc(locinput, -1);
2561 /* If it could work, try it. */
2563 UCHARAT(PL_reginput) == c1 ||
2564 UCHARAT(PL_reginput) == c2)
2570 /* Couldn't or didn't -- back up. */
2572 PL_reginput = locinput = HOPc(locinput, -1);
2579 if (PL_reg_call_cc) {
2580 re_cc_state *cur_call_cc = PL_reg_call_cc;
2581 CURCUR *cctmp = PL_regcc;
2582 regexp *re = PL_reg_re;
2583 CHECKPOINT cp, lastcp;
2585 cp = regcppush(0); /* Save *all* the positions. */
2587 regcp_set_to(PL_reg_call_cc->ss); /* Restore parens of
2589 PL_reginput = locinput; /* Make position available to
2591 cache_re(PL_reg_call_cc->re);
2592 PL_regcc = PL_reg_call_cc->cc;
2593 PL_reg_call_cc = PL_reg_call_cc->prev;
2594 if (regmatch(cur_call_cc->node)) {
2595 PL_reg_call_cc = cur_call_cc;
2601 PL_reg_call_cc = cur_call_cc;
2607 PerlIO_printf(Perl_debug_log,
2608 "%*s continuation failed...\n",
2609 REPORT_CODE_OFF+PL_regindent*2, "")
2613 if (locinput < PL_regtill)
2614 sayNO; /* Cannot match: too short. */
2617 PL_reginput = locinput; /* put where regtry can find it */
2618 sayYES; /* Success! */
2621 PL_reginput = locinput;
2626 if (UTF) { /* XXXX This is absolutely
2627 broken, we read before
2629 s = HOPMAYBEc(locinput, -scan->flags);
2635 if (locinput < PL_bostr + scan->flags)
2637 PL_reginput = locinput - scan->flags;
2642 PL_reginput = locinput;
2647 if (UTF) { /* XXXX This is absolutely
2648 broken, we read before
2650 s = HOPMAYBEc(locinput, -scan->flags);
2651 if (!s || s < PL_bostr)
2656 if (locinput < PL_bostr + scan->flags)
2658 PL_reginput = locinput - scan->flags;
2663 PL_reginput = locinput;
2666 inner = NEXTOPER(NEXTOPER(scan));
2667 if (regmatch(inner) != n) {
2682 if (OP(scan) == SUSPEND) {
2683 locinput = PL_reginput;
2684 nextchr = UCHARAT(locinput);
2689 next = scan + ARG(scan);
2694 PerlIO_printf(PerlIO_stderr(), "%lx %d\n",
2695 (unsigned long)scan, OP(scan));
2696 Perl_croak(aTHX_ "regexp memory corruption");
2702 * We get here only if there's trouble -- normally "case END" is
2703 * the terminating point.
2705 Perl_croak(aTHX_ "corrupted regexp pointers");
2723 - regrepeat - repeatedly match something simple, report how many
2726 * [This routine now assumes that it will only match on things of length 1.
2727 * That was true before, but now we assume scan - reginput is the count,
2728 * rather than incrementing count on every character. [Er, except utf8.]]
2731 S_regrepeat(pTHX_ regnode *p, I32 max)
2734 register char *scan;
2735 register char *opnd;
2737 register char *loceol = PL_regeol;
2738 register I32 hardcount = 0;
2741 if (max != REG_INFTY && max < loceol - scan)
2742 loceol = scan + max;
2743 opnd = (char *) OPERAND(p);
2746 while (scan < loceol && *scan != '\n')
2754 while (scan < loceol && *scan != '\n') {
2755 scan += UTF8SKIP(scan);
2761 while (scan < loceol) {
2762 scan += UTF8SKIP(scan);
2766 case EXACT: /* length of string is 1 */
2767 c = UCHARAT(++opnd);
2768 while (scan < loceol && UCHARAT(scan) == c)
2771 case EXACTF: /* length of string is 1 */
2772 c = UCHARAT(++opnd);
2773 while (scan < loceol &&
2774 (UCHARAT(scan) == c || UCHARAT(scan) == PL_fold[c]))
2777 case EXACTFL: /* length of string is 1 */
2778 PL_reg_flags |= RF_tainted;
2779 c = UCHARAT(++opnd);
2780 while (scan < loceol &&
2781 (UCHARAT(scan) == c || UCHARAT(scan) == PL_fold_locale[c]))
2786 while (scan < loceol && REGINCLASSUTF8(p, (U8*)scan)) {
2787 scan += UTF8SKIP(scan);
2792 while (scan < loceol && REGINCLASS(opnd, *scan))
2796 while (scan < loceol && isALNUM(*scan))
2801 while (scan < loceol && swash_fetch(PL_utf8_alnum, (U8*)scan)) {
2802 scan += UTF8SKIP(scan);
2807 PL_reg_flags |= RF_tainted;
2808 while (scan < loceol && isALNUM_LC(*scan))
2812 PL_reg_flags |= RF_tainted;
2814 while (scan < loceol && isALNUM_LC_utf8((U8*)scan)) {
2815 scan += UTF8SKIP(scan);
2821 while (scan < loceol && !isALNUM(*scan))
2826 while (scan < loceol && !swash_fetch(PL_utf8_alnum, (U8*)scan)) {
2827 scan += UTF8SKIP(scan);
2832 PL_reg_flags |= RF_tainted;
2833 while (scan < loceol && !isALNUM_LC(*scan))
2837 PL_reg_flags |= RF_tainted;
2839 while (scan < loceol && !isALNUM_LC_utf8((U8*)scan)) {
2840 scan += UTF8SKIP(scan);
2845 while (scan < loceol && isSPACE(*scan))
2850 while (scan < loceol && (*scan == ' ' || swash_fetch(PL_utf8_space,(U8*)scan))) {
2851 scan += UTF8SKIP(scan);
2856 PL_reg_flags |= RF_tainted;
2857 while (scan < loceol && isSPACE_LC(*scan))
2861 PL_reg_flags |= RF_tainted;
2863 while (scan < loceol && (*scan == ' ' || isSPACE_LC_utf8((U8*)scan))) {
2864 scan += UTF8SKIP(scan);
2869 while (scan < loceol && !isSPACE(*scan))
2874 while (scan < loceol && !(*scan == ' ' || swash_fetch(PL_utf8_space,(U8*)scan))) {
2875 scan += UTF8SKIP(scan);
2880 PL_reg_flags |= RF_tainted;
2881 while (scan < loceol && !isSPACE_LC(*scan))
2885 PL_reg_flags |= RF_tainted;
2887 while (scan < loceol && !(*scan == ' ' || isSPACE_LC_utf8((U8*)scan))) {
2888 scan += UTF8SKIP(scan);
2893 while (scan < loceol && isDIGIT(*scan))
2898 while (scan < loceol && swash_fetch(PL_utf8_digit,(U8*)scan)) {
2899 scan += UTF8SKIP(scan);
2905 while (scan < loceol && !isDIGIT(*scan))
2910 while (scan < loceol && !swash_fetch(PL_utf8_digit,(U8*)scan)) {
2911 scan += UTF8SKIP(scan);
2915 default: /* Called on something of 0 width. */
2916 break; /* So match right here or not at all. */
2922 c = scan - PL_reginput;
2927 SV *prop = sv_newmortal();
2930 PerlIO_printf(Perl_debug_log,
2931 "%*s %s can match %ld times out of %ld...\n",
2932 REPORT_CODE_OFF+1, "", SvPVX(prop),c,max);
2939 - regrepeat_hard - repeatedly match something, report total lenth and length
2941 * The repeater is supposed to have constant length.
2945 S_regrepeat_hard(pTHX_ regnode *p, I32 max, I32 *lp)
2948 register char *scan;
2949 register char *start;
2950 register char *loceol = PL_regeol;
2952 I32 count = 0, res = 1;
2957 start = PL_reginput;
2959 while (PL_reginput < loceol && (scan = PL_reginput, res = regmatch(p))) {
2962 while (start < PL_reginput) {
2964 start += UTF8SKIP(start);
2975 while (PL_reginput < loceol && (scan = PL_reginput, res = regmatch(p))) {
2977 *lp = l = PL_reginput - start;
2978 if (max != REG_INFTY && l*max < loceol - scan)
2979 loceol = scan + l*max;
2992 - reginclass - determine if a character falls into a character class
2996 S_reginclass(pTHX_ register char *p, register I32 c)
2999 char flags = ANYOF_FLAGS(p);
3003 if (ANYOF_BITMAP_TEST(p, c))
3005 else if (flags & ANYOF_FOLD) {
3007 if (flags & ANYOF_LOCALE) {
3008 PL_reg_flags |= RF_tainted;
3009 cf = PL_fold_locale[c];
3013 if (ANYOF_BITMAP_TEST(p, cf))
3017 if (!match && (flags & ANYOF_CLASS)) {
3018 PL_reg_flags |= RF_tainted;
3020 (ANYOF_CLASS_TEST(p, ANYOF_ALNUM) && isALNUM_LC(c)) ||
3021 (ANYOF_CLASS_TEST(p, ANYOF_NALNUM) && !isALNUM_LC(c)) ||
3022 (ANYOF_CLASS_TEST(p, ANYOF_SPACE) && isSPACE_LC(c)) ||
3023 (ANYOF_CLASS_TEST(p, ANYOF_NSPACE) && !isSPACE_LC(c)) ||
3024 (ANYOF_CLASS_TEST(p, ANYOF_DIGIT) && isDIGIT_LC(c)) ||
3025 (ANYOF_CLASS_TEST(p, ANYOF_NDIGIT) && !isDIGIT_LC(c)) ||
3026 (ANYOF_CLASS_TEST(p, ANYOF_ALNUMC) && isALNUMC_LC(c)) ||
3027 (ANYOF_CLASS_TEST(p, ANYOF_NALNUMC) && !isALNUMC_LC(c)) ||
3028 (ANYOF_CLASS_TEST(p, ANYOF_ALPHA) && isALPHA_LC(c)) ||
3029 (ANYOF_CLASS_TEST(p, ANYOF_NALPHA) && !isALPHA_LC(c)) ||
3030 (ANYOF_CLASS_TEST(p, ANYOF_ASCII) && isASCII(c)) ||
3031 (ANYOF_CLASS_TEST(p, ANYOF_NASCII) && !isASCII(c)) ||
3032 (ANYOF_CLASS_TEST(p, ANYOF_CNTRL) && isCNTRL_LC(c)) ||
3033 (ANYOF_CLASS_TEST(p, ANYOF_NCNTRL) && !isCNTRL_LC(c)) ||
3034 (ANYOF_CLASS_TEST(p, ANYOF_GRAPH) && isGRAPH_LC(c)) ||
3035 (ANYOF_CLASS_TEST(p, ANYOF_NGRAPH) && !isGRAPH_LC(c)) ||
3036 (ANYOF_CLASS_TEST(p, ANYOF_LOWER) && isLOWER_LC(c)) ||
3037 (ANYOF_CLASS_TEST(p, ANYOF_NLOWER) && !isLOWER_LC(c)) ||
3038 (ANYOF_CLASS_TEST(p, ANYOF_PRINT) && isPRINT_LC(c)) ||
3039 (ANYOF_CLASS_TEST(p, ANYOF_NPRINT) && !isPRINT_LC(c)) ||
3040 (ANYOF_CLASS_TEST(p, ANYOF_PUNCT) && isPUNCT_LC(c)) ||
3041 (ANYOF_CLASS_TEST(p, ANYOF_NPUNCT) && !isPUNCT_LC(c)) ||
3042 (ANYOF_CLASS_TEST(p, ANYOF_UPPER) && isUPPER_LC(c)) ||
3043 (ANYOF_CLASS_TEST(p, ANYOF_NUPPER) && !isUPPER_LC(c)) ||
3044 (ANYOF_CLASS_TEST(p, ANYOF_XDIGIT) && isXDIGIT(c)) ||
3045 (ANYOF_CLASS_TEST(p, ANYOF_NXDIGIT) && !isXDIGIT(c))
3046 ) /* How's that for a conditional? */
3052 return (flags & ANYOF_INVERT) ? !match : match;
3056 S_reginclassutf8(pTHX_ regnode *f, U8 *p)
3059 char flags = ARG1(f);
3061 SV *sv = (SV*)PL_regdata->data[ARG2(f)];
3063 if (swash_fetch(sv, p))
3065 else if (flags & ANYOF_FOLD) {
3068 if (flags & ANYOF_LOCALE) {
3069 PL_reg_flags |= RF_tainted;
3070 uv_to_utf8(tmpbuf, toLOWER_LC_utf8(p));
3073 uv_to_utf8(tmpbuf, toLOWER_utf8(p));
3074 if (swash_fetch(sv, tmpbuf))
3078 /* UTF8 combined with ANYOF_CLASS is ill-defined. */
3080 return (flags & ANYOF_INVERT) ? !match : match;
3084 S_reghop(pTHX_ U8 *s, I32 off)
3088 while (off-- && s < (U8*)PL_regeol)
3093 if (s > (U8*)PL_bostr) {
3096 while (s > (U8*)PL_bostr && (*s & 0xc0) == 0x80)
3098 } /* XXX could check well-formedness here */
3106 S_reghopmaybe(pTHX_ U8* s, I32 off)
3110 while (off-- && s < (U8*)PL_regeol)
3117 if (s > (U8*)PL_bostr) {
3120 while (s > (U8*)PL_bostr && (*s & 0xc0) == 0x80)
3122 } /* XXX could check well-formedness here */
3139 restore_pos(pTHXo_ void *arg)
3142 if (PL_reg_eval_set) {
3143 if (PL_reg_oldsaved) {
3144 PL_reg_re->subbeg = PL_reg_oldsaved;
3145 PL_reg_re->sublen = PL_reg_oldsavedlen;
3146 RX_MATCH_COPIED_on(PL_reg_re);
3148 PL_reg_magic->mg_len = PL_reg_oldpos;
3149 PL_reg_eval_set = 0;
3150 PL_curpm = PL_reg_oldcurpm;