PL_ prefix to all perlvars, part1
[p5sagit/p5-mst-13.2.git] / regexec.c
CommitLineData
a0d0e21e 1/* regexec.c
2 */
3
4/*
5 * "One Ring to rule them all, One Ring to find them..."
6 */
7
a687059c 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!
10 */
11
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.
15 */
16
e50aee73 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.
20*/
21
b9d5759e 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
26# endif
27/* need access to debugger hooks */
28# ifndef DEBUGGING
29# define DEBUGGING
30# endif
31#endif
32
33#ifdef PERL_IN_XSUB_RE
d06ea78c 34/* We *really* need to overwrite these symbols: */
56953603 35# define Perl_regexec_flags my_regexec
36# define Perl_regdump my_regdump
37# define Perl_regprop my_regprop
d06ea78c 38/* *These* symbols are masked to allow static link. */
39# define Perl_pregexec my_pregexec
56953603 40#endif
41
f0fcb552 42/*SUPPRESS 112*/
a687059c 43/*
e50aee73 44 * pregcomp and pregexec -- regsub and regerror are not used in perl
a687059c 45 *
46 * Copyright (c) 1986 by University of Toronto.
47 * Written by Henry Spencer. Not derived from licensed software.
48 *
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:
52 *
53 * 1. The author is not responsible for the consequences of use of
54 * this software, no matter how awful, even if they arise
55 * from defects in it.
56 *
57 * 2. The origin of this software must not be misrepresented, either
58 * by explicit claim or by omission.
59 *
60 * 3. Altered versions must be plainly marked as such, and must not
61 * be misrepresented as being the original software.
62 *
63 **** Alterations to Henry's code are...
64 ****
9607fc9c 65 **** Copyright (c) 1991-1997, Larry Wall
a687059c 66 ****
9ef589d8 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.
a687059c 69 *
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.
73 */
74#include "EXTERN.h"
75#include "perl.h"
76#include "regcomp.h"
77
c277df42 78#define RF_tainted 1 /* tainted information used? */
79#define RF_warned 2 /* warned about big count? */
ce862d02 80#define RF_evaled 4 /* Did an EVAL with setting? */
81
82#define RS_init 1 /* eval environment created */
83#define RS_set 2 /* replsv value is set */
c277df42 84
a687059c 85#ifndef STATIC
86#define STATIC static
87#endif
88
76e3520e 89#ifndef PERL_OBJECT
a0d0e21e 90typedef I32 CHECKPOINT;
91
c277df42 92/*
93 * Forwards.
94 */
95
96static I32 regmatch _((regnode *prog));
97static I32 regrepeat _((regnode *p, I32 max));
98static I32 regrepeat_hard _((regnode *p, I32 max, I32 *lp));
99static I32 regtry _((regexp *prog, char *startpos));
ae5c130c 100
c277df42 101static bool reginclass _((char *p, I32 c));
55497cff 102static CHECKPOINT regcppush _((I32 parenfloor));
103static char * regcppop _((void));
76e3520e 104#endif
ae5c130c 105#define REGINCLASS(p,c) (*(p) ? reginclass(p,c) : ANYOF_TEST(p,c))
a0d0e21e 106
76e3520e 107STATIC CHECKPOINT
8ac85365 108regcppush(I32 parenfloor)
a0d0e21e 109{
11343788 110 dTHR;
3280af22 111 int retval = PL_savestack_ix;
112 int i = (PL_regsize - parenfloor) * 4;
a0d0e21e 113 int p;
114
115 SSCHECK(i + 5);
3280af22 116 for (p = PL_regsize; p > parenfloor; p--) {
117 SSPUSHPTR(PL_regendp[p]);
118 SSPUSHPTR(PL_regstartp[p]);
119 SSPUSHPTR(PL_reg_start_tmp[p]);
a0d0e21e 120 SSPUSHINT(p);
121 }
3280af22 122 SSPUSHINT(PL_regsize);
123 SSPUSHINT(*PL_reglastparen);
124 SSPUSHPTR(PL_reginput);
a0d0e21e 125 SSPUSHINT(i + 3);
126 SSPUSHINT(SAVEt_REGCONTEXT);
127 return retval;
128}
129
c277df42 130/* These are needed since we do not localize EVAL nodes: */
c3464db5 131# define REGCP_SET DEBUG_r(PerlIO_printf(Perl_debug_log, \
132 " Setting an EVAL scope, savestack=%i\n", \
3280af22 133 PL_savestack_ix)); lastcp = PL_savestack_ix
c3464db5 134
3280af22 135# define REGCP_UNWIND DEBUG_r(lastcp != PL_savestack_ix ? \
c3464db5 136 PerlIO_printf(Perl_debug_log, \
137 " Clearing an EVAL scope, savestack=%i..%i\n", \
3280af22 138 lastcp, PL_savestack_ix) : 0); regcpblow(lastcp)
c277df42 139
76e3520e 140STATIC char *
8ac85365 141regcppop(void)
a0d0e21e 142{
11343788 143 dTHR;
a0d0e21e 144 I32 i = SSPOPINT;
145 U32 paren = 0;
146 char *input;
147 char *tmps;
148 assert(i == SAVEt_REGCONTEXT);
149 i = SSPOPINT;
150 input = (char *) SSPOPPTR;
3280af22 151 *PL_reglastparen = SSPOPINT;
152 PL_regsize = SSPOPINT;
c277df42 153 for (i -= 3; i > 0; i -= 4) {
a0d0e21e 154 paren = (U32)SSPOPINT;
3280af22 155 PL_reg_start_tmp[paren] = (char *) SSPOPPTR;
156 PL_regstartp[paren] = (char *) SSPOPPTR;
a0d0e21e 157 tmps = (char*)SSPOPPTR;
3280af22 158 if (paren <= *PL_reglastparen)
159 PL_regendp[paren] = tmps;
c277df42 160 DEBUG_r(
c3464db5 161 PerlIO_printf(Perl_debug_log,
162 " restoring \\%d to %d(%d)..%d%s\n",
3280af22 163 paren, PL_regstartp[paren] - PL_regbol,
164 PL_reg_start_tmp[paren] - PL_regbol,
165 PL_regendp[paren] - PL_regbol,
166 (paren > *PL_reglastparen ? "(no)" : ""));
c277df42 167 );
a0d0e21e 168 }
c277df42 169 DEBUG_r(
3280af22 170 if (*PL_reglastparen + 1 <= PL_regnpar) {
c3464db5 171 PerlIO_printf(Perl_debug_log,
172 " restoring \\%d..\\%d to undef\n",
3280af22 173 *PL_reglastparen + 1, PL_regnpar);
c277df42 174 }
175 );
3280af22 176 for (paren = *PL_reglastparen + 1; paren <= PL_regnpar; paren++) {
177 if (paren > PL_regsize)
178 PL_regstartp[paren] = Nullch;
179 PL_regendp[paren] = Nullch;
a0d0e21e 180 }
181 return input;
182}
183
c277df42 184#define regcpblow(cp) LEAVE_SCOPE(cp)
a0d0e21e 185
a687059c 186/*
e50aee73 187 * pregexec and friends
a687059c 188 */
189
190/*
c277df42 191 - pregexec - match a regexp against a string
a687059c 192 */
c277df42 193I32
c3464db5 194pregexec(register regexp *prog, char *stringarg, register char *strend,
195 char *strbeg, I32 minend, SV *screamer, U32 nosave)
c277df42 196/* strend: pointer to null at end of string */
197/* strbeg: real beginning of string */
198/* minend: end of match must be >=minend after stringarg. */
199/* nosave: For optimizations. */
200{
201 return
202 regexec_flags(prog, stringarg, strend, strbeg, minend, screamer, NULL,
203 nosave ? 0 : REXEC_COPY_STR);
204}
205
a687059c 206/*
c277df42 207 - regexec_flags - match a regexp against a string
a687059c 208 */
79072805 209I32
c3464db5 210regexec_flags(register regexp *prog, char *stringarg, register char *strend,
211 char *strbeg, I32 minend, SV *screamer, void *data, U32 flags)
c277df42 212/* strend: pointer to null at end of string */
213/* strbeg: real beginning of string */
214/* minend: end of match must be >=minend after stringarg. */
215/* data: May be used for some additional optimizations. */
216/* nosave: For optimizations. */
a687059c 217{
5c0ca799 218 dTHR;
a0d0e21e 219 register char *s;
c277df42 220 register regnode *c;
a0d0e21e 221 register char *startpos = stringarg;
222 register I32 tmp;
c277df42 223 I32 minlen; /* must match at least this many chars */
a0d0e21e 224 I32 dontbother = 0; /* how many characters not to try at end */
225 CURCUR cc;
c277df42 226 I32 start_shift = 0; /* Offset of the start to find
227 constant substr. */
228 I32 end_shift = 0; /* Same for the end. */
229 I32 scream_pos = -1; /* Internal iterator of scream. */
230 char *scream_olds;
3280af22 231 SV* oreplsv = GvSV(PL_replgv);
a687059c 232
a0d0e21e 233 cc.cur = 0;
4633a7c4 234 cc.oldcc = 0;
3280af22 235 PL_regcc = &cc;
a0d0e21e 236
3280af22 237 PL_regprecomp = prog->precomp; /* Needed for error messages. */
a0d0e21e 238#ifdef DEBUGGING
3280af22 239 PL_regnarrate = PL_debug & 512;
240 PL_regprogram = prog->program;
a0d0e21e 241#endif
242
243 /* Be paranoid... */
244 if (prog == NULL || startpos == NULL) {
245 croak("NULL regexp parameter");
246 return 0;
247 }
248
c277df42 249 minlen = prog->minlen;
250 if (strend - startpos < minlen) goto phooey;
251
a0d0e21e 252 if (startpos == strbeg) /* is ^ valid at stringarg? */
3280af22 253 PL_regprev = '\n';
a0d0e21e 254 else {
3280af22 255 PL_regprev = stringarg[-1];
256 if (!PL_multiline && PL_regprev == '\n')
257 PL_regprev = '\0'; /* force ^ to NOT match */
a0d0e21e 258 }
bbce6d69 259
a0d0e21e 260 /* Check validity of program. */
261 if (UCHARAT(prog->program) != MAGIC) {
262 FAIL("corrupted regexp program");
263 }
264
3280af22 265 PL_regnpar = prog->nparens;
266 PL_reg_flags = 0;
267 PL_reg_eval_set = 0;
a0d0e21e 268
269 /* If there is a "must appear" string, look for it. */
270 s = startpos;
c277df42 271 if (!(flags & REXEC_CHECKED)
272 && prog->check_substr != Nullsv &&
774d564b 273 !(prog->reganch & ROPT_ANCH_GPOS) &&
c277df42 274 (!(prog->reganch & (ROPT_ANCH_BOL | ROPT_ANCH_MBOL))
3280af22 275 || (PL_multiline && prog->check_substr == prog->anchored_substr)) )
a0d0e21e 276 {
c277df42 277 start_shift = prog->check_offset_min;
278 /* Should be nonnegative! */
279 end_shift = minlen - start_shift - SvCUR(prog->check_substr);
280 if (screamer) {
3280af22 281 if (PL_screamfirst[BmRARE(prog->check_substr)] >= 0)
c277df42 282 s = screaminstr(screamer, prog->check_substr,
283 start_shift + (stringarg - strbeg),
284 end_shift, &scream_pos, 0);
a0d0e21e 285 else
286 s = Nullch;
c277df42 287 scream_olds = s;
0a12ae7d 288 }
a0d0e21e 289 else
c277df42 290 s = fbm_instr((unsigned char*)s + start_shift,
291 (unsigned char*)strend - end_shift,
411d5715 292 prog->check_substr, 0);
a0d0e21e 293 if (!s) {
c277df42 294 ++BmUSEFUL(prog->check_substr); /* hooray */
a0d0e21e 295 goto phooey; /* not present */
c277df42 296 } else if ((s - stringarg) > prog->check_offset_max) {
297 ++BmUSEFUL(prog->check_substr); /* hooray/2 */
298 s -= prog->check_offset_max;
299 } else if (!prog->naughty
300 && --BmUSEFUL(prog->check_substr) < 0
301 && prog->check_substr == prog->float_substr) { /* boo */
302 SvREFCNT_dec(prog->check_substr);
303 prog->check_substr = Nullsv; /* disable */
304 prog->float_substr = Nullsv; /* clear */
a0d0e21e 305 s = startpos;
c277df42 306 } else s = startpos;
a0d0e21e 307 }
a687059c 308
c277df42 309 /* Mark beginning of line for ^ and lookbehind. */
3280af22 310 PL_regbol = startpos;
311 PL_bostr = strbeg;
a687059c 312
a0d0e21e 313 /* Mark end of line for $ (and such) */
3280af22 314 PL_regeol = strend;
a687059c 315
a0d0e21e 316 /* see how far we have to get to not match where we matched before */
3280af22 317 PL_regtill = startpos+minend;
a687059c 318
c277df42 319 DEBUG_r(
320 PerlIO_printf(Perl_debug_log,
321 "Matching `%.60s%s' against `%.*s%s'\n",
322 prog->precomp,
323 (strlen(prog->precomp) > 60 ? "..." : ""),
324 (strend - startpos > 60 ? 60 : strend - startpos),
325 startpos,
326 (strend - startpos > 60 ? "..." : ""))
327 );
328
a0d0e21e 329 /* Simplest case: anchored match need be tried only once. */
774d564b 330 /* [unless only anchor is BOL and multiline is set] */
a0d0e21e 331 if (prog->reganch & ROPT_ANCH) {
332 if (regtry(prog, startpos))
333 goto got_it;
774d564b 334 else if (!(prog->reganch & ROPT_ANCH_GPOS) &&
3280af22 335 (PL_multiline || (prog->reganch & ROPT_IMPLICIT)
c277df42 336 || (prog->reganch & ROPT_ANCH_MBOL)))
774d564b 337 {
a0d0e21e 338 if (minlen)
339 dontbother = minlen - 1;
340 strend -= dontbother;
341 /* for multiline we only have to try after newlines */
342 if (s > startpos)
343 s--;
344 while (s < strend) {
345 if (*s++ == '\n') {
346 if (s < strend && regtry(prog, s))
347 goto got_it;
348 }
35c8bce7 349 }
35c8bce7 350 }
a0d0e21e 351 goto phooey;
352 }
35c8bce7 353
a0d0e21e 354 /* Messy cases: unanchored match. */
c277df42 355 if (prog->anchored_substr && prog->reganch & ROPT_SKIP) {
356 /* we have /x+whatever/ */
357 /* it must be a one character string */
358 char ch = SvPVX(prog->anchored_substr)[0];
359 while (s < strend) {
360 if (*s == ch) {
361 if (regtry(prog, s)) goto got_it;
a0d0e21e 362 s++;
c277df42 363 while (s < strend && *s == ch)
364 s++;
a0d0e21e 365 }
c277df42 366 s++;
a687059c 367 }
c277df42 368 }
369 /*SUPPRESS 560*/
370 else if (prog->anchored_substr != Nullsv
371 || (prog->float_substr != Nullsv
372 && prog->float_max_offset < strend - s)) {
373 SV *must = prog->anchored_substr
374 ? prog->anchored_substr : prog->float_substr;
375 I32 back_max =
376 prog->anchored_substr ? prog->anchored_offset : prog->float_max_offset;
377 I32 back_min =
378 prog->anchored_substr ? prog->anchored_offset : prog->float_min_offset;
379 I32 delta = back_max - back_min;
380 char *last = strend - SvCUR(must) - back_min; /* Cannot start after this */
381 char *last1 = s - 1; /* Last position checked before */
382
383 /* XXXX check_substr already used to find `s', can optimize if
384 check_substr==must. */
385 scream_pos = -1;
386 dontbother = end_shift;
387 strend -= dontbother;
388 while ( (s <= last) &&
389 (screamer
390 ? (s = screaminstr(screamer, must, s + back_min - strbeg,
391 end_shift, &scream_pos, 0))
392 : (s = fbm_instr((unsigned char*)s + back_min,
411d5715 393 (unsigned char*)strend, must, 0))) ) {
c277df42 394 if (s - back_max > last1) {
395 last1 = s - back_min;
396 s = s - back_max;
397 } else {
398 char *t = last1 + 1;
399
400 last1 = s - back_min;
401 s = t;
a0d0e21e 402 }
c277df42 403 while (s <= last1) {
a0d0e21e 404 if (regtry(prog, s))
405 goto got_it;
406 s++;
407 }
408 }
409 goto phooey;
c277df42 410 } else if (c = prog->regstclass) {
a0d0e21e 411 I32 doevery = (prog->reganch & ROPT_SKIP) == 0;
161b471a 412 char *Class;
a687059c 413
a0d0e21e 414 if (minlen)
415 dontbother = minlen - 1;
416 strend -= dontbother; /* don't bother with what can't match */
417 tmp = 1;
418 /* We know what class it must start with. */
419 switch (OP(c)) {
420 case ANYOF:
161b471a 421 Class = (char *) OPERAND(c);
a0d0e21e 422 while (s < strend) {
ae5c130c 423 if (REGINCLASS(Class, *s)) {
a0d0e21e 424 if (tmp && regtry(prog, s))
425 goto got_it;
426 else
427 tmp = doevery;
a687059c 428 }
a0d0e21e 429 else
430 tmp = 1;
431 s++;
432 }
433 break;
bbce6d69 434 case BOUNDL:
3280af22 435 PL_reg_flags |= RF_tainted;
bbce6d69 436 /* FALL THROUGH */
a0d0e21e 437 case BOUND:
438 if (minlen)
439 dontbother++,strend--;
3280af22 440 tmp = (s != startpos) ? UCHARAT(s - 1) : PL_regprev;
95bac841 441 tmp = ((OP(c) == BOUND ? isALNUM(tmp) : isALNUM_LC(tmp)) != 0);
a0d0e21e 442 while (s < strend) {
95bac841 443 if (tmp == !(OP(c) == BOUND ? isALNUM(*s) : isALNUM_LC(*s))) {
a0d0e21e 444 tmp = !tmp;
445 if (regtry(prog, s))
446 goto got_it;
a687059c 447 }
a0d0e21e 448 s++;
449 }
450 if ((minlen || tmp) && regtry(prog,s))
451 goto got_it;
452 break;
bbce6d69 453 case NBOUNDL:
3280af22 454 PL_reg_flags |= RF_tainted;
bbce6d69 455 /* FALL THROUGH */
a0d0e21e 456 case NBOUND:
457 if (minlen)
458 dontbother++,strend--;
3280af22 459 tmp = (s != startpos) ? UCHARAT(s - 1) : PL_regprev;
95bac841 460 tmp = ((OP(c) == NBOUND ? isALNUM(tmp) : isALNUM_LC(tmp)) != 0);
a0d0e21e 461 while (s < strend) {
95bac841 462 if (tmp == !(OP(c) == NBOUND ? isALNUM(*s) : isALNUM_LC(*s)))
a0d0e21e 463 tmp = !tmp;
464 else if (regtry(prog, s))
465 goto got_it;
466 s++;
467 }
468 if ((minlen || !tmp) && regtry(prog,s))
469 goto got_it;
470 break;
471 case ALNUM:
472 while (s < strend) {
bbce6d69 473 if (isALNUM(*s)) {
474 if (tmp && regtry(prog, s))
475 goto got_it;
476 else
477 tmp = doevery;
478 }
479 else
480 tmp = 1;
481 s++;
482 }
483 break;
484 case ALNUML:
3280af22 485 PL_reg_flags |= RF_tainted;
bbce6d69 486 while (s < strend) {
487 if (isALNUM_LC(*s)) {
a0d0e21e 488 if (tmp && regtry(prog, s))
489 goto got_it;
a687059c 490 else
a0d0e21e 491 tmp = doevery;
492 }
493 else
494 tmp = 1;
495 s++;
496 }
497 break;
498 case NALNUM:
499 while (s < strend) {
bbce6d69 500 if (!isALNUM(*s)) {
501 if (tmp && regtry(prog, s))
502 goto got_it;
503 else
504 tmp = doevery;
505 }
506 else
507 tmp = 1;
508 s++;
509 }
510 break;
511 case NALNUML:
3280af22 512 PL_reg_flags |= RF_tainted;
bbce6d69 513 while (s < strend) {
514 if (!isALNUM_LC(*s)) {
a0d0e21e 515 if (tmp && regtry(prog, s))
516 goto got_it;
a687059c 517 else
a0d0e21e 518 tmp = doevery;
a687059c 519 }
a0d0e21e 520 else
521 tmp = 1;
522 s++;
523 }
524 break;
525 case SPACE:
526 while (s < strend) {
527 if (isSPACE(*s)) {
528 if (tmp && regtry(prog, s))
529 goto got_it;
530 else
531 tmp = doevery;
2304df62 532 }
a0d0e21e 533 else
534 tmp = 1;
535 s++;
536 }
537 break;
bbce6d69 538 case SPACEL:
3280af22 539 PL_reg_flags |= RF_tainted;
bbce6d69 540 while (s < strend) {
541 if (isSPACE_LC(*s)) {
542 if (tmp && regtry(prog, s))
543 goto got_it;
544 else
545 tmp = doevery;
546 }
547 else
548 tmp = 1;
549 s++;
550 }
551 break;
a0d0e21e 552 case NSPACE:
553 while (s < strend) {
554 if (!isSPACE(*s)) {
555 if (tmp && regtry(prog, s))
556 goto got_it;
557 else
558 tmp = doevery;
a687059c 559 }
a0d0e21e 560 else
561 tmp = 1;
562 s++;
563 }
564 break;
bbce6d69 565 case NSPACEL:
3280af22 566 PL_reg_flags |= RF_tainted;
bbce6d69 567 while (s < strend) {
568 if (!isSPACE_LC(*s)) {
569 if (tmp && regtry(prog, s))
570 goto got_it;
571 else
572 tmp = doevery;
573 }
574 else
575 tmp = 1;
576 s++;
577 }
578 break;
a0d0e21e 579 case DIGIT:
580 while (s < strend) {
581 if (isDIGIT(*s)) {
582 if (tmp && regtry(prog, s))
583 goto got_it;
584 else
585 tmp = doevery;
2b69d0c2 586 }
a0d0e21e 587 else
588 tmp = 1;
589 s++;
590 }
591 break;
592 case NDIGIT:
593 while (s < strend) {
594 if (!isDIGIT(*s)) {
595 if (tmp && regtry(prog, s))
596 goto got_it;
597 else
598 tmp = doevery;
a687059c 599 }
a0d0e21e 600 else
601 tmp = 1;
602 s++;
603 }
604 break;
a687059c 605 }
a0d0e21e 606 }
607 else {
c277df42 608 dontbother = 0;
609 if (prog->float_substr != Nullsv) { /* Trim the end. */
610 char *last;
611 I32 oldpos = scream_pos;
612
613 if (screamer) {
614 last = screaminstr(screamer, prog->float_substr, s - strbeg,
615 end_shift, &scream_pos, 1); /* last one */
616 if (!last) {
617 last = scream_olds; /* Only one occurence. */
618 }
619 } else {
620 STRLEN len;
621 char *little = SvPV(prog->float_substr, len);
622 last = rninstr(s, strend, little, little + len);
623 }
624 if (last == NULL) goto phooey; /* Should not happen! */
625 dontbother = strend - last - 1;
626 }
627 if (minlen && (dontbother < minlen))
a0d0e21e 628 dontbother = minlen - 1;
629 strend -= dontbother;
630 /* We don't know much -- general case. */
631 do {
632 if (regtry(prog, s))
633 goto got_it;
634 } while (s++ < strend);
635 }
636
637 /* Failure. */
638 goto phooey;
a687059c 639
a0d0e21e 640got_it:
420218e7 641 strend += dontbother; /* uncheat */
a0d0e21e 642 prog->subbeg = strbeg;
643 prog->subend = strend;
3280af22 644 RX_MATCH_TAINTED_set(prog, PL_reg_flags & RF_tainted);
5f05dabc 645
646 /* make sure $`, $&, $', and $digit will work later */
c277df42 647 if (strbeg != prog->subbase) { /* second+ //g match. */
648 if (!(flags & REXEC_COPY_STR)) {
137443ea 649 if (prog->subbase) {
650 Safefree(prog->subbase);
651 prog->subbase = Nullch;
652 }
653 }
654 else {
655 I32 i = strend - startpos + (stringarg - strbeg);
656 s = savepvn(strbeg, i);
657 Safefree(prog->subbase);
658 prog->subbase = s;
659 prog->subbeg = prog->subbase;
660 prog->subend = prog->subbase + i;
661 s = prog->subbase + (stringarg - strbeg);
662 for (i = 0; i <= prog->nparens; i++) {
663 if (prog->endp[i]) {
664 prog->startp[i] = s + (prog->startp[i] - startpos);
665 prog->endp[i] = s + (prog->endp[i] - startpos);
666 }
a0d0e21e 667 }
668 }
a0d0e21e 669 }
ce862d02 670 /* Preserve the current value of $^R */
3280af22 671 if (oreplsv != GvSV(PL_replgv)) {
672 sv_setsv(oreplsv, GvSV(PL_replgv));/* So that when GvSV(replgv) is
ce862d02 673 restored, the value remains
674 the same. */
675 }
a0d0e21e 676 return 1;
677
678phooey:
a0d0e21e 679 return 0;
a687059c 680}
681
682/*
683 - regtry - try match at specific point
684 */
76e3520e 685STATIC I32 /* 0 failure, 1 success */
8ac85365 686regtry(regexp *prog, char *startpos)
a687059c 687{
c277df42 688 dTHR;
a0d0e21e 689 register I32 i;
690 register char **sp;
691 register char **ep;
c277df42 692 CHECKPOINT lastcp;
a0d0e21e 693
3280af22 694 if ((prog->reganch & ROPT_EVAL_SEEN) && !PL_reg_eval_set) {
695 PL_reg_eval_set = RS_init;
ce862d02 696 DEBUG_r(DEBUG_s(
c3464db5 697 PerlIO_printf(Perl_debug_log, " setting stack tmpbase at %i\n",
3280af22 698 PL_stack_sp - PL_stack_base);
ce862d02 699 ));
700 SAVEINT(cxstack[cxstack_ix].blk_oldsp);
3280af22 701 cxstack[cxstack_ix].blk_oldsp = PL_stack_sp - PL_stack_base;
ce862d02 702 /* Otherwise OP_NEXTSTATE will free whatever on stack now. */
703 SAVETMPS;
704 /* Apparently this is not needed, judging by wantarray. */
705 /* SAVEINT(cxstack[cxstack_ix].blk_gimme);
706 cxstack[cxstack_ix].blk_gimme = G_SCALAR; */
707 }
3280af22 708 PL_reginput = startpos;
709 PL_regstartp = prog->startp;
710 PL_regendp = prog->endp;
711 PL_reglastparen = &prog->lastparen;
a0d0e21e 712 prog->lastparen = 0;
3280af22 713 PL_regsize = 0;
714 if (PL_reg_start_tmpl <= prog->nparens) {
715 PL_reg_start_tmpl = prog->nparens*3/2 + 3;
716 if(PL_reg_start_tmp)
717 Renew(PL_reg_start_tmp, PL_reg_start_tmpl, char*);
c277df42 718 else
3280af22 719 New(22,PL_reg_start_tmp, PL_reg_start_tmpl, char*);
c277df42 720 }
a0d0e21e 721
722 sp = prog->startp;
723 ep = prog->endp;
3280af22 724 PL_regdata = prog->data;
a0d0e21e 725 if (prog->nparens) {
726 for (i = prog->nparens; i >= 0; i--) {
727 *sp++ = NULL;
728 *ep++ = NULL;
a687059c 729 }
a0d0e21e 730 }
c277df42 731 REGCP_SET;
7e5428c5 732 if (regmatch(prog->program + 1)) {
a0d0e21e 733 prog->startp[0] = startpos;
3280af22 734 prog->endp[0] = PL_reginput;
a0d0e21e 735 return 1;
736 }
c277df42 737 REGCP_UNWIND;
738 return 0;
a687059c 739}
740
741/*
742 - regmatch - main matching routine
743 *
744 * Conceptually the strategy is simple: check to see whether the current
745 * node matches, call self recursively to see whether the rest matches,
746 * and then act accordingly. In practice we make some effort to avoid
747 * recursion, in particular by going through "ordinary" nodes (that don't
748 * need to know whether the rest of the match failed) by a loop instead of
749 * by recursion.
750 */
751/* [lwall] I've hoisted the register declarations to the outer block in order to
752 * maybe save a little bit of pushing and popping on the stack. It also takes
753 * advantage of machines that use a register save mask on subroutine entry.
754 */
76e3520e 755STATIC I32 /* 0 failure, 1 success */
c277df42 756regmatch(regnode *prog)
a687059c 757{
c277df42 758 dTHR;
759 register regnode *scan; /* Current node. */
760 regnode *next; /* Next node. */
761 regnode *inner; /* Next node in internal branch. */
c3464db5 762 register I32 nextchr; /* renamed nextchr - nextchar colides with
763 function of same name */
a0d0e21e 764 register I32 n; /* no or next */
765 register I32 ln; /* len or last */
766 register char *s; /* operand or save */
3280af22 767 register char *locinput = PL_reginput;
c277df42 768 register I32 c1, c2, paren; /* case fold search, parenth */
769 int minmod = 0, sw = 0, logical = 0;
4633a7c4 770#ifdef DEBUGGING
3280af22 771 PL_regindent++;
4633a7c4 772#endif
a0d0e21e 773
76e3520e 774 nextchr = UCHARAT(locinput);
a0d0e21e 775 scan = prog;
776 while (scan != NULL) {
c277df42 777#define sayNO_L (logical ? (logical = 0, sw = 0, goto cont) : sayNO)
a687059c 778#ifdef DEBUGGING
c277df42 779# define sayYES goto yes
780# define sayNO goto no
781# define saySAME(x) if (x) goto yes; else goto no
782# define REPORT_CODE_OFF 24
4633a7c4 783#else
c277df42 784# define sayYES return 1
785# define sayNO return 0
786# define saySAME(x) return x
a687059c 787#endif
c277df42 788 DEBUG_r( {
789 SV *prop = sv_newmortal();
3280af22 790 int docolor = *PL_colors[0];
c277df42 791 int taill = (docolor ? 10 : 7); /* 3 chars for "> <" */
3280af22 792 int l = (PL_regeol - locinput > taill ? taill : PL_regeol - locinput);
793 int pref_len = (locinput - PL_bostr > (5 + taill) - l
794 ? (5 + taill) - l : locinput - PL_bostr);
c277df42 795
3280af22 796 if (l + pref_len < (5 + taill) && l < PL_regeol - locinput)
797 l = ( PL_regeol - locinput > (5 + taill) - pref_len
798 ? (5 + taill) - pref_len : PL_regeol - locinput);
c277df42 799 regprop(prop, scan);
800 PerlIO_printf(Perl_debug_log,
54dc92de 801 "%4i <%s%.*s%s%s%s%.*s%s>%*s|%3d:%*s%s\n",
3280af22 802 locinput - PL_bostr,
803 PL_colors[2], pref_len, locinput - pref_len, PL_colors[3],
c277df42 804 (docolor ? "" : "> <"),
3280af22 805 PL_colors[0], l, locinput, PL_colors[1],
c277df42 806 15 - l - pref_len + 1,
807 "",
3280af22 808 scan - PL_regprogram, PL_regindent*2, "",
c277df42 809 SvPVX(prop));
810 } );
a687059c 811
c277df42 812 next = scan + NEXT_OFF(scan);
a0d0e21e 813 if (next == scan)
814 next = NULL;
a687059c 815
a0d0e21e 816 switch (OP(scan)) {
817 case BOL:
3280af22 818 if (locinput == PL_bostr
819 ? PL_regprev == '\n'
820 : (PL_multiline &&
821 (nextchr || locinput < PL_regeol) && locinput[-1] == '\n') )
a0d0e21e 822 {
823 /* regtill = regbol; */
824 break;
825 }
4633a7c4 826 sayNO;
a0d0e21e 827 case MBOL:
3280af22 828 if (locinput == PL_bostr
829 ? PL_regprev == '\n'
830 : ((nextchr || locinput < PL_regeol) && locinput[-1] == '\n') )
a0d0e21e 831 {
832 break;
833 }
4633a7c4 834 sayNO;
a0d0e21e 835 case SBOL:
3280af22 836 if (locinput == PL_regbol && PL_regprev == '\n')
a0d0e21e 837 break;
4633a7c4 838 sayNO;
774d564b 839 case GPOS:
3280af22 840 if (locinput == PL_regbol)
a0d0e21e 841 break;
4633a7c4 842 sayNO;
a0d0e21e 843 case EOL:
3280af22 844 if (PL_multiline)
a0d0e21e 845 goto meol;
846 else
847 goto seol;
848 case MEOL:
849 meol:
3280af22 850 if ((nextchr || locinput < PL_regeol) && nextchr != '\n')
4633a7c4 851 sayNO;
a0d0e21e 852 break;
853 case SEOL:
854 seol:
3280af22 855 if ((nextchr || locinput < PL_regeol) && nextchr != '\n')
4633a7c4 856 sayNO;
3280af22 857 if (PL_regeol - locinput > 1)
4633a7c4 858 sayNO;
a0d0e21e 859 break;
b85d18e9 860 case EOS:
3280af22 861 if (PL_regeol != locinput)
b85d18e9 862 sayNO;
863 break;
a0d0e21e 864 case SANY:
3280af22 865 if (!nextchr && locinput >= PL_regeol)
4633a7c4 866 sayNO;
76e3520e 867 nextchr = UCHARAT(++locinput);
a0d0e21e 868 break;
869 case ANY:
3280af22 870 if (!nextchr && locinput >= PL_regeol || nextchr == '\n')
4633a7c4 871 sayNO;
76e3520e 872 nextchr = UCHARAT(++locinput);
a0d0e21e 873 break;
bbce6d69 874 case EXACT:
161b471a 875 s = (char *) OPERAND(scan);
c277df42 876 ln = UCHARAT(s++);
a0d0e21e 877 /* Inline the first character, for speed. */
76e3520e 878 if (UCHARAT(s) != nextchr)
4633a7c4 879 sayNO;
3280af22 880 if (PL_regeol - locinput < ln)
4633a7c4 881 sayNO;
36477c24 882 if (ln > 1 && memNE(s, locinput, ln))
4633a7c4 883 sayNO;
a0d0e21e 884 locinput += ln;
76e3520e 885 nextchr = UCHARAT(locinput);
bbce6d69 886 break;
887 case EXACTFL:
3280af22 888 PL_reg_flags |= RF_tainted;
bbce6d69 889 /* FALL THROUGH */
890 case EXACTF:
161b471a 891 s = (char *) OPERAND(scan);
c277df42 892 ln = UCHARAT(s++);
bbce6d69 893 /* Inline the first character, for speed. */
76e3520e 894 if (UCHARAT(s) != nextchr &&
bbce6d69 895 UCHARAT(s) != ((OP(scan) == EXACTF)
76e3520e 896 ? fold : fold_locale)[nextchr])
bbce6d69 897 sayNO;
3280af22 898 if (PL_regeol - locinput < ln)
bbce6d69 899 sayNO;
5f05dabc 900 if (ln > 1 && (OP(scan) == EXACTF
901 ? ibcmp(s, locinput, ln)
902 : ibcmp_locale(s, locinput, ln)))
bbce6d69 903 sayNO;
904 locinput += ln;
76e3520e 905 nextchr = UCHARAT(locinput);
a0d0e21e 906 break;
907 case ANYOF:
161b471a 908 s = (char *) OPERAND(scan);
76e3520e 909 if (nextchr < 0)
910 nextchr = UCHARAT(locinput);
873ef191 911 if (!REGINCLASS(s, nextchr))
4633a7c4 912 sayNO;
3280af22 913 if (!nextchr && locinput >= PL_regeol)
4633a7c4 914 sayNO;
76e3520e 915 nextchr = UCHARAT(++locinput);
a0d0e21e 916 break;
bbce6d69 917 case ALNUML:
3280af22 918 PL_reg_flags |= RF_tainted;
bbce6d69 919 /* FALL THROUGH */
a0d0e21e 920 case ALNUM:
76e3520e 921 if (!nextchr)
4633a7c4 922 sayNO;
bbce6d69 923 if (!(OP(scan) == ALNUM
76e3520e 924 ? isALNUM(nextchr) : isALNUM_LC(nextchr)))
4633a7c4 925 sayNO;
76e3520e 926 nextchr = UCHARAT(++locinput);
a0d0e21e 927 break;
bbce6d69 928 case NALNUML:
3280af22 929 PL_reg_flags |= RF_tainted;
bbce6d69 930 /* FALL THROUGH */
a0d0e21e 931 case NALNUM:
3280af22 932 if (!nextchr && locinput >= PL_regeol)
4633a7c4 933 sayNO;
bbce6d69 934 if (OP(scan) == NALNUM
76e3520e 935 ? isALNUM(nextchr) : isALNUM_LC(nextchr))
4633a7c4 936 sayNO;
76e3520e 937 nextchr = UCHARAT(++locinput);
a0d0e21e 938 break;
bbce6d69 939 case BOUNDL:
940 case NBOUNDL:
3280af22 941 PL_reg_flags |= RF_tainted;
bbce6d69 942 /* FALL THROUGH */
a0d0e21e 943 case BOUND:
bbce6d69 944 case NBOUND:
945 /* was last char in word? */
3280af22 946 ln = (locinput != PL_regbol) ? UCHARAT(locinput - 1) : PL_regprev;
bbce6d69 947 if (OP(scan) == BOUND || OP(scan) == NBOUND) {
948 ln = isALNUM(ln);
76e3520e 949 n = isALNUM(nextchr);
bbce6d69 950 }
951 else {
952 ln = isALNUM_LC(ln);
76e3520e 953 n = isALNUM_LC(nextchr);
bbce6d69 954 }
95bac841 955 if (((!ln) == (!n)) == (OP(scan) == BOUND || OP(scan) == BOUNDL))
4633a7c4 956 sayNO;
a0d0e21e 957 break;
bbce6d69 958 case SPACEL:
3280af22 959 PL_reg_flags |= RF_tainted;
bbce6d69 960 /* FALL THROUGH */
a0d0e21e 961 case SPACE:
3280af22 962 if (!nextchr && locinput >= PL_regeol)
4633a7c4 963 sayNO;
bbce6d69 964 if (!(OP(scan) == SPACE
76e3520e 965 ? isSPACE(nextchr) : isSPACE_LC(nextchr)))
4633a7c4 966 sayNO;
76e3520e 967 nextchr = UCHARAT(++locinput);
a0d0e21e 968 break;
bbce6d69 969 case NSPACEL:
3280af22 970 PL_reg_flags |= RF_tainted;
bbce6d69 971 /* FALL THROUGH */
a0d0e21e 972 case NSPACE:
76e3520e 973 if (!nextchr)
4633a7c4 974 sayNO;
bbce6d69 975 if (OP(scan) == SPACE
76e3520e 976 ? isSPACE(nextchr) : isSPACE_LC(nextchr))
4633a7c4 977 sayNO;
76e3520e 978 nextchr = UCHARAT(++locinput);
a0d0e21e 979 break;
980 case DIGIT:
76e3520e 981 if (!isDIGIT(nextchr))
4633a7c4 982 sayNO;
76e3520e 983 nextchr = UCHARAT(++locinput);
a0d0e21e 984 break;
985 case NDIGIT:
3280af22 986 if (!nextchr && locinput >= PL_regeol)
4633a7c4 987 sayNO;
76e3520e 988 if (isDIGIT(nextchr))
4633a7c4 989 sayNO;
76e3520e 990 nextchr = UCHARAT(++locinput);
a0d0e21e 991 break;
c8756f30 992 case REFFL:
3280af22 993 PL_reg_flags |= RF_tainted;
c8756f30 994 /* FALL THROUGH */
c277df42 995 case REF:
c8756f30 996 case REFF:
c277df42 997 n = ARG(scan); /* which paren pair */
3280af22 998 s = PL_regstartp[n];
999 if (*PL_reglastparen < n || !s)
af3f8c16 1000 sayNO; /* Do not match unless seen CLOSEn. */
3280af22 1001 if (s == PL_regendp[n])
a0d0e21e 1002 break;
1003 /* Inline the first character, for speed. */
76e3520e 1004 if (UCHARAT(s) != nextchr &&
c8756f30 1005 (OP(scan) == REF ||
1006 (UCHARAT(s) != ((OP(scan) == REFF
76e3520e 1007 ? fold : fold_locale)[nextchr]))))
4633a7c4 1008 sayNO;
3280af22 1009 ln = PL_regendp[n] - s;
1010 if (locinput + ln > PL_regeol)
4633a7c4 1011 sayNO;
c8756f30 1012 if (ln > 1 && (OP(scan) == REF
1013 ? memNE(s, locinput, ln)
1014 : (OP(scan) == REFF
1015 ? ibcmp(s, locinput, ln)
1016 : ibcmp_locale(s, locinput, ln))))
4633a7c4 1017 sayNO;
a0d0e21e 1018 locinput += ln;
76e3520e 1019 nextchr = UCHARAT(locinput);
a0d0e21e 1020 break;
1021
1022 case NOTHING:
c277df42 1023 case TAIL:
a0d0e21e 1024 break;
1025 case BACK:
1026 break;
c277df42 1027 case EVAL:
1028 {
1029 dSP;
1030 OP_4tree *oop = op;
3280af22 1031 COP *ocurcop = PL_curcop;
1032 SV **ocurpad = PL_curpad;
c277df42 1033 SV *ret;
1034
1035 n = ARG(scan);
3280af22 1036 op = (OP_4tree*)PL_regdata->data[n];
c277df42 1037 DEBUG_r( PerlIO_printf(Perl_debug_log, " re_eval 0x%x\n", op) );
3280af22 1038 PL_curpad = AvARRAY((AV*)PL_regdata->data[n + 1]);
c277df42 1039
76e3520e 1040 CALLRUNOPS(); /* Scalar context. */
c277df42 1041 SPAGAIN;
1042 ret = POPs;
1043 PUTBACK;
1044
1045 if (logical) {
1046 logical = 0;
1047 sw = SvTRUE(ret);
ce862d02 1048 } else
3280af22 1049 sv_setsv(save_scalar(PL_replgv), ret);
c277df42 1050 op = oop;
3280af22 1051 PL_curpad = ocurpad;
1052 PL_curcop = ocurcop;
c277df42 1053 break;
1054 }
a0d0e21e 1055 case OPEN:
c277df42 1056 n = ARG(scan); /* which paren pair */
3280af22 1057 PL_reg_start_tmp[n] = locinput;
1058 if (n > PL_regsize)
1059 PL_regsize = n;
a0d0e21e 1060 break;
1061 case CLOSE:
c277df42 1062 n = ARG(scan); /* which paren pair */
3280af22 1063 PL_regstartp[n] = PL_reg_start_tmp[n];
1064 PL_regendp[n] = locinput;
1065 if (n > *PL_reglastparen)
1066 *PL_reglastparen = n;
a0d0e21e 1067 break;
c277df42 1068 case GROUPP:
1069 n = ARG(scan); /* which paren pair */
3280af22 1070 sw = (*PL_reglastparen >= n && PL_regendp[n] != NULL);
c277df42 1071 break;
1072 case IFTHEN:
1073 if (sw)
1074 next = NEXTOPER(NEXTOPER(scan));
1075 else {
1076 next = scan + ARG(scan);
1077 if (OP(next) == IFTHEN) /* Fake one. */
1078 next = NEXTOPER(NEXTOPER(next));
1079 }
1080 break;
1081 case LOGICAL:
1082 logical = 1;
1083 break;
a0d0e21e 1084 case CURLYX: {
1085 CURCUR cc;
3280af22 1086 CHECKPOINT cp = PL_savestack_ix;
c277df42 1087
1088 if (OP(PREVOPER(next)) == NOTHING) /* LONGJMP */
1089 next += ARG(next);
3280af22 1090 cc.oldcc = PL_regcc;
1091 PL_regcc = &cc;
1092 cc.parenfloor = *PL_reglastparen;
a0d0e21e 1093 cc.cur = -1;
1094 cc.min = ARG1(scan);
1095 cc.max = ARG2(scan);
c277df42 1096 cc.scan = NEXTOPER(scan) + EXTRA_STEP_2ARGS;
a0d0e21e 1097 cc.next = next;
1098 cc.minmod = minmod;
1099 cc.lastloc = 0;
3280af22 1100 PL_reginput = locinput;
a0d0e21e 1101 n = regmatch(PREVOPER(next)); /* start on the WHILEM */
1102 regcpblow(cp);
3280af22 1103 PL_regcc = cc.oldcc;
4633a7c4 1104 saySAME(n);
a0d0e21e 1105 }
1106 /* NOT REACHED */
1107 case WHILEM: {
1108 /*
1109 * This is really hard to understand, because after we match
1110 * what we're trying to match, we must make sure the rest of
1111 * the RE is going to match for sure, and to do that we have
1112 * to go back UP the parse tree by recursing ever deeper. And
1113 * if it fails, we have to reset our parent's current state
1114 * that we can try again after backing off.
1115 */
1116
c277df42 1117 CHECKPOINT cp, lastcp;
3280af22 1118 CURCUR* cc = PL_regcc;
c277df42 1119 char *lastloc = cc->lastloc; /* Detection of 0-len. */
1120
4633a7c4 1121 n = cc->cur + 1; /* how many we know we matched */
3280af22 1122 PL_reginput = locinput;
a0d0e21e 1123
c277df42 1124 DEBUG_r(
1125 PerlIO_printf(Perl_debug_log,
1126 "%*s %ld out of %ld..%ld cc=%lx\n",
3280af22 1127 REPORT_CODE_OFF+PL_regindent*2, "",
c277df42 1128 (long)n, (long)cc->min,
1129 (long)cc->max, (long)cc)
1130 );
4633a7c4 1131
a0d0e21e 1132 /* If degenerate scan matches "", assume scan done. */
1133
579cf2c3 1134 if (locinput == cc->lastloc && n >= cc->min) {
3280af22 1135 PL_regcc = cc->oldcc;
1136 ln = PL_regcc->cur;
c277df42 1137 DEBUG_r(
c3464db5 1138 PerlIO_printf(Perl_debug_log,
1139 "%*s empty match detected, try continuation...\n",
3280af22 1140 REPORT_CODE_OFF+PL_regindent*2, "")
c277df42 1141 );
a0d0e21e 1142 if (regmatch(cc->next))
4633a7c4 1143 sayYES;
c277df42 1144 DEBUG_r(
c3464db5 1145 PerlIO_printf(Perl_debug_log,
1146 "%*s failed...\n",
3280af22 1147 REPORT_CODE_OFF+PL_regindent*2, "")
c277df42 1148 );
3280af22 1149 PL_regcc->cur = ln;
1150 PL_regcc = cc;
4633a7c4 1151 sayNO;
a0d0e21e 1152 }
1153
1154 /* First just match a string of min scans. */
1155
1156 if (n < cc->min) {
1157 cc->cur = n;
1158 cc->lastloc = locinput;
4633a7c4 1159 if (regmatch(cc->scan))
1160 sayYES;
1161 cc->cur = n - 1;
c277df42 1162 cc->lastloc = lastloc;
1163 DEBUG_r(
c3464db5 1164 PerlIO_printf(Perl_debug_log,
1165 "%*s failed...\n",
3280af22 1166 REPORT_CODE_OFF+PL_regindent*2, "")
c277df42 1167 );
4633a7c4 1168 sayNO;
a0d0e21e 1169 }
1170
1171 /* Prefer next over scan for minimal matching. */
1172
1173 if (cc->minmod) {
3280af22 1174 PL_regcc = cc->oldcc;
1175 ln = PL_regcc->cur;
5f05dabc 1176 cp = regcppush(cc->parenfloor);
c277df42 1177 REGCP_SET;
5f05dabc 1178 if (regmatch(cc->next)) {
c277df42 1179 regcpblow(cp);
4633a7c4 1180 sayYES; /* All done. */
5f05dabc 1181 }
c277df42 1182 REGCP_UNWIND;
5f05dabc 1183 regcppop();
3280af22 1184 PL_regcc->cur = ln;
1185 PL_regcc = cc;
a0d0e21e 1186
c277df42 1187 if (n >= cc->max) { /* Maximum greed exceeded? */
3280af22 1188 if (PL_dowarn && n >= REG_INFTY
1189 && !(PL_reg_flags & RF_warned)) {
1190 PL_reg_flags |= RF_warned;
c3464db5 1191 warn("Complex regular subexpression recursion "
1192 "limit (%d) exceeded", REG_INFTY - 1);
c277df42 1193 }
4633a7c4 1194 sayNO;
c277df42 1195 }
a687059c 1196
c277df42 1197 DEBUG_r(
c3464db5 1198 PerlIO_printf(Perl_debug_log,
1199 "%*s trying longer...\n",
3280af22 1200 REPORT_CODE_OFF+PL_regindent*2, "")
c277df42 1201 );
a0d0e21e 1202 /* Try scanning more and see if it helps. */
3280af22 1203 PL_reginput = locinput;
a0d0e21e 1204 cc->cur = n;
1205 cc->lastloc = locinput;
5f05dabc 1206 cp = regcppush(cc->parenfloor);
c277df42 1207 REGCP_SET;
5f05dabc 1208 if (regmatch(cc->scan)) {
c277df42 1209 regcpblow(cp);
4633a7c4 1210 sayYES;
5f05dabc 1211 }
c277df42 1212 DEBUG_r(
c3464db5 1213 PerlIO_printf(Perl_debug_log,
1214 "%*s failed...\n",
3280af22 1215 REPORT_CODE_OFF+PL_regindent*2, "")
c277df42 1216 );
1217 REGCP_UNWIND;
5f05dabc 1218 regcppop();
4633a7c4 1219 cc->cur = n - 1;
c277df42 1220 cc->lastloc = lastloc;
4633a7c4 1221 sayNO;
a0d0e21e 1222 }
1223
1224 /* Prefer scan over next for maximal matching. */
1225
1226 if (n < cc->max) { /* More greed allowed? */
5f05dabc 1227 cp = regcppush(cc->parenfloor);
a0d0e21e 1228 cc->cur = n;
1229 cc->lastloc = locinput;
c277df42 1230 REGCP_SET;
5f05dabc 1231 if (regmatch(cc->scan)) {
c277df42 1232 regcpblow(cp);
4633a7c4 1233 sayYES;
5f05dabc 1234 }
c277df42 1235 REGCP_UNWIND;
a0d0e21e 1236 regcppop(); /* Restore some previous $<digit>s? */
3280af22 1237 PL_reginput = locinput;
c277df42 1238 DEBUG_r(
c3464db5 1239 PerlIO_printf(Perl_debug_log,
1240 "%*s failed, try continuation...\n",
3280af22 1241 REPORT_CODE_OFF+PL_regindent*2, "")
c277df42 1242 );
1243 }
3280af22 1244 if (PL_dowarn && n >= REG_INFTY && !(PL_reg_flags & RF_warned)) {
1245 PL_reg_flags |= RF_warned;
c277df42 1246 warn("count exceeded %d", REG_INFTY - 1);
a0d0e21e 1247 }
1248
1249 /* Failed deeper matches of scan, so see if this one works. */
3280af22 1250 PL_regcc = cc->oldcc;
1251 ln = PL_regcc->cur;
a0d0e21e 1252 if (regmatch(cc->next))
4633a7c4 1253 sayYES;
c277df42 1254 DEBUG_r(
c3464db5 1255 PerlIO_printf(Perl_debug_log, "%*s failed...\n",
3280af22 1256 REPORT_CODE_OFF+PL_regindent*2, "")
c277df42 1257 );
3280af22 1258 PL_regcc->cur = ln;
1259 PL_regcc = cc;
4633a7c4 1260 cc->cur = n - 1;
c277df42 1261 cc->lastloc = lastloc;
4633a7c4 1262 sayNO;
a0d0e21e 1263 }
1264 /* NOT REACHED */
c277df42 1265 case BRANCHJ:
1266 next = scan + ARG(scan);
1267 if (next == scan)
1268 next = NULL;
1269 inner = NEXTOPER(NEXTOPER(scan));
1270 goto do_branch;
1271 case BRANCH:
1272 inner = NEXTOPER(scan);
1273 do_branch:
1274 {
1275 CHECKPOINT lastcp;
1276 c1 = OP(scan);
1277 if (OP(next) != c1) /* No choice. */
1278 next = inner; /* Avoid recursion. */
a0d0e21e 1279 else {
3280af22 1280 int lastparen = *PL_reglastparen;
c277df42 1281
1282 REGCP_SET;
a0d0e21e 1283 do {
3280af22 1284 PL_reginput = locinput;
c277df42 1285 if (regmatch(inner))
4633a7c4 1286 sayYES;
c277df42 1287 REGCP_UNWIND;
3280af22 1288 for (n = *PL_reglastparen; n > lastparen; n--)
1289 PL_regendp[n] = 0;
1290 *PL_reglastparen = n;
c277df42 1291 scan = next;
a0d0e21e 1292 /*SUPPRESS 560*/
c277df42 1293 if (n = (c1 == BRANCH ? NEXT_OFF(next) : ARG(next)))
1294 next += n;
a0d0e21e 1295 else
c277df42 1296 next = NULL;
c277df42 1297 inner = NEXTOPER(scan);
1298 if (c1 == BRANCHJ) {
1299 inner = NEXTOPER(inner);
1300 }
1301 } while (scan != NULL && OP(scan) == c1);
4633a7c4 1302 sayNO;
a0d0e21e 1303 /* NOTREACHED */
a687059c 1304 }
a0d0e21e 1305 }
1306 break;
1307 case MINMOD:
1308 minmod = 1;
1309 break;
c277df42 1310 case CURLYM:
1311 {
00db4c45 1312 I32 l = 0;
c277df42 1313 CHECKPOINT lastcp;
1314
1315 /* We suppose that the next guy does not need
1316 backtracking: in particular, it is of constant length,
1317 and has no parenths to influence future backrefs. */
1318 ln = ARG1(scan); /* min to match */
1319 n = ARG2(scan); /* max to match */
c277df42 1320 paren = scan->flags;
1321 if (paren) {
3280af22 1322 if (paren > PL_regsize)
1323 PL_regsize = paren;
1324 if (paren > *PL_reglastparen)
1325 *PL_reglastparen = paren;
c277df42 1326 }
dc45a647 1327 scan = NEXTOPER(scan) + NODE_STEP_REGNODE;
c277df42 1328 if (paren)
1329 scan += NEXT_OFF(scan); /* Skip former OPEN. */
3280af22 1330 PL_reginput = locinput;
c277df42 1331 if (minmod) {
1332 minmod = 0;
1333 if (ln && regrepeat_hard(scan, ln, &l) < ln)
1334 sayNO;
5f4b28b2 1335 if (ln && l == 0 && n >= ln
c277df42 1336 /* In fact, this is tricky. If paren, then the
1337 fact that we did/didnot match may influence
1338 future execution. */
1339 && !(paren && ln == 0))
1340 ln = n;
3280af22 1341 locinput = PL_reginput;
c277df42 1342 if (regkind[(U8)OP(next)] == EXACT) {
1343 c1 = UCHARAT(OPERAND(next) + 1);
1344 if (OP(next) == EXACTF)
1345 c2 = fold[c1];
1346 else if (OP(next) == EXACTFL)
1347 c2 = fold_locale[c1];
1348 else
1349 c2 = c1;
1350 } else
1351 c1 = c2 = -1000;
1352 REGCP_SET;
5f4b28b2 1353 /* This may be improved if l == 0. */
c277df42 1354 while (n >= ln || (n == REG_INFTY && ln > 0 && l)) { /* ln overflow ? */
1355 /* If it could work, try it. */
1356 if (c1 == -1000 ||
3280af22 1357 UCHARAT(PL_reginput) == c1 ||
1358 UCHARAT(PL_reginput) == c2)
c277df42 1359 {
1360 if (paren) {
1361 if (n) {
3280af22 1362 PL_regstartp[paren] = PL_reginput - l;
1363 PL_regendp[paren] = PL_reginput;
c277df42 1364 } else
3280af22 1365 PL_regendp[paren] = NULL;
c277df42 1366 }
1367 if (regmatch(next))
1368 sayYES;
1369 REGCP_UNWIND;
1370 }
1371 /* Couldn't or didn't -- move forward. */
3280af22 1372 PL_reginput = locinput;
c277df42 1373 if (regrepeat_hard(scan, 1, &l)) {
1374 ln++;
3280af22 1375 locinput = PL_reginput;
c277df42 1376 }
1377 else
1378 sayNO;
1379 }
1380 } else {
1381 n = regrepeat_hard(scan, n, &l);
1382 if (n != 0 && l == 0
1383 /* In fact, this is tricky. If paren, then the
1384 fact that we did/didnot match may influence
1385 future execution. */
1386 && !(paren && ln == 0))
1387 ln = n;
3280af22 1388 locinput = PL_reginput;
c277df42 1389 DEBUG_r(
5c0ca799 1390 PerlIO_printf(Perl_debug_log,
1391 "%*s matched %ld times, len=%ld...\n",
3280af22 1392 REPORT_CODE_OFF+PL_regindent*2, "", n, l)
c277df42 1393 );
1394 if (n >= ln) {
1395 if (regkind[(U8)OP(next)] == EXACT) {
1396 c1 = UCHARAT(OPERAND(next) + 1);
1397 if (OP(next) == EXACTF)
1398 c2 = fold[c1];
1399 else if (OP(next) == EXACTFL)
1400 c2 = fold_locale[c1];
1401 else
1402 c2 = c1;
1403 } else
1404 c1 = c2 = -1000;
1405 }
1406 REGCP_SET;
1407 while (n >= ln) {
1408 /* If it could work, try it. */
1409 if (c1 == -1000 ||
3280af22 1410 UCHARAT(PL_reginput) == c1 ||
1411 UCHARAT(PL_reginput) == c2)
c277df42 1412 {
1413 DEBUG_r(
c3464db5 1414 PerlIO_printf(Perl_debug_log,
1415 "%*s trying tail with n=%ld...\n",
3280af22 1416 REPORT_CODE_OFF+PL_regindent*2, "", n)
c277df42 1417 );
1418 if (paren) {
1419 if (n) {
3280af22 1420 PL_regstartp[paren] = PL_reginput - l;
1421 PL_regendp[paren] = PL_reginput;
c277df42 1422 } else
3280af22 1423 PL_regendp[paren] = NULL;
c277df42 1424 }
1425 if (regmatch(next))
1426 sayYES;
1427 REGCP_UNWIND;
1428 }
1429 /* Couldn't or didn't -- back up. */
1430 n--;
1431 locinput -= l;
3280af22 1432 PL_reginput = locinput;
c277df42 1433 }
1434 }
1435 sayNO;
1436 break;
1437 }
1438 case CURLYN:
1439 paren = scan->flags; /* Which paren to set */
3280af22 1440 if (paren > PL_regsize)
1441 PL_regsize = paren;
1442 if (paren > *PL_reglastparen)
1443 *PL_reglastparen = paren;
c277df42 1444 ln = ARG1(scan); /* min to match */
1445 n = ARG2(scan); /* max to match */
dc45a647 1446 scan = regnext(NEXTOPER(scan) + NODE_STEP_REGNODE);
c277df42 1447 goto repeat;
a0d0e21e 1448 case CURLY:
c277df42 1449 paren = 0;
a0d0e21e 1450 ln = ARG1(scan); /* min to match */
1451 n = ARG2(scan); /* max to match */
dc45a647 1452 scan = NEXTOPER(scan) + NODE_STEP_REGNODE;
a0d0e21e 1453 goto repeat;
1454 case STAR:
1455 ln = 0;
c277df42 1456 n = REG_INFTY;
a0d0e21e 1457 scan = NEXTOPER(scan);
c277df42 1458 paren = 0;
a0d0e21e 1459 goto repeat;
1460 case PLUS:
c277df42 1461 ln = 1;
1462 n = REG_INFTY;
1463 scan = NEXTOPER(scan);
1464 paren = 0;
1465 repeat:
a0d0e21e 1466 /*
1467 * Lookahead to avoid useless match attempts
1468 * when we know what character comes next.
1469 */
bbce6d69 1470 if (regkind[(U8)OP(next)] == EXACT) {
1471 c1 = UCHARAT(OPERAND(next) + 1);
1472 if (OP(next) == EXACTF)
1473 c2 = fold[c1];
1474 else if (OP(next) == EXACTFL)
1475 c2 = fold_locale[c1];
1476 else
1477 c2 = c1;
1478 }
a0d0e21e 1479 else
bbce6d69 1480 c1 = c2 = -1000;
3280af22 1481 PL_reginput = locinput;
a0d0e21e 1482 if (minmod) {
c277df42 1483 CHECKPOINT lastcp;
a0d0e21e 1484 minmod = 0;
1485 if (ln && regrepeat(scan, ln) < ln)
4633a7c4 1486 sayNO;
c277df42 1487 REGCP_SET;
1488 while (n >= ln || (n == REG_INFTY && ln > 0)) { /* ln overflow ? */
a0d0e21e 1489 /* If it could work, try it. */
bbce6d69 1490 if (c1 == -1000 ||
3280af22 1491 UCHARAT(PL_reginput) == c1 ||
1492 UCHARAT(PL_reginput) == c2)
bbce6d69 1493 {
c277df42 1494 if (paren) {
1495 if (n) {
3280af22 1496 PL_regstartp[paren] = PL_reginput - 1;
1497 PL_regendp[paren] = PL_reginput;
c277df42 1498 } else
3280af22 1499 PL_regendp[paren] = NULL;
c277df42 1500 }
a0d0e21e 1501 if (regmatch(next))
4633a7c4 1502 sayYES;
c277df42 1503 REGCP_UNWIND;
bbce6d69 1504 }
c277df42 1505 /* Couldn't or didn't -- move forward. */
3280af22 1506 PL_reginput = locinput + ln;
a0d0e21e 1507 if (regrepeat(scan, 1)) {
1508 ln++;
3280af22 1509 PL_reginput = locinput + ln;
c277df42 1510 } else
4633a7c4 1511 sayNO;
a0d0e21e 1512 }
1513 }
1514 else {
c277df42 1515 CHECKPOINT lastcp;
a0d0e21e 1516 n = regrepeat(scan, n);
1517 if (ln < n && regkind[(U8)OP(next)] == EOL &&
3280af22 1518 (!PL_multiline || OP(next) == SEOL))
a0d0e21e 1519 ln = n; /* why back off? */
c277df42 1520 REGCP_SET;
1521 if (paren) {
1522 while (n >= ln) {
1523 /* If it could work, try it. */
1524 if (c1 == -1000 ||
3280af22 1525 UCHARAT(PL_reginput) == c1 ||
1526 UCHARAT(PL_reginput) == c2)
c277df42 1527 {
1528 if (paren && n) {
1529 if (n) {
3280af22 1530 PL_regstartp[paren] = PL_reginput - 1;
1531 PL_regendp[paren] = PL_reginput;
c277df42 1532 } else
3280af22 1533 PL_regendp[paren] = NULL;
c277df42 1534 }
1535 if (regmatch(next))
1536 sayYES;
1537 REGCP_UNWIND;
1538 }
1539 /* Couldn't or didn't -- back up. */
1540 n--;
3280af22 1541 PL_reginput = locinput + n;
c277df42 1542 }
1543 } else {
1544 while (n >= ln) {
1545 /* If it could work, try it. */
1546 if (c1 == -1000 ||
3280af22 1547 UCHARAT(PL_reginput) == c1 ||
1548 UCHARAT(PL_reginput) == c2)
c277df42 1549 {
1550 if (regmatch(next))
1551 sayYES;
1552 REGCP_UNWIND;
1553 }
1554 /* Couldn't or didn't -- back up. */
1555 n--;
3280af22 1556 PL_reginput = locinput + n;
bbce6d69 1557 }
a0d0e21e 1558 }
1559 }
4633a7c4 1560 sayNO;
c277df42 1561 break;
a0d0e21e 1562 case END:
3280af22 1563 if (locinput < PL_regtill)
7e5428c5 1564 sayNO; /* Cannot match: too short. */
1565 /* Fall through */
1566 case SUCCEED:
3280af22 1567 PL_reginput = locinput; /* put where regtry can find it */
4633a7c4 1568 sayYES; /* Success! */
c277df42 1569 case SUSPEND:
1570 n = 1;
1571 goto do_ifmatch;
a0d0e21e 1572 case UNLESSM:
c277df42 1573 n = 0;
3280af22 1574 if (locinput < PL_bostr + scan->flags)
c277df42 1575 goto say_yes;
1576 goto do_ifmatch;
1577 case IFMATCH:
1578 n = 1;
3280af22 1579 if (locinput < PL_bostr + scan->flags)
c277df42 1580 goto say_no;
1581 do_ifmatch:
3280af22 1582 PL_reginput = locinput - scan->flags;
c277df42 1583 inner = NEXTOPER(NEXTOPER(scan));
1584 if (regmatch(inner) != n) {
1585 say_no:
1586 if (logical) {
1587 logical = 0;
1588 sw = 0;
1589 goto do_longjump;
1590 } else
1591 sayNO;
1592 }
1593 say_yes:
1594 if (logical) {
1595 logical = 0;
1596 sw = 1;
1597 }
fe44a5e8 1598 if (OP(scan) == SUSPEND) {
3280af22 1599 locinput = PL_reginput;
565764a8 1600 nextchr = UCHARAT(locinput);
fe44a5e8 1601 }
c277df42 1602 /* FALL THROUGH. */
1603 case LONGJMP:
1604 do_longjump:
1605 next = scan + ARG(scan);
1606 if (next == scan)
1607 next = NULL;
a0d0e21e 1608 break;
1609 default:
c030ccd9 1610 PerlIO_printf(PerlIO_stderr(), "%lx %d\n",
c277df42 1611 (unsigned long)scan, OP(scan));
a0d0e21e 1612 FAIL("regexp memory corruption");
a687059c 1613 }
a0d0e21e 1614 scan = next;
1615 }
a687059c 1616
a0d0e21e 1617 /*
1618 * We get here only if there's trouble -- normally "case END" is
1619 * the terminating point.
1620 */
1621 FAIL("corrupted regexp pointers");
1622 /*NOTREACHED*/
4633a7c4 1623 sayNO;
1624
1625yes:
1626#ifdef DEBUGGING
3280af22 1627 PL_regindent--;
4633a7c4 1628#endif
1629 return 1;
1630
1631no:
1632#ifdef DEBUGGING
3280af22 1633 PL_regindent--;
4633a7c4 1634#endif
a0d0e21e 1635 return 0;
a687059c 1636}
1637
1638/*
1639 - regrepeat - repeatedly match something simple, report how many
1640 */
1641/*
1642 * [This routine now assumes that it will only match on things of length 1.
1643 * That was true before, but now we assume scan - reginput is the count,
1644 * rather than incrementing count on every character.]
1645 */
76e3520e 1646STATIC I32
c277df42 1647regrepeat(regnode *p, I32 max)
a687059c 1648{
5c0ca799 1649 dTHR;
a0d0e21e 1650 register char *scan;
1651 register char *opnd;
1652 register I32 c;
3280af22 1653 register char *loceol = PL_regeol;
a0d0e21e 1654
3280af22 1655 scan = PL_reginput;
c277df42 1656 if (max != REG_INFTY && max < loceol - scan)
a0d0e21e 1657 loceol = scan + max;
161b471a 1658 opnd = (char *) OPERAND(p);
a0d0e21e 1659 switch (OP(p)) {
1660 case ANY:
1661 while (scan < loceol && *scan != '\n')
1662 scan++;
1663 break;
1664 case SANY:
1665 scan = loceol;
1666 break;
bbce6d69 1667 case EXACT: /* length of string is 1 */
1668 c = UCHARAT(++opnd);
1669 while (scan < loceol && UCHARAT(scan) == c)
1670 scan++;
1671 break;
1672 case EXACTF: /* length of string is 1 */
1673 c = UCHARAT(++opnd);
1674 while (scan < loceol &&
1675 (UCHARAT(scan) == c || UCHARAT(scan) == fold[c]))
1676 scan++;
1677 break;
1678 case EXACTFL: /* length of string is 1 */
3280af22 1679 PL_reg_flags |= RF_tainted;
bbce6d69 1680 c = UCHARAT(++opnd);
1681 while (scan < loceol &&
1682 (UCHARAT(scan) == c || UCHARAT(scan) == fold_locale[c]))
a0d0e21e 1683 scan++;
1684 break;
1685 case ANYOF:
ae5c130c 1686 while (scan < loceol && REGINCLASS(opnd, *scan))
a0d0e21e 1687 scan++;
a0d0e21e 1688 break;
1689 case ALNUM:
1690 while (scan < loceol && isALNUM(*scan))
1691 scan++;
1692 break;
bbce6d69 1693 case ALNUML:
3280af22 1694 PL_reg_flags |= RF_tainted;
bbce6d69 1695 while (scan < loceol && isALNUM_LC(*scan))
1696 scan++;
1697 break;
a0d0e21e 1698 case NALNUM:
1699 while (scan < loceol && !isALNUM(*scan))
1700 scan++;
1701 break;
bbce6d69 1702 case NALNUML:
3280af22 1703 PL_reg_flags |= RF_tainted;
bbce6d69 1704 while (scan < loceol && !isALNUM_LC(*scan))
1705 scan++;
1706 break;
a0d0e21e 1707 case SPACE:
1708 while (scan < loceol && isSPACE(*scan))
1709 scan++;
1710 break;
bbce6d69 1711 case SPACEL:
3280af22 1712 PL_reg_flags |= RF_tainted;
bbce6d69 1713 while (scan < loceol && isSPACE_LC(*scan))
1714 scan++;
1715 break;
a0d0e21e 1716 case NSPACE:
1717 while (scan < loceol && !isSPACE(*scan))
1718 scan++;
1719 break;
bbce6d69 1720 case NSPACEL:
3280af22 1721 PL_reg_flags |= RF_tainted;
bbce6d69 1722 while (scan < loceol && !isSPACE_LC(*scan))
1723 scan++;
1724 break;
a0d0e21e 1725 case DIGIT:
1726 while (scan < loceol && isDIGIT(*scan))
1727 scan++;
1728 break;
1729 case NDIGIT:
1730 while (scan < loceol && !isDIGIT(*scan))
1731 scan++;
1732 break;
1733 default: /* Called on something of 0 width. */
1734 break; /* So match right here or not at all. */
1735 }
a687059c 1736
3280af22 1737 c = scan - PL_reginput;
1738 PL_reginput = scan;
a687059c 1739
c277df42 1740 DEBUG_r(
1741 {
1742 SV *prop = sv_newmortal();
1743
1744 regprop(prop, p);
1745 PerlIO_printf(Perl_debug_log,
1746 "%*s %s can match %ld times out of %ld...\n",
1747 REPORT_CODE_OFF+1, "", SvPVX(prop),c,max);
1748 });
1749
a0d0e21e 1750 return(c);
a687059c 1751}
1752
1753/*
c277df42 1754 - regrepeat_hard - repeatedly match something, report total lenth and length
1755 *
1756 * The repeater is supposed to have constant length.
1757 */
1758
76e3520e 1759STATIC I32
c277df42 1760regrepeat_hard(regnode *p, I32 max, I32 *lp)
1761{
5c0ca799 1762 dTHR;
c277df42 1763 register char *scan;
1764 register char *start;
3280af22 1765 register char *loceol = PL_regeol;
c277df42 1766 I32 l = -1;
1767
3280af22 1768 start = PL_reginput;
1769 while (PL_reginput < loceol && (scan = PL_reginput, regmatch(p))) {
c277df42 1770 if (l == -1) {
3280af22 1771 *lp = l = PL_reginput - start;
c277df42 1772 if (max != REG_INFTY && l*max < loceol - scan)
1773 loceol = scan + l*max;
1774 if (l == 0) {
1775 return max;
1776 }
1777 }
1778 }
3280af22 1779 if (PL_reginput < loceol)
1780 PL_reginput = scan;
c277df42 1781 else
3280af22 1782 scan = PL_reginput;
c277df42 1783
1784 return (scan - start)/l;
1785}
1786
1787/*
bbce6d69 1788 - regclass - determine if a character falls into a character class
1789 */
1790
76e3520e 1791STATIC bool
8ac85365 1792reginclass(register char *p, register I32 c)
bbce6d69 1793{
5c0ca799 1794 dTHR;
bbce6d69 1795 char flags = *p;
1796 bool match = FALSE;
1797
1798 c &= 0xFF;
ae5c130c 1799 if (ANYOF_TEST(p, c))
bbce6d69 1800 match = TRUE;
1801 else if (flags & ANYOF_FOLD) {
1802 I32 cf;
1803 if (flags & ANYOF_LOCALE) {
3280af22 1804 PL_reg_flags |= RF_tainted;
bbce6d69 1805 cf = fold_locale[c];
1806 }
1807 else
1808 cf = fold[c];
ae5c130c 1809 if (ANYOF_TEST(p, cf))
bbce6d69 1810 match = TRUE;
1811 }
1812
1813 if (!match && (flags & ANYOF_ISA)) {
3280af22 1814 PL_reg_flags |= RF_tainted;
bbce6d69 1815
1816 if (((flags & ANYOF_ALNUML) && isALNUM_LC(c)) ||
1817 ((flags & ANYOF_NALNUML) && !isALNUM_LC(c)) ||
1818 ((flags & ANYOF_SPACEL) && isSPACE_LC(c)) ||
1819 ((flags & ANYOF_NSPACEL) && !isSPACE_LC(c)))
1820 {
1821 match = TRUE;
1822 }
1823 }
1824
ae5c130c 1825 return (flags & ANYOF_INVERT) ? !match : match;
bbce6d69 1826}
1827
161b471a 1828
1829