regexec.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/* regexec.c
*/
/*
* "One Ring to rule them all, One Ring to find them..."
*/
/* NOTE: this is derived from Henry Spencer's regexp code, and should not
* confused with the original package (see point 3 below). Thanks, Henry!
*/
/* Additional note: this code is very heavily munged from Henry's version
* in places. In some spots I've traded clarity for efficiency, so don't
* blame Henry for some of the lack of readability.
*/
/* The names of the functions have been changed from regcomp and
* regexec to pregcomp and pregexec in order to avoid conflicts
* with the POSIX routines of the same names.
*/
#ifdef PERL_EXT_RE_BUILD
/* need to replace pregcomp et al, so enable that */
# ifndef PERL_IN_XSUB_RE
# define PERL_IN_XSUB_RE
# endif
/* need access to debugger hooks */
# if defined(PERL_EXT_RE_DEBUG) && !defined(DEBUGGING)
# define DEBUGGING
# endif
#endif
#ifdef PERL_IN_XSUB_RE
/* We *really* need to overwrite these symbols: */
# define Perl_regexec_flags my_regexec
# define Perl_regdump my_regdump
# define Perl_regprop my_regprop
# define Perl_re_intuit_start my_re_intuit_start
/* *These* symbols are masked to allow static link. */
# define Perl_pregexec my_pregexec
# define Perl_reginitcolors my_reginitcolors
# define Perl_regclass_swash my_regclass_swash
# define PERL_NO_GET_CONTEXT
#endif
/*SUPPRESS 112*/
/*
* pregcomp and pregexec -- regsub and regerror are not used in perl
*
* Copyright (c) 1986 by University of Toronto.
* Written by Henry Spencer. Not derived from licensed software.
*
* Permission is granted to anyone to use this software for any
* purpose on any computer system, and to redistribute it freely,
* subject to the following restrictions:
*
* 1. The author is not responsible for the consequences of use of
* this software, no matter how awful, even if they arise
* from defects in it.
*
* 2. The origin of this software must not be misrepresented, either
* by explicit claim or by omission.
*
* 3. Altered versions must be plainly marked as such, and must not
* be misrepresented as being the original software.
*
**** Alterations to Henry's code are...
****
**** Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
**** 2000, 2001, 2002, 2003, 2004, by Larry Wall and others
****
**** You may distribute under the terms of either the GNU General Public
**** License or the Artistic License, as specified in the README file.
*
* Beware that some of this code is subtly aware of the way operator
* precedence is structured in regular expressions. Serious changes in
* regular-expression syntax might require a total rethink.
*/
#include "EXTERN.h"
#define PERL_IN_REGEXEC_C
#include "perl.h"
#include "regcomp.h"
#ifndef STATIC
#define STATIC static
#endif
/*
* Forwards.
*/
)
#define HOPMAYBE3(pos,off,lim) (PL_reg_match_utf8 ? reghopmaybe3((U8*)pos, off, (U8*)lim) : (U8*)(pos + off))
#define LOAD_UTF8_CHARCLASS(a,b) STMT_START { if (!CAT2(PL_utf8_,a)) { ENTER; save_re_context(); (void)CAT2(is_utf8_, a)((U8*)b); LEAVE; } } STMT_END
/* for use after a quantifier and before an EXACT-like node -- japhy */
)
)
/*
Search for mandatory following text node; for lookahead, the text must
follow but for lookbehind (rn->flags != 0) we skip to the next step.
*/
} STMT_END
{
int retval = PL_savestack_ix;
#define REGCP_PAREN_ELEMS 4
int p;
if (paren_elems_to_push < 0)
#define REGCP_OTHER_ELEMS 6
for (p = PL_regsize; p > parenfloor; p--) {
/* REGCP_PARENS_ELEMS are pushed per pairs of parentheses. */
SSPUSHINT(PL_regendp[p]);
SSPUSHINT(PL_regstartp[p]);
SSPUSHINT(p);
}
/* REGCP_OTHER_ELEMS are pushed in any case, parentheses or no. */
#define REGCP_FRAME_ELEMS 2
/* REGCP_FRAME_ELEMS are part of the REGCP_OTHER_ELEMS and
* are needed for the regexp context stack bookkeeping. */
return retval;
}
/* These are needed since we do not localize EVAL nodes: */
STATIC char *
{
I32 i;
char *input;
/* Pop REGCP_OTHER_ELEMS before the parentheses loop starts. */
i = SSPOPINT;
i = SSPOPINT; /* Parentheses elements to pop. */
/* Now restore the parentheses context. */
for (i -= (REGCP_OTHER_ELEMS - REGCP_FRAME_ELEMS);
i > 0; i -= REGCP_PAREN_ELEMS) {
if (paren <= *PL_reglastparen)
);
}
}
);
#if 1
/* It would seem that the similar code in regtry()
* already takes care of this, and in fact it is in
* a better location to since this code can #if 0-ed out
* but the code in regtry() is needed or otherwise tests
* (as of patchlevel 7877) will fail. Then again,
* this code seems to be necessary or otherwise
* building DynaLoader will fail:
* "Error: '*' not in typemap in DynaLoader.xs, line 164"
* --jhi */
}
#endif
return input;
}
STATIC char *
{
regcppop();
return Nullch;
}
typedef struct re_cc_state
{
struct re_cc_state *prev;
} re_cc_state;
if (paren) { \
if (n) { \
} \
else \
} \
sayYES; \
if (paren && n) \
}
/*
* pregexec and friends
*/
/*
- pregexec - match a regexp against a string
*/
/* strend: pointer to null at end of string */
/* strbeg: real beginning of string */
/* minend: end of match must be >=minend after stringarg. */
/* nosave: For optimizations. */
{
return
nosave ? 0 : REXEC_COPY_STR);
}
STATIC void
{
#ifdef DEBUGGING
#endif
}
/*
* Need to implement the following flags for reg_anch:
*
* USE_INTUIT_NOML - Useful to call re_intuit_start() first
* USE_INTUIT_ML
* INTUIT_AUTORITATIVE_NOML - Can trust a positive answer
* INTUIT_AUTORITATIVE_ML
* INTUIT_ONCE_NOML - Intuit can match in one location only.
* INTUIT_ONCE_ML
*
* Another flag for this function: SECOND_TIME (so that float substrs
* with giant delta may be not rechecked).
*/
/* Assumptions: if ANCH_GPOS, then strpos is anchored. XXXX Check GPOS logic */
/* If SCREAM, then SvPVX(sv) should be compatible with strpos and strend.
Otherwise, only SvCUR(sv) is used to get strbeg. */
/* XXXX We assume that strpos is strbeg unless sv. */
/* XXXX Some places assume that there is a fixed substring.
An update may be needed if optimizer marks as "INTUITable"
RExen without fixed substrings. Similarly, it is assumed that
lengths of all the strings are no more than minlen, thus they
cannot come from lookahead.
(Or minlen should take into account lookahead.) */
/* A failure to find a constant substring means that there is no need to make
an expensive call to REx engine, thus we celebrate a failure. Similarly,
finding a substring too deep into the string means that less calls to
regtry() should be needed.
REx compiler's optimizer found 4 possible hints:
a) Anchored substring;
b) Fixed substring;
c) Whether we are anchored (beginning-of-line or \G);
d) First node (of those at offset 0) which may distingush positions;
We use a)b)d) and multiline-part of c), and try to find a position in the
string which does not contradict any of them.
*/
/* Most of decisions we do here should have been done at compile time.
The nodes of the REx which we used for the search should have been
deleted from the finite automaton. */
char *
{
register I32 start_shift = 0;
/* Should be nonnegative! */
register char *s;
char *strbeg;
char *t;
#ifdef DEBUGGING
#endif
"UTF-8 regex...\n"));
PL_reg_flags |= RF_utf8;
}
DEBUG_r({
char *s = PL_reg_match_utf8 ?
int len = PL_reg_match_utf8 ?
if (!PL_colorset)
if (PL_reg_match_utf8)
"UTF-8 target...\n"));
"%sGuessing start of match, REx%s `%s%.60s%s%s' against `%s%.*s%s%s'...\n",
PL_colors[1],
PL_colors[0],
s, PL_colors[1],
);
});
/* CHR_DIST() would be more correct here but it makes things slow. */
"String too short... [re_intuit_start]\n"));
goto fail;
}
if (do_utf8) {
} else {
}
if (check == &PL_sv_undef) {
"Non-utf string cannot match utf check string\n"));
goto fail;
}
&& !PL_multiline ) ); /* Check after \n? */
if (!ml_anch) {
| ROPT_IMPLICIT)) /* not a real BOL */
/* SvCUR is not set on references: SvRV and SvPVX overlap */
goto fail;
}
/* Substring at constant offset from beg-of-str... */
goto fail_finish;
}
/* Now should match s[0..slen-2] */
slen--;
|| (slen > 1
goto fail_finish;
}
}
goto report_neq;
goto success_at_start;
}
}
/* Match is anchored, but substr is not anchored wrt beg-of-str. */
s = strpos;
if (!ml_anch) {
}
}
else { /* Can match at random position */
ml_anch = 0;
s = strpos;
/* Should be nonnegative! */
}
#ifdef DEBUGGING /* 7/99: reports of failure (with the older version) */
if (end_shift < 0)
#endif
/* Find a possible match in the region s..strend by looking for
if (flags & REXEC_SCREAM) {
else
goto fail_finish;
/* we may be pointing at the wrong string */
if (s && RX_MATCH_COPIED(prog))
if (data)
*data->scream_olds = s;
}
else
/* Update the count-of-usability, remove useless subpatterns,
unshift s. */
(s ? "Found" : "Did not find"),
PL_colors[0],
(s ? " at offset " : "...\n") ) );
if (!s)
goto fail_finish;
check_at = s;
/* Finish the diagnostic message */
/* Got a candidate. Check MBOL anchoring, and the *other* substr.
Start with the other substr.
XXXX no SCREAM optimization yet - and a very coarse implementation
XXXX /ttx+/ results in anchored=`ttx', floating=`x'. floating will
*always* match. Probably should be marked during compile...
Probably it is right to do no SCREAM here...
*/
if (do_utf8 ? (prog->float_utf8 && prog->anchored_utf8) : (prog->float_substr && prog->anchored_substr)) {
/* Take into account the "other" substring. */
/* XXXX May be hopelessly wrong for UTF... */
if (!other_last)
other_last = strpos;
{
char *s1 = s;
t = s - prog->check_offset_max;
&& (!do_utf8
&& t > strpos)))
/* EMPTY */;
else
t = strpos;
if (t < other_last) /* These positions already checked */
t = other_last;
/* XXXX It is not documented what units *_offsets are in. Assume bytes. */
/* On end-of-str: see comment below. */
if (must == &PL_sv_undef) {
s = (char*)NULL;
}
else
s = fbm_instr(
(unsigned char*)t,
must,
PL_multiline ? FBMrf_MULTILINE : 0
);
"%s anchored substr `%s%.*s%s'%s",
(s ? "Found" : "Contradicts"),
PL_colors[0],
if (!s) {
", giving up...\n"));
goto fail_finish;
}
", trying floating at offset %ld...\n",
goto restart;
}
else {
(long)(s - i_strpos)));
s = s1;
if (t == strpos)
goto try_at_start;
goto try_at_offset;
}
}
}
else { /* Take into account the floating substring. */
char *s1 = s;
if (s < other_last)
s = other_last;
/* XXXX It is not documented what units *_offsets are in. Assume bytes. */
/* fbm_instr() takes into account exact value of end-of-str
if the check is SvTAIL(ed). Since false positives are OK,
and end-of-str is not later than strend we are OK. */
if (must == &PL_sv_undef) {
s = (char*)NULL;
}
else
s = fbm_instr((unsigned char*)s,
(s ? "Found" : "Contradicts"),
PL_colors[0],
if (!s) {
", giving up...\n"));
goto fail_finish;
}
", trying anchored starting at offset %ld...\n",
other_last = last;
goto restart;
}
else {
(long)(s - i_strpos)));
other_last = s; /* Fix this later. --Hugo */
s = s1;
if (t == strpos)
goto try_at_start;
goto try_at_offset;
}
}
}
t = s - prog->check_offset_max;
&& (!do_utf8
&& t > strpos))) {
/* Fixed substring is found far enough so that the match
cannot start at strpos. */
/* Eventually fbm_*() should handle this, but often
anchored_offset is not 0, so this check will not be wasted. */
/* XXXX In the code below we prefer to look for "^" even in
presence of anchored substrings. And we search even
beyond the found float position. These pessimizations
are historical artefacts only. */
if (*t == '\n') {
/* Since we moved from the found position,
we definitely contradict the found anchored
substr. Due to the above check we do not
contradict "check" substr.
Thus we can arrive here only if check substr
is float. Redo checking for "other"=="fixed".
*/
strpos = t + 1;
DEBUG_r(PerlIO_printf(Perl_debug_log, "Found /%s^%s/m at offset %ld, rescanning for anchored from offset %ld...\n",
PL_colors[0],PL_colors[1], (long)(strpos - i_strpos), (long)(strpos - i_strpos + prog->anchored_offset)));
goto do_other_anchored;
}
/* We don't contradict the found floating substring. */
/* XXXX Why not check for STCLASS? */
s = t + 1;
goto set_useful;
}
/* Position contradicts check-string */
/* XXXX probably better to look for check-string
than for "\n", so one should lower the limit for t? */
DEBUG_r(PerlIO_printf(Perl_debug_log, "Found /%s^%s/m, restarting lookup for check-string at offset %ld...\n",
goto restart;
}
t++;
}
goto fail_finish;
}
else {
}
s = t;
}
else {
/* The found string does not prohibit matching at strpos,
- no optimization of calling REx engine can be performed,
unless it was an MBOL and we are not after MBOL,
or a future STCLASS check will fail this. */
/* Even in this situation we may use MBOL flag if strpos is offset
wrt the start of the string. */
/* May be due to an implicit anchor of m{.*foo} */
{
t = strpos;
goto find_anchor;
}
);
&& (do_utf8 ? (
) : (
)))
{
/* If flags & SOMETHING - do not do it many times on the same match */
s = strpos;
/* XXXX This is a remnant of the old implementation. It
looks wasteful, since now INTUIT can use many
other heuristics. */
}
else
s = strpos;
}
/* Last resort... */
/* XXXX BmUSEFUL already changed, maybe multiple change is meaningful... */
if (prog->regstclass) {
/* minlen == 0 is possible if regstclass is \b or \B,
and the fixed substr is ''$.
Since minlen is already taken into account, s+1 is before strend;
accidentally, minlen >= 1 guaranties no false positives at s + 1
even for \b or \B. But (minlen? 1 : 0) below assumes that
regstclass does not come from lookahead... */
/* If regstclass takes bytelength more than 1: If charlength==1, OK.
This leaves EXACTF only, which is dealt with in find_byclass(). */
: 1);
: strend);
t = s;
if (!s) {
#ifdef DEBUGGING
char *what = 0;
#endif
"Could not match STCLASS...\n") );
goto fail;
}
"This position contradicts STCLASS...\n") );
goto fail;
/* Contradict one of substrings */
/* XXXX Should be taken into account earlier? */
"Could not match STCLASS...\n") );
goto fail;
}
if (!check)
goto giveup;
"Looking for %s substr starting at offset %ld...\n",
goto restart;
}
/* Have both, check_string is floating */
goto retry_floating_check;
/* Recheck anchored substring, but not floating... */
s = check_at;
if (!check)
goto giveup;
"Looking for anchored substr starting at offset %ld...\n",
(long)(other_last - i_strpos)) );
goto do_other_anchored;
}
/* Another way we could have checked stclass at the
current position only: */
if (ml_anch) {
s = t = t + 1;
if (!check)
goto giveup;
"Looking for /%s^%s/m starting at offset %ld...\n",
goto try_at_offset;
}
goto fail;
/* Check is floating subtring. */
t = check_at - start_shift;
goto hop_and_restart;
}
if (t != s) {
"By STCLASS: moving %ld --> %ld\n",
);
}
else {
"Does not contradict STCLASS...\n");
);
}
}
return s;
fail_finish: /* Substring not found */
fail:
return Nullch;
}
/* We know what class REx starts with. Try to find this position... */
STATIC char *
{
char *m;
unsigned int c1;
unsigned int c2;
char *e;
register bool do_utf8 = PL_reg_match_utf8;
/* We know what class it must start with. */
switch (OP(c)) {
case ANYOF:
if (do_utf8) {
if ((ANYOF_FLAGS(c) & ANYOF_UNICODE) ||
!UTF8_IS_INVARIANT((U8)s[0]) ?
REGINCLASS(c, (U8*)s)) {
goto got_it;
else
}
else
tmp = 1;
s += uskip;
}
}
else {
while (s < strend) {
if (REGINCLASS(c, (U8*)s) ||
(ANYOF_FOLD_SHARP_S(c, s, strend) &&
/* The assignment of 2 is intentional:
* for the folded sharp s, the skip is 2. */
(skip = SHARP_S_SKIP))) {
goto got_it;
else
}
else
tmp = 1;
s += skip;
}
}
break;
case CANY:
while (s < strend) {
goto got_it;
else
s++;
}
break;
case EXACTF:
m = STRING(c);
if (UTF) {
lnc = 0;
lnc++;
}
}
else {
}
goto do_exactf;
case EXACTFL:
m = STRING(c);
if (norun && e < s)
e = s; /* Due to minlen logic of intuit() */
/* The idea in the EXACTF* cases is to first find the
* first character of the EXACTF* node and then, if
* necessary, case-insensitively compare the full
* text of the node. The c1 and c2 are the first
* characters (though in Unicode it gets a bit
* more complicated because there are more cases
* than just upper and lower: one needs to use
* the so-called folding case for case-insensitive
* matching (called "loose matching" in Unicode).
* ibcmp_utf8() will do just that. */
if (do_utf8) {
UV c, f;
/* Upper and lower of 1st char are equal -
* probably not a "letter". */
while (s <= e) {
0 : UTF8_ALLOW_ANY);
if ( c == c1
ibcmp_utf8(s, (char **)0, 0, do_utf8,
goto got_it;
else {
uvchr_to_utf8(tmpbuf, c);
if ( f != c
!ibcmp_utf8((char *) foldbuf,
m,
goto got_it;
}
s += len;
}
}
else {
while (s <= e) {
0 : UTF8_ALLOW_ANY);
/* Handle some of the three Greek sigmas cases.
* Note that not all the possible combinations
* are handled here: some of them are handled
* by the standard folding rules, and some of
* them (the character class or ANYOF cases)
* are handled during compiletime in
* regexec.c:S_regclass(). */
if (c == (UV)UNICODE_GREEK_CAPITAL_LETTER_SIGMA ||
ibcmp_utf8(s, (char **)0, 0, do_utf8,
goto got_it;
else {
uvchr_to_utf8(tmpbuf, c);
if ( f != c
!ibcmp_utf8((char *) foldbuf,
m,
goto got_it;
}
s += len;
}
}
}
else {
while (s <= e) {
: ibcmp_locale(s, m, ln)))
goto got_it;
s++;
}
else
while (s <= e) {
: ibcmp_locale(s, m, ln)))
goto got_it;
s++;
}
}
break;
case BOUNDL:
/* FALL THROUGH */
case BOUND:
if (do_utf8) {
if (s == PL_bostr)
tmp = '\n';
else {
}
isALNUM_LC_utf8((U8*)s)))
{
goto got_it;
}
s += uskip;
}
}
else {
while (s < strend) {
if (tmp ==
goto got_it;
}
s++;
}
}
goto got_it;
break;
case NBOUNDL:
/* FALL THROUGH */
case NBOUND:
if (do_utf8) {
if (s == PL_bostr)
tmp = '\n';
else {
}
isALNUM_LC_utf8((U8*)s)))
goto got_it;
s += uskip;
}
}
else {
while (s < strend) {
if (tmp ==
goto got_it;
s++;
}
}
goto got_it;
break;
case ALNUM:
if (do_utf8) {
goto got_it;
else
}
else
tmp = 1;
s += uskip;
}
}
else {
while (s < strend) {
if (isALNUM(*s)) {
goto got_it;
else
}
else
tmp = 1;
s++;
}
}
break;
case ALNUML:
if (do_utf8) {
if (isALNUM_LC_utf8((U8*)s)) {
goto got_it;
else
}
else
tmp = 1;
s += uskip;
}
}
else {
while (s < strend) {
if (isALNUM_LC(*s)) {
goto got_it;
else
}
else
tmp = 1;
s++;
}
}
break;
case NALNUM:
if (do_utf8) {
goto got_it;
else
}
else
tmp = 1;
s += uskip;
}
}
else {
while (s < strend) {
if (!isALNUM(*s)) {
goto got_it;
else
}
else
tmp = 1;
s++;
}
}
break;
case NALNUML:
if (do_utf8) {
if (!isALNUM_LC_utf8((U8*)s)) {
goto got_it;
else
}
else
tmp = 1;
s += uskip;
}
}
else {
while (s < strend) {
if (!isALNUM_LC(*s)) {
goto got_it;
else
}
else
tmp = 1;
s++;
}
}
break;
case SPACE:
if (do_utf8) {
goto got_it;
else
}
else
tmp = 1;
s += uskip;
}
}
else {
while (s < strend) {
if (isSPACE(*s)) {
goto got_it;
else
}
else
tmp = 1;
s++;
}
}
break;
case SPACEL:
if (do_utf8) {
goto got_it;
else
}
else
tmp = 1;
s += uskip;
}
}
else {
while (s < strend) {
if (isSPACE_LC(*s)) {
goto got_it;
else
}
else
tmp = 1;
s++;
}
}
break;
case NSPACE:
if (do_utf8) {
goto got_it;
else
}
else
tmp = 1;
s += uskip;
}
}
else {
while (s < strend) {
if (!isSPACE(*s)) {
goto got_it;
else
}
else
tmp = 1;
s++;
}
}
break;
case NSPACEL:
if (do_utf8) {
goto got_it;
else
}
else
tmp = 1;
s += uskip;
}
}
else {
while (s < strend) {
if (!isSPACE_LC(*s)) {
goto got_it;
else
}
else
tmp = 1;
s++;
}
}
break;
case DIGIT:
if (do_utf8) {
goto got_it;
else
}
else
tmp = 1;
s += uskip;
}
}
else {
while (s < strend) {
if (isDIGIT(*s)) {
goto got_it;
else
}
else
tmp = 1;
s++;
}
}
break;
case DIGITL:
if (do_utf8) {
if (isDIGIT_LC_utf8((U8*)s)) {
goto got_it;
else
}
else
tmp = 1;
s += uskip;
}
}
else {
while (s < strend) {
if (isDIGIT_LC(*s)) {
goto got_it;
else
}
else
tmp = 1;
s++;
}
}
break;
case NDIGIT:
if (do_utf8) {
goto got_it;
else
}
else
tmp = 1;
s += uskip;
}
}
else {
while (s < strend) {
if (!isDIGIT(*s)) {
goto got_it;
else
}
else
tmp = 1;
s++;
}
}
break;
case NDIGITL:
if (do_utf8) {
if (!isDIGIT_LC_utf8((U8*)s)) {
goto got_it;
else
}
else
tmp = 1;
s += uskip;
}
}
else {
while (s < strend) {
if (!isDIGIT_LC(*s)) {
goto got_it;
else
}
else
tmp = 1;
s++;
}
}
break;
default:
break;
}
return 0;
return s;
}
/*
- regexec_flags - match a regexp against a string
*/
/* strend: pointer to null at end of string */
/* strbeg: real beginning of string */
/* minend: end of match must be >=minend after stringarg. */
/* data: May be used for some additional optimizations. */
/* nosave: For optimizations. */
{
register char *s;
register regnode *c;
/* I32 start_shift = 0; */ /* Offset of the start to find
constant substr. */ /* CC */
char *scream_olds;
#ifdef DEBUGGING
#endif
PL_regcc = 0;
#ifdef DEBUGGING
#endif
/* Be paranoid... */
return 0;
}
"String too short [regexec_flags]...\n"));
goto phooey;
}
/* Check validity of program. */
}
PL_reg_flags = 0;
PL_reg_eval_set = 0;
PL_reg_maxiter = 0;
PL_reg_flags |= RF_utf8;
/* Mark beginning of line for ^ and lookbehind. */
/* Mark end of line for $ (and such) */
/* see how far we have to get to not match where we matched before */
/* We start without call_cc context. */
PL_reg_call_cc = 0;
/* If there is a "must appear" string, look for it. */
s = startpos;
if (s > PL_reg_ganch)
goto phooey;
s = PL_reg_ganch;
}
}
else /* pos() not defined */
}
d.scream_olds = &scream_olds;
d.scream_pos = &scream_pos;
if (!s) {
goto phooey; /* not present */
}
}
DEBUG_r({
if (!PL_colorset)
"%sMatching REx%s `%s%*.*s%s%s' against `%s%.*s%s%s'\n",
PL_colors[1],
PL_colors[0],
);
});
/* Simplest case: anchored match need be tried only once. */
/* [unless only anchor is BOL and multiline is set] */
goto got_it;
{
char *end;
if (minlen)
/* for multiline we only have to try after newlines */
if (s == startpos)
goto after_try;
while (1) {
goto got_it;
if (s >= end)
goto phooey;
if (!s)
goto phooey;
}
else
s++;
}
} else {
if (s > startpos)
s--;
while (s < end) {
if (*s++ == '\n') { /* don't need PL_utf8skip here */
goto got_it;
}
}
}
}
goto phooey;
goto got_it;
goto phooey;
}
/* Messy cases: unanchored match. */
/* we have /x+whatever/ */
/* it must be a one character string (XXXX Except UTF?) */
char ch;
#ifdef DEBUGGING
int did_match = 0;
#endif
if (do_utf8) {
while (s < strend) {
if (*s == ch) {
s += UTF8SKIP(s);
s += UTF8SKIP(s);
}
s += UTF8SKIP(s);
}
}
else {
while (s < strend) {
if (*s == ch) {
s++;
s++;
}
s++;
}
}
"Did not find anchored character...\n")
);
}
/*SUPPRESS 560*/
char *last;
char *last1; /* Last position checked before */
#ifdef DEBUGGING
int did_match = 0;
#endif
} else {
}
if (must == &PL_sv_undef)
/* could not downgrade utf8 check substring, so must fail */
goto phooey;
if (s > PL_bostr)
else
/* XXXX check_substr already used to find `s', can optimize if
check_substr==must. */
scream_pos = -1;
while ( (s <= last) &&
((flags & REXEC_SCREAM)
end_shift, &scream_pos, 0))
PL_multiline ? FBMrf_MULTILINE : 0))) ) {
/* we may be pointing at the wrong string */
}
else {
s = t;
}
if (do_utf8) {
while (s <= last1) {
goto got_it;
s += UTF8SKIP(s);
}
}
else {
while (s <= last1) {
goto got_it;
s++;
}
}
}
"Did not find %s substr `%s%.*s%s'%s...\n",
? "anchored" : "floating"),
PL_colors[0],
);
goto phooey;
}
else if ((c = prog->regstclass)) {
if (minlen) {
/* don't bother with what can't match */
}
DEBUG_r({
char *s0;
char *s1;
int len0;
int len1;
"Matching stclass `%*.*s' against `%*.*s'\n",
});
goto got_it;
}
else {
dontbother = 0;
/* Trim the end. */
char *last;
SV* float_real;
if (flags & REXEC_SCREAM) {
if (!last)
/* we may be pointing at the wrong string */
else if (RX_MATCH_COPIED(prog))
}
else {
if (SvTAIL(float_real)) {
else if (!PL_multiline)
else
goto find_last;
} else {
if (len)
else
}
}
"%sCan't trim the tail, match fails (should not happen)%s\n",
goto phooey; /* Should not happen! */
}
}
/* We don't know much -- general case. */
if (do_utf8) {
for (;;) {
goto got_it;
if (s >= strend)
break;
s += UTF8SKIP(s);
};
}
else {
do {
goto got_it;
} while (s++ < strend);
}
}
/* Failure. */
goto phooey;
if (PL_reg_eval_set) {
/* Preserve the current value of $^R */
restored, the value remains
the same. */
restore_pos(aTHX_ 0);
}
/* make sure $`, $&, $', and $digit will work later */
if ( !(flags & REXEC_NOT_FIRST) ) {
if (RX_MATCH_COPIED(prog)) {
}
if (flags & REXEC_COPY_STR) {
}
else {
}
}
return 1;
if (PL_reg_eval_set)
restore_pos(aTHX_ 0);
return 0;
}
/*
- regtry - try match at specific point
*/
{
register I32 i;
#ifdef DEBUGGING
PL_regindent = 0; /* XXXX Not good when matches are reenterable... */
#endif
));
/* Otherwise OP_NEXTSTATE will free whatever on stack now. */
/* Apparently this is not needed, judging by wantarray. */
/* SAVEI8(cxstack[cxstack_ix].blk_gimme);
cxstack[cxstack_ix].blk_gimme = G_SCALAR; */
if (PL_reg_sv) {
/* Make $_ available to executed code. */
/* SAVE_DEFSV does *not* suffice here for USE_5005THREADS */
}
/* prepare for quick setting of pos */
}
PL_reg_magic = mg;
}
if (!PL_reg_curpm) {
#ifdef USE_ITHREADS
{
/* so we know which PL_regex_padav element is PL_reg_curpm */
}
#endif
}
if (RX_MATCH_COPIED(prog)) {
/* Here is a serious problem: we cannot rewrite subbeg,
since it may be needed if this match fails. Thus
$` inside (?{}) could fail... */
}
else
}
prog->lastcloseparen = 0;
PL_regsize = 0;
if(PL_reg_start_tmp)
else
}
/* XXXX What this code is doing here?!!! There should be no need
to do this again and again, PL_reglastparen should take care of
this! --ilya*/
* Actually, the code in regcppop() (which Ilya may be meaning by
* PL_reglastparen), is not needed at all by the test suite
* enough, for building DynaLoader, or otherwise this
* "Error: '*' not in typemap in DynaLoader.xs, line 164"
* will happen. Meanwhile, this code *is* needed for the
* above-mentioned test suite tests to succeed. The common theme
* on those tests seems to be returning null fields from matches.
* --jhi */
#if 1
*++sp = -1;
*++ep = -1;
}
}
#endif
return 1;
}
return 0;
}
#define RE_UNWIND_BRANCH 1
#define RE_UNWIND_BRANCHJ 2
union re_unwind_t;
typedef struct { /* XX: makes sense to enlarge it... */
typedef struct {
char *locinput;
#ifdef DEBUGGING
int regindent;
#endif
typedef union re_unwind_t {
} re_unwind_t;
#define sayNO_ANYOF goto no_anyof
#define sayYES_FINAL goto yes_final
#define sayYES_LOUD goto yes_loud
#define sayNO_FINAL goto no_final
#define sayNO_SILENT goto do_no
#define REPORT_CODE_OFF 24
/*
- regmatch - main matching routine
*
* Conceptually the strategy is simple: check to see whether the current
* node matches, call self recursively to see whether the rest matches,
* and then act accordingly. In practice we make some effort to avoid
* recursion, in particular by going through "ordinary" nodes (that don't
* need to know whether the rest of the match failed) by a loop instead of
* by recursion.
*/
/* [lwall] I've hoisted the register declarations to the outer block in order to
* maybe save a little bit of pushing and popping on the stack. It also takes
* advantage of machines that use a register save mask on subroutine entry.
*/
{
function of same name */
register I32 n; /* no or next */
register char *s = Nullch; /* operand or save */
register char *locinput = PL_reginput;
#if 0
#endif
register bool do_utf8 = PL_reg_match_utf8;
#ifdef DEBUGGING
#endif
#ifdef DEBUGGING
PL_regindent++;
#endif
/* Note that nextchr is a byte even in UTF */
DEBUG_r( {
/* The part of the string before starttry has one color
(pref0_len chars), between starttry and current
position another one (pref_len - pref0_len chars),
after the current position the third one.
We assume that pref0_len <= pref_len, otherwise we
decrease pref0_len. */
int pref0_len;
pref_len++;
l--;
if (pref0_len < 0)
pref0_len = 0;
{
char *s0 =
PL_colors[4],
PL_colors[5],
PL_colors[2],
PL_colors[3],
PL_colors[0],
PL_colors[1],
"",
}
});
case BOL:
{
/* regtill = regbol; */
break;
}
case MBOL:
{
break;
}
case SBOL:
break;
case GPOS:
if (locinput == PL_reg_ganch)
break;
case EOL:
if (PL_multiline)
goto meol;
else
goto seol;
case MEOL:
meol:
break;
case SEOL:
seol:
break;
case EOS:
break;
case SANY:
if (do_utf8) {
}
else
break;
case CANY:
break;
case REG_ANY:
if (do_utf8) {
}
else
break;
case EXACT:
/* The target and the pattern have differing utf8ness. */
char *l = locinput;
char *e = s + ln;
if (do_utf8) {
/* The target is utf8, the pattern is not utf8. */
while (s < e) {
if (l >= PL_regeol)
if (NATIVE_TO_UNI(*(U8*)s) !=
0 : UTF8_ALLOW_ANY))
l += ulen;
s ++;
}
}
else {
/* The target is not utf8, the pattern is utf8. */
while (s < e) {
if (l >= PL_regeol)
if (NATIVE_TO_UNI(*((U8*)l)) !=
0 : UTF8_ALLOW_ANY))
s += ulen;
l ++;
}
}
locinput = l;
break;
}
/* The target and the pattern have the same utf8ness. */
/* Inline the first character, for speed. */
break;
case EXACTFL:
/* FALL THROUGH */
case EXACTF:
/* Either target or the pattern are utf8. */
char *l = locinput;
char *e = PL_regeol;
l, &e, 0, do_utf8)) {
/* One more case for the sharp s:
* pack("U0U*", 0xDF) =~ /ss/i,
* the 0xC3 0x9F are the UTF-8
* byte sequence for the U+00DF. */
if (!(do_utf8 &&
toLOWER(s[0]) == 's' &&
ln >= 2 &&
(U8)l[0] == 0xC3 &&
e - l >= 2 &&
}
locinput = e;
break;
}
/* Neither the target and the pattern are utf8. */
/* Inline the first character, for speed. */
break;
case ANYOF:
if (do_utf8) {
break;
}
else {
if (nextchr < 0)
break;
}
/* If we might have the case of the German sharp s
* in a casefolding Unicode character class. */
locinput += SHARP_S_SKIP;
}
else
break;
case ALNUML:
/* FALL THROUGH */
case ALNUM:
if (!nextchr)
if (do_utf8) {
{
}
break;
}
break;
case NALNUML:
/* FALL THROUGH */
case NALNUM:
if (do_utf8) {
{
}
break;
}
break;
case BOUNDL:
case NBOUNDL:
/* FALL THROUGH */
case BOUND:
case NBOUND:
/* was last char in word? */
if (do_utf8) {
ln = '\n';
else {
}
}
else {
}
}
else {
}
else {
n = isALNUM_LC(nextchr);
}
}
break;
case SPACEL:
/* FALL THROUGH */
case SPACE:
if (!nextchr)
if (do_utf8) {
if (UTF8_IS_CONTINUED(nextchr)) {
{
}
break;
}
}
else {
}
break;
case NSPACEL:
/* FALL THROUGH */
case NSPACE:
if (do_utf8) {
{
}
break;
}
break;
case DIGITL:
/* FALL THROUGH */
case DIGIT:
if (!nextchr)
if (do_utf8) {
{
}
break;
}
break;
case NDIGITL:
/* FALL THROUGH */
case NDIGIT:
if (do_utf8) {
{
}
break;
}
break;
case CLUMP:
if (do_utf8) {
}
else
locinput++;
break;
case REFFL:
/* FALL THROUGH */
case REF:
case REFF:
ln = PL_regstartp[n];
sayNO; /* Do not match unless seen CLOSEn. */
if (ln == PL_regendp[n])
break;
char *l = locinput;
char *e = PL_bostr + PL_regendp[n];
/*
* Note that we can't do the "other character" lookup trick as
* in the 8-bit case (no pun intended) because in Unicode we
* have to map both upper and title case to lower case.
*/
while (s < e) {
if (l >= PL_regeol)
s += ulen1;
l += ulen2;
}
}
locinput = l;
break;
}
/* Inline the first character, for speed. */
break;
case NOTHING:
case TAIL:
break;
case BACK:
break;
case EVAL:
{
dSP;
{
else {
}
}
if (logical) {
int toggleutf;
else if (SvSMAGICAL(ret)) {
if (SvGMAGICAL(ret))
else
}
if (mg) {
(void)ReREFCNT_inc(re);
}
else {
char *oprecomp = PL_regprecomp;
| SVs_GMG)))
PERL_MAGIC_qr,0,0);
PL_regsize = osize;
PL_regnpar = onpar;
}
"Entering embedded `%s%.60s%s%s'\n",
PL_colors[0],
PL_colors[1],
);
PL_regcc = 0;
*PL_reglastparen = 0;
*PL_reglastcloseparen = 0;
PL_reg_call_cc = &state;
/* XXXX This is too dramatic a measure... */
PL_reg_maxiter = 0;
/* Even though we succeeded, we need to restore
global variables, since we may be wrapped inside
SUSPEND, thus the match may be not finished yet. */
/* XXXX Do this only if SUSPENDed? */
/* XXXX This is too dramatic a measure... */
PL_reg_maxiter = 0;
/* These are needed even if not SUSPEND. */
}
regcppop();
/* XXXX This is too dramatic a measure... */
PL_reg_maxiter = 0;
logical = 0;
}
logical = 0;
}
else {
}
break;
}
case OPEN:
PL_reg_start_tmp[n] = locinput;
if (n > PL_regsize)
PL_regsize = n;
break;
case CLOSE:
if (n > (I32)*PL_reglastparen)
*PL_reglastparen = n;
*PL_reglastcloseparen = n;
break;
case GROUPP:
break;
case IFTHEN:
if (sw)
else {
}
break;
case LOGICAL:
break;
/*******************************************************************
PL_regcc contains infoblock about the innermost (...)* loop, and
a pointer to the next outer infoblock.
1) After matching X, regnode for CURLYX is processed;
2) This regnode creates infoblock on the stack, and calls
regmatch() recursively with the starting point at WHILEM node;
3) Each hit of WHILEM node tries to match A and Z (in the order
greediness). The information about where are nodes for "A"
and "Z" is read from the infoblock, as is info on how many times "A"
was already matched, and greediness.
4) After A matches, the same WHILEM node is hit again.
5) Each time WHILEM is hit, PL_regcc is the infoblock created by CURLYX
of the same pair. Thus when WHILEM tries to match Z, it temporarily
resets PL_regcc, since this Y(A)*Z can be a part of some other loop:
as in (Y(A)*Z)*. If Z matches, the automaton will hit the WHILEM node
of the external loop.
Currently present infoblocks form a tree with a stem formed by PL_curcc
and whatever it mentions via ->next, and additional attached trees
corresponding to temporarily unset infoblocks as in "5" above.
In the following picture infoblocks for outer loop of
(Y(A)*?Z)*?T are denoted O, for inner I. NULL starting block
is denoted by x. The matched string is YAAZYAZT. Temporarily postponed
infoblocks are drawn below the "reset" infoblock.
In fact in the picture below we do not show failed matches for Z and T
by WHILEM blocks. [We illustrate minimal matches, since for them it is
more obvious *why* one needs to *temporary* unset infoblocks.]
Matched REx position InfoBlocks Comment
(Y(A)*?Z)*?T x
Y(A)*?Z)*?T x <- O
Y (A)*?Z)*?T x <- O
Y A)*?Z)*?T x <- O <- I
YA )*?Z)*?T x <- O <- I
YA A)*?Z)*?T x <- O <- I
YAA )*?Z)*?T x <- O <- I
YAA Z)*?T x <- O # Temporary unset I
I
YAAZ Y(A)*?Z)*?T x <- O
I
YAAZY (A)*?Z)*?T x <- O
I
YAAZY A)*?Z)*?T x <- O <- I
I
YAAZYA )*?Z)*?T x <- O <- I
I
YAAZYA Z)*?T x <- O # Temporary unset I
I,I
YAAZYAZ )*?T x <- O
I,I
YAAZYAZ T x # Temporary unset O
O
I,I
YAAZYAZT x
O
I,I
*******************************************************************/
case CURLYX: {
/* XXXX Probably it is better to teach regpush to support
parenfloor > PL_regsize... */
saySAME(n);
}
/* NOT REACHED */
case WHILEM: {
/*
* This is really hard to understand, because after we match
* what we're trying to match, we must make sure the rest of
* the REx is going to match for sure, and to do that we have
* to go back UP the parse tree by recursing ever deeper. And
* if it fails, we have to reset our parent's current state
* that we can try again after backing off.
*/
);
/* If degenerate scan matches "", assume scan done. */
if (PL_regcc)
"%*s empty match detected, try continuation...\n",
);
if (PL_regcc)
}
/* First just match a string of min scans. */
}
/* Check whether we already were at this position.
Postpone detection until we know the match is not
*that* much linear. */
if (!PL_reg_maxiter) {
}
if (PL_reg_leftiter-- == 0) {
if (PL_reg_poscache) {
}
}
else {
}
"%sDetected a super-linear match, switching on caching%s...\n",
);
}
if (PL_reg_leftiter < 0) {
b = o % 8;
o /= 8;
if (PL_reg_poscache[o] & (1<<b)) {
"%*s already tried at this position...\n",
);
if (PL_reg_flags & RF_false)
else
}
PL_reg_poscache[o] |= (1<<b);
}
}
/* Prefer next over scan for minimal matching. */
if (PL_regcc)
sayYES; /* All done. */
}
regcppop();
if (PL_regcc)
&& !(PL_reg_flags & RF_warned)) {
"Complex regular subexpression recursion",
REG_INFTY - 1);
}
}
"%*s trying longer...\n",
);
/* Try scanning more and see if it helps. */
}
regcppop();
}
/* Prefer scan over next for maximal matching. */
}
regcppop(); /* Restore some previous $<digit>s? */
"%*s failed, try continuation...\n",
);
}
&& !(PL_reg_flags & RF_warned)) {
"Complex regular subexpression recursion",
REG_INFTY - 1);
}
/* Failed deeper matches of scan, so see if this one works. */
if (PL_regcc)
if (PL_regcc)
}
/* NOT REACHED */
case BRANCHJ:
goto do_branch;
case BRANCH:
{
else {
/* Put unwinding data on stack */
#ifdef DEBUGGING
#endif
/* Now go into the first branch */
}
}
break;
case MINMOD:
minmod = 1;
break;
case CURLYM:
{
I32 l = 0;
/* We suppose that the next guy does not need
backtracking: in particular, it is of constant length,
and has no parenths to influence future backrefs. */
if (paren) {
if (paren > PL_regsize)
PL_regsize = paren;
*PL_reglastparen = paren;
}
if (paren)
if (minmod) {
minmod = 0;
/* if we matched something zero-length we don't need to
backtrack - capturing parens are already defined, so
the caveat in the maximal case doesn't apply
XXXX if ln == 0, we can redo this check first time
through the following loop
*/
if (ln && l == 0)
n = ln; /* don't backtrack */
else {
goto assume_ok_MM;
}
else
}
}
else
/* This may be improved if l == 0. */
/* If it could work, try it. */
if (c1 == -1000 ||
{
if (paren) {
if (ln) {
}
else
}
}
/* Couldn't or didn't -- move forward. */
ln++;
}
else
}
}
else {
n = regrepeat_hard(scan, n, &l);
/* if we matched something zero-length we don't need to
backtrack, unless the minimum count is zero and we
are capturing the result - in that case the capture
being defined or not may affect later execution
*/
ln = n; /* don't backtrack */
);
if (n >= ln) {
else {
goto assume_ok_REG;
}
else
}
}
else
}
while (n >= ln) {
/* If it could work, try it. */
if (c1 == -1000 ||
{
);
if (paren) {
if (n) {
}
else
}
}
/* Couldn't or didn't -- back up. */
n--;
}
}
break;
}
case CURLYN:
if (paren > PL_regsize)
PL_regsize = paren;
*PL_reglastparen = paren;
goto repeat;
case CURLY:
paren = 0;
goto repeat;
case STAR:
ln = 0;
n = REG_INFTY;
paren = 0;
goto repeat;
case PLUS:
ln = 1;
n = REG_INFTY;
paren = 0;
/*
* Lookahead to avoid useless match attempts
* when we know what character comes next.
*/
/*
* Used to only do .*x and .*?x, but now it allows
* for )'s, ('s and (?{ ... })'s to be in the way
* of the quantifier and the EXACT-like node. -- japhy
*/
U8 *s;
else {
goto assume_ok_easy;
}
if (!UTF) {
}
else { /* UTF */
0 : UTF8_ALLOW_ANY);
0 : UTF8_ALLOW_ANY);
}
else {
0 : UTF8_ALLOW_ANY);
}
}
}
}
else
if (minmod) {
minmod = 0;
if (c1 != -1000) {
char *e; /* Should not check after this */
int count = 0;
if (n == REG_INFTY) {
e = PL_regeol - 1;
if (do_utf8)
while (UTF8_IS_CONTINUATION(*(U8*)e))
e--;
}
else if (do_utf8) {
int m = n - ln;
for (e = locinput;
e += UTF8SKIP(e);
}
else {
if (e >= PL_regeol)
e = PL_regeol - 1;
}
while (1) {
/* Find place 'next' could work */
if (!do_utf8) {
while (locinput <= e &&
locinput++;
} else {
while (locinput <= e
locinput++;
}
}
else {
/* count initialised to
* utf8_distance(old, locinput) */
while (locinput <= e &&
UTF8_MAXLEN, &len,
count++;
}
} else {
/* count initialised to
* utf8_distance(old, locinput) */
while (locinput <= e) {
UTF8_MAXLEN, &len,
0 : UTF8_ALLOW_ANY);
break;
count++;
}
}
}
if (locinput > e)
/* PL_reginput == old now */
}
/* PL_reginput == locinput now */
/* Couldn't or didn't -- move forward. */
if (do_utf8)
else
locinput++;
count = 1;
}
}
else
UV c;
if (c1 != -1000) {
if (do_utf8)
UTF8_MAXLEN, 0,
0 : UTF8_ALLOW_ANY);
else
c = UCHARAT(PL_reginput);
/* If it could work, try it. */
{
}
}
/* If it could work, try it. */
else if (c1 == -1000)
{
}
/* Couldn't or didn't -- move forward. */
ln++;
}
else
}
}
else {
{
ln = n; /* why back off? */
/* ...because $ and \Z can match before *and* after
newline at the end. Consider "\n\n" =~ /\n+\Z\n/.
We should back off by one in this case. */
ln--;
}
if (paren) {
UV c = 0;
while (n >= ln) {
if (c1 != -1000) {
if (do_utf8)
UTF8_MAXLEN, 0,
0 : UTF8_ALLOW_ANY);
else
c = UCHARAT(PL_reginput);
}
/* If it could work, try it. */
{
}
/* Couldn't or didn't -- back up. */
n--;
}
}
else {
UV c = 0;
while (n >= ln) {
if (c1 != -1000) {
if (do_utf8)
UTF8_MAXLEN, 0,
0 : UTF8_ALLOW_ANY);
else
c = UCHARAT(PL_reginput);
}
/* If it could work, try it. */
{
}
/* Couldn't or didn't -- back up. */
n--;
}
}
}
break;
case END:
if (PL_reg_call_cc) {
the caller. */
the callcc. */
}
regcppop();
"%*s continuation failed...\n",
);
}
if (locinput < PL_regtill) {
"%sMatch possible, but length=%ld is smaller than requested=%ld, failing!%s\n",
PL_colors[4],
(long)(locinput - PL_reg_starttry),
(long)(PL_regtill - PL_reg_starttry),
PL_colors[5]));
sayNO_FINAL; /* Cannot match: too short. */
}
sayYES_FINAL; /* Success! */
case SUCCEED:
sayYES_LOUD; /* Success! */
case SUSPEND:
n = 1;
goto do_ifmatch;
case UNLESSM:
n = 0;
if (!s)
goto say_yes;
PL_reginput = s;
}
else
PL_reg_flags ^= RF_false;
goto do_ifmatch;
case IFMATCH:
n = 1;
if (!s)
goto say_no;
PL_reginput = s;
}
else
if (n == 0)
PL_reg_flags ^= RF_false;
if (logical) {
logical = 0;
sw = 0;
goto do_longjump;
}
else
}
if (n == 0)
PL_reg_flags ^= RF_false;
if (logical) {
logical = 0;
sw = 1;
}
}
/* FALL THROUGH. */
case LONGJMP:
break;
default:
}
}
/*
* We get here only if there's trouble -- normally "case END" is
* the terminating point.
*/
/*NOTREACHED*/
"%*s %scould match...%s\n",
);
goto yes;
yes:
#ifdef DEBUGGING
PL_regindent--;
#endif
#if 0 /* Breaks $^R */
if (unwind)
#endif
return 1;
no:
"%*s %sfailed...%s\n",
);
goto do_no;
if (unwind) {
case RE_UNWIND_BRANCH:
case RE_UNWIND_BRANCHJ:
{
for (n = *PL_reglastparen; n > lastparen; n--)
PL_regendp[n] = -1;
*PL_reglastparen = n;
if ( !scan ||
#ifdef DEBUGGING
PL_regindent--;
#endif
goto do_no;
}
/* Have more choice yet. Reuse the same uwb. */
/*SUPPRESS 560*/
next += n;
else
#ifdef DEBUGGING
#endif
goto reenter;
}
/* NOT REACHED */
default:
}
/* NOT REACHED */
}
#ifdef DEBUGGING
PL_regindent--;
#endif
return 0;
}
/*
- regrepeat - repeatedly match something simple, report how many
*/
/*
* [This routine now assumes that it will only match on things of length 1.
* That was true before, but now we assume scan - reginput is the count,
* rather than incrementing count on every character. [Er, except utf8.]]
*/
{
register char *scan;
register I32 c;
register bool do_utf8 = PL_reg_match_utf8;
scan = PL_reginput;
switch (OP(p)) {
case REG_ANY:
if (do_utf8) {
hardcount++;
}
} else {
scan++;
}
break;
case SANY:
if (do_utf8) {
hardcount++;
}
}
else
break;
case CANY:
break;
case EXACT: /* length of string is 1 */
scan++;
break;
case EXACTF: /* length of string is 1 */
scan++;
break;
case EXACTFL: /* length of string is 1 */
scan++;
break;
case ANYOF:
if (do_utf8) {
hardcount++;
}
} else {
scan++;
}
break;
case ALNUM:
if (do_utf8) {
hardcount++;
}
} else {
scan++;
}
break;
case ALNUML:
if (do_utf8) {
hardcount++;
}
} else {
scan++;
}
break;
case NALNUM:
if (do_utf8) {
hardcount++;
}
} else {
scan++;
}
break;
case NALNUML:
if (do_utf8) {
hardcount++;
}
} else {
scan++;
}
break;
case SPACE:
if (do_utf8) {
(*scan == ' ' ||
hardcount++;
}
} else {
scan++;
}
break;
case SPACEL:
if (do_utf8) {
hardcount++;
}
} else {
scan++;
}
break;
case NSPACE:
if (do_utf8) {
!(*scan == ' ' ||
hardcount++;
}
} else {
scan++;
break;
}
case NSPACEL:
if (do_utf8) {
hardcount++;
}
} else {
scan++;
}
break;
case DIGIT:
if (do_utf8) {
hardcount++;
}
} else {
scan++;
}
break;
case NDIGIT:
if (do_utf8) {
hardcount++;
}
} else {
scan++;
}
break;
default: /* Called on something of 0 width. */
break; /* So match right here or not at all. */
}
if (hardcount)
c = hardcount;
else
c = scan - PL_reginput;
PL_reginput = scan;
{
});
return(c);
}
/*
- regrepeat_hard - repeatedly match something, report total lenth and length
*
* The repeater is supposed to have constant length.
*/
{
register char *start;
I32 l = 0;
if (!max)
return 0;
start = PL_reginput;
if (PL_reg_match_utf8) {
if (!count++) {
l = 0;
while (start < PL_reginput) {
l++;
}
*lp = l;
if (l == 0)
return max;
}
return count;
}
}
else {
if (!count++) {
if (l == 0)
return max;
}
}
}
if (!res)
PL_reginput = scan;
return count;
}
/*
- regclass_swash - prepare the utf8 swash
*/
SV *
{
SV **a, **b;
/* See the end of regcomp.c:S_reglass() for
* documentation of these array elements. */
if (a)
sw = *a;
}
if (b)
alt = *b;
}
}
if (listsvp)
if (altsvp)
return sw;
}
/*
- reginclass - determine if a character falls into a character class
The n is the ANYOF regnode, the p is the target string, lenp
is pointer to the maximum length of how far to go in the p
(if the lenp is zero, UTF8SKIP(p) is used),
do_utf8 tells whether the target string is in UTF-8.
*/
STATIC bool
{
char flags = ANYOF_FLAGS(n);
UV c = *p;
if (do_utf8 && !UTF8_IS_INVARIANT(c))
if (lenp)
*lenp = 0;
if (do_utf8 && !ANYOF_RUNTIME(n)) {
}
if (!match) {
if (sw) {
else if (flags & ANYOF_FOLD) {
I32 i;
break;
}
}
}
if (!match) {
}
}
}
}
}
if (!match && c < 256) {
if (ANYOF_BITMAP_TEST(n, c))
else if (flags & ANYOF_FOLD) {
U8 f;
if (flags & ANYOF_LOCALE) {
f = PL_fold_locale[c];
}
else
f = PL_fold[c];
if (f != c && ANYOF_BITMAP_TEST(n, f))
}
if (
) /* How's that for a conditional? */
{
}
}
}
}
{
}
{
if (off >= 0) {
/* XXX could check well-formedness here */
s += UTF8SKIP(s);
}
}
else {
while (off++) {
if (s > lim) {
s--;
if (UTF8_IS_CONTINUED(*s)) {
s--;
}
/* XXX could check well-formedness here */
}
}
}
return s;
}
{
}
{
if (off >= 0) {
/* XXX could check well-formedness here */
s += UTF8SKIP(s);
}
if (off >= 0)
return 0;
}
else {
while (off++) {
if (s > lim) {
s--;
if (UTF8_IS_CONTINUED(*s)) {
s--;
}
/* XXX could check well-formedness here */
}
else
break;
}
if (off <= 0)
return 0;
}
return s;
}
static void
{
if (PL_reg_eval_set) {
if (PL_reg_oldsaved) {
}
PL_reg_eval_set = 0;
}
}
STATIC void
{
}
}
}
STATIC void
{
} else {
}
}
} else {
}
}
}