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 */
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 /* *These* symbols are masked to allow static link. */
39 # define Perl_pregexec my_pregexec
44 * pregcomp and pregexec -- regsub and regerror are not used in perl
46 * Copyright (c) 1986 by University of Toronto.
47 * Written by Henry Spencer. Not derived from licensed software.
49 * Permission is granted to anyone to use this software for any
50 * purpose on any computer system, and to redistribute it freely,
51 * subject to the following restrictions:
53 * 1. The author is not responsible for the consequences of use of
54 * this software, no matter how awful, even if they arise
57 * 2. The origin of this software must not be misrepresented, either
58 * by explicit claim or by omission.
60 * 3. Altered versions must be plainly marked as such, and must not
61 * be misrepresented as being the original software.
63 **** Alterations to Henry's code are...
65 **** Copyright (c) 1991-1998, Larry Wall
67 **** You may distribute under the terms of either the GNU General Public
68 **** License or the Artistic License, as specified in the README file.
70 * Beware that some of this code is subtly aware of the way operator
71 * precedence is structured in regular expressions. Serious changes in
72 * regular-expression syntax might require a total rethink.
78 #define RF_tainted 1 /* tainted information used? */
79 #define RF_warned 2 /* warned about big count? */
80 #define RF_evaled 4 /* Did an EVAL with setting? */
81 #define RF_utf8 8 /* String contains multibyte chars? */
83 #define UTF (PL_reg_flags & RF_utf8)
85 #define RS_init 1 /* eval environment created */
86 #define RS_set 2 /* replsv value is set */
93 typedef I32 CHECKPOINT;
99 static I32 regmatch _((regnode *prog));
100 static I32 regrepeat _((regnode *p, I32 max));
101 static I32 regrepeat_hard _((regnode *p, I32 max, I32 *lp));
102 static I32 regtry _((regexp *prog, char *startpos));
104 static bool reginclass _((char *p, I32 c));
105 static bool reginclassutf8 _((regnode *f, U8* p));
106 static CHECKPOINT regcppush _((I32 parenfloor));
107 static char * regcppop _((void));
110 #define REGINCLASS(p,c) (*(p) ? reginclass(p,c) : ANYOF_TEST(p,c))
111 #define REGINCLASSUTF8(f,p) (ARG1(f) ? reginclassutf8(f,p) : swash_fetch((SV*)PL_regdata->data[ARG2(f)],p))
113 #define CHR_SVLEN(sv) (UTF ? sv_len_utf8(sv) : SvCUR(sv))
114 #define CHR_DIST(a,b) (UTF ? utf8_distance(a,b) : a - b)
116 static char * reghop _((unsigned char *pos, I32 off));
117 static char * reghopmaybe _((unsigned char *pos, I32 off));
118 #define HOP(pos,off) (UTF ? reghop(pos, off) : (pos + off))
119 #define HOPMAYBE(pos,off) (UTF ? reghopmaybe(pos, off) : (pos + off))
122 regcppush(I32 parenfloor)
125 int retval = PL_savestack_ix;
126 int i = (PL_regsize - parenfloor) * 4;
130 for (p = PL_regsize; p > parenfloor; p--) {
131 SSPUSHPTR(PL_regendp[p]);
132 SSPUSHPTR(PL_regstartp[p]);
133 SSPUSHPTR(PL_reg_start_tmp[p]);
136 SSPUSHINT(PL_regsize);
137 SSPUSHINT(*PL_reglastparen);
138 SSPUSHPTR(PL_reginput);
140 SSPUSHINT(SAVEt_REGCONTEXT);
144 /* These are needed since we do not localize EVAL nodes: */
145 # define REGCP_SET DEBUG_r(PerlIO_printf(Perl_debug_log, \
146 " Setting an EVAL scope, savestack=%i\n", \
147 PL_savestack_ix)); lastcp = PL_savestack_ix
149 # define REGCP_UNWIND DEBUG_r(lastcp != PL_savestack_ix ? \
150 PerlIO_printf(Perl_debug_log, \
151 " Clearing an EVAL scope, savestack=%i..%i\n", \
152 lastcp, PL_savestack_ix) : 0); regcpblow(lastcp)
162 assert(i == SAVEt_REGCONTEXT);
164 input = (char *) SSPOPPTR;
165 *PL_reglastparen = SSPOPINT;
166 PL_regsize = SSPOPINT;
167 for (i -= 3; i > 0; i -= 4) {
168 paren = (U32)SSPOPINT;
169 PL_reg_start_tmp[paren] = (char *) SSPOPPTR;
170 PL_regstartp[paren] = (char *) SSPOPPTR;
171 tmps = (char*)SSPOPPTR;
172 if (paren <= *PL_reglastparen)
173 PL_regendp[paren] = tmps;
175 PerlIO_printf(Perl_debug_log,
176 " restoring \\%d to %d(%d)..%d%s\n",
177 paren, PL_regstartp[paren] - PL_regbol,
178 PL_reg_start_tmp[paren] - PL_regbol,
179 PL_regendp[paren] - PL_regbol,
180 (paren > *PL_reglastparen ? "(no)" : ""));
184 if (*PL_reglastparen + 1 <= PL_regnpar) {
185 PerlIO_printf(Perl_debug_log,
186 " restoring \\%d..\\%d to undef\n",
187 *PL_reglastparen + 1, PL_regnpar);
190 for (paren = *PL_reglastparen + 1; paren <= PL_regnpar; paren++) {
191 if (paren > PL_regsize)
192 PL_regstartp[paren] = Nullch;
193 PL_regendp[paren] = Nullch;
198 #define regcpblow(cp) LEAVE_SCOPE(cp)
201 * pregexec and friends
205 - pregexec - match a regexp against a string
208 pregexec(register regexp *prog, char *stringarg, register char *strend,
209 char *strbeg, I32 minend, SV *screamer, U32 nosave)
210 /* strend: pointer to null at end of string */
211 /* strbeg: real beginning of string */
212 /* minend: end of match must be >=minend after stringarg. */
213 /* nosave: For optimizations. */
216 regexec_flags(prog, stringarg, strend, strbeg, minend, screamer, NULL,
217 nosave ? 0 : REXEC_COPY_STR);
221 - regexec_flags - match a regexp against a string
224 regexec_flags(register regexp *prog, char *stringarg, register char *strend,
225 char *strbeg, I32 minend, SV *screamer, void *data, U32 flags)
226 /* strend: pointer to null at end of string */
227 /* strbeg: real beginning of string */
228 /* minend: end of match must be >=minend after stringarg. */
229 /* data: May be used for some additional optimizations. */
230 /* nosave: For optimizations. */
235 register char *startpos = stringarg;
237 I32 minlen; /* must match at least this many chars */
238 I32 dontbother = 0; /* how many characters not to try at end */
240 I32 start_shift = 0; /* Offset of the start to find
241 constant substr. */ /* CC */
242 I32 end_shift = 0; /* Same for the end. */ /* CC */
243 I32 scream_pos = -1; /* Internal iterator of scream. */
245 SV* oreplsv = GvSV(PL_replgv);
251 PL_regprecomp = prog->precomp; /* Needed for error messages. */
253 PL_regnarrate = PL_debug & 512;
254 PL_regprogram = prog->program;
258 if (prog == NULL || startpos == NULL) {
259 croak("NULL regexp parameter");
263 minlen = prog->minlen;
264 if (strend - startpos < minlen) goto phooey;
266 if (startpos == strbeg) /* is ^ valid at stringarg? */
269 PL_regprev = (U32)stringarg[-1];
270 if (!PL_multiline && PL_regprev == '\n')
271 PL_regprev = '\0'; /* force ^ to NOT match */
274 /* Check validity of program. */
275 if (UCHARAT(prog->program) != MAGIC) {
276 FAIL("corrupted regexp program");
279 PL_regnpar = prog->nparens;
283 if (prog->reganch & ROPT_UTF8)
284 PL_reg_flags |= RF_utf8;
286 /* Mark beginning of line for ^ and lookbehind. */
287 PL_regbol = startpos;
290 /* Mark end of line for $ (and such) */
293 /* see how far we have to get to not match where we matched before */
294 PL_regtill = startpos+minend;
296 /* If there is a "must appear" string, look for it. */
298 if (!(flags & REXEC_CHECKED)
299 && prog->check_substr != Nullsv &&
300 !(prog->reganch & ROPT_ANCH_GPOS) &&
301 (!(prog->reganch & (ROPT_ANCH_BOL | ROPT_ANCH_MBOL))
302 || (PL_multiline && prog->check_substr == prog->anchored_substr)) )
305 start_shift = prog->check_offset_min; /* okay to underestimate on CC */
306 /* Should be nonnegative! */
307 end_shift = minlen - start_shift - CHR_SVLEN(prog->check_substr);
309 if (PL_screamfirst[BmRARE(prog->check_substr)] >= 0)
310 s = screaminstr(screamer, prog->check_substr,
311 start_shift + (stringarg - strbeg),
312 end_shift, &scream_pos, 0);
318 s = fbm_instr((unsigned char*)s + start_shift,
319 (unsigned char*)strend - end_shift,
320 prog->check_substr, 0);
322 ++BmUSEFUL(prog->check_substr); /* hooray */
323 goto phooey; /* not present */
325 else if (s - stringarg > prog->check_offset_max &&
327 ? ((t = reghopmaybe(s, -(prog->check_offset_max))) && t >= stringarg)
328 : (t = s - prog->check_offset_max) != 0
332 ++BmUSEFUL(prog->check_substr); /* hooray/2 */
335 else if (!(prog->reganch & ROPT_NAUGHTY)
336 && --BmUSEFUL(prog->check_substr) < 0
337 && prog->check_substr == prog->float_substr) { /* boo */
338 SvREFCNT_dec(prog->check_substr);
339 prog->check_substr = Nullsv; /* disable */
340 prog->float_substr = Nullsv; /* clear */
348 PerlIO_printf(Perl_debug_log,
349 "Matching `%.60s%s' against `%.*s%s'\n",
351 (strlen(prog->precomp) > 60 ? "..." : ""),
352 (strend - startpos > 60 ? 60 : strend - startpos),
354 (strend - startpos > 60 ? "..." : ""))
357 PL_regdata = prog->data;
359 /* Simplest case: anchored match need be tried only once. */
360 /* [unless only anchor is BOL and multiline is set] */
361 if (prog->reganch & ROPT_ANCH) {
362 if (regtry(prog, startpos))
364 else if (!(prog->reganch & ROPT_ANCH_GPOS) &&
365 (PL_multiline || (prog->reganch & ROPT_IMPLICIT)
366 || (prog->reganch & ROPT_ANCH_MBOL)))
369 dontbother = minlen - 1;
370 strend = HOP(strend, -dontbother);
371 /* for multiline we only have to try after newlines */
375 if (*s++ == '\n') { /* don't need utf8skip here */
376 if (s < strend && regtry(prog, s))
384 /* Messy cases: unanchored match. */
385 if (prog->anchored_substr && prog->reganch & ROPT_SKIP) {
386 /* we have /x+whatever/ */
387 /* it must be a one character string */
388 char ch = SvPVX(prog->anchored_substr)[0];
392 if (regtry(prog, s)) goto got_it;
394 while (s < strend && *s == ch)
403 if (regtry(prog, s)) goto got_it;
405 while (s < strend && *s == ch)
413 else if (prog->anchored_substr != Nullsv
414 || (prog->float_substr != Nullsv
415 && prog->float_max_offset < strend - s)) {
416 SV *must = prog->anchored_substr
417 ? prog->anchored_substr : prog->float_substr;
419 prog->anchored_substr ? prog->anchored_offset : prog->float_max_offset;
421 prog->anchored_substr ? prog->anchored_offset : prog->float_min_offset;
422 I32 delta = back_max - back_min;
423 char *last = HOP(strend, 0-(CHR_SVLEN(must) + back_min)); /* Cannot start after this */
424 char *last1; /* Last position checked before */
429 last1 = s - 1; /* bogus */
431 /* XXXX check_substr already used to find `s', can optimize if
432 check_substr==must. */
434 dontbother = end_shift;
435 strend = HOP(strend, -dontbother);
436 while ( (s <= last) &&
438 ? (s = screaminstr(screamer, must, HOP(s, back_min) - strbeg,
439 end_shift, &scream_pos, 0))
440 : (s = fbm_instr((unsigned char*)HOP(s, back_min),
441 (unsigned char*)strend, must, 0))) ) {
442 if (HOP(s, -back_max) > last1) {
443 last1 = HOP(s, -back_min);
444 s = HOP(s, -back_max);
447 char *t = (last1 >= PL_bostr) ? HOP(last1, 1) : last1 + 1;
449 last1 = HOP(s, -back_min);
469 else if (c = prog->regstclass) {
470 I32 doevery = (prog->reganch & ROPT_SKIP) == 0;
474 dontbother = minlen - 1;
475 strend = HOP(strend, -dontbother); /* don't bother with what can't match */
477 /* We know what class it must start with. */
480 cc = (char *) OPERAND(c);
482 if (REGINCLASSUTF8(c, (U8*)s)) {
483 if (tmp && regtry(prog, s))
494 cc = (char *) OPERAND(c);
496 if (REGINCLASS(cc, *s)) {
497 if (tmp && regtry(prog, s))
508 PL_reg_flags |= RF_tainted;
515 tmp = (s != startpos) ? UCHARAT(s - 1) : PL_regprev;
516 tmp = ((OP(c) == BOUND ? isALNUM(tmp) : isALNUM_LC(tmp)) != 0);
518 if (tmp == !(OP(c) == BOUND ? isALNUM(*s) : isALNUM_LC(*s))) {
525 if ((minlen || tmp) && regtry(prog,s))
529 PL_reg_flags |= RF_tainted;
534 strend = reghop(strend, -1);
536 tmp = (I32)(s != startpos) ? utf8_to_uv(reghop(s, -1), 0) : PL_regprev;
537 tmp = ((OP(c) == BOUND ? isALNUM_uni(tmp) : isALNUM_LC_uni(tmp)) != 0);
539 if (tmp == !(OP(c) == BOUND ? swash_fetch(PL_utf8_alnum, s) : isALNUM_LC_utf8(s))) {
546 if ((minlen || tmp) && regtry(prog,s))
550 PL_reg_flags |= RF_tainted;
557 tmp = (s != startpos) ? UCHARAT(s - 1) : PL_regprev;
558 tmp = ((OP(c) == NBOUND ? isALNUM(tmp) : isALNUM_LC(tmp)) != 0);
560 if (tmp == !(OP(c) == NBOUND ? isALNUM(*s) : isALNUM_LC(*s)))
562 else if (regtry(prog, s))
566 if ((minlen || !tmp) && regtry(prog,s))
570 PL_reg_flags |= RF_tainted;
575 strend = reghop(strend, -1);
577 tmp = (I32)(s != startpos) ? utf8_to_uv(reghop(s, -1), 0) : PL_regprev;
578 tmp = ((OP(c) == NBOUND ? isALNUM_uni(tmp) : isALNUM_LC_uni(tmp)) != 0);
580 if (tmp == !(OP(c) == NBOUND ? swash_fetch(PL_utf8_alnum, s) : isALNUM_LC_utf8(s)))
582 else if (regtry(prog, s))
586 if ((minlen || !tmp) && regtry(prog,s))
592 if (tmp && regtry(prog, s))
604 if (swash_fetch(PL_utf8_alnum, s)) {
605 if (tmp && regtry(prog, s))
616 PL_reg_flags |= RF_tainted;
618 if (isALNUM_LC(*s)) {
619 if (tmp && regtry(prog, s))
630 PL_reg_flags |= RF_tainted;
632 if (isALNUM_LC_utf8(s)) {
633 if (tmp && regtry(prog, s))
646 if (tmp && regtry(prog, s))
658 if (!swash_fetch(PL_utf8_alnum, s)) {
659 if (tmp && regtry(prog, s))
670 PL_reg_flags |= RF_tainted;
672 if (!isALNUM_LC(*s)) {
673 if (tmp && regtry(prog, s))
684 PL_reg_flags |= RF_tainted;
686 if (!isALNUM_LC_utf8(s)) {
687 if (tmp && regtry(prog, s))
700 if (tmp && regtry(prog, s))
712 if (*s == ' ' || swash_fetch(PL_utf8_space,s)) {
713 if (tmp && regtry(prog, s))
724 PL_reg_flags |= RF_tainted;
726 if (isSPACE_LC(*s)) {
727 if (tmp && regtry(prog, s))
738 PL_reg_flags |= RF_tainted;
740 if (*s == ' ' || isSPACE_LC_utf8(s)) {
741 if (tmp && regtry(prog, s))
754 if (tmp && regtry(prog, s))
766 if (!(*s == ' ' || swash_fetch(PL_utf8_space,s))) {
767 if (tmp && regtry(prog, s))
778 PL_reg_flags |= RF_tainted;
780 if (!isSPACE_LC(*s)) {
781 if (tmp && regtry(prog, s))
792 PL_reg_flags |= RF_tainted;
794 if (!(*s == ' ' || isSPACE_LC_utf8(s))) {
795 if (tmp && regtry(prog, s))
808 if (tmp && regtry(prog, s))
820 if (swash_fetch(PL_utf8_digit,s)) {
821 if (tmp && regtry(prog, s))
834 if (tmp && regtry(prog, s))
846 if (!swash_fetch(PL_utf8_digit,s)) {
847 if (tmp && regtry(prog, s))
861 if (prog->float_substr != Nullsv) { /* Trim the end. */
863 I32 oldpos = scream_pos;
866 last = screaminstr(screamer, prog->float_substr, s - strbeg,
867 end_shift, &scream_pos, 1); /* last one */
869 last = scream_olds; /* Only one occurence. */
874 char *little = SvPV(prog->float_substr, len);
876 last = rninstr(s, strend, little, little + len);
878 last = strend; /* matching `$' */
880 if (last == NULL) goto phooey; /* Should not happen! */
881 dontbother = strend - last + prog->float_min_offset;
883 if (minlen && (dontbother < minlen))
884 dontbother = minlen - 1;
885 strend -= dontbother; /* this one's always in bytes! */
886 /* We don't know much -- general case. */
900 } while (s++ < strend);
908 prog->subbeg = strbeg;
909 prog->subend = PL_regeol; /* strend may have been modified */
910 RX_MATCH_TAINTED_set(prog, PL_reg_flags & RF_tainted);
912 /* make sure $`, $&, $', and $digit will work later */
913 if (strbeg != prog->subbase) { /* second+ //g match. */
914 if (!(flags & REXEC_COPY_STR)) {
916 Safefree(prog->subbase);
917 prog->subbase = Nullch;
921 I32 i = PL_regeol - startpos + (stringarg - strbeg);
922 s = savepvn(strbeg, i);
923 Safefree(prog->subbase);
925 prog->subbeg = prog->subbase;
926 prog->subend = prog->subbase + i;
927 s = prog->subbase + (stringarg - strbeg);
928 for (i = 0; i <= prog->nparens; i++) {
930 prog->startp[i] = s + (prog->startp[i] - startpos);
931 prog->endp[i] = s + (prog->endp[i] - startpos);
936 /* Preserve the current value of $^R */
937 if (oreplsv != GvSV(PL_replgv)) {
938 sv_setsv(oreplsv, GvSV(PL_replgv));/* So that when GvSV(replgv) is
939 restored, the value remains
949 - regtry - try match at specific point
951 STATIC I32 /* 0 failure, 1 success */
952 regtry(regexp *prog, char *startpos)
960 if ((prog->reganch & ROPT_EVAL_SEEN) && !PL_reg_eval_set) {
961 PL_reg_eval_set = RS_init;
963 PerlIO_printf(Perl_debug_log, " setting stack tmpbase at %i\n",
964 PL_stack_sp - PL_stack_base);
966 SAVEINT(cxstack[cxstack_ix].blk_oldsp);
967 cxstack[cxstack_ix].blk_oldsp = PL_stack_sp - PL_stack_base;
968 /* Otherwise OP_NEXTSTATE will free whatever on stack now. */
970 /* Apparently this is not needed, judging by wantarray. */
971 /* SAVEINT(cxstack[cxstack_ix].blk_gimme);
972 cxstack[cxstack_ix].blk_gimme = G_SCALAR; */
974 PL_reginput = startpos;
975 PL_regstartp = prog->startp;
976 PL_regendp = prog->endp;
977 PL_reglastparen = &prog->lastparen;
980 if (PL_reg_start_tmpl <= prog->nparens) {
981 PL_reg_start_tmpl = prog->nparens*3/2 + 3;
983 Renew(PL_reg_start_tmp, PL_reg_start_tmpl, char*);
985 New(22,PL_reg_start_tmp, PL_reg_start_tmpl, char*);
991 for (i = prog->nparens; i >= 0; i--) {
997 if (regmatch(prog->program + 1)) {
998 prog->startp[0] = startpos;
999 prog->endp[0] = PL_reginput;
1007 - regmatch - main matching routine
1009 * Conceptually the strategy is simple: check to see whether the current
1010 * node matches, call self recursively to see whether the rest matches,
1011 * and then act accordingly. In practice we make some effort to avoid
1012 * recursion, in particular by going through "ordinary" nodes (that don't
1013 * need to know whether the rest of the match failed) by a loop instead of
1016 /* [lwall] I've hoisted the register declarations to the outer block in order to
1017 * maybe save a little bit of pushing and popping on the stack. It also takes
1018 * advantage of machines that use a register save mask on subroutine entry.
1020 STATIC I32 /* 0 failure, 1 success */
1021 regmatch(regnode *prog)
1024 register regnode *scan; /* Current node. */
1025 regnode *next; /* Next node. */
1026 regnode *inner; /* Next node in internal branch. */
1027 register I32 nextchr; /* renamed nextchr - nextchar colides with
1028 function of same name */
1029 register I32 n; /* no or next */
1030 register I32 ln; /* len or last */
1031 register char *s; /* operand or save */
1032 register char *locinput = PL_reginput;
1033 register I32 c1, c2, paren; /* case fold search, parenth */
1034 int minmod = 0, sw = 0, logical = 0;
1039 /* Note that nextchr is a byte even in UTF */
1040 nextchr = UCHARAT(locinput);
1042 while (scan != NULL) {
1043 #define sayNO_L (logical ? (logical = 0, sw = 0, goto cont) : sayNO)
1045 # define sayYES goto yes
1046 # define sayNO goto no
1047 # define saySAME(x) if (x) goto yes; else goto no
1048 # define REPORT_CODE_OFF 24
1050 # define sayYES return 1
1051 # define sayNO return 0
1052 # define saySAME(x) return x
1055 SV *prop = sv_newmortal();
1056 int docolor = *PL_colors[0];
1057 int taill = (docolor ? 10 : 7); /* 3 chars for "> <" */
1058 int l = (PL_regeol - locinput > taill ? taill : PL_regeol - locinput);
1059 int pref_len = (locinput - PL_bostr > (5 + taill) - l
1060 ? (5 + taill) - l : locinput - PL_bostr);
1062 if (l + pref_len < (5 + taill) && l < PL_regeol - locinput)
1063 l = ( PL_regeol - locinput > (5 + taill) - pref_len
1064 ? (5 + taill) - pref_len : PL_regeol - locinput);
1065 regprop(prop, scan);
1066 PerlIO_printf(Perl_debug_log,
1067 "%4i <%s%.*s%s%s%s%.*s%s>%*s|%3d:%*s%s\n",
1068 locinput - PL_bostr,
1069 PL_colors[2], pref_len, locinput - pref_len, PL_colors[3],
1070 (docolor ? "" : "> <"),
1071 PL_colors[0], l, locinput, PL_colors[1],
1072 15 - l - pref_len + 1,
1074 scan - PL_regprogram, PL_regindent*2, "",
1078 next = scan + NEXT_OFF(scan);
1084 if (locinput == PL_bostr
1085 ? PL_regprev == '\n'
1087 (nextchr || locinput < PL_regeol) && locinput[-1] == '\n') )
1089 /* regtill = regbol; */
1094 if (locinput == PL_bostr
1095 ? PL_regprev == '\n'
1096 : ((nextchr || locinput < PL_regeol) && locinput[-1] == '\n') )
1102 if (locinput == PL_regbol && PL_regprev == '\n')
1106 if (locinput == PL_regbol)
1116 if ((nextchr || locinput < PL_regeol) && nextchr != '\n')
1121 if ((nextchr || locinput < PL_regeol) && nextchr != '\n')
1123 if (PL_regeol - locinput > 1)
1127 if (PL_regeol != locinput)
1131 if (nextchr & 0x80) {
1132 locinput += utf8skip[nextchr];
1133 if (locinput > PL_regeol)
1135 nextchr = UCHARAT(locinput);
1138 if (!nextchr && locinput >= PL_regeol)
1140 nextchr = UCHARAT(++locinput);
1143 if (!nextchr && locinput >= PL_regeol)
1145 nextchr = UCHARAT(++locinput);
1148 if (nextchr & 0x80) {
1149 locinput += utf8skip[nextchr];
1150 if (locinput > PL_regeol)
1152 nextchr = UCHARAT(locinput);
1155 if (!nextchr && locinput >= PL_regeol || nextchr == '\n')
1157 nextchr = UCHARAT(++locinput);
1160 if (!nextchr && locinput >= PL_regeol || nextchr == '\n')
1162 nextchr = UCHARAT(++locinput);
1165 s = (char *) OPERAND(scan);
1167 /* Inline the first character, for speed. */
1168 if (UCHARAT(s) != nextchr)
1170 if (PL_regeol - locinput < ln)
1172 if (ln > 1 && memNE(s, locinput, ln))
1175 nextchr = UCHARAT(locinput);
1178 PL_reg_flags |= RF_tainted;
1181 s = (char *) OPERAND(scan);
1187 c1 = OP(scan) == EXACTF;
1191 if (utf8_to_uv(s, 0) != (c1 ? toLOWER_utf8(l) : toLOWER_LC_utf8(l)))
1197 nextchr = UCHARAT(locinput);
1201 /* Inline the first character, for speed. */
1202 if (UCHARAT(s) != nextchr &&
1203 UCHARAT(s) != ((OP(scan) == EXACTF)
1204 ? fold : fold_locale)[nextchr])
1206 if (PL_regeol - locinput < ln)
1208 if (ln > 1 && (OP(scan) == EXACTF
1209 ? ibcmp(s, locinput, ln)
1210 : ibcmp_locale(s, locinput, ln)))
1213 nextchr = UCHARAT(locinput);
1216 s = (char *) OPERAND(scan);
1217 if (!REGINCLASSUTF8(scan, (U8*)locinput))
1219 if (locinput >= PL_regeol)
1221 locinput += utf8skip[nextchr];
1222 nextchr = UCHARAT(locinput);
1225 s = (char *) OPERAND(scan);
1227 nextchr = UCHARAT(locinput);
1228 if (!REGINCLASS(s, nextchr))
1230 if (!nextchr && locinput >= PL_regeol)
1232 nextchr = UCHARAT(++locinput);
1235 PL_reg_flags |= RF_tainted;
1240 if (!(OP(scan) == ALNUM
1241 ? isALNUM(nextchr) : isALNUM_LC(nextchr)))
1243 nextchr = UCHARAT(++locinput);
1246 PL_reg_flags |= RF_tainted;
1251 if (nextchr & 0x80) {
1252 if (!(OP(scan) == ALNUMUTF8
1253 ? swash_fetch(PL_utf8_alnum, locinput) : isALNUM_LC_utf8(locinput)))
1255 locinput += utf8skip[nextchr];
1256 nextchr = UCHARAT(locinput);
1259 if (!(OP(scan) == ALNUMUTF8
1260 ? isALNUM(nextchr) : isALNUM_LC(nextchr)))
1262 nextchr = UCHARAT(++locinput);
1265 PL_reg_flags |= RF_tainted;
1268 if (!nextchr && locinput >= PL_regeol)
1270 if (OP(scan) == NALNUM
1271 ? isALNUM(nextchr) : isALNUM_LC(nextchr))
1273 nextchr = UCHARAT(++locinput);
1276 PL_reg_flags |= RF_tainted;
1279 if (!nextchr && locinput >= PL_regeol)
1281 if (nextchr & 0x80) {
1282 if (OP(scan) == NALNUMUTF8
1283 ? swash_fetch(PL_utf8_alnum, locinput) : isALNUM_LC_utf8(locinput))
1285 locinput += utf8skip[nextchr];
1286 nextchr = UCHARAT(locinput);
1289 if (OP(scan) == NALNUMUTF8
1290 ? isALNUM(nextchr) : isALNUM_LC(nextchr))
1292 nextchr = UCHARAT(++locinput);
1296 PL_reg_flags |= RF_tainted;
1300 /* was last char in word? */
1301 ln = (locinput != PL_regbol) ? UCHARAT(locinput - 1) : PL_regprev;
1302 if (OP(scan) == BOUND || OP(scan) == NBOUND) {
1304 n = isALNUM(nextchr);
1307 ln = isALNUM_LC(ln);
1308 n = isALNUM_LC(nextchr);
1310 if (((!ln) == (!n)) == (OP(scan) == BOUND || OP(scan) == BOUNDL))
1315 PL_reg_flags |= RF_tainted;
1319 /* was last char in word? */
1320 ln = (locinput != PL_regbol) ? utf8_to_uv(reghop(locinput, -1), 0) : PL_regprev;
1321 if (OP(scan) == BOUNDUTF8 || OP(scan) == NBOUNDUTF8) {
1322 ln = isALNUM_uni(ln);
1323 n = swash_fetch(PL_utf8_alnum, locinput);
1326 ln = isALNUM_LC_uni(ln);
1327 n = isALNUM_LC_utf8(locinput);
1329 if (((!ln) == (!n)) == (OP(scan) == BOUNDUTF8 || OP(scan) == BOUNDLUTF8))
1333 PL_reg_flags |= RF_tainted;
1336 if (!nextchr && locinput >= PL_regeol)
1338 if (!(OP(scan) == SPACE
1339 ? isSPACE(nextchr) : isSPACE_LC(nextchr)))
1341 nextchr = UCHARAT(++locinput);
1344 PL_reg_flags |= RF_tainted;
1347 if (!nextchr && locinput >= PL_regeol)
1349 if (nextchr & 0x80) {
1350 if (!(OP(scan) == SPACEUTF8
1351 ? swash_fetch(PL_utf8_space,locinput) : isSPACE_LC_utf8(locinput)))
1353 locinput += utf8skip[nextchr];
1354 nextchr = UCHARAT(locinput);
1357 if (!(OP(scan) == SPACEUTF8
1358 ? isSPACE(nextchr) : isSPACE_LC(nextchr)))
1360 nextchr = UCHARAT(++locinput);
1363 PL_reg_flags |= RF_tainted;
1368 if (OP(scan) == SPACE
1369 ? isSPACE(nextchr) : isSPACE_LC(nextchr))
1371 nextchr = UCHARAT(++locinput);
1374 PL_reg_flags |= RF_tainted;
1379 if (nextchr & 0x80) {
1380 if (OP(scan) == NSPACEUTF8
1381 ? swash_fetch(PL_utf8_space,locinput) : isSPACE_LC_utf8(locinput))
1383 locinput += utf8skip[nextchr];
1384 nextchr = UCHARAT(locinput);
1387 if (OP(scan) == NSPACEUTF8
1388 ? isSPACE(nextchr) : isSPACE_LC(nextchr))
1390 nextchr = UCHARAT(++locinput);
1393 if (!isDIGIT(nextchr))
1395 nextchr = UCHARAT(++locinput);
1398 if (nextchr & 0x80) {
1399 if (!(swash_fetch(PL_utf8_digit,locinput)))
1401 locinput += utf8skip[nextchr];
1402 nextchr = UCHARAT(locinput);
1405 if (!isDIGIT(nextchr))
1407 nextchr = UCHARAT(++locinput);
1410 if (!nextchr && locinput >= PL_regeol)
1412 if (isDIGIT(nextchr))
1414 nextchr = UCHARAT(++locinput);
1417 if (!nextchr && locinput >= PL_regeol)
1419 if (nextchr & 0x80) {
1420 if (swash_fetch(PL_utf8_digit,locinput))
1422 locinput += utf8skip[nextchr];
1423 nextchr = UCHARAT(locinput);
1426 if (isDIGIT(nextchr))
1428 nextchr = UCHARAT(++locinput);
1431 if (locinput >= PL_regeol || swash_fetch(PL_utf8_mark, locinput))
1433 locinput += utf8skip[nextchr];
1434 while (locinput < PL_regeol && swash_fetch(PL_utf8_mark, locinput))
1435 locinput += UTF8SKIP(locinput);
1436 if (locinput > PL_regeol)
1438 nextchr = UCHARAT(locinput);
1441 PL_reg_flags |= RF_tainted;
1445 n = ARG(scan); /* which paren pair */
1446 s = PL_regstartp[n];
1447 if (*PL_reglastparen < n || !s)
1448 sayNO; /* Do not match unless seen CLOSEn. */
1449 if (s == PL_regendp[n])
1452 if (UTF && OP(scan) != REF) { /* REF can do byte comparison */
1454 char *e = PL_regendp[n];
1456 * Note that we can't do the "other character" lookup trick as
1457 * in the 8-bit case (no pun intended) because in Unicode we
1458 * have to map both upper and title case to lower case.
1460 if (OP(scan) == REFF) {
1464 if (toLOWER_utf8(s) != toLOWER_utf8(l))
1474 if (toLOWER_LC_utf8(s) != toLOWER_LC_utf8(l))
1481 nextchr = UCHARAT(locinput);
1485 /* Inline the first character, for speed. */
1486 if (UCHARAT(s) != nextchr &&
1488 (UCHARAT(s) != ((OP(scan) == REFF
1489 ? fold : fold_locale)[nextchr]))))
1491 ln = PL_regendp[n] - s;
1492 if (locinput + ln > PL_regeol)
1494 if (ln > 1 && (OP(scan) == REF
1495 ? memNE(s, locinput, ln)
1497 ? ibcmp(s, locinput, ln)
1498 : ibcmp_locale(s, locinput, ln))))
1501 nextchr = UCHARAT(locinput);
1512 OP_4tree *oop = PL_op;
1513 COP *ocurcop = PL_curcop;
1514 SV **ocurpad = PL_curpad;
1518 PL_op = (OP_4tree*)PL_regdata->data[n];
1519 DEBUG_r( PerlIO_printf(Perl_debug_log, " re_eval 0x%x\n", PL_op) );
1520 PL_curpad = AvARRAY((AV*)PL_regdata->data[n + 1]);
1522 CALLRUNOPS(); /* Scalar context. */
1532 sv_setsv(save_scalar(PL_replgv), ret);
1534 PL_curpad = ocurpad;
1535 PL_curcop = ocurcop;
1539 n = ARG(scan); /* which paren pair */
1540 PL_reg_start_tmp[n] = locinput;
1545 n = ARG(scan); /* which paren pair */
1546 PL_regstartp[n] = PL_reg_start_tmp[n];
1547 PL_regendp[n] = locinput;
1548 if (n > *PL_reglastparen)
1549 *PL_reglastparen = n;
1552 n = ARG(scan); /* which paren pair */
1553 sw = (*PL_reglastparen >= n && PL_regendp[n] != NULL);
1557 next = NEXTOPER(NEXTOPER(scan));
1559 next = scan + ARG(scan);
1560 if (OP(next) == IFTHEN) /* Fake one. */
1561 next = NEXTOPER(NEXTOPER(next));
1569 CHECKPOINT cp = PL_savestack_ix;
1571 if (OP(PREVOPER(next)) == NOTHING) /* LONGJMP */
1573 cc.oldcc = PL_regcc;
1575 cc.parenfloor = *PL_reglastparen;
1577 cc.min = ARG1(scan);
1578 cc.max = ARG2(scan);
1579 cc.scan = NEXTOPER(scan) + EXTRA_STEP_2ARGS;
1583 PL_reginput = locinput;
1584 n = regmatch(PREVOPER(next)); /* start on the WHILEM */
1586 PL_regcc = cc.oldcc;
1592 * This is really hard to understand, because after we match
1593 * what we're trying to match, we must make sure the rest of
1594 * the RE is going to match for sure, and to do that we have
1595 * to go back UP the parse tree by recursing ever deeper. And
1596 * if it fails, we have to reset our parent's current state
1597 * that we can try again after backing off.
1600 CHECKPOINT cp, lastcp;
1601 CURCUR* cc = PL_regcc;
1602 char *lastloc = cc->lastloc; /* Detection of 0-len. */
1604 n = cc->cur + 1; /* how many we know we matched */
1605 PL_reginput = locinput;
1608 PerlIO_printf(Perl_debug_log,
1609 "%*s %ld out of %ld..%ld cc=%lx\n",
1610 REPORT_CODE_OFF+PL_regindent*2, "",
1611 (long)n, (long)cc->min,
1612 (long)cc->max, (long)cc)
1615 /* If degenerate scan matches "", assume scan done. */
1617 if (locinput == cc->lastloc && n >= cc->min) {
1618 PL_regcc = cc->oldcc;
1621 PerlIO_printf(Perl_debug_log,
1622 "%*s empty match detected, try continuation...\n",
1623 REPORT_CODE_OFF+PL_regindent*2, "")
1625 if (regmatch(cc->next))
1628 PerlIO_printf(Perl_debug_log,
1630 REPORT_CODE_OFF+PL_regindent*2, "")
1637 /* First just match a string of min scans. */
1641 cc->lastloc = locinput;
1642 if (regmatch(cc->scan))
1645 cc->lastloc = lastloc;
1647 PerlIO_printf(Perl_debug_log,
1649 REPORT_CODE_OFF+PL_regindent*2, "")
1654 /* Prefer next over scan for minimal matching. */
1657 PL_regcc = cc->oldcc;
1659 cp = regcppush(cc->parenfloor);
1661 if (regmatch(cc->next)) {
1663 sayYES; /* All done. */
1670 if (n >= cc->max) { /* Maximum greed exceeded? */
1671 if (ckWARN(WARN_UNSAFE) && n >= REG_INFTY
1672 && !(PL_reg_flags & RF_warned)) {
1673 PL_reg_flags |= RF_warned;
1674 warner(WARN_UNSAFE, "%s limit (%d) exceeded",
1675 "Complex regular subexpression recursion",
1682 PerlIO_printf(Perl_debug_log,
1683 "%*s trying longer...\n",
1684 REPORT_CODE_OFF+PL_regindent*2, "")
1686 /* Try scanning more and see if it helps. */
1687 PL_reginput = locinput;
1689 cc->lastloc = locinput;
1690 cp = regcppush(cc->parenfloor);
1692 if (regmatch(cc->scan)) {
1697 PerlIO_printf(Perl_debug_log,
1699 REPORT_CODE_OFF+PL_regindent*2, "")
1704 cc->lastloc = lastloc;
1708 /* Prefer scan over next for maximal matching. */
1710 if (n < cc->max) { /* More greed allowed? */
1711 cp = regcppush(cc->parenfloor);
1713 cc->lastloc = locinput;
1715 if (regmatch(cc->scan)) {
1720 regcppop(); /* Restore some previous $<digit>s? */
1721 PL_reginput = locinput;
1723 PerlIO_printf(Perl_debug_log,
1724 "%*s failed, try continuation...\n",
1725 REPORT_CODE_OFF+PL_regindent*2, "")
1728 if (ckWARN(WARN_UNSAFE) && n >= REG_INFTY
1729 && !(PL_reg_flags & RF_warned)) {
1730 PL_reg_flags |= RF_warned;
1731 warner(WARN_UNSAFE, "%s limit (%d) exceeded",
1732 "Complex regular subexpression recursion",
1736 /* Failed deeper matches of scan, so see if this one works. */
1737 PL_regcc = cc->oldcc;
1739 if (regmatch(cc->next))
1742 PerlIO_printf(Perl_debug_log, "%*s failed...\n",
1743 REPORT_CODE_OFF+PL_regindent*2, "")
1748 cc->lastloc = lastloc;
1753 next = scan + ARG(scan);
1756 inner = NEXTOPER(NEXTOPER(scan));
1759 inner = NEXTOPER(scan);
1764 if (OP(next) != c1) /* No choice. */
1765 next = inner; /* Avoid recursion. */
1767 int lastparen = *PL_reglastparen;
1771 PL_reginput = locinput;
1772 if (regmatch(inner))
1775 for (n = *PL_reglastparen; n > lastparen; n--)
1777 *PL_reglastparen = n;
1780 if (n = (c1 == BRANCH ? NEXT_OFF(next) : ARG(next)))
1784 inner = NEXTOPER(scan);
1785 if (c1 == BRANCHJ) {
1786 inner = NEXTOPER(inner);
1788 } while (scan != NULL && OP(scan) == c1);
1802 /* We suppose that the next guy does not need
1803 backtracking: in particular, it is of constant length,
1804 and has no parenths to influence future backrefs. */
1805 ln = ARG1(scan); /* min to match */
1806 n = ARG2(scan); /* max to match */
1807 paren = scan->flags;
1809 if (paren > PL_regsize)
1811 if (paren > *PL_reglastparen)
1812 *PL_reglastparen = paren;
1814 scan = NEXTOPER(scan) + NODE_STEP_REGNODE;
1816 scan += NEXT_OFF(scan); /* Skip former OPEN. */
1817 PL_reginput = locinput;
1820 if (ln && regrepeat_hard(scan, ln, &l) < ln)
1822 if (ln && l == 0 && n >= ln
1823 /* In fact, this is tricky. If paren, then the
1824 fact that we did/didnot match may influence
1825 future execution. */
1826 && !(paren && ln == 0))
1828 locinput = PL_reginput;
1829 if (regkind[(U8)OP(next)] == EXACT) {
1830 c1 = UCHARAT(OPERAND(next) + 1);
1831 if (OP(next) == EXACTF)
1833 else if (OP(next) == EXACTFL)
1834 c2 = fold_locale[c1];
1841 /* This may be improved if l == 0. */
1842 while (n >= ln || (n == REG_INFTY && ln > 0 && l)) { /* ln overflow ? */
1843 /* If it could work, try it. */
1845 UCHARAT(PL_reginput) == c1 ||
1846 UCHARAT(PL_reginput) == c2)
1850 PL_regstartp[paren] = HOP(PL_reginput, -l);
1851 PL_regendp[paren] = PL_reginput;
1854 PL_regendp[paren] = NULL;
1860 /* Couldn't or didn't -- move forward. */
1861 PL_reginput = locinput;
1862 if (regrepeat_hard(scan, 1, &l)) {
1864 locinput = PL_reginput;
1871 n = regrepeat_hard(scan, n, &l);
1872 if (n != 0 && l == 0
1873 /* In fact, this is tricky. If paren, then the
1874 fact that we did/didnot match may influence
1875 future execution. */
1876 && !(paren && ln == 0))
1878 locinput = PL_reginput;
1880 PerlIO_printf(Perl_debug_log,
1881 "%*s matched %ld times, len=%ld...\n",
1882 REPORT_CODE_OFF+PL_regindent*2, "", n, l)
1885 if (regkind[(U8)OP(next)] == EXACT) {
1886 c1 = UCHARAT(OPERAND(next) + 1);
1887 if (OP(next) == EXACTF)
1889 else if (OP(next) == EXACTFL)
1890 c2 = fold_locale[c1];
1899 /* If it could work, try it. */
1901 UCHARAT(PL_reginput) == c1 ||
1902 UCHARAT(PL_reginput) == c2)
1905 PerlIO_printf(Perl_debug_log,
1906 "%*s trying tail with n=%ld...\n",
1907 REPORT_CODE_OFF+PL_regindent*2, "", n)
1911 PL_regstartp[paren] = HOP(PL_reginput, -l);
1912 PL_regendp[paren] = PL_reginput;
1915 PL_regendp[paren] = NULL;
1921 /* Couldn't or didn't -- back up. */
1923 locinput = HOP(locinput, -l);
1924 PL_reginput = locinput;
1931 paren = scan->flags; /* Which paren to set */
1932 if (paren > PL_regsize)
1934 if (paren > *PL_reglastparen)
1935 *PL_reglastparen = paren;
1936 ln = ARG1(scan); /* min to match */
1937 n = ARG2(scan); /* max to match */
1938 scan = regnext(NEXTOPER(scan) + NODE_STEP_REGNODE);
1942 ln = ARG1(scan); /* min to match */
1943 n = ARG2(scan); /* max to match */
1944 scan = NEXTOPER(scan) + NODE_STEP_REGNODE;
1949 scan = NEXTOPER(scan);
1955 scan = NEXTOPER(scan);
1959 * Lookahead to avoid useless match attempts
1960 * when we know what character comes next.
1962 if (regkind[(U8)OP(next)] == EXACT) {
1963 c1 = UCHARAT(OPERAND(next) + 1);
1964 if (OP(next) == EXACTF)
1966 else if (OP(next) == EXACTFL)
1967 c2 = fold_locale[c1];
1973 PL_reginput = locinput;
1977 if (ln && regrepeat(scan, ln) < ln)
1979 locinput = PL_reginput;
1981 while (n >= ln || (n == REG_INFTY && ln > 0)) { /* ln overflow ? */
1982 /* If it could work, try it. */
1984 UCHARAT(PL_reginput) == c1 ||
1985 UCHARAT(PL_reginput) == c2)
1989 PL_regstartp[paren] = HOP(PL_reginput, -1);
1990 PL_regendp[paren] = PL_reginput;
1993 PL_regendp[paren] = NULL;
1999 /* Couldn't or didn't -- move forward. */
2000 PL_reginput = locinput;
2001 if (regrepeat(scan, 1)) {
2003 locinput = PL_reginput;
2011 n = regrepeat(scan, n);
2012 locinput = PL_reginput;
2013 if (ln < n && regkind[(U8)OP(next)] == EOL &&
2014 (!PL_multiline || OP(next) == SEOL))
2015 ln = n; /* why back off? */
2019 /* If it could work, try it. */
2021 UCHARAT(PL_reginput) == c1 ||
2022 UCHARAT(PL_reginput) == c2)
2026 PL_regstartp[paren] = HOP(PL_reginput, -1);
2027 PL_regendp[paren] = PL_reginput;
2030 PL_regendp[paren] = NULL;
2036 /* Couldn't or didn't -- back up. */
2038 PL_reginput = locinput = HOP(locinput, -1);
2043 /* If it could work, try it. */
2045 UCHARAT(PL_reginput) == c1 ||
2046 UCHARAT(PL_reginput) == c2)
2052 /* Couldn't or didn't -- back up. */
2054 PL_reginput = locinput = HOP(locinput, -1);
2061 if (locinput < PL_regtill)
2062 sayNO; /* Cannot match: too short. */
2065 PL_reginput = locinput; /* put where regtry can find it */
2066 sayYES; /* Success! */
2073 s = HOPMAYBE(locinput, -scan->flags);
2079 PL_reginput = locinput;
2084 s = HOPMAYBE(locinput, -scan->flags);
2090 PL_reginput = locinput;
2093 inner = NEXTOPER(NEXTOPER(scan));
2094 if (regmatch(inner) != n) {
2109 if (OP(scan) == SUSPEND) {
2110 locinput = PL_reginput;
2111 nextchr = UCHARAT(locinput);
2116 next = scan + ARG(scan);
2121 PerlIO_printf(PerlIO_stderr(), "%lx %d\n",
2122 (unsigned long)scan, OP(scan));
2123 FAIL("regexp memory corruption");
2129 * We get here only if there's trouble -- normally "case END" is
2130 * the terminating point.
2132 FAIL("corrupted regexp pointers");
2150 - regrepeat - repeatedly match something simple, report how many
2153 * [This routine now assumes that it will only match on things of length 1.
2154 * That was true before, but now we assume scan - reginput is the count,
2155 * rather than incrementing count on every character. [Er, except utf8.]]
2158 regrepeat(regnode *p, I32 max)
2161 register char *scan;
2162 register char *opnd;
2164 register char *loceol = PL_regeol;
2165 register I32 hardcount = 0;
2168 if (max != REG_INFTY && max < loceol - scan)
2169 loceol = scan + max;
2170 opnd = (char *) OPERAND(p);
2173 while (scan < loceol && *scan != '\n')
2181 while (scan < loceol && *scan != '\n') {
2182 scan += UTF8SKIP(scan);
2188 while (scan < loceol) {
2189 scan += UTF8SKIP(scan);
2193 case EXACT: /* length of string is 1 */
2194 c = UCHARAT(++opnd);
2195 while (scan < loceol && UCHARAT(scan) == c)
2198 case EXACTF: /* length of string is 1 */
2199 c = UCHARAT(++opnd);
2200 while (scan < loceol &&
2201 (UCHARAT(scan) == c || UCHARAT(scan) == fold[c]))
2204 case EXACTFL: /* length of string is 1 */
2205 PL_reg_flags |= RF_tainted;
2206 c = UCHARAT(++opnd);
2207 while (scan < loceol &&
2208 (UCHARAT(scan) == c || UCHARAT(scan) == fold_locale[c]))
2213 while (scan < loceol && REGINCLASSUTF8(p, (U8*)scan)) {
2214 scan += UTF8SKIP(scan);
2219 while (scan < loceol && REGINCLASS(opnd, *scan))
2223 while (scan < loceol && isALNUM(*scan))
2228 while (scan < loceol && swash_fetch(PL_utf8_alnum, scan)) {
2229 scan += UTF8SKIP(scan);
2234 PL_reg_flags |= RF_tainted;
2235 while (scan < loceol && isALNUM_LC(*scan))
2239 PL_reg_flags |= RF_tainted;
2241 while (scan < loceol && isALNUM_LC_utf8(scan)) {
2242 scan += UTF8SKIP(scan);
2248 while (scan < loceol && !isALNUM(*scan))
2253 while (scan < loceol && !swash_fetch(PL_utf8_alnum, scan)) {
2254 scan += UTF8SKIP(scan);
2259 PL_reg_flags |= RF_tainted;
2260 while (scan < loceol && !isALNUM_LC(*scan))
2264 PL_reg_flags |= RF_tainted;
2266 while (scan < loceol && !isALNUM_LC_utf8(scan)) {
2267 scan += UTF8SKIP(scan);
2272 while (scan < loceol && isSPACE(*scan))
2277 while (scan < loceol && (*scan == ' ' || swash_fetch(PL_utf8_space,scan))) {
2278 scan += UTF8SKIP(scan);
2283 PL_reg_flags |= RF_tainted;
2284 while (scan < loceol && isSPACE_LC(*scan))
2288 PL_reg_flags |= RF_tainted;
2290 while (scan < loceol && (*scan == ' ' || isSPACE_LC_utf8(scan))) {
2291 scan += UTF8SKIP(scan);
2296 while (scan < loceol && !isSPACE(*scan))
2301 while (scan < loceol && !(*scan == ' ' || swash_fetch(PL_utf8_space,scan))) {
2302 scan += UTF8SKIP(scan);
2307 PL_reg_flags |= RF_tainted;
2308 while (scan < loceol && !isSPACE_LC(*scan))
2312 PL_reg_flags |= RF_tainted;
2314 while (scan < loceol && !(*scan == ' ' || isSPACE_LC_utf8(scan))) {
2315 scan += UTF8SKIP(scan);
2320 while (scan < loceol && isDIGIT(*scan))
2325 while (scan < loceol && swash_fetch(PL_utf8_digit,scan)) {
2326 scan += UTF8SKIP(scan);
2332 while (scan < loceol && !isDIGIT(*scan))
2337 while (scan < loceol && !swash_fetch(PL_utf8_digit,scan)) {
2338 scan += UTF8SKIP(scan);
2342 default: /* Called on something of 0 width. */
2343 break; /* So match right here or not at all. */
2349 c = scan - PL_reginput;
2354 SV *prop = sv_newmortal();
2357 PerlIO_printf(Perl_debug_log,
2358 "%*s %s can match %ld times out of %ld...\n",
2359 REPORT_CODE_OFF+1, "", SvPVX(prop),c,max);
2366 - regrepeat_hard - repeatedly match something, report total lenth and length
2368 * The repeater is supposed to have constant length.
2372 regrepeat_hard(regnode *p, I32 max, I32 *lp)
2375 register char *scan;
2376 register char *start;
2377 register char *loceol = PL_regeol;
2384 start = PL_reginput;
2386 while (PL_reginput < loceol && (scan = PL_reginput, regmatch(p))) {
2389 while (start < PL_reginput) {
2391 start += UTF8SKIP(start);
2402 while (PL_reginput < loceol && (scan = PL_reginput, regmatch(p))) {
2404 *lp = l = PL_reginput - start;
2405 if (max != REG_INFTY && l*max < loceol - scan)
2406 loceol = scan + l*max;
2412 if (PL_reginput < loceol)
2419 - regclass - determine if a character falls into a character class
2423 reginclass(register char *p, register I32 c)
2430 if (ANYOF_TEST(p, c))
2432 else if (flags & ANYOF_FOLD) {
2434 if (flags & ANYOF_LOCALE) {
2435 PL_reg_flags |= RF_tainted;
2436 cf = fold_locale[c];
2440 if (ANYOF_TEST(p, cf))
2444 if (!match && (flags & ANYOF_ISA)) {
2445 PL_reg_flags |= RF_tainted;
2447 if (((flags & ANYOF_ALNUML) && isALNUM_LC(c)) ||
2448 ((flags & ANYOF_NALNUML) && !isALNUM_LC(c)) ||
2449 ((flags & ANYOF_SPACEL) && isSPACE_LC(c)) ||
2450 ((flags & ANYOF_NSPACEL) && !isSPACE_LC(c)))
2456 return (flags & ANYOF_INVERT) ? !match : match;
2460 reginclassutf8(regnode *f, U8 *p)
2463 char flags = ARG1(f);
2465 SV *sv = (SV*)PL_regdata->data[ARG2(f)];
2467 if (swash_fetch(sv, p))
2469 else if (flags & ANYOF_FOLD) {
2472 if (flags & ANYOF_LOCALE) {
2473 PL_reg_flags |= RF_tainted;
2474 uv_to_utf8(tmpbuf, toLOWER_LC_utf8(p));
2477 uv_to_utf8(tmpbuf, toLOWER_utf8(p));
2478 if (swash_fetch(sv, tmpbuf))
2482 if (!match && (flags & ANYOF_ISA)) {
2483 PL_reg_flags |= RF_tainted;
2485 if (((flags & ANYOF_ALNUML) && isALNUM_LC_utf8(p)) ||
2486 ((flags & ANYOF_NALNUML) && !isALNUM_LC_utf8(p)) ||
2487 ((flags & ANYOF_SPACEL) && isSPACE_LC_utf8(p)) ||
2488 ((flags & ANYOF_NSPACEL) && !isSPACE_LC_utf8(p)))
2494 return (flags & ANYOF_INVERT) ? !match : match;
2498 reghop(unsigned char *s, I32 off)
2502 while (off-- && s < (U8*)PL_regeol)
2507 if (s > (U8*)PL_bostr) {
2510 while (s > (U8*)PL_bostr && (*s & 0xc0) == 0x80)
2512 } /* XXX could check well-formedness here */
2520 reghopmaybe(unsigned char *s, I32 off)
2524 while (off-- && s < (U8*)PL_regeol)
2531 if (s > (U8*)PL_bostr) {
2534 while (s > (U8*)PL_bostr && (*s & 0xc0) == 0x80)
2536 } /* XXX could check well-formedness here */