U16 flags16; /* are we folding, multilining? */
char *precomp; /* uncompiled string. */
regexp *rx;
+ char *start; /* Start of input for compile */
char *end; /* End of input for compile */
char *parse; /* Input-scan pointer. */
I32 whilem_seen; /* number of WHILEM in this expr */
+ regnode *emit_start; /* Start of emitted-code area */
regnode *emit; /* Code-emit pointer; ®dummy = don't = compiling */
I32 naughty; /* How bad is this pattern? */
I32 sawback; /* Did we see \1, ...? */
#define RExC_flags16 (pRExC_state->flags16)
#define RExC_precomp (pRExC_state->precomp)
#define RExC_rx (pRExC_state->rx)
+#define RExC_start (pRExC_state->start)
#define RExC_end (pRExC_state->end)
#define RExC_parse (pRExC_state->parse)
#define RExC_whilem_seen (pRExC_state->whilem_seen)
+#define RExC_offsets (pRExC_state->rx->offsets) /* I am not like the others */
#define RExC_emit (pRExC_state->emit)
+#define RExC_emit_start (pRExC_state->emit_start)
#define RExC_naughty (pRExC_state->naughty)
#define RExC_sawback (pRExC_state->sawback)
#define RExC_seen (pRExC_state->seen)
/* Allow for side effects in s */
#define REGC(c,s) STMT_START { if (!SIZE_ONLY) *(s) = (c); else (s);} STMT_END
+/* Macros for recording node offsets. 20001227 mjd@plover.com
+ * Nodes are numbered 1, 2, 3, 4. Node #n's position is recorded in
+ * element 2*n-1 of the array. Element #2n holds the byte length node #n.
+ * Element 0 holds the number n.
+ */
+
+#define MJD_OFFSET_DEBUG(x)
+/* #define MJD_OFFSET_DEBUG(x) fprintf x */
+
+
+# define Set_Node_Offset_To_R(node,byte) \
+ STMT_START { \
+ if (! SIZE_ONLY) { \
+ if((node) < 0) { \
+ Perl_croak(aTHX_ "value of node is %d in Offset macro", node); \
+ } else { \
+ RExC_offsets[2*(node)-1] = (byte); \
+ } \
+ } \
+ } STMT_END
+
+# define Set_Node_Offset(node,byte) Set_Node_Offset_To_R((node)-RExC_emit_start, (byte)-RExC_start)
+# define Set_Cur_Node_Offset Set_Node_Offset(RExC_emit, RExC_parse)
+
+# define Set_Node_Length_To_R(node,len) \
+ STMT_START { \
+ if (! SIZE_ONLY) { \
+ MJD_OFFSET_DEBUG((stderr, "** (%d) size of node %d is %d.\n", __LINE__, (node), (len))); \
+ if((node) < 0) { \
+ Perl_croak(aTHX_ "value of node is %d in Length macro", node); \
+ } else { \
+ RExC_offsets[2*(node)] = (len); \
+ } \
+ } \
+ } STMT_END
+
+# define Set_Node_Length(node,len) Set_Node_Length_To_R((node)-RExC_emit_start, len)
+# define Set_Cur_Node_Length(len) Set_Node_Length(RExC_emit, len)
+# define Set_Node_Cur_Length(node) Set_Node_Length(node, RExC_parse - parse_start)
+
+/* Get offsets and lengths */
+#define Node_Offset(n) (RExC_offsets[2*((n)-RExC_emit_start)-1])
+#define Node_Length(n) (RExC_offsets[2*((n)-RExC_emit_start)])
+
static void clear_re(pTHXo_ void *r);
/* Mark that we cannot extend a found fixed substring at this point.
#endif
n = regnext(n);
}
- else {
+ else if (stringok) {
int oldl = STR_LEN(scan);
regnode *nnext = regnext(n);
-
+
if (oldl + STR_LEN(n) > U8_MAX)
break;
NEXT_OFF(scan) += NEXT_OFF(n);
STR_LEN(scan) += STR_LEN(n);
next = n + NODE_SZ_STR(n);
/* Now we can overwrite *n : */
- Move(STRING(n), STRING(scan) + oldl,
- STR_LEN(n), char);
+ Move(STRING(n), STRING(scan) + oldl, STR_LEN(n), char);
#ifdef DEBUGGING
- if (stringok)
- stop = next - 1;
+ stop = next - 1;
#endif
n = nnext;
}
if (UTF) {
U8 *s = (U8*)STRING(scan);
l = utf8_length(s, s + l);
- uc = utf8_to_uv_simple(s, NULL);
+ uc = utf8_to_uvchr(s, NULL);
}
min += l;
if (flags & SCF_DO_SUBSTR) { /* Update longest substr. */
if (UTF) {
U8 *s = (U8 *)STRING(scan);
l = utf8_length(s, s + l);
- uc = utf8_to_uv_simple(s, NULL);
+ uc = utf8_to_uvchr(s, NULL);
}
min += l;
if (data && (flags & SCF_DO_SUBSTR))
else
RExC_utf8 = 0;
- RExC_precomp = savepvn(exp, xend - exp);
+ RExC_precomp = exp;
DEBUG_r(if (!PL_colorset) reginitcolors());
DEBUG_r(PerlIO_printf(Perl_debug_log, "%sCompiling REx%s `%s%*s%s'\n",
PL_colors[4],PL_colors[5],PL_colors[0],
/* First pass: determine size, legality. */
RExC_parse = exp;
+ RExC_start = exp;
RExC_end = xend;
RExC_naughty = 0;
RExC_npar = 1;
REGC((U8)REG_MAGIC, (char*)RExC_emit);
#endif
if (reg(pRExC_state, 0, &flags) == NULL) {
- Safefree(RExC_precomp);
RExC_precomp = Nullch;
return(NULL);
}
#endif
r->refcnt = 1;
r->prelen = xend - exp;
- r->precomp = RExC_precomp;
+ r->precomp = savepvn(RExC_precomp, r->prelen);
r->subbeg = NULL;
r->reganch = pm->op_pmflags & PMf_COMPILETIME;
r->nparens = RExC_npar - 1; /* set early to validate backrefs */
r->startp = 0; /* Useful during FAIL. */
r->endp = 0; /* Useful during FAIL. */
+ Newz(1304, r->offsets, 2*RExC_size+1, U32); /* MJD 20001228 */
+ if (r->offsets) {
+ r->offsets[0] = RExC_size;
+ }
+ DEBUG_r(PerlIO_printf(Perl_debug_log,
+ "%s %u bytes for offset annotations.\n",
+ r->offsets ? "Got" : "Couldn't get",
+ (2*RExC_size+1) * sizeof(U32)));
+
RExC_rx = r;
/* Second pass: emit code. */
RExC_end = xend;
RExC_naughty = 0;
RExC_npar = 1;
+ RExC_emit_start = r->program;
RExC_emit = r->program;
/* Store the count of eval-groups for security checks: */
RExC_emit->next_off = ((RExC_seen_evals > U16_MAX) ? U16_MAX : RExC_seen_evals);
r->reganch |= ROPT_LOOKBEHIND_SEEN;
if (RExC_seen & REG_SEEN_EVAL)
r->reganch |= ROPT_EVAL_SEEN;
+ if (RExC_seen & REG_SEEN_SANY)
+ r->reganch |= ROPT_SANY_SEEN;
Newz(1002, r->startp, RExC_npar, I32);
Newz(1002, r->endp, RExC_npar, I32);
PL_regdata = r->data; /* for regprop() */
register regnode *ender = 0;
register I32 parno = 0;
I32 flags, oregflags = RExC_flags16, have_branch = 0, open = 0;
+ char * parse_start = RExC_parse; /* MJD */
char *oregcomp_parse = RExC_parse;
char c;
/* Make an OPEN node, if parenthesized. */
if (paren) {
- if (*RExC_parse == '?') {
+ if (*RExC_parse == '?') { /* (?...) */
U16 posflags = 0, negflags = 0;
U16 *flagsp = &posflags;
int logical = 0;
paren = *RExC_parse++;
ret = NULL; /* For look-ahead/behind. */
switch (paren) {
- case '<':
+ case '<': /* (?<...) */
RExC_seen |= REG_SEEN_LOOKBEHIND;
if (*RExC_parse == '!')
paren = ',';
if (*RExC_parse != '=' && *RExC_parse != '!')
goto unknown;
RExC_parse++;
- case '=':
- case '!':
+ case '=': /* (?=...) */
+ case '!': /* (?!...) */
RExC_seen_zerolen++;
- case ':':
- case '>':
+ case ':': /* (?:...) */
+ case '>': /* (?>...) */
break;
- case '$':
- case '@':
+ case '$': /* (?$...) */
+ case '@': /* (?@...) */
vFAIL2("Sequence (?%c...) not implemented", (int)paren);
break;
- case '#':
+ case '#': /* (?#...) */
while (*RExC_parse && *RExC_parse != ')')
RExC_parse++;
if (*RExC_parse != ')')
nextchar(pRExC_state);
*flagp = TRYAGAIN;
return NULL;
- case 'p':
+ case 'p': /* (?p...) */
if (SIZE_ONLY)
vWARN(RExC_parse, "(?p{}) is deprecated - use (??{})");
/* FALL THROUGH*/
- case '?':
+ case '?': /* (??...) */
logical = 1;
paren = *RExC_parse++;
/* FALL THROUGH */
- case '{':
+ case '{': /* (?{...}) */
{
I32 count = 1, n = 0;
char c;
if (!SIZE_ONLY)
ret->flags = 2;
regtail(pRExC_state, ret, reganode(pRExC_state, EVAL, n));
+ /* deal with the length of this later - MJD */
return ret;
}
return reganode(pRExC_state, EVAL, n);
}
- case '(':
+ case '(': /* (?(?{...})...) and (?(?=...)...) */
{
- if (RExC_parse[0] == '?') {
+ if (RExC_parse[0] == '?') { /* (?(?...)) */
if (RExC_parse[1] == '=' || RExC_parse[1] == '!'
|| RExC_parse[1] == '<'
|| RExC_parse[1] == '{') { /* Lookahead or eval. */
}
}
else if (RExC_parse[0] >= '1' && RExC_parse[0] <= '9' ) {
+ /* (?(1)...) */
parno = atoi(RExC_parse++);
while (isDIGIT(*RExC_parse))
RExC_parse++;
- ret = reganode(pRExC_state, GROUPP, parno);
+ ret = reganode(pRExC_state, GROUPP, parno);
+
if ((c = *nextchar(pRExC_state)) != ')')
vFAIL("Switch condition not recognized");
insert_if:
break;
default:
--RExC_parse;
- parse_flags:
+ parse_flags: /* (?i) */
while (*RExC_parse && strchr("iogcmsx", *RExC_parse)) {
if (*RExC_parse != 'o')
pmflag(flagsp, *RExC_parse);
return NULL;
}
}
- else {
+ else { /* (...) */
parno = RExC_npar;
RExC_npar++;
ret = reganode(pRExC_state, OPEN, parno);
+ Set_Node_Length(ret, 1); /* MJD */
+ Set_Node_Offset(ret, RExC_parse); /* MJD */
open = 1;
}
}
- else
+ else /* ! paren */
ret = NULL;
/* Pick up the branches, linking them together. */
+ parse_start = RExC_parse; /* MJD */
br = regbranch(pRExC_state, &flags, 1);
+ /* branch_len = (paren != 0); */
+
if (br == NULL)
return(NULL);
if (*RExC_parse == '|') {
if (!SIZE_ONLY && RExC_extralen) {
reginsert(pRExC_state, BRANCHJ, br);
}
- else
+ else { /* MJD */
reginsert(pRExC_state, BRANCH, br);
+ Set_Node_Length(br, paren != 0);
+ Set_Node_Offset_To_R(br-RExC_emit_start, parse_start-RExC_start);
+ }
have_branch = 1;
if (SIZE_ONLY)
RExC_extralen += 1; /* For BRANCHJ-BRANCH. */
RExC_extralen += 2; /* Account for LONGJMP. */
nextchar(pRExC_state);
br = regbranch(pRExC_state, &flags, 0);
+
if (br == NULL)
return(NULL);
regtail(pRExC_state, lastbr, br); /* BRANCH -> BRANCH. */
break;
case 1:
ender = reganode(pRExC_state, CLOSE, parno);
+ Set_Node_Offset(ender,RExC_parse+1); /* MJD */
+ Set_Node_Length(ender,1); /* MJD */
break;
case '<':
case ',':
else {
if (!SIZE_ONLY && RExC_extralen)
ret = reganode(pRExC_state, BRANCHJ,0);
- else
+ else {
ret = reg_node(pRExC_state, BRANCH);
+ Set_Node_Length(ret, 1);
+ }
}
if (!first && SIZE_ONLY)
char *maxpos;
I32 min;
I32 max = REG_INFTY;
+ char *parse_start;
ret = regatom(pRExC_state, &flags);
if (ret == NULL) {
op = *RExC_parse;
if (op == '{' && regcurly(RExC_parse)) {
+ parse_start = RExC_parse; /* MJD */
next = RExC_parse + 1;
maxpos = Nullch;
while (isDIGIT(*next) || *next == ',') {
if ((flags&SIMPLE)) {
RExC_naughty += 2 + RExC_naughty / 2;
reginsert(pRExC_state, CURLY, ret);
+ Set_Node_Offset(ret, parse_start+1); /* MJD */
+ Set_Node_Cur_Length(ret);
}
else {
regnode *w = reg_node(pRExC_state, WHILEM);
NEXT_OFF(ret) = 3; /* Go over LONGJMP. */
}
reginsert(pRExC_state, CURLYX,ret);
+ /* MJD hk */
+ Set_Node_Offset(ret, parse_start+1);
+ Set_Node_Length(ret,
+ op == '{' ? (RExC_parse - parse_start) : 1);
+
if (!SIZE_ONLY && RExC_extralen)
NEXT_OFF(ret) = 3; /* Go over NOTHING to LONGJMP. */
regtail(pRExC_state, ret, reg_node(pRExC_state, NOTHING));
vFAIL("Regexp *+ operand could be empty");
#endif
+ parse_start = RExC_parse;
nextchar(pRExC_state);
*flagp = (op != '+') ? (WORST|SPSTART|HASWIDTH) : (WORST|HASWIDTH);
{
register regnode *ret = 0;
I32 flags;
+ char *parse_start = RExC_parse;
*flagp = WORST; /* Tentatively. */
ret = reg_node(pRExC_state, SBOL);
else
ret = reg_node(pRExC_state, BOL);
+ Set_Node_Length(ret, 1); /* MJD */
break;
case '$':
nextchar(pRExC_state);
ret = reg_node(pRExC_state, SEOL);
else
ret = reg_node(pRExC_state, EOL);
+ Set_Node_Length(ret, 1); /* MJD */
break;
case '.':
nextchar(pRExC_state);
ret = reg_node(pRExC_state, REG_ANY);
*flagp |= HASWIDTH|SIMPLE;
RExC_naughty++;
+ Set_Node_Length(ret, 1); /* MJD */
break;
case '[':
{
}
nextchar(pRExC_state);
*flagp |= HASWIDTH|SIMPLE;
+ Set_Node_Length(ret, RExC_parse - oregcomp_parse + 1); /* MJD */
break;
}
case '(':
ret = reg_node(pRExC_state, SBOL);
*flagp |= SIMPLE;
nextchar(pRExC_state);
+ Set_Node_Length(ret, 2); /* MJD */
break;
case 'G':
ret = reg_node(pRExC_state, GPOS);
RExC_seen |= REG_SEEN_GPOS;
*flagp |= SIMPLE;
nextchar(pRExC_state);
+ Set_Node_Length(ret, 2); /* MJD */
break;
case 'Z':
ret = reg_node(pRExC_state, SEOL);
*flagp |= SIMPLE;
RExC_seen_zerolen++; /* Do not optimize RE away */
nextchar(pRExC_state);
+ Set_Node_Length(ret, 2); /* MJD */
break;
case 'C':
ret = reg_node(pRExC_state, SANY);
+ RExC_seen |= REG_SEEN_SANY;
*flagp |= HASWIDTH|SIMPLE;
nextchar(pRExC_state);
+ Set_Node_Length(ret, 2); /* MJD */
break;
case 'X':
ret = reg_node(pRExC_state, CLUMP);
*flagp |= HASWIDTH;
nextchar(pRExC_state);
- if (UTF && !PL_utf8_mark)
- is_utf8_mark((U8*)"~"); /* preload table */
+ Set_Node_Length(ret, 2); /* MJD */
break;
case 'w':
ret = reg_node(pRExC_state, LOC ? ALNUML : ALNUM);
*flagp |= HASWIDTH|SIMPLE;
nextchar(pRExC_state);
- if (UTF && !PL_utf8_alnum)
- is_utf8_alnum((U8*)"a"); /* preload table */
+ Set_Node_Length(ret, 2); /* MJD */
break;
case 'W':
ret = reg_node(pRExC_state, LOC ? NALNUML : NALNUM);
*flagp |= HASWIDTH|SIMPLE;
nextchar(pRExC_state);
- if (UTF && !PL_utf8_alnum)
- is_utf8_alnum((U8*)"a"); /* preload table */
+ Set_Node_Length(ret, 2); /* MJD */
break;
case 'b':
RExC_seen_zerolen++;
ret = reg_node(pRExC_state, LOC ? BOUNDL : BOUND);
*flagp |= SIMPLE;
nextchar(pRExC_state);
- if (UTF && !PL_utf8_alnum)
- is_utf8_alnum((U8*)"a"); /* preload table */
+ Set_Node_Length(ret, 2); /* MJD */
break;
case 'B':
RExC_seen_zerolen++;
ret = reg_node(pRExC_state, LOC ? NBOUNDL : NBOUND);
*flagp |= SIMPLE;
nextchar(pRExC_state);
- if (UTF && !PL_utf8_alnum)
- is_utf8_alnum((U8*)"a"); /* preload table */
+ Set_Node_Length(ret, 2); /* MJD */
break;
case 's':
ret = reg_node(pRExC_state, LOC ? SPACEL : SPACE);
*flagp |= HASWIDTH|SIMPLE;
nextchar(pRExC_state);
- if (UTF && !PL_utf8_space)
- is_utf8_space((U8*)" "); /* preload table */
+ Set_Node_Length(ret, 2); /* MJD */
break;
case 'S':
ret = reg_node(pRExC_state, LOC ? NSPACEL : NSPACE);
*flagp |= HASWIDTH|SIMPLE;
nextchar(pRExC_state);
- if (UTF && !PL_utf8_space)
- is_utf8_space((U8*)" "); /* preload table */
+ Set_Node_Length(ret, 2); /* MJD */
break;
case 'd':
ret = reg_node(pRExC_state, DIGIT);
*flagp |= HASWIDTH|SIMPLE;
nextchar(pRExC_state);
- if (UTF && !PL_utf8_digit)
- is_utf8_digit((U8*)"1"); /* preload table */
+ Set_Node_Length(ret, 2); /* MJD */
break;
case 'D':
ret = reg_node(pRExC_state, NDIGIT);
*flagp |= HASWIDTH|SIMPLE;
nextchar(pRExC_state);
- if (UTF && !PL_utf8_digit)
- is_utf8_digit((U8*)"1"); /* preload table */
+ Set_Node_Length(ret, 2); /* MJD */
break;
case 'p':
case 'P':
{ /* a lovely hack--pretend we saw [\pX] instead */
char* oldregxend = RExC_end;
+ char* parse_start = RExC_parse;
if (RExC_parse[1] == '{') {
RExC_end = strchr(RExC_parse, '}');
RExC_end = oldregxend;
RExC_parse--;
+ Set_Node_Cur_Length(ret); /* MJD */
nextchar(pRExC_state);
*flagp |= HASWIDTH|SIMPLE;
}
if (num > 9 && num >= RExC_npar)
goto defchar;
else {
+ char * parse_start = RExC_parse - 1; /* MJD */
while (isDIGIT(*RExC_parse))
RExC_parse++;
? (LOC ? REFFL : REFF)
: REF, num);
*flagp |= HASWIDTH;
+
+ /* override incorrect value set in reganode MJD */
+ Set_Node_Offset(ret, parse_start+1);
+ Set_Node_Cur_Length(ret); /* MJD */
RExC_parse--;
nextchar(pRExC_state);
}
register char *p;
char *oldp, *s;
STRLEN numlen;
+ char *parse_start = RExC_parse - 1;
RExC_parse++;
p++;
break;
case 'e':
-#ifdef ASCIIish
- ender = '\033';
-#else
- ender = '\047';
-#endif
+ ender = ASCII_TO_NATIVE('\033');
p++;
break;
case 'a':
-#ifdef ASCIIish
- ender = '\007';
-#else
- ender = '\057';
-#endif
+ ender = ASCII_TO_NATIVE('\007');
p++;
break;
case 'x':
else {
numlen = 1; /* allow underscores */
ender = (UV)scan_hex(p + 1, e - p - 1, &numlen);
+ if (ender > 0xff)
+ RExC_utf8 = 1;
/* numlen is generous */
if (numlen + len >= 127) {
p--;
default:
normal_default:
if (UTF8_IS_START(*p) && UTF) {
- ender = utf8_to_uv((U8*)p, RExC_end - p,
+ ender = utf8n_to_uvchr((U8*)p, RExC_end - p,
&numlen, 0);
p += numlen;
}
p = regwhite(p, RExC_end);
if (UTF && FOLD) {
if (LOC)
- ender = toLOWER_LC_uni(ender);
+ ender = toLOWER_LC_uvchr(ender);
else
ender = toLOWER_uni(ender);
}
if (ISMULT2(p)) { /* Back off on ?+*. */
if (len)
p = oldp;
- /* ender is a Unicode value so it can be > 0xff --
- * in other words, do not use UTF8_IS_CONTINUED(). */
- else if (ender >= 0x80 && UTF) {
+ else if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(ender)) && UTF) {
reguni(pRExC_state, ender, s, &numlen);
s += numlen;
len += numlen;
}
break;
}
- /* ender is a Unicode value so it can be > 0xff --
- * in other words, do not use UTF8_IS_CONTINUED(). */
- if (ender >= 0x80 && UTF) {
+ if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(ender)) && UTF) {
reguni(pRExC_state, ender, s, &numlen);
s += numlen;
len += numlen - 1;
}
loopdone:
RExC_parse = p - 1;
+ Set_Node_Cur_Length(ret); /* MJD */
nextchar(pRExC_state);
{
/* len is STRLEN which is unsigned, need to copy to signed */
bool need_class = 0;
SV *listsv;
register char *e;
+ char *parse_start = RExC_parse; /* MJD */
UV n;
bool dont_optimize_invert = FALSE;
if (!range)
rangebegin = RExC_parse;
if (UTF) {
- value = utf8_to_uv((U8*)RExC_parse,
+ value = utf8n_to_uvchr((U8*)RExC_parse,
RExC_end - RExC_parse,
&numlen, 0);
RExC_parse += numlen;
namedclass = regpposixcc(pRExC_state, value);
else if (value == '\\') {
if (UTF) {
- value = utf8_to_uv((U8*)RExC_parse,
+ value = utf8n_to_uvchr((U8*)RExC_parse,
RExC_end - RExC_parse,
&numlen, 0);
RExC_parse += numlen;
case 't': value = '\t'; break;
case 'f': value = '\f'; break;
case 'b': value = '\b'; break;
-#ifdef ASCIIish
- case 'e': value = '\033'; break;
- case 'a': value = '\007'; break;
-#else
- case 'e': value = '\047'; break;
- case 'a': value = '\057'; break;
-#endif
+ case 'e': value = ASCII_TO_NATIVE('\033');break;
+ case 'a': value = ASCII_TO_NATIVE('\007');break;
case 'x':
if (*RExC_parse == '{') {
e = strchr(RExC_parse++, '}');
else {
ANYOF_FLAGS(ret) |= ANYOF_UNICODE;
Perl_sv_catpvf(aTHX_ listsv,
- /* 0x002D is Unicode for '-' */
- "%04"UVxf"\n002D\n", (UV)lastvalue);
+ "%04"UVxf"\n%04"UVxf"\n", (UV)lastvalue, (UV) '-');
}
}
if (LOC)
ANYOF_CLASS_SET(ret, ANYOF_ASCII);
else {
-#ifdef ASCIIish
+#ifndef EBCDIC
for (value = 0; value < 128; value++)
ANYOF_BITMAP_SET(ret, value);
#else /* EBCDIC */
- for (value = 0; value < 256; value++)
- if (isASCII(value))
- ANYOF_BITMAP_SET(ret, value);
+ for (value = 0; value < 256; value++) {
+ if (PL_hints & HINT_RE_ASCIIR) {
+ if (NATIVE_TO_ASCII(value) < 128)
+ ANYOF_BITMAP_SET(ret, value);
+ }
+ else {
+ if (isASCII(value))
+ ANYOF_BITMAP_SET(ret, value);
+ }
+ }
#endif /* EBCDIC */
}
dont_optimize_invert = TRUE;
if (LOC)
ANYOF_CLASS_SET(ret, ANYOF_NASCII);
else {
-#ifdef ASCIIish
+#ifndef EBCDIC
for (value = 128; value < 256; value++)
ANYOF_BITMAP_SET(ret, value);
#else /* EBCDIC */
- for (value = 0; value < 256; value++)
- if (!isASCII(value))
- ANYOF_BITMAP_SET(ret, value);
+ for (value = 0; value < 256; value++) {
+ if (PL_hints & HINT_RE_ASCIIR) {
+ if (NATIVE_TO_ASCII(value) >= 128)
+ ANYOF_BITMAP_SET(ret, value);
+ }
+ else {
+ if (!isASCII(value))
+ ANYOF_BITMAP_SET(ret, value);
+ }
+ }
#endif /* EBCDIC */
}
dont_optimize_invert = TRUE;
} /* end of namedclass \blah */
if (range) {
- if (lastvalue > value) /* b-a */ {
+ if (((lastvalue > value) && !(PL_hints & HINT_RE_ASCIIR)) ||
+ ((NATIVE_TO_UNI(lastvalue) > NATIVE_TO_UNI(value)) && (PL_hints & HINT_RE_ASCIIR))) /* b-a */ {
Simple_vFAIL4("Invalid [] range \"%*.*s\"",
RExC_parse - rangebegin,
RExC_parse - rangebegin,
/* now is the next time */
if (!SIZE_ONLY) {
if (lastvalue < 256 && value < 256) {
-#ifndef ASCIIish /* EBCDIC, for example. */
- if ((isLOWER(lastvalue) && isLOWER(value)) ||
+#ifdef EBCDIC /* EBCDIC, for example. */
+ if (PL_hints & HINT_RE_ASCIIR) {
+ IV i;
+ /* New style scheme for ranges:
+ * after :
+ * use re 'asciir';
+ * do ranges in ASCII/Unicode space
+ */
+ for (i = NATIVE_TO_ASCII(lastvalue) ; i <= NATIVE_TO_ASCII(value); i++)
+ ANYOF_BITMAP_SET(ret, ASCII_TO_NATIVE(i));
+ }
+ else if ((isLOWER(lastvalue) && isLOWER(value)) ||
(isUPPER(lastvalue) && isUPPER(value)))
{
IV i;
NODE_ALIGN_FILL(ret);
ptr = ret;
FILL_ADVANCE_NODE(ptr, op);
+ if (RExC_offsets) { /* MJD */
+ MJD_OFFSET_DEBUG((stderr, "%s:%u: (op %s) %s %u <- %u (len %u) (max %u).\n",
+ "reg_node", __LINE__,
+ reg_name[op],
+ RExC_emit - RExC_emit_start > RExC_offsets[0]
+ ? "Overwriting end of array!\n" : "OK",
+ RExC_emit - RExC_emit_start,
+ RExC_parse - RExC_start,
+ RExC_offsets[0]));
+ Set_Node_Offset(RExC_emit, RExC_parse + (op == END));
+ }
+
RExC_emit = ptr;
return(ret);
NODE_ALIGN_FILL(ret);
ptr = ret;
FILL_ADVANCE_NODE_ARG(ptr, op, arg);
+ if (RExC_offsets) { /* MJD */
+ MJD_OFFSET_DEBUG((stderr, "%s: %s %u <- %u (max %u).\n",
+ "reganode",
+ RExC_emit - RExC_emit_start > RExC_offsets[0] ?
+ "Overwriting end of array!\n" : "OK",
+ RExC_emit - RExC_emit_start,
+ RExC_parse - RExC_start,
+ RExC_offsets[0]));
+ Set_Cur_Node_Offset;
+ }
+
RExC_emit = ptr;
return(ret);
STATIC void
S_reguni(pTHX_ RExC_state_t *pRExC_state, UV uv, char* s, STRLEN* lenp)
{
- *lenp = SIZE_ONLY ? UNISKIP(uv) : (uv_to_utf8((U8*)s, uv) - (U8*)s);
+ *lenp = SIZE_ONLY ? UNISKIP(uv) : (uvchr_to_utf8((U8*)s, uv) - (U8*)s);
}
/*
src = RExC_emit;
RExC_emit += NODE_STEP_REGNODE + offset;
dst = RExC_emit;
- while (src > opnd)
+ while (src > opnd) {
StructCopy(--src, --dst, regnode);
+ if (RExC_offsets) { /* MJD 20010112 */
+ MJD_OFFSET_DEBUG((stderr, "%s: %s copy %u -> %u (max %u).\n",
+ "reg_insert",
+ dst - RExC_emit_start > RExC_offsets[0]
+ ? "Overwriting end of array!\n" : "OK",
+ src - RExC_emit_start,
+ dst - RExC_emit_start,
+ RExC_offsets[0]));
+ Set_Node_Offset_To_R(dst-RExC_emit_start, Node_Offset(src));
+ Set_Node_Length_To_R(dst-RExC_emit_start, Node_Length(src));
+ }
+ }
+
place = opnd; /* Op node, where operand used to be. */
+ if (RExC_offsets) { /* MJD */
+ MJD_OFFSET_DEBUG((stderr, "%s: %s %u <- %u (max %u).\n",
+ "reginsert",
+ place - RExC_emit_start > RExC_offsets[0]
+ ? "Overwriting end of array!\n" : "OK",
+ place - RExC_emit_start,
+ RExC_parse - RExC_start,
+ RExC_offsets[0]));
+ Set_Node_Offset(place, RExC_parse);
+ }
src = NEXTOPER(place);
FILL_ADVANCE_NODE(place, op);
Zero(src, offset, regnode);
node = dumpuntil(start, NEXTOPER(node), NEXTOPER(node) + 1, sv, l + 1);
}
else if (op == ANYOF) {
- node = NEXTOPER(node);
- node += ANYOF_SKIP;
+ node = next;
}
else if (PL_regkind[(U8)op] == EXACT) {
/* Literal string, where present. */
if (r->reganch & ROPT_EVAL_SEEN)
PerlIO_printf(Perl_debug_log, "with eval ");
PerlIO_printf(Perl_debug_log, "\n");
+ if (r->offsets) {
+ U32 i;
+ U32 len = r->offsets[0];
+ PerlIO_printf(Perl_debug_log, "Offsets: [%u]\n\t", r->offsets[0]);
+ for (i = 1; i <= len; i++)
+ PerlIO_printf(Perl_debug_log, "%u[%u] ",
+ r->offsets[i*2-1],
+ r->offsets[i*2]);
+ PerlIO_printf(Perl_debug_log, "\n");
+ }
#endif /* DEBUGGING */
}
U8 s[UTF8_MAXLEN+1];
for (i = 0; i <= 256; i++) { /* just the first 256 */
- U8 *e = uv_to_utf8(s, i);
+ U8 *e = uvchr_to_utf8(s, i);
if (i < 256 && swash_fetch(sw, s)) {
if (rangestart == -1)
if (i <= rangestart + 3)
for (; rangestart < i; rangestart++) {
- for(e = uv_to_utf8(s, rangestart), p = s; p < e; p++)
+ for(e = uvchr_to_utf8(s, rangestart), p = s; p < e; p++)
put_byte(sv, *p);
}
else {
- for (e = uv_to_utf8(s, rangestart), p = s; p < e; p++)
+ for (e = uvchr_to_utf8(s, rangestart), p = s; p < e; p++)
put_byte(sv, *p);
sv_catpv(sv, "-");
- for (e = uv_to_utf8(s, i - 1), p = s; p < e; p++)
+ for (e = uvchr_to_utf8(s, i - 1), p = s; p < e; p++)
put_byte(sv, *p);
}
rangestart = -1;
if (r->precomp)
Safefree(r->precomp);
+ if (r->offsets) /* 20010421 MJD */
+ Safefree(r->offsets);
if (RX_MATCH_COPIED(r))
Safefree(r->subbeg);
if (r->substrs) {
{
ReREFCNT_dec((regexp *)r);
}
+