#define HOPc(pos,off) ((char*)HOP(pos,off))
#define HOPMAYBEc(pos,off) ((char*)HOPMAYBE(pos,off))
+#define HOPBACK(pos, off) ( \
+ (UTF && DO_UTF8(PL_reg_sv)) \
+ ? reghopmaybe((U8*)pos, -off) \
+ : (pos - off >= PL_bostr) \
+ ? (U8*)(pos - off) \
+ : (U8*)NULL \
+)
+#define HOPBACKc(pos, off) (char*)HOPBACK(pos, off)
+
#define reghop3_c(pos,off,lim) ((char*)reghop3((U8*)pos, off, (U8*)lim))
#define reghopmaybe3_c(pos,off,lim) ((char*)reghopmaybe3((U8*)pos, off, (U8*)lim))
#define HOP3(pos,off,lim) (DO_UTF8(PL_reg_sv) ? reghop3((U8*)pos, off, (U8*)lim) : (U8*)(pos + off))
int paren_elems_to_push = (PL_regsize - parenfloor) * REGCP_PAREN_ELEMS;
int p;
+ if (paren_elems_to_push < 0)
+ Perl_croak(aTHX_ "panic: paren_elems_to_push < 0");
+
#define REGCP_OTHER_ELEMS 5
SSCHECK(paren_elems_to_push + REGCP_OTHER_ELEMS);
for (p = PL_regsize; p > parenfloor; p--) {
&& !PL_multiline ) ); /* Check after \n? */
if (!ml_anch) {
- if ( !(prog->reganch & ROPT_ANCH_GPOS) /* Checked by the caller */
+ if ( !(prog->reganch & (ROPT_ANCH_GPOS /* Checked by the caller */
+ | ROPT_IMPLICIT)) /* not a real BOL */
/* SvCUR is not set on references: SvRV and SvPVX overlap */
&& sv && !SvROK(sv)
&& (strpos != strbeg)) {
/* FALL THROUGH */
case BOUND:
if (do_utf8) {
- if (s == startpos)
+ if (s == PL_bostr)
tmp = '\n';
else {
U8 *r = reghop3((U8*)s, -1, (U8*)startpos);
- tmp = (I32)utf8n_to_uvuni(r, s - (char*)r, 0, 0);
+ tmp = (I32)utf8n_to_uvchr(r, s - (char*)r, 0, 0);
}
tmp = ((OP(c) == BOUND ?
isALNUM_uni(tmp) : isALNUM_LC_uvchr(UNI_TO_NATIVE(tmp))) != 0);
LOAD_UTF8_CHARCLASS(alnum,"a");
while (s < strend) {
if (tmp == !(OP(c) == BOUND ?
- swash_fetch(PL_utf8_alnum, (U8*)s) :
+ swash_fetch(PL_utf8_alnum, (U8*)s, do_utf8) :
isALNUM_LC_utf8((U8*)s)))
{
tmp = !tmp;
}
}
else {
- tmp = (s != startpos) ? UCHARAT(s - 1) : '\n';
+ tmp = (s != PL_bostr) ? UCHARAT(s - 1) : '\n';
tmp = ((OP(c) == BOUND ? isALNUM(tmp) : isALNUM_LC(tmp)) != 0);
while (s < strend) {
if (tmp ==
/* FALL THROUGH */
case NBOUND:
if (do_utf8) {
- if (s == startpos)
+ if (s == PL_bostr)
tmp = '\n';
else {
U8 *r = reghop3((U8*)s, -1, (U8*)startpos);
- tmp = (I32)utf8n_to_uvuni(r, s - (char*)r, 0, 0);
+ tmp = (I32)utf8n_to_uvchr(r, s - (char*)r, 0, 0);
}
tmp = ((OP(c) == NBOUND ?
isALNUM_uni(tmp) : isALNUM_LC_uvchr(UNI_TO_NATIVE(tmp))) != 0);
LOAD_UTF8_CHARCLASS(alnum,"a");
while (s < strend) {
if (tmp == !(OP(c) == NBOUND ?
- swash_fetch(PL_utf8_alnum, (U8*)s) :
+ swash_fetch(PL_utf8_alnum, (U8*)s, do_utf8) :
isALNUM_LC_utf8((U8*)s)))
tmp = !tmp;
else if ((norun || regtry(prog, s)))
}
}
else {
- tmp = (s != startpos) ? UCHARAT(s - 1) : '\n';
+ tmp = (s != PL_bostr) ? UCHARAT(s - 1) : '\n';
tmp = ((OP(c) == NBOUND ?
isALNUM(tmp) : isALNUM_LC(tmp)) != 0);
while (s < strend) {
if (do_utf8) {
LOAD_UTF8_CHARCLASS(alnum,"a");
while (s < strend) {
- if (swash_fetch(PL_utf8_alnum, (U8*)s)) {
+ if (swash_fetch(PL_utf8_alnum, (U8*)s, do_utf8)) {
if (tmp && (norun || regtry(prog, s)))
goto got_it;
else
if (do_utf8) {
LOAD_UTF8_CHARCLASS(alnum,"a");
while (s < strend) {
- if (!swash_fetch(PL_utf8_alnum, (U8*)s)) {
+ if (!swash_fetch(PL_utf8_alnum, (U8*)s, do_utf8)) {
if (tmp && (norun || regtry(prog, s)))
goto got_it;
else
if (do_utf8) {
LOAD_UTF8_CHARCLASS(space," ");
while (s < strend) {
- if (*s == ' ' || swash_fetch(PL_utf8_space,(U8*)s)) {
+ if (*s == ' ' || swash_fetch(PL_utf8_space,(U8*)s, do_utf8)) {
if (tmp && (norun || regtry(prog, s)))
goto got_it;
else
if (do_utf8) {
LOAD_UTF8_CHARCLASS(space," ");
while (s < strend) {
- if (!(*s == ' ' || swash_fetch(PL_utf8_space,(U8*)s))) {
+ if (!(*s == ' ' || swash_fetch(PL_utf8_space,(U8*)s, do_utf8))) {
if (tmp && (norun || regtry(prog, s)))
goto got_it;
else
if (do_utf8) {
LOAD_UTF8_CHARCLASS(digit,"0");
while (s < strend) {
- if (swash_fetch(PL_utf8_digit,(U8*)s)) {
+ if (swash_fetch(PL_utf8_digit,(U8*)s, do_utf8)) {
if (tmp && (norun || regtry(prog, s)))
goto got_it;
else
if (do_utf8) {
LOAD_UTF8_CHARCLASS(digit,"0");
while (s < strend) {
- if (!swash_fetch(PL_utf8_digit,(U8*)s)) {
+ if (!swash_fetch(PL_utf8_digit,(U8*)s, do_utf8)) {
if (tmp && (norun || regtry(prog, s)))
goto got_it;
else
if (strend - startpos < minlen) goto phooey;
}
- if (startpos == strbeg) /* is ^ valid at stringarg? */
- PL_regprev = '\n';
- else {
- if (prog->reganch & ROPT_UTF8 && do_utf8) {
- U8 *s = reghop3((U8*)stringarg, -1, (U8*)strbeg);
- PL_regprev = utf8n_to_uvuni(s, (U8*)stringarg - s, NULL, 0);
- }
- else
- PL_regprev = (U32)stringarg[-1];
- if (!PL_multiline && PL_regprev == '\n')
- PL_regprev = '\0'; /* force ^ to NOT match */
- }
-
/* Check validity of program. */
if (UCHARAT(prog->program) != REG_MAGIC) {
Perl_croak(aTHX_ "corrupted regexp program");
PL_reg_ganch = startpos;
else if (sv && SvTYPE(sv) >= SVt_PVMG
&& SvMAGIC(sv)
- && (mg = mg_find(sv, 'g')) && mg->mg_len >= 0) {
+ && (mg = mg_find(sv, PERL_MAGIC_regex_global))
+ && mg->mg_len >= 0) {
PL_reg_ganch = strbeg + mg->mg_len; /* Defined pos() */
if (prog->reganch & ROPT_ANCH_GPOS) {
if (s > PL_reg_ganch)
}
if (!(SvTYPE(PL_reg_sv) >= SVt_PVMG && SvMAGIC(PL_reg_sv)
- && (mg = mg_find(PL_reg_sv, 'g')))) {
+ && (mg = mg_find(PL_reg_sv, PERL_MAGIC_regex_global)))) {
/* prepare for quick setting of pos */
- sv_magic(PL_reg_sv, (SV*)0, 'g', Nullch, 0);
- mg = mg_find(PL_reg_sv, 'g');
+ sv_magic(PL_reg_sv, (SV*)0,
+ PERL_MAGIC_regex_global, Nullch, 0);
+ mg = mg_find(PL_reg_sv, PERL_MAGIC_regex_global);
mg->mg_len = -1;
}
PL_reg_magic = mg;
switch (OP(scan)) {
case BOL:
- if (locinput == PL_bostr
- ? PL_regprev == '\n'
- : (PL_multiline &&
- (nextchr || locinput < PL_regeol) && locinput[-1] == '\n') )
+ if (locinput == PL_bostr || (PL_multiline &&
+ (nextchr || locinput < PL_regeol) && locinput[-1] == '\n') )
{
/* regtill = regbol; */
break;
}
sayNO;
case MBOL:
- if (locinput == PL_bostr
- ? PL_regprev == '\n'
- : ((nextchr || locinput < PL_regeol) && locinput[-1] == '\n') )
+ if (locinput == PL_bostr ||
+ ((nextchr || locinput < PL_regeol) && locinput[-1] == '\n'))
{
break;
}
if (l >= PL_regeol) {
sayNO;
}
- if ((UTF ? utf8n_to_uvuni((U8*)s, e - s, 0, 0) : *((U8*)s)) !=
+ if ((UTF ? utf8n_to_uvchr((U8*)s, e - s, 0, 0) : *((U8*)s)) !=
(c1 ? toLOWER_utf8((U8*)l) : toLOWER_LC_utf8((U8*)l)))
sayNO;
s += UTF ? UTF8SKIP(s) : 1;
sayNO;
if (do_utf8) {
if (!(OP(scan) == ALNUM
- ? swash_fetch(PL_utf8_alnum, (U8*)locinput)
+ ? swash_fetch(PL_utf8_alnum, (U8*)locinput, do_utf8)
: isALNUM_LC_utf8((U8*)locinput)))
{
sayNO;
if (do_utf8) {
LOAD_UTF8_CHARCLASS(alnum,"a");
if (OP(scan) == NALNUM
- ? swash_fetch(PL_utf8_alnum, (U8*)locinput)
+ ? swash_fetch(PL_utf8_alnum, (U8*)locinput, do_utf8)
: isALNUM_LC_utf8((U8*)locinput))
{
sayNO;
case NBOUND:
/* was last char in word? */
if (do_utf8) {
- if (locinput == PL_regbol)
- ln = PL_regprev;
+ if (locinput == PL_bostr)
+ ln = '\n';
else {
U8 *r = reghop((U8*)locinput, -1);
- ln = utf8n_to_uvuni(r, s - (char*)r, 0, 0);
+ ln = utf8n_to_uvchr(r, s - (char*)r, 0, 0);
}
if (OP(scan) == BOUND || OP(scan) == NBOUND) {
ln = isALNUM_uni(ln);
LOAD_UTF8_CHARCLASS(alnum,"a");
- n = swash_fetch(PL_utf8_alnum, (U8*)locinput);
+ n = swash_fetch(PL_utf8_alnum, (U8*)locinput, do_utf8);
}
else {
ln = isALNUM_LC_uvchr(UNI_TO_NATIVE(ln));
}
}
else {
- ln = (locinput != PL_regbol) ?
- UCHARAT(locinput - 1) : PL_regprev;
+ ln = (locinput != PL_bostr) ?
+ UCHARAT(locinput - 1) : '\n';
if (OP(scan) == BOUND || OP(scan) == NBOUND) {
ln = isALNUM(ln);
n = isALNUM(nextchr);
if (UTF8_IS_CONTINUED(nextchr)) {
LOAD_UTF8_CHARCLASS(space," ");
if (!(OP(scan) == SPACE
- ? swash_fetch(PL_utf8_space, (U8*)locinput)
+ ? swash_fetch(PL_utf8_space, (U8*)locinput, do_utf8)
: isSPACE_LC_utf8((U8*)locinput)))
{
sayNO;
if (do_utf8) {
LOAD_UTF8_CHARCLASS(space," ");
if (OP(scan) == NSPACE
- ? swash_fetch(PL_utf8_space, (U8*)locinput)
+ ? swash_fetch(PL_utf8_space, (U8*)locinput, do_utf8)
: isSPACE_LC_utf8((U8*)locinput))
{
sayNO;
if (do_utf8) {
LOAD_UTF8_CHARCLASS(digit,"0");
if (!(OP(scan) == DIGIT
- ? swash_fetch(PL_utf8_digit, (U8*)locinput)
+ ? swash_fetch(PL_utf8_digit, (U8*)locinput, do_utf8)
: isDIGIT_LC_utf8((U8*)locinput)))
{
sayNO;
if (do_utf8) {
LOAD_UTF8_CHARCLASS(digit,"0");
if (OP(scan) == NDIGIT
- ? swash_fetch(PL_utf8_digit, (U8*)locinput)
+ ? swash_fetch(PL_utf8_digit, (U8*)locinput, do_utf8)
: isDIGIT_LC_utf8((U8*)locinput))
{
sayNO;
break;
case CLUMP:
LOAD_UTF8_CHARCLASS(mark,"~");
- if (locinput >= PL_regeol || swash_fetch(PL_utf8_mark,(U8*)locinput))
+ if (locinput >= PL_regeol ||
+ swash_fetch(PL_utf8_mark,(U8*)locinput, do_utf8))
sayNO;
locinput += PL_utf8skip[nextchr];
- while (locinput < PL_regeol && swash_fetch(PL_utf8_mark,(U8*)locinput))
+ while (locinput < PL_regeol &&
+ swash_fetch(PL_utf8_mark,(U8*)locinput, do_utf8))
locinput += UTF8SKIP(locinput);
if (locinput > PL_regeol)
sayNO;
SV *sv = SvROK(ret) ? SvRV(ret) : ret;
if(SvMAGICAL(sv))
- mg = mg_find(sv, 'r');
+ mg = mg_find(sv, PERL_MAGIC_qr);
}
if (mg) {
re = (regexp *)mg->mg_obj;
I32 osize = PL_regsize;
I32 onpar = PL_regnpar;
- pm.op_pmflags = 0;
+ Zero(&pm, 1, PMOP);
re = CALLREGCOMP(aTHX_ t, t + len, &pm);
if (!(SvFLAGS(ret)
& (SVs_TEMP | SVs_PADTMP | SVf_READONLY)))
- sv_magic(ret,(SV*)ReREFCNT_inc(re),'r',0,0);
+ sv_magic(ret,(SV*)ReREFCNT_inc(re),
+ PERL_MAGIC_qr,0,0);
PL_regprecomp = oprecomp;
PL_regsize = osize;
PL_regnpar = onpar;
c = utf8_to_uvchr((U8*)PL_reginput, NULL);
else
c = UCHARAT(PL_reginput);
+ /* If it could work, try it. */
+ if (c == c1 || c == c2)
+ {
+ TRYPAREN(paren, n, PL_reginput);
+ REGCP_UNWIND(lastcp);
+ }
}
/* If it could work, try it. */
- if (c1 == -1000 || c == c1 || c == c2)
+ else if (c1 == -1000)
{
TRYPAREN(paren, n, PL_reginput);
REGCP_UNWIND(lastcp);
case UNLESSM:
n = 0;
if (scan->flags) {
- if (UTF) { /* XXXX This is absolutely
- broken, we read before
- start of string. */
- s = HOPMAYBEc(locinput, -scan->flags);
- if (!s)
- goto say_yes;
- PL_reginput = s;
- }
- else {
- if (locinput < PL_bostr + scan->flags)
- goto say_yes;
- PL_reginput = locinput - scan->flags;
- goto do_ifmatch;
- }
+ s = HOPBACKc(locinput, scan->flags);
+ if (!s)
+ goto say_yes;
+ PL_reginput = s;
}
else
PL_reginput = locinput;
case IFMATCH:
n = 1;
if (scan->flags) {
- if (UTF) { /* XXXX This is absolutely
- broken, we read before
- start of string. */
- s = HOPMAYBEc(locinput, -scan->flags);
- if (!s || s < PL_bostr)
- goto say_no;
- PL_reginput = s;
- }
- else {
- if (locinput < PL_bostr + scan->flags)
- goto say_no;
- PL_reginput = locinput - scan->flags;
- goto do_ifmatch;
- }
+ s = HOPBACKc(locinput, scan->flags);
+ if (!s)
+ goto say_no;
+ PL_reginput = s;
}
else
PL_reginput = locinput;
loceol = PL_regeol;
LOAD_UTF8_CHARCLASS(alnum,"a");
while (hardcount < max && scan < loceol &&
- swash_fetch(PL_utf8_alnum, (U8*)scan)) {
+ swash_fetch(PL_utf8_alnum, (U8*)scan, do_utf8)) {
scan += UTF8SKIP(scan);
hardcount++;
}
loceol = PL_regeol;
LOAD_UTF8_CHARCLASS(alnum,"a");
while (hardcount < max && scan < loceol &&
- !swash_fetch(PL_utf8_alnum, (U8*)scan)) {
+ !swash_fetch(PL_utf8_alnum, (U8*)scan, do_utf8)) {
scan += UTF8SKIP(scan);
hardcount++;
}
loceol = PL_regeol;
LOAD_UTF8_CHARCLASS(space," ");
while (hardcount < max && scan < loceol &&
- (*scan == ' ' || swash_fetch(PL_utf8_space,(U8*)scan))) {
+ (*scan == ' ' ||
+ swash_fetch(PL_utf8_space,(U8*)scan, do_utf8))) {
scan += UTF8SKIP(scan);
hardcount++;
}
loceol = PL_regeol;
LOAD_UTF8_CHARCLASS(space," ");
while (hardcount < max && scan < loceol &&
- !(*scan == ' ' || swash_fetch(PL_utf8_space,(U8*)scan))) {
+ !(*scan == ' ' ||
+ swash_fetch(PL_utf8_space,(U8*)scan, do_utf8))) {
scan += UTF8SKIP(scan);
hardcount++;
}
loceol = PL_regeol;
LOAD_UTF8_CHARCLASS(digit,"0");
while (hardcount < max && scan < loceol &&
- swash_fetch(PL_utf8_digit,(U8*)scan)) {
+ swash_fetch(PL_utf8_digit, (U8*)scan, do_utf8)) {
scan += UTF8SKIP(scan);
hardcount++;
}
loceol = PL_regeol;
LOAD_UTF8_CHARCLASS(digit,"0");
while (hardcount < max && scan < loceol &&
- !swash_fetch(PL_utf8_digit,(U8*)scan)) {
+ !swash_fetch(PL_utf8_digit, (U8*)scan, do_utf8)) {
scan += UTF8SKIP(scan);
hardcount++;
}
char flags = ANYOF_FLAGS(n);
bool match = FALSE;
UV c;
- STRLEN len;
+ STRLEN len = 0;
- if (do_utf8)
- c = utf8_to_uvchr(p, &len);
- else
- c = *p;
+ c = do_utf8 ? utf8_to_uvchr(p, &len) : *p;
if (do_utf8 || (flags & ANYOF_UNICODE)) {
if (do_utf8 && !ANYOF_RUNTIME(n)) {
if (len != (STRLEN)-1 && c < 256 && ANYOF_BITMAP_TEST(n, c))
match = TRUE;
}
- if (do_utf8 && flags & ANYOF_UNICODE_ALL && c >= 256)
+ if (!match && do_utf8 && (flags & ANYOF_UNICODE_ALL) && c >= 256)
match = TRUE;
if (!match) {
SV *sw = regclass_swash(n, TRUE, 0);
if (sw) {
- if (swash_fetch(sw, p))
+ if (swash_fetch(sw, p, do_utf8))
match = TRUE;
else if (flags & ANYOF_FOLD) {
U8 tmpbuf[UTF8_MAXLEN+1];
}
else
uvchr_to_utf8(tmpbuf, toLOWER_utf8(p));
- if (swash_fetch(sw, tmpbuf))
+ if (swash_fetch(sw, tmpbuf, do_utf8))
match = TRUE;
}
}
if (ANYOF_BITMAP_TEST(n, c))
match = TRUE;
else if (flags & ANYOF_FOLD) {
- I32 f;
+ I32 f;
if (flags & ANYOF_LOCALE) {
PL_reg_flags |= RF_tainted;