char *start; /* Start of input for compile */
char *end; /* End of input for compile */
char *parse; /* Input-scan pointer. */
- char *adjusted_start; /* 'start', adjusted. See code use */
- STRLEN precomp_adj; /* an offset beyond precomp. See code use */
+ char *copy_start; /* start of copy of input within
+ constructed parse string */
+ char *copy_start_in_input; /* Position in input string
+ corresponding to copy_start */
SSize_t whilem_seen; /* number of WHILEM in this expr */
regnode *emit_start; /* Start of emitted-code area */
regnode *emit_bound; /* First regnode outside of the
#define RExC_flags (pRExC_state->flags)
#define RExC_pm_flags (pRExC_state->pm_flags)
#define RExC_precomp (pRExC_state->precomp)
-#define RExC_precomp_adj (pRExC_state->precomp_adj)
-#define RExC_adjusted_start (pRExC_state->adjusted_start)
+#define RExC_copy_start_in_input (pRExC_state->copy_start_in_input)
+#define RExC_copy_start_in_constructed (pRExC_state->copy_start)
#define RExC_precomp_end (pRExC_state->precomp_end)
#define RExC_rx_sv (pRExC_state->rx_sv)
#define RExC_rx (pRExC_state->rx)
} \
} STMT_END
-#define RETURN_NULL_ON_RESTART_OR_FLAGS(flags,flagp,extra) \
+#define RETURN_FAIL_ON_RESTART_OR_FLAGS(flags,flagp,extra) \
RETURN_X_ON_RESTART_OR_FLAGS(NULL,flags,flagp,extra)
#define RETURN_X_ON_RESTART(X, flags,flagp) \
RETURN_X_ON_RESTART_OR_FLAGS( X, flags, flagp, 0)
-#define RETURN_NULL_ON_RESTART_FLAGP_OR_FLAGS(flagp,extra) \
+#define RETURN_FAIL_ON_RESTART_FLAGP_OR_FLAGS(flagp,extra) \
if (*(flagp) & (RESTART_PASS1|(extra))) return NULL
#define MUST_RESTART(flags) ((flags) & (RESTART_PASS1))
-#define RETURN_NULL_ON_RESTART(flags,flagp) \
+#define RETURN_FAIL_ON_RESTART(flags,flagp) \
RETURN_X_ON_RESTART(NULL, flags,flagp)
-#define RETURN_NULL_ON_RESTART_FLAGP(flagp) \
- RETURN_NULL_ON_RESTART_FLAGP_OR_FLAGS(flagp,0)
+#define RETURN_FAIL_ON_RESTART_FLAGP(flagp) \
+ RETURN_FAIL_ON_RESTART_FLAGP_OR_FLAGS(flagp,0)
/* This converts the named class defined in regcomp.h to its equivalent class
* number defined in handy.h. */
* the form of something that is completely different from the input, or
* something that uses the input as part of the alternate. In the first case,
* there should be no possibility of an error, as we are in complete control of
- * the alternate string. But in the second case we don't control the input
- * portion, so there may be errors in that. Here's an example:
+ * the alternate string. But in the second case we don't completely control
+ * the input portion, so there may be errors in that. Here's an example:
* /[abc\x{DF}def]/ui
* is handled specially because \x{df} folds to a sequence of more than one
- * character, 'ss'. What is done is to create and parse an alternate string,
+ * character: 'ss'. What is done is to create and parse an alternate string,
* which looks like this:
* /(?:\x{DF}|[abc\x{DF}def])/ui
* where it uses the input unchanged in the middle of something it constructs,
* class while in this substitute parse.) 'abc' and 'def' may have errors that
* need to be reported. The general situation looks like this:
*
+ * |<------- identical ------>|
* sI tI xI eI
- * Input: ----------------------------------------------------
+ * Input: ---------------------------------------------------------------
* Constructed: ---------------------------------------------------
* sC tC xC eC EC
+ * |<------- identical ------>|
*
- * The input string sI..eI is the input pattern. The string sC..EC is the
- * constructed substitute parse string. The portions sC..tC and eC..EC are
- * constructed by us. The portion tC..eC is an exact duplicate of the input
- * pattern tI..eI. In the diagram, these are vertically aligned. Suppose that
- * while parsing, we find an error at xC. We want to display a message showing
- * the real input string. Thus we need to find the point xI in it which
- * corresponds to xC. xC >= tC, since the portion of the string sC..tC has
- * been constructed by us, and so shouldn't have errors. We get:
+ * sI..eI is the portion of the input pattern we are concerned with here.
+ * sC..EC is the constructed substitute parse string.
+ * sC..tC is constructed by us
+ * tC..eC is an exact duplicate of the portion of the input pattern tI..eI.
+ * In the diagram, these are vertically aligned.
+ * eC..EC is also constructed by us.
+ * xC is the position in the substitute parse string where we found a
+ * problem.
+ * xI is the position in the original pattern corresponding to xC.
*
- * xI = sI + (tI - sI) + (xC - tC)
+ * We want to display a message showing the real input string. Thus we need to
+ * translate from xC to xI. We know that xC >= tC, since the portion of the
+ * string sC..tC has been constructed by us, and so shouldn't have errors. We
+ * get:
+ * xI = tI + (xC - tC)
*
- * and, the offset into sI is:
+ * When the substitute parse is constructed, the code needs to set:
+ * RExC_start (sC)
+ * RExC_end (eC)
+ * RExC_copy_start_in_input (tI)
+ * RExC_copy_start_in_constructed (tC)
+ * and restore them when done.
*
- * (xI - sI) = (tI - sI) + (xC - tC)
- *
- * When the substitute is constructed, we save (tI -sI) as RExC_precomp_adj,
- * and we save tC as RExC_adjusted_start.
- *
- * During normal processing of the input pattern, everything points to that,
- * with RExC_precomp_adj set to 0, and RExC_adjusted_start set to sI.
+ * During normal processing of the input pattern, both
+ * 'RExC_copy_start_in_input' and 'RExC_copy_start_in_constructed' are set to
+ * sI, so that xC equals xI.
*/
-#define tI_sI RExC_precomp_adj
-#define tC RExC_adjusted_start
-#define sC RExC_precomp
-#define xI_offset(xC) ((IV) (tI_sI + (xC - tC)))
-#define xI(xC) (sC + xI_offset(xC))
-#define eC RExC_precomp_end
+#define sI RExC_precomp
+#define eI RExC_precomp_end
+#define sC RExC_start
+#define eC RExC_end
+#define tI RExC_copy_start_in_input
+#define tC RExC_copy_start_in_constructed
+#define xI(xC) (tI + (xC - tC))
+#define xI_offset(xC) (xI(xC) - sI)
#define REPORT_LOCATION_ARGS(xC) \
UTF8fARG(UTF, \
- (xI(xC) > eC) /* Don't run off end */ \
+ (xI(xC) > eI) /* Don't run off end */ \
? eC - sC /* Length before the <--HERE */ \
- : ( __ASSERT_(xI_offset(xC) >= 0) xI_offset(xC) ), \
- sC), /* The input pattern printed up to the <--HERE */ \
+ : ((xI_offset(xC) >= 0) \
+ ? xI_offset(xC) \
+ : (Perl_croak(aTHX_ "panic: %s: %d: negative offset: %" \
+ IVdf " trying to output message for " \
+ " pattern %.*s", \
+ __FILE__, __LINE__, (IV) xI_offset(xC), \
+ ((int) (eC - sC)), sC), 0)), \
+ sI), /* The input pattern printed up to the <--HERE */ \
UTF8fARG(UTF, \
- (xI(xC) > eC) ? 0 : eC - xI(xC), /* Length after <--HERE */ \
- (xI(xC) > eC) ? eC : xI(xC)) /* pattern after <--HERE */
+ (xI(xC) > eI) ? 0 : eI - xI(xC), /* Length after <--HERE */ \
+ (xI(xC) > eI) ? eI : xI(xC)) /* pattern after <--HERE */
/* Used to point after bad bytes for an error message, but avoid skipping
* past a nul byte. */
assert(RExC_rxi->data->what[n] == 's');
if (ary[1] && ary[1] != &PL_sv_undef) { /* Has compile-time swash */
- invlist = sv_2mortal(invlist_clone(_get_swash_invlist(ary[1])));
+ invlist = sv_2mortal(invlist_clone(_get_swash_invlist(ary[1]), NULL));
}
else if (ary[0] && ary[0] != &PL_sv_undef) {
/* Here no compile-time swash, and no run-time only data. Use the
* node's inversion list */
- invlist = sv_2mortal(invlist_clone(ary[3]));
+ invlist = sv_2mortal(invlist_clone(ary[3], NULL));
}
/* Get the code points valid only under UTF-8 locales */
* ANYOF node, with the first NUM_ANYOF_CODE_POINTS code points in a bit
* map */
- SV* invlist = invlist_clone(ssc->invlist);
+ SV* invlist = invlist_clone(ssc->invlist, NULL);
PERL_ARGS_ASSERT_SSC_FINALIZE;
) {
regnode *fix = convert;
U32 word = trie->wordcount;
+#ifdef RE_TRACK_PATTERN_OFFSETS
mjd_nodelen++;
+#endif
Set_Node_Offset_Length(convert, mjd_offset, state - 1);
while( ++fix < n ) {
Set_Node_Offset_Length(fix, 0, 0);
optimisation.
*/
while( optimize < jumper ) {
+#ifdef RE_TRACK_PATTERN_OFFSETS
mjd_nodelen += Node_Length((optimize));
+#endif
OP( optimize ) = OPTIMIZED;
Set_Node_Offset_Length(optimize,0,0);
optimize++;
/* Cannot expect anything... */
scan_commit(pRExC_state, data, minlenp, is_inf);
data->pos_min += 1;
- data->pos_delta += 1;
+ if (data->pos_delta != SSize_t_MAX) {
+ data->pos_delta += 1;
+ }
data->cur_is_floating = 1; /* float */
}
}
invert = 1;
/* FALLTHROUGH */
case ASCII:
- my_invlist = invlist_clone(PL_XPosix_ptrs[_CC_ASCII]);
+ my_invlist = invlist_clone(PL_Posix_ptrs[_CC_ASCII], NULL);
/* This can be handled as a Posix class */
goto join_posix_and_ascii;
/* FALLTHROUGH */
case POSIXA:
assert(FLAGS(scan) != _CC_ASCII);
- _invlist_intersection(PL_XPosix_ptrs[FLAGS(scan)],
- PL_XPosix_ptrs[_CC_ASCII],
- &my_invlist);
+ my_invlist = invlist_clone(PL_Posix_ptrs[FLAGS(scan)], NULL);
goto join_posix_and_ascii;
case NPOSIXD:
/* FALLTHROUGH */
case POSIXD:
case POSIXU:
- my_invlist = invlist_clone(PL_XPosix_ptrs[FLAGS(scan)]);
+ my_invlist = invlist_clone(PL_XPosix_ptrs[FLAGS(scan)], NULL);
/* NPOSIXD matches all upper Latin1 code points unless the
* target string being matched is UTF-8, which is
REGEXP *
Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_count,
OP *expr, const regexp_engine* eng, REGEXP *old_re,
- bool *is_bare_re, U32 orig_rx_flags, U32 pm_flags)
+ bool *is_bare_re, const U32 orig_rx_flags, const U32 pm_flags)
{
- REGEXP *rx;
+ REGEXP *Rx; /* Capital 'R' means points to a REGEXP */
struct regexp *r;
regexp_internal *ri;
STRLEN plen;
set_regex_charset(&rx_flags, REGEX_UNICODE_CHARSET);
}
- RExC_precomp = exp;
- RExC_precomp_adj = 0;
+ RExC_copy_start_in_constructed = RExC_copy_start_in_input = RExC_precomp = exp;
RExC_flags = rx_flags;
RExC_pm_flags = pm_flags;
/* First pass: determine size, legality. */
RExC_parse = exp;
- RExC_start = RExC_adjusted_start = exp;
+ RExC_start = RExC_copy_start_in_constructed = exp;
RExC_end = exp + plen;
RExC_precomp_end = RExC_end;
RExC_naughty = 0;
goto redo_first_pass;
}
- Perl_croak(aTHX_ "panic: reg returned NULL to re_op_compile for sizing pass, flags=%#" UVxf, (UV) flags);
+ Perl_croak(aTHX_ "panic: reg returned failure to re_op_compile for sizing pass, flags=%#" UVxf, (UV) flags);
}
DEBUG_PARSE_r({
/* Allocate space and zero-initialize. Note, the two step process
of zeroing when in debug mode, thus anything assigned has to
happen after that */
- rx = (REGEXP*) newSV_type(SVt_REGEXP);
- r = ReANY(rx);
+ Rx = (REGEXP*) newSV_type(SVt_REGEXP);
+ r = ReANY(Rx);
Newxc(ri, sizeof(regexp_internal) + (unsigned)RExC_size * sizeof(regnode),
char, regexp_internal);
if ( r == NULL || ri == NULL )
/* make sure PL_bitcount bounds not exceeded */
assert(sizeof(STD_PAT_MODS) <= 8);
- p = sv_grow(MUTABLE_SV(rx), wraplen + 1); /* +1 for the ending NUL */
- SvPOK_on(rx);
+ p = sv_grow(MUTABLE_SV(Rx), wraplen + 1); /* +1 for the ending NUL */
+ SvPOK_on(Rx);
if (RExC_utf8)
- SvFLAGS(rx) |= SVf_UTF8;
+ SvFLAGS(Rx) |= SVf_UTF8;
*p++='('; *p++='?';
/* If a default, cover it using the caret */
*p++ = ':';
Copy(RExC_precomp, p, plen, char);
- assert ((RX_WRAPPED(rx) - p) < 16);
- r->pre_prefix = p - RX_WRAPPED(rx);
+ assert ((RX_WRAPPED(Rx) - p) < 16);
+ r->pre_prefix = p - RX_WRAPPED(Rx);
p += plen;
if (has_runon)
*p++ = '\n';
*p++ = ')';
*p = 0;
- SvCUR_set(rx, p - RX_WRAPPED(rx));
+ SvCUR_set(Rx, p - RX_WRAPPED(Rx));
}
r->intflags = 0;
(UV)((2*RExC_size+1) * sizeof(U32))));
#endif
SetProgLen(ri,RExC_size);
- RExC_rx_sv = rx;
+ RExC_rx_sv = Rx;
RExC_rx = r;
RExC_rxi = ri;
}
RExC_npar = 1;
if (reg(pRExC_state, 0, &flags,1) == NULL) {
- ReREFCNT_dec(rx);
- Perl_croak(aTHX_ "panic: reg returned NULL to re_op_compile for generation pass, flags=%#" UVxf, (UV) flags);
+ ReREFCNT_dec(Rx);
+ Perl_croak(aTHX_ "panic: reg returned failure to re_op_compile for generation pass, flags=%#" UVxf, (UV) flags);
}
DEBUG_OPTIMISE_r(
Perl_re_printf( aTHX_ "Starting post parse optimization\n");
/*dmq: removed as part of de-PMOP: pm->op_pmflags = RExC_flags; */
if (UTF)
- SvUTF8_on(rx); /* Unicode in it? */
+ SvUTF8_on(Rx); /* Unicode in it? */
ri->regstclass = NULL;
if (RExC_naughty >= TOO_NAUGHTY) /* Probably an expensive pattern. */
r->intflags |= PREGf_NAUGHTY;
* by setting the regexp SV to readonly-only instead. If the
* pattern's been recompiled, the USEDness should remain. */
if (old_re && SvREADONLY(old_re))
- SvREADONLY_on(rx);
+ SvREADONLY_on(Rx);
#endif
- return rx;
+ return Rx;
}
return zero_addr + *offset;
}
-#endif
-
PERL_STATIC_INLINE void
S_invlist_set_len(pTHX_ SV* const invlist, const UV len, const bool offset)
{
PERL_UNUSED_CONTEXT;
PERL_ARGS_ASSERT_INVLIST_SET_LEN;
- assert(SvTYPE(invlist) == SVt_INVLIST);
+ assert(is_invlist(invlist));
SvCUR_set(invlist,
(len == 0)
assert(SvLEN(invlist) == 0 || SvCUR(invlist) <= SvLEN(invlist));
}
-#ifndef PERL_IN_XSUB_RE
-
STATIC void
S_invlist_replace_list_destroys_src(pTHX_ SV * dest, SV * src)
{
PERL_ARGS_ASSERT_INVLIST_REPLACE_LIST_DESTROYS_SRC;
- assert(SvTYPE(src) == SVt_INVLIST);
- assert(SvTYPE(dest) == SVt_INVLIST);
+ assert(is_invlist(src));
+ assert(is_invlist(dest));
assert(! invlist_is_iterating(src));
assert(SvCUR(src) == 0 || SvCUR(src) < SvLEN(src));
* */
PERL_ARGS_ASSERT_GET_INVLIST_PREVIOUS_INDEX_ADDR;
- assert(SvTYPE(invlist) == SVt_INVLIST);
+ assert(is_invlist(invlist));
return &(((XINVLIST*) SvANY(invlist))->prev_index);
}
PERL_ARGS_ASSERT_INVLIST_TRIM;
- assert(SvTYPE(invlist) == SVt_INVLIST);
+ assert(is_invlist(invlist));
SvPV_renew(invlist, MAX(min_size, SvCUR(invlist) + 1));
}
{
PERL_ARGS_ASSERT_INVLIST_CLEAR;
- assert(SvTYPE(invlist) == SVt_INVLIST);
+ assert(is_invlist(invlist));
invlist_set_len(invlist, 0, 0);
invlist_trim(invlist);
PERL_ARGS_ASSERT_INVLIST_MAX;
- assert(SvTYPE(invlist) == SVt_INVLIST);
+ assert(is_invlist(invlist));
/* Assumes worst case, in which the 0 element is not counted in the
* inversion list, so subtracts 1 for that */
? FROM_INTERNAL_SIZE(SvCUR(invlist)) - 1
: FROM_INTERNAL_SIZE(SvLEN(invlist)) - 1;
}
+
+STATIC void
+S_initialize_invlist_guts(pTHX_ SV* invlist, const Size_t initial_size)
+{
+ PERL_ARGS_ASSERT_INITIALIZE_INVLIST_GUTS;
+
+ /* First 1 is in case the zero element isn't in the list; second 1 is for
+ * trailing NUL */
+ SvGROW(invlist, TO_INTERNAL_SIZE(initial_size + 1) + 1);
+ invlist_set_len(invlist, 0, 0);
+
+ /* Force iterinit() to be used to get iteration to work */
+ invlist_iterfinish(invlist);
+
+ *get_invlist_previous_index_addr(invlist) = 0;
+}
+
SV*
Perl__new_invlist(pTHX_ IV initial_size)
{
/* Allocate the initial space */
new_list = newSV_type(SVt_INVLIST);
- /* First 1 is in case the zero element isn't in the list; second 1 is for
- * trailing NUL */
- SvGROW(new_list, TO_INTERNAL_SIZE(initial_size + 1) + 1);
- invlist_set_len(new_list, 0, 0);
-
- /* Force iterinit() to be used to get iteration to work */
- *get_invlist_iter_addr(new_list) = (STRLEN) UV_MAX;
-
- *get_invlist_previous_index_addr(new_list) = 0;
+ initialize_invlist_guts(new_list, initial_size);
return new_list;
}
PERL_ARGS_ASSERT_INVLIST_EXTEND;
- assert(SvTYPE(invlist) == SVt_INVLIST);
+ assert(is_invlist(invlist));
/* Add one to account for the zero element at the beginning which may not
* be counted by the calling parameters */
PERL_ARGS_ASSERT__INVLIST_UNION_MAYBE_COMPLEMENT_2ND;
assert(a != b);
- assert(*output == NULL || SvTYPE(*output) == SVt_INVLIST);
+ assert(*output == NULL || is_invlist(*output));
len_b = _invlist_len(b);
if (len_b == 0) {
* union. We can just return a copy of 'a' if '*output' doesn't point
* to an existing list */
if (*output == NULL) {
- *output = invlist_clone(a);
+ *output = invlist_clone(a, NULL);
return;
}
}
/* Here, '*output' is to be overwritten by 'a' */
- u = invlist_clone(a);
+ u = invlist_clone(a, NULL);
invlist_replace_list_destroys_src(*output, u);
SvREFCNT_dec_NN(u);
* the clone */
SV ** dest = (*output == NULL) ? output : &u;
- *dest = invlist_clone(b);
+ *dest = invlist_clone(b, NULL);
if (complement_b) {
_invlist_invert(*dest);
}
PERL_ARGS_ASSERT__INVLIST_INTERSECTION_MAYBE_COMPLEMENT_2ND;
assert(a != b);
- assert(*i == NULL || SvTYPE(*i) == SVt_INVLIST);
+ assert(*i == NULL || is_invlist(*i));
/* Special case if either one is empty */
len_a = (a == NULL) ? 0 : _invlist_len(a);
}
if (*i == NULL) {
- *i = invlist_clone(a);
+ *i = invlist_clone(a, NULL);
return;
}
- r = invlist_clone(a);
+ r = invlist_clone(a, NULL);
invlist_replace_list_destroys_src(*i, r);
SvREFCNT_dec_NN(r);
return;
*get_invlist_offset_addr(invlist) = ! *get_invlist_offset_addr(invlist);
}
-#endif
-
-PERL_STATIC_INLINE SV*
-S_invlist_clone(pTHX_ SV* const invlist)
+SV*
+Perl_invlist_clone(pTHX_ SV* const invlist, SV* new_invlist)
{
/* Return a new inversion list that is a copy of the input one, which is
* unchanged. The new list will not be mortal even if the old one was. */
- /* Need to allocate extra space to accommodate Perl's addition of a
- * trailing NUL to SvPV's, since it thinks they are always strings */
- SV* new_invlist = _new_invlist(_invlist_len(invlist) + 1);
- STRLEN physical_length = SvCUR(invlist);
- bool offset = *(get_invlist_offset_addr(invlist));
+ const STRLEN nominal_length = _invlist_len(invlist); /* Why not +1 XXX */
+ const STRLEN physical_length = SvCUR(invlist);
+ const bool offset = *(get_invlist_offset_addr(invlist));
PERL_ARGS_ASSERT_INVLIST_CLONE;
+ /* Need to allocate extra space to accommodate Perl's addition of a
+ * trailing NUL to SvPV's, since it thinks they are always strings */
+ if (new_invlist == NULL) {
+ new_invlist = _new_invlist(nominal_length);
+ }
+ else {
+ sv_upgrade(new_invlist, SVt_INVLIST);
+ initialize_invlist_guts(new_invlist, nominal_length);
+ }
+
*(get_invlist_offset_addr(new_invlist)) = offset;
- invlist_set_len(new_invlist, _invlist_len(invlist), offset);
+ invlist_set_len(new_invlist, nominal_length, offset);
Copy(SvPVX(invlist), SvPVX(new_invlist), physical_length, char);
return new_invlist;
}
+#endif
+
PERL_STATIC_INLINE STRLEN*
S_get_invlist_iter_addr(SV* invlist)
{
PERL_ARGS_ASSERT_GET_INVLIST_ITER_ADDR;
- assert(SvTYPE(invlist) == SVt_INVLIST);
+ assert(is_invlist(invlist));
return &(((XINVLIST*) SvANY(invlist))->iterator);
}
RExC_parse++;
is_neg = TRUE;
}
+ endptr = RExC_end;
if (grok_atoUV(RExC_parse, &unum, &endptr)
&& unum <= I32_MAX
) {
ret->flags = 1;
tail = reg(pRExC_state, 1, &flag, depth+1);
- RETURN_NULL_ON_RESTART(flag,flagp);
+ RETURN_FAIL_ON_RESTART(flag,flagp);
REGTAIL(pRExC_state, ret, tail);
goto insert_if;
}
}
else if (RExC_parse[0] >= '1' && RExC_parse[0] <= '9' ) {
UV uv;
+ endptr = RExC_end;
if (grok_atoUV(RExC_parse, &uv, &endptr)
&& uv <= I32_MAX
) {
/* (?(1)...) */
char c;
UV uv;
+ endptr = RExC_end;
if (grok_atoUV(RExC_parse, &uv, &endptr)
&& uv <= I32_MAX
) {
REGTAIL(pRExC_state, ret, reganode(pRExC_state, IFTHEN, 0));
br = regbranch(pRExC_state, &flags, 1,depth+1);
if (br == NULL) {
- RETURN_NULL_ON_RESTART(flags,flagp);
- FAIL2("panic: regbranch returned NULL, flags=%#" UVxf,
+ RETURN_FAIL_ON_RESTART(flags,flagp);
+ FAIL2("panic: regbranch returned failure, flags=%#" UVxf,
(UV) flags);
} else
REGTAIL(pRExC_state, br, reganode(pRExC_state,
lastbr = reganode(pRExC_state, IFTHEN, 0);
if (!regbranch(pRExC_state, &flags, 1,depth+1)) {
- RETURN_NULL_ON_RESTART(flags,flagp);
- FAIL2("panic: regbranch returned NULL, flags=%#" UVxf,
+ RETURN_FAIL_ON_RESTART(flags,flagp);
+ FAIL2("panic: regbranch returned failure, flags=%#" UVxf,
(UV) flags);
}
REGTAIL(pRExC_state, ret, lastbr);
/* branch_len = (paren != 0); */
if (br == NULL) {
- RETURN_NULL_ON_RESTART(flags,flagp);
- FAIL2("panic: regbranch returned NULL, flags=%#" UVxf, (UV) flags);
+ RETURN_FAIL_ON_RESTART(flags,flagp);
+ FAIL2("panic: regbranch returned failure, flags=%#" UVxf, (UV) flags);
}
if (*RExC_parse == '|') {
if (!SIZE_ONLY && RExC_extralen) {
br = regbranch(pRExC_state, &flags, 0, depth+1);
if (br == NULL) {
- RETURN_NULL_ON_RESTART(flags,flagp);
- FAIL2("panic: regbranch returned NULL, flags=%#" UVxf, (UV) flags);
+ RETURN_FAIL_ON_RESTART(flags,flagp);
+ FAIL2("panic: regbranch returned failure, flags=%#" UVxf, (UV) flags);
}
REGTAIL(pRExC_state, lastbr, br); /* BRANCH -> BRANCH. */
lastbr = br;
if (latest == NULL) {
if (flags & TRYAGAIN)
continue;
- RETURN_NULL_ON_RESTART(flags,flagp);
- FAIL2("panic: regpiece returned NULL, flags=%#" UVxf, (UV) flags);
+ RETURN_FAIL_ON_RESTART(flags,flagp);
+ FAIL2("panic: regpiece returned failure, flags=%#" UVxf, (UV) flags);
}
else if (ret == NULL)
ret = latest;
ret = regatom(pRExC_state, &flags,depth+1);
if (ret == NULL) {
- RETURN_NULL_ON_RESTART_OR_FLAGS(flags,flagp,TRYAGAIN);
- FAIL2("panic: regatom returned NULL, flags=%#" UVxf, (UV) flags);
+ RETURN_FAIL_ON_RESTART_OR_FLAGS(flags,flagp,TRYAGAIN);
+ FAIL2("panic: regatom returned failure, flags=%#" UVxf, (UV) flags);
}
op = *RExC_parse;
maxpos = next;
RExC_parse++;
if (isDIGIT(*RExC_parse)) {
+ endptr = RExC_end;
if (!grok_atoUV(RExC_parse, &uv, &endptr))
vFAIL("Invalid quantifier in {,}");
if (uv >= REG_INFTY)
else
maxpos = RExC_parse;
if (isDIGIT(*maxpos)) {
+ endptr = RExC_end;
if (!grok_atoUV(maxpos, &uv, &endptr))
vFAIL("Invalid quantifier in {,}");
if (uv >= REG_INFTY)
* *node_p, nor *code_point_p, nor *flagp.
*
* If <cp_count> is not NULL, the caller wants to know the length (in code
- * points) that this \N sequence matches. This is set even if the function
- * returns FALSE, as detailed below.
+ * points) that this \N sequence matches. This is set, and the input is
+ * parsed for errors, even if the function returns FALSE, as detailed below.
*
* There are 5 possibilities here, as detailed in the next 5 paragraphs.
*
/* Loop through the hex digits of the current code point */
do {
/* Adding this digit will shift the result 4 bits. If that
- * result would be above IV_MAX, it's overflow */
- if (cp > IV_MAX >> 4) {
+ * result would be above the legal max, it's overflow */
+ if (cp > MAX_LEGAL_CP >> 4) {
/* Find the end of the code point */
do {
* in utf8.c */
vFAIL4("Use of code point 0x%.*s is not allowed; the"
" permissible max is 0x%" UVxf,
- (int) (RExC_parse - start_digit), start_digit, IV_MAX);
+ (int) (RExC_parse - start_digit), start_digit,
+ MAX_LEGAL_CP);
}
/* Accumulate this (valid) digit into the running total */
}
/* Here, looks like its really a multiple character sequence. Fail
- * if that's not what the caller wants. */
- if (! node_p) {
-
- /* But even if failing, we count the code points if requested, and
- * don't back up up the pointer as the caller is expected to
- * handle this situation */
- if (cp_count) {
- char * dot = RExC_parse + 1;
- do {
- dot = (char *) memchr(dot, '.', endbrace - dot);
- if (! dot) {
- break;
- }
- count++;
- dot++;
- } while (dot < endbrace);
- count++;
-
- *cp_count = count;
- RExC_parse = endbrace;
- nextchar(pRExC_state);
- }
- else { /* Back up the pointer. */
- RExC_parse = p;
- }
+ * if that's not what the caller wants. But continue with counting
+ * and error checking if they still want a count */
+ if (! node_p && ! cp_count) {
return FALSE;
}
* form \x{char1}\x{char2}... and then call reg recursively to
* parse it (enclosing in "(?: ... )" ). That way, it retains its
* atomicness, while not having to worry about special handling
- * that some code points may have. */
+ * that some code points may have. We don't create a subpattern,
+ * but go through the motions of code point counting and error
+ * checking, if the caller doesn't want a node returned. */
- if (count == 1) {
+ if (node_p && count == 1) {
substitute_parse = newSVpvs("?:");
}
do_concat:
- /* Convert to notation the rest of the code understands */
- sv_catpv(substitute_parse, "\\x{");
- sv_catpvn(substitute_parse, start_digit, RExC_parse - start_digit);
- sv_catpv(substitute_parse, "}");
+ if (node_p) {
+ /* Convert to notation the rest of the code understands */
+ sv_catpvs(substitute_parse, "\\x{");
+ sv_catpvn(substitute_parse, start_digit,
+ RExC_parse - start_digit);
+ sv_catpvs(substitute_parse, "}");
+ }
/* Move to after the dot (or ending brace the final time through.)
* */
RExC_parse++;
+ count++;
} while (RExC_parse < endbrace);
- sv_catpv(substitute_parse, ")");
+ if (! node_p) { /* Doesn't want the node */
+ assert (cp_count);
+
+ *cp_count = count;
+ return FALSE;
+ }
+
+ sv_catpvs(substitute_parse, ")");
#ifdef EBCDIC
/* The values are Unicode, and therefore have to be converted to native
* constructs. This can be called from within a substitute parse already.
* The error reporting mechanism doesn't work for 2 levels of this, but the
* code above has validated this new construct, so there should be no
- * errors generated by the below.*/
+ * errors generated by the below. And this isn' an exact copy, so the
+ * mechanism to seamlessly deal with this won't work. XXX Maybe should
+ * turn off all warnings for safety? */
save_start = RExC_start;
orig_end = RExC_end;
if (! *node_p) {
RETURN_X_ON_RESTART(FALSE, flags,flagp);
- FAIL2("panic: reg returned NULL to grok_bslash_N, flags=%#" UVxf,
+ FAIL2("panic: reg returned failure to grok_bslash_N, flags=%#" UVxf,
(UV) flags);
}
*flagp |= flags&(HASWIDTH|SPSTART|SIMPLE|POSTPONED);
* in which case return I32_MAX (rather than possibly 32-bit wrapping) */
static I32
-S_backref_value(char *p)
+S_backref_value(char *p, char *e)
{
- const char* endptr;
+ const char* endptr = e;
UV val;
if (grok_atoUV(p, &val, &endptr) && val <= I32_MAX)
return (I32)val;
NULL,
NULL);
if (ret == NULL) {
- RETURN_NULL_ON_RESTART_FLAGP_OR_FLAGS(flagp,NEED_UTF8);
- FAIL2("panic: regclass returned NULL to regatom, flags=%#" UVxf,
+ RETURN_FAIL_ON_RESTART_FLAGP_OR_FLAGS(flagp,NEED_UTF8);
+ FAIL2("panic: regclass returned failure to regatom, flags=%#" UVxf,
(UV) *flagp);
}
if (*RExC_parse != ']') {
}
goto tryagain;
}
- RETURN_NULL_ON_RESTART(flags,flagp);
- FAIL2("panic: reg returned NULL to regatom, flags=%#" UVxf,
+ RETURN_FAIL_ON_RESTART(flags,flagp);
+ FAIL2("panic: reg returned failure to regatom, flags=%#" UVxf,
(UV) flags);
}
*flagp |= flags&(HASWIDTH|SPSTART|SIMPLE|POSTPONED);
TRUE, /* Allow an optimized regnode result */
NULL,
NULL);
- RETURN_NULL_ON_RESTART_FLAGP(flagp);
+ RETURN_FAIL_ON_RESTART_FLAGP(flagp);
/* regclass() can only return RESTART_PASS1 and NEED_UTF8 if
* multi-char folds are allowed. */
if (!ret)
- FAIL2("panic: regclass returned NULL to regatom, flags=%#" UVxf,
+ FAIL2("panic: regclass returned failure to regatom, flags=%#" UVxf,
(UV) *flagp);
RExC_parse--;
break;
}
- RETURN_NULL_ON_RESTART_FLAGP(flagp);
+ RETURN_FAIL_ON_RESTART_FLAGP(flagp);
/* Here, evaluates to a single code point. Go get that */
RExC_parse = parse_start;
if (RExC_parse >= RExC_end) {
goto unterminated_g;
}
- num = S_backref_value(RExC_parse);
+ num = S_backref_value(RExC_parse, RExC_end);
if (num == 0)
vFAIL("Reference to invalid group 0");
else if (num == I32_MAX) {
}
}
else {
- num = S_backref_value(RExC_parse);
+ num = S_backref_value(RExC_parse, RExC_end);
/* bare \NNN might be backref or octal - if it is larger
* than or equal RExC_npar then it is assumed to be an
* octal escape. Note RExC_npar is +1 from the actual
* need to figure this out until pass 2) */
bool maybe_exactfu = PASS2;
+ /* To see if RExC_uni_semantics changes during parsing of the node.
+ * */
+ bool uni_semantics_at_node_start;
+
/* The node_type may change below, but since the size of the node
* doesn't change, it works */
ret = reg_node(pRExC_state, node_type);
|| UTF8_IS_INVARIANT(UCHARAT(RExC_parse))
|| UTF8_IS_START(UCHARAT(RExC_parse)));
+ uni_semantics_at_node_start = cBOOL(RExC_uni_semantics);
+
/* Here, we have a literal character. Find the maximal string of
* them in the input that we can fit into a single EXACTish node.
* We quit at the first non-literal or when the node gets full, or
) {
if (*flagp & NEED_UTF8)
FAIL("panic: grok_bslash_N set NEED_UTF8");
- RETURN_NULL_ON_RESTART_FLAGP(flagp);
+ RETURN_FAIL_ON_RESTART_FLAGP(flagp);
/* Here, it wasn't a single code point. Go close
* up this EXACTish node. The switch() prior to
/* NOTE, RExC_npar is 1 more than the actual number of
* parens we have seen so far, hence the < RExC_npar below. */
- if ( !isDIGIT(p[1]) || S_backref_value(p) < RExC_npar)
+ if ( !isDIGIT(p[1]) || S_backref_value(p, RExC_end) < RExC_npar)
{ /* Not to be treated as an octal constant, go
find backref */
--p;
} /* End of switch on '\' */
break;
case '{':
- /* Currently we allow an lbrace at the start of a construct
- * without raising a warning. This is because we think we
- * will never want such a brace to be meant to be other
- * than taken literally. */
+ /* Trying to gain new uses for '{' without breaking too
+ * much existing code is hard. The solution currently
+ * adopted is:
+ * 1) If there is no ambiguity that a '{' should always
+ * be taken literally, at the start of a construct, we
+ * just do so.
+ * 2) If the literal '{' conflicts with our desired use
+ * of it as a metacharacter, we die. The deprecation
+ * cycles for this have come and gone.
+ * 3) If there is ambiguity, we raise a simple warning.
+ * This could happen, for example, if the user
+ * intended it to introduce a quantifier, but slightly
+ * misspelled the quantifier. Without this warning,
+ * the quantifier would silently be taken as a literal
+ * string of characters instead of a meta construct */
if (len || (p > RExC_start && isALPHA_A(*(p - 1)))) {
-
- /* But, we raise a fatal warning otherwise, as the
- * deprecation cycle has come and gone. Except that it
- * turns out that some heavily-relied on upstream
- * software, notably GNU Autoconf, have failed to fix
- * their uses. For these, don't make it fatal unless
- * we anticipate using the '{' for something else.
- * This happens after any alpha, and for a looser {m,n}
- * quantifier specification */
if ( RExC_strict
|| ( p > parse_start + 1
&& isALPHA_A(*(p - 1))
"illegal here");
}
if (PASS2) {
- ckWARNregdep(p + 1,
- "Unescaped left brace in regex is "
- "deprecated here (and will be fatal "
- "in Perl 5.30), passed through");
+ ckWARNreg(p + 1, "Unescaped left brace in regex is"
+ " passed through");
}
}
goto normal_default;
ender = 's';
added_len = 2;
}
+ else if ( uni_semantics_at_node_start
+ != RExC_uni_semantics)
+ {
+ /* Here, we are supossed to be using Unicode
+ * rules, but this folding node is not. This
+ * happens during pass 1 when the node started
+ * out not under Unicode rules, but a \N{} was
+ * encountered during the processing of it,
+ * causing Unicode rules to be switched into.
+ * Pass 1 continues uninterrupted, as by the
+ * time we get to pass 2, we will know enough
+ * to generate the correct folds. Except in
+ * this one case, we need to restart the node,
+ * because the fold of the sharp s requires 2
+ * characters, and the sizing needs to account
+ * for that. */
+ p = oldp;
+ goto loopdone;
+ }
else {
RExC_seen_unfolded_sharp_s = 1;
maybe_exactfu = FALSE;
/* Position parse to next real character */
skip_to_be_ignored_text(pRExC_state, &RExC_parse,
FALSE /* Don't force to /x */ );
- if (PASS2 && *RExC_parse == '{' && OP(ret) != SBOL && ! regcurly(RExC_parse)) {
- ckWARNregdep(RExC_parse + 1, "Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.30), passed through");
+ if ( PASS2 && *RExC_parse == '{'
+ && OP(ret) != SBOL && ! regcurly(RExC_parse))
+ {
+ if (RExC_strict || new_regcurly(RExC_parse, RExC_end)) {
+ RExC_parse++;
+ vFAIL("Unescaped left brace in regex is illegal here");
+ }
+ ckWARNreg(RExC_parse + 1, "Unescaped left brace in regex is"
+ " passed through");
}
return(ret);
¤t,
&posix_warnings
))
- FAIL2("panic: regclass returned NULL to handle_sets, "
+ FAIL2("panic: regclass returned failure to handle_sets, "
"flags=%#" UVxf, (UV) *flagp);
/* function call leaves parse pointing to the ']', except
¤t,
NULL))
{
- FAIL2("panic: regclass returned NULL to handle_sets, "
+ FAIL2("panic: regclass returned failure to handle_sets, "
"flags=%#" UVxf, (UV) *flagp);
}
NULL
))
{
- FAIL2("panic: regclass returned NULL to handle_sets, "
+ FAIL2("panic: regclass returned failure to handle_sets, "
"flags=%#" UVxf, (UV) *flagp);
}
if (av_tindex_skip_len_mg(stack) < 0 /* Was empty */
|| ((final = av_pop(stack)) == NULL)
|| ! IS_OPERAND(final)
- || SvTYPE(final) != SVt_INVLIST
+ || ! is_invlist(final)
|| av_tindex_skip_len_mg(stack) >= 0) /* More left on stack */
{
bad_syntax:
NULL
);
if (!node)
- FAIL2("panic: regclass returned NULL to handle_sets, flags=%#" UVxf,
+ FAIL2("panic: regclass returned failure to handle_sets, flags=%#" UVxf,
PTR2UV(flagp));
/* Fix up the node type if we are in locale. (We have pretended we are
if (*flagp & NEED_UTF8)
FAIL("panic: grok_bslash_N set NEED_UTF8");
- RETURN_NULL_ON_RESTART_FLAGP(flagp);
+ RETURN_FAIL_ON_RESTART_FLAGP(flagp);
if (cp_count < 0) {
vFAIL("\\N in a character class must be a named character: \\N{...}");
* anyway, to save a little time */
|_CORE_SWASH_INIT_ACCEPT_INVLIST;
+ SvREFCNT_dec(swash); /* Free any left-overs */
if (RExC_parse >= RExC_end)
vFAIL2("Empty \\%c", (U8)value);
if (*RExC_parse == '{') {
}
RExC_parse++;
+
+ /* White space is allowed adjacent to the braces and after
+ * any '^', even when not under /x */
while (isSPACE(*RExC_parse)) {
RExC_parse++;
}
while (isSPACE(*(RExC_parse + n - 1)))
n--;
- for (i = RExC_parse; i < RExC_parse + n; i++) {
- if (isCNTRL(*i) && *i != '\t') {
- char * name = Perl_form(aTHX_ "%.*s", (int)n, RExC_parse);
- RExC_parse = e + 1;
- vFAIL2("Can't find Unicode property definition \"%s\"", name);
- }
- }
} /* The \p isn't immediately followed by a '{' */
else if (! isALPHA(*RExC_parse)) {
RExC_parse += (UTF) ? UTF8SKIP(RExC_parse) : 1;
n = 1;
}
if (!SIZE_ONLY) {
- SV* invlist;
- char* name;
+ char* name = RExC_parse;
char* base_name; /* name after any packages are stripped */
char* lookup_name = NULL;
const char * const colon_colon = "::";
+ bool invert;
+
+ SV* invlist;
+
+ /* Temporary workaround for [perl #133136]. For this
+ * precise input that is in the .t that is failing, load
+ * utf8.pm, which is what the test wants, so that that
+ * .t passes */
+ if ( memEQs(RExC_start, e + 1 - RExC_start,
+ "foo\\p{Alnum}")
+ && ! hv_common(GvHVn(PL_incgv),
+ NULL,
+ "utf8.pm", sizeof("utf8.pm") - 1,
+ 0, HV_FETCH_ISEXISTS, NULL, 0))
+ {
+ require_pv("utf8.pm");
+ }
+ invlist = parse_uniprop_string(name, n, FOLD, &invert);
+ if (invlist) {
+ if (invert) {
+ value ^= 'P' ^ 'p';
+ }
+ }
+ else {
/* Try to get the definition of the property into
* <invlist>. If /i is in effect, the effective property
* 2f833f5208e26b208886e51e09e2c072b5eabb46 */
name = savepv(Perl_form(aTHX_ "%.*s", (int)n, RExC_parse));
SAVEFREEPV(name);
+
+ for (i = RExC_parse; i < RExC_parse + n; i++) {
+ if (isCNTRL(*i) && *i != '\t') {
+ RExC_parse = e + 1;
+ vFAIL2("Can't find Unicode property definition \"%s\"", name);
+ }
+ }
+
if (FOLD) {
lookup_name = savepv(Perl_form(aTHX_ "__%s_i", name));
/* Look up the property name, and get its swash and
* inversion list, if the property is found */
- SvREFCNT_dec(swash); /* Free any left-overs */
swash = _core_swash_init("utf8",
(lookup_name)
? lookup_name
{
has_user_defined_property = TRUE;
}
- else if
+ }
+ }
+ if (invlist) {
+ if (! has_user_defined_property &&
/* We warn on matching an above-Unicode code point
* if the match would return true, except don't
* warn for \p{All}, which has exactly one element
* = 0 */
(_invlist_contains_cp(invlist, 0x110000)
&& (! (_invlist_len(invlist) == 1
- && *invlist_array(invlist) == 0)))
+ && *invlist_array(invlist) == 0))))
{
warn_super = TRUE;
}
-
/* Invert if asking for the complement */
if (value == 'P') {
_invlist_union_complement_2nd(properties,
/* The swash can't be used as-is, because we've
* inverted things; delay removing it to here after
* have copied its invlist above */
- SvREFCNT_dec_NN(swash);
+ if (! swash) {
+ SvREFCNT_dec_NN(invlist);
+ }
+ SvREFCNT_dec(swash);
swash = NULL;
}
else {
_invlist_union(properties, invlist, &properties);
+ if (! swash) {
+ SvREFCNT_dec_NN(invlist);
+ }
}
- }
- }
+ }
+ } /* End of actually getting the values in pass 2 */
+
RExC_parse = e + 1;
namedclass = ANYOF_UNIPROP; /* no official name, but it's
named */
}
}
else if ( UNI_SEMANTICS
+ || AT_LEAST_ASCII_RESTRICTED
|| classnum == _CC_ASCII
|| (DEPENDS_SEMANTICS && ( classnum == _CC_DIGIT
|| classnum == _CC_XDIGIT)))
{
- /* We usually have to worry about /d and /a affecting what
- * POSIX classes match, with special code needed for /d
- * because we won't know until runtime what all matches.
- * But there is no extra work needed under /u, and
- * [:ascii:] is unaffected by /a and /d; and :digit: and
- * :xdigit: don't have runtime differences under /d. So we
- * can special case these, and avoid some extra work below,
- * and at runtime. */
+ /* We usually have to worry about /d a affecting what POSIX
+ * classes match, with special code needed because we won't
+ * know until runtime what all matches. But there is no
+ * extra work needed under /u and /a; and [:ascii:] is
+ * unaffected by /d; and :digit: and :xdigit: don't have
+ * runtime differences under /d. So we can special case
+ * these, and avoid some extra work below, and at runtime.
+ * */
_invlist_union_maybe_complement_2nd(
simple_posixes,
- PL_XPosix_ptrs[classnum],
+ ((AT_LEAST_ASCII_RESTRICTED)
+ ? PL_Posix_ptrs[classnum]
+ : PL_XPosix_ptrs[classnum]),
namedclass % 2 != 0,
&simple_posixes);
}
char *save_end = RExC_end;
char *save_parse = RExC_parse;
char *save_start = RExC_start;
- STRLEN prefix_end = 0; /* We copy the character class after a
- prefix supplied here. This is the size
- + 1 of that prefix */
+ Size_t constructed_prefix_len = 0; /* This gives the length of the
+ constructed portion of the
+ substitute parse. */
bool first_time = TRUE; /* First multi-char occurrence doesn't get
a "|" */
I32 reg_flags;
assert(! invert);
- assert(RExC_precomp_adj == 0); /* Only one level of recursion allowed */
+ /* Only one level of recursion allowed */
+ assert(RExC_copy_start_in_constructed == RExC_precomp);
#if 0 /* Have decided not to deal with multi-char folds in inverted classes,
because too confusing */
if (invert) {
- sv_catpv(substitute_parse, "(?:");
+ sv_catpvs(substitute_parse, "(?:");
}
#endif
&PL_sv_undef)
{
if (! first_time) {
- sv_catpv(substitute_parse, "|");
+ sv_catpvs(substitute_parse, "|");
}
first_time = FALSE;
/* If the character class contains anything else besides these
* multi-character folds, have to include it in recursive parsing */
if (element_count) {
- sv_catpv(substitute_parse, "|[");
- prefix_end = SvCUR(substitute_parse);
+ sv_catpvs(substitute_parse, "|[");
+ constructed_prefix_len = SvCUR(substitute_parse);
sv_catpvn(substitute_parse, orig_parse, RExC_parse - orig_parse);
/* Put in a closing ']' only if not going off the end, as otherwise
* we are adding something that really isn't there */
if (RExC_parse < RExC_end) {
- sv_catpv(substitute_parse, "]");
+ sv_catpvs(substitute_parse, "]");
}
}
- sv_catpv(substitute_parse, ")");
+ sv_catpvs(substitute_parse, ")");
#if 0
if (invert) {
/* This is a way to get the parse to skip forward a whole named
* sequence instead of matching the 2nd character when it fails the
* first */
- sv_catpv(substitute_parse, "(*THEN)(*SKIP)(*FAIL)|.)");
+ sv_catpvs(substitute_parse, "(*THEN)(*SKIP)(*FAIL)|.)");
}
#endif
/* Set up the data structure so that any errors will be properly
* reported. See the comments at the definition of
* REPORT_LOCATION_ARGS for details */
- RExC_precomp_adj = orig_parse - RExC_precomp;
- RExC_start = RExC_parse = SvPV(substitute_parse, len);
- RExC_adjusted_start = RExC_start + prefix_end;
+ RExC_copy_start_in_input = (char *) orig_parse;
+ RExC_start = RExC_parse = SvPV(substitute_parse, len);
+ RExC_copy_start_in_constructed = RExC_start + constructed_prefix_len;
RExC_end = RExC_parse + len;
RExC_in_multi_char_class = 1;
RExC_emit = (regnode *)orig_emit;
/* And restore so can parse the rest of the pattern */
RExC_parse = save_parse;
- RExC_start = RExC_adjusted_start = save_start;
- RExC_precomp_adj = 0;
+ RExC_start = RExC_copy_start_in_constructed = RExC_copy_start_in_input = save_start;
RExC_end = save_end;
RExC_in_multi_char_class = 0;
SvREFCNT_dec_NN(multi_char_matches);
}
}
if (posixes || nposixes) {
-
- /* We have to adjust /a and /aa */
- if (AT_LEAST_ASCII_RESTRICTED) {
-
- /* Under /a and /aa, nothing above ASCII matches these */
- if (posixes) {
- _invlist_intersection(posixes,
- PL_XPosix_ptrs[_CC_ASCII],
- &posixes);
- }
-
- /* Under /a and /aa, everything above ASCII matches these
- * complements */
- if (nposixes) {
- _invlist_union_complement_2nd(nposixes,
- PL_XPosix_ptrs[_CC_ASCII],
- &nposixes);
- }
- }
-
if (! DEPENDS_SEMANTICS) {
/* For everything but /d, we can just add the current 'posixes' and
*
* Handle the case where there something like \W separately */
if (nposixes) {
- SV* only_non_utf8_list = invlist_clone(PL_UpperLatin1);
+ SV* only_non_utf8_list = invlist_clone(PL_UpperLatin1, NULL);
/* A complemented posix class matches all upper Latin1
* characters if not in UTF-8. And it matches just certain
));
}
else if (! *output_invlist) {
- *output_invlist = invlist_clone(invlist);
+ *output_invlist = invlist_clone(invlist, NULL);
}
else {
_invlist_union(*output_invlist, invlist, output_invlist);
if (RExC_offsets) { /* MJD 20010112 */
MJD_OFFSET_DEBUG(
("%s(%d): (op %s) %s copy %" UVuf " -> %" UVuf " (max %" UVuf ").\n",
- "reg_insert",
+ "reginsert",
__LINE__,
PL_reg_name[op],
(UV)(dst - RExC_emit_start) > RExC_offsets[0]
#endif
src = NEXTOPER(place);
place->flags = 0;
- FILL_ADVANCE_NODE(place, op);
+ FILL_NODE(place, op);
Zero(src, offset, regnode);
}
U8 index = FLAGS(o) * 2;
if (index < C_ARRAY_LENGTH(anyofs)) {
if (*anyofs[index] != '[') {
- sv_catpv(sv, "[");
+ sv_catpvs(sv, "[");
}
sv_catpv(sv, anyofs[index]);
if (*anyofs[index] != '[') {
- sv_catpv(sv, "]");
+ sv_catpvs(sv, "]");
}
}
else {
* don't change the caller's list) */
if (nonbitmap_invlist) {
assert(invlist_highest(nonbitmap_invlist) < NUM_ANYOF_CODE_POINTS);
- invlist = invlist_clone(nonbitmap_invlist);
+ invlist = invlist_clone(nonbitmap_invlist, NULL);
}
else { /* Worst case size is every other code point is matched */
invlist = _new_invlist(NUM_ANYOF_CODE_POINTS / 2);
/* And this flag for matching all non-ASCII 0xFF and below */
if (flags & ANYOF_SHARED_d_MATCHES_ALL_NON_UTF8_NON_ASCII_non_d_WARN_SUPER)
{
- not_utf8 = invlist_clone(PL_UpperLatin1);
+ not_utf8 = invlist_clone(PL_UpperLatin1, NULL);
}
}
else if (OP(node) == ANYOFL) {
/* Since this list is passed in, we have to make a copy before
* modifying it */
- only_utf8_locale = invlist_clone(only_utf8_locale_invlist);
+ only_utf8_locale = invlist_clone(only_utf8_locale_invlist, NULL);
_invlist_subtract(only_utf8_locale, invlist, &only_utf8_locale);
#endif /* DEBUGGING */
+#ifndef PERL_IN_XSUB_RE
+
+#include "uni_keywords.h"
+
+void
+Perl_init_uniprops(pTHX)
+{
+ /* Set up the inversion list global variables */
+
+ PL_XPosix_ptrs[_CC_ASCII] = _new_invlist_C_array(uni_prop_ptrs[UNI_ASCII]);
+ PL_XPosix_ptrs[_CC_ALPHANUMERIC] = _new_invlist_C_array(uni_prop_ptrs[UNI_XPOSIXALNUM]);
+ PL_XPosix_ptrs[_CC_ALPHA] = _new_invlist_C_array(uni_prop_ptrs[UNI_XPOSIXALPHA]);
+ PL_XPosix_ptrs[_CC_BLANK] = _new_invlist_C_array(uni_prop_ptrs[UNI_XPOSIXBLANK]);
+ PL_XPosix_ptrs[_CC_CASED] = _new_invlist_C_array(uni_prop_ptrs[UNI_CASED]);
+ PL_XPosix_ptrs[_CC_CNTRL] = _new_invlist_C_array(uni_prop_ptrs[UNI_XPOSIXCNTRL]);
+ PL_XPosix_ptrs[_CC_DIGIT] = _new_invlist_C_array(uni_prop_ptrs[UNI_XPOSIXDIGIT]);
+ PL_XPosix_ptrs[_CC_GRAPH] = _new_invlist_C_array(uni_prop_ptrs[UNI_XPOSIXGRAPH]);
+ PL_XPosix_ptrs[_CC_LOWER] = _new_invlist_C_array(uni_prop_ptrs[UNI_XPOSIXLOWER]);
+ PL_XPosix_ptrs[_CC_PRINT] = _new_invlist_C_array(uni_prop_ptrs[UNI_XPOSIXPRINT]);
+ PL_XPosix_ptrs[_CC_PUNCT] = _new_invlist_C_array(uni_prop_ptrs[UNI_XPOSIXPUNCT]);
+ PL_XPosix_ptrs[_CC_SPACE] = _new_invlist_C_array(uni_prop_ptrs[UNI_XPOSIXSPACE]);
+ PL_XPosix_ptrs[_CC_UPPER] = _new_invlist_C_array(uni_prop_ptrs[UNI_XPOSIXUPPER]);
+ PL_XPosix_ptrs[_CC_VERTSPACE] = _new_invlist_C_array(uni_prop_ptrs[UNI_VERTSPACE]);
+ PL_XPosix_ptrs[_CC_WORDCHAR] = _new_invlist_C_array(uni_prop_ptrs[UNI_XPOSIXWORD]);
+ PL_XPosix_ptrs[_CC_XDIGIT] = _new_invlist_C_array(uni_prop_ptrs[UNI_XPOSIXXDIGIT]);
+
+ PL_Posix_ptrs[_CC_ASCII] = _new_invlist_C_array(uni_prop_ptrs[UNI_ASCII]);
+ PL_Posix_ptrs[_CC_ALPHANUMERIC] = _new_invlist_C_array(uni_prop_ptrs[UNI_POSIXALNUM]);
+ PL_Posix_ptrs[_CC_ALPHA] = _new_invlist_C_array(uni_prop_ptrs[UNI_POSIXALPHA]);
+ PL_Posix_ptrs[_CC_BLANK] = _new_invlist_C_array(uni_prop_ptrs[UNI_POSIXBLANK]);
+ PL_Posix_ptrs[_CC_CASED] = PL_Posix_ptrs[_CC_ALPHA];
+ PL_Posix_ptrs[_CC_CNTRL] = _new_invlist_C_array(uni_prop_ptrs[UNI_POSIXCNTRL]);
+ PL_Posix_ptrs[_CC_DIGIT] = _new_invlist_C_array(uni_prop_ptrs[UNI_POSIXDIGIT]);
+ PL_Posix_ptrs[_CC_GRAPH] = _new_invlist_C_array(uni_prop_ptrs[UNI_POSIXGRAPH]);
+ PL_Posix_ptrs[_CC_LOWER] = _new_invlist_C_array(uni_prop_ptrs[UNI_POSIXLOWER]);
+ PL_Posix_ptrs[_CC_PRINT] = _new_invlist_C_array(uni_prop_ptrs[UNI_POSIXPRINT]);
+ PL_Posix_ptrs[_CC_PUNCT] = _new_invlist_C_array(uni_prop_ptrs[UNI_POSIXPUNCT]);
+ PL_Posix_ptrs[_CC_SPACE] = _new_invlist_C_array(uni_prop_ptrs[UNI_POSIXSPACE]);
+ PL_Posix_ptrs[_CC_UPPER] = _new_invlist_C_array(uni_prop_ptrs[UNI_POSIXUPPER]);
+ PL_Posix_ptrs[_CC_VERTSPACE] = NULL;
+ PL_Posix_ptrs[_CC_WORDCHAR] = _new_invlist_C_array(uni_prop_ptrs[UNI_POSIXWORD]);
+ PL_Posix_ptrs[_CC_XDIGIT] = _new_invlist_C_array(uni_prop_ptrs[UNI_POSIXXDIGIT]);
+
+ PL_GCB_invlist = _new_invlist_C_array(_Perl_GCB_invlist);
+ PL_SB_invlist = _new_invlist_C_array(_Perl_SB_invlist);
+ PL_WB_invlist = _new_invlist_C_array(_Perl_WB_invlist);
+ PL_LB_invlist = _new_invlist_C_array(_Perl_LB_invlist);
+ PL_SCX_invlist = _new_invlist_C_array(_Perl_SCX_invlist);
+
+ PL_AboveLatin1 = _new_invlist_C_array(AboveLatin1_invlist);
+ PL_Latin1 = _new_invlist_C_array(Latin1_invlist);
+ PL_UpperLatin1 = _new_invlist_C_array(UpperLatin1_invlist);
+
+ PL_Assigned_invlist = _new_invlist_C_array(uni_prop_ptrs[UNI_ASSIGNED]);
+
+ PL_utf8_perl_idstart = _new_invlist_C_array(uni_prop_ptrs[UNI__PERL_IDSTART]);
+ PL_utf8_perl_idcont = _new_invlist_C_array(uni_prop_ptrs[UNI__PERL_IDCONT]);
+
+ PL_utf8_charname_begin = _new_invlist_C_array(uni_prop_ptrs[UNI__PERL_CHARNAME_BEGIN]);
+ PL_utf8_charname_continue = _new_invlist_C_array(uni_prop_ptrs[UNI__PERL_CHARNAME_CONTINUE]);
+
+ PL_utf8_foldable = _new_invlist_C_array(uni_prop_ptrs[UNI__PERL_ANY_FOLDS]);
+ PL_HasMultiCharFold = _new_invlist_C_array(uni_prop_ptrs[
+ UNI__PERL_FOLDS_TO_MULTI_CHAR]);
+ PL_NonL1NonFinalFold = _new_invlist_C_array(
+ NonL1_Perl_Non_Final_Folds_invlist);
+
+ PL_utf8_toupper = _new_invlist_C_array(Uppercase_Mapping_invlist);
+ PL_utf8_tolower = _new_invlist_C_array(Lowercase_Mapping_invlist);
+ PL_utf8_totitle = _new_invlist_C_array(Titlecase_Mapping_invlist);
+ PL_utf8_tofold = _new_invlist_C_array(Case_Folding_invlist);
+ PL_utf8_tosimplefold = _new_invlist_C_array(Simple_Case_Folding_invlist);
+ PL_utf8_foldclosures = _new_invlist_C_array(_Perl_IVCF_invlist);
+ PL_utf8_mark = _new_invlist_C_array(uni_prop_ptrs[UNI_M]);
+
+ /* The below are used only by deprecated functions. They could be removed */
+ PL_utf8_xidcont = _new_invlist_C_array(uni_prop_ptrs[UNI_XIDC]);
+ PL_utf8_idcont = _new_invlist_C_array(uni_prop_ptrs[UNI_IDC]);
+ PL_utf8_xidstart = _new_invlist_C_array(uni_prop_ptrs[UNI_XIDS]);
+}
+
+SV *
+Perl_parse_uniprop_string(pTHX_ const char * const name, const Size_t name_len,
+ const bool to_fold, bool * invert)
+{
+ /* Parse the interior meat of \p{} passed to this in 'name' with length
+ * 'name_len', and return an inversion list if a property with 'name' is
+ * found, or NULL if not. 'name' point to the input with leading and
+ * trailing space trimmed. 'to_fold' indicates if /i is in effect.
+ *
+ * When the return is an inversion list, '*invert' will be set to a boolean
+ * indicating if it should be inverted or not
+ *
+ * This currently doesn't handle all cases. A NULL return indicates the
+ * caller should try a different approach
+ */
+
+ char* lookup_name;
+ bool stricter = FALSE;
+ bool is_nv_type = FALSE; /* nv= or numeric_value=, or possibly one
+ of the cjk numeric properties (though
+ it requires extra effort to compile
+ them) */
+ unsigned int i;
+ unsigned int j = 0, lookup_len;
+ int equals_pos = -1; /* Where the '=' is found, or negative if none */
+ int slash_pos = -1; /* Where the '/' is found, or negative if none */
+ int table_index = 0;
+ bool starts_with_In_or_Is = FALSE;
+ Size_t lookup_offset = 0;
+
+ PERL_ARGS_ASSERT_PARSE_UNIPROP_STRING;
+
+ /* The input will be modified into 'lookup_name' */
+ Newx(lookup_name, name_len, char);
+ SAVEFREEPV(lookup_name);
+
+ /* Parse the input. */
+ for (i = 0; i < name_len; i++) {
+ char cur = name[i];
+
+ /* These characters can be freely ignored in most situations. Later it
+ * may turn out we shouldn't have ignored them, and we have to reparse,
+ * but we don't have enough information yet to make that decision */
+ if (cur == '-' || cur == '_' || isSPACE_A(cur)) {
+ continue;
+ }
+
+ /* Case differences are also ignored. Our lookup routine assumes
+ * everything is lowercase */
+ if (isUPPER_A(cur)) {
+ lookup_name[j++] = toLOWER(cur);
+ continue;
+ }
+
+ /* A double colon is either an error, or a package qualifier to a
+ * subroutine user-defined property; neither of which do we currently
+ * handle
+ *
+ * But a single colon is a synonym for '=' */
+ if (cur == ':') {
+ if (i < name_len - 1 && name[i+1] == ':') {
+ return NULL;
+ }
+ cur = '=';
+ }
+
+ /* Otherwise, this character is part of the name. */
+ lookup_name[j++] = cur;
+
+ /* Only the equals sign needs further processing */
+ if (cur == '=') {
+ equals_pos = j; /* Note where it occurred in the input */
+ break;
+ }
+ }
+
+ /* Here, we are either done with the whole property name, if it was simple;
+ * or are positioned just after the '=' if it is compound. */
+
+ if (equals_pos >= 0) {
+ assert(! stricter); /* We shouldn't have set this yet */
+
+ /* Space immediately after the '=' is ignored */
+ i++;
+ for (; i < name_len; i++) {
+ if (! isSPACE_A(name[i])) {
+ break;
+ }
+ }
+
+ /* Certain properties need special handling. They may optionally be
+ * prefixed by 'is'. Ignore that prefix for the purposes of checking
+ * if this is one of those properties */
+ if (memBEGINPs(lookup_name, name_len, "is")) {
+ lookup_offset = 2;
+ }
+
+ /* Then check if it is one of these properties. This is hard-coded
+ * because easier this way, and the list is unlikely to change. There
+ * are several properties like this in the Unihan DB, which is unlikely
+ * to be compiled, and they all end with 'numeric'. The interiors
+ * aren't checked for the precise property. This would stop working if
+ * a cjk property were to be created that ended with 'numeric' and
+ * wasn't a numeric type */
+ is_nv_type = memEQs(lookup_name + lookup_offset,
+ j - 1 - lookup_offset, "numericvalue")
+ || memEQs(lookup_name + lookup_offset,
+ j - 1 - lookup_offset, "nv")
+ || ( memENDPs(lookup_name + lookup_offset,
+ j - 1 - lookup_offset, "numeric")
+ && ( memBEGINPs(lookup_name + lookup_offset,
+ j - 1 - lookup_offset, "cjk")
+ || memBEGINPs(lookup_name + lookup_offset,
+ j - 1 - lookup_offset, "k")));
+ if ( is_nv_type
+ || memEQs(lookup_name + lookup_offset,
+ j - 1 - lookup_offset, "canonicalcombiningclass")
+ || memEQs(lookup_name + lookup_offset,
+ j - 1 - lookup_offset, "ccc")
+ || memEQs(lookup_name + lookup_offset,
+ j - 1 - lookup_offset, "age")
+ || memEQs(lookup_name + lookup_offset,
+ j - 1 - lookup_offset, "in")
+ || memEQs(lookup_name + lookup_offset,
+ j - 1 - lookup_offset, "presentin"))
+ {
+ unsigned int k;
+
+ /* What makes these properties special is that the stuff after the
+ * '=' is a number. Therefore, we can't throw away '-'
+ * willy-nilly, as those could be a minus sign. Other stricter
+ * rules also apply. However, these properties all can have the
+ * rhs not be a number, in which case they contain at least one
+ * alphabetic. In those cases, the stricter rules don't apply.
+ * But the numeric type properties can have the alphas [Ee] to
+ * signify an exponent, and it is still a number with stricter
+ * rules. So look for an alpha that signifys not-strict */
+ stricter = TRUE;
+ for (k = i; k < name_len; k++) {
+ if ( isALPHA_A(name[k])
+ && (! is_nv_type || ! isALPHA_FOLD_EQ(name[k], 'E')))
+ {
+ stricter = FALSE;
+ break;
+ }
+ }
+ }
+
+ if (stricter) {
+
+ /* A number may have a leading '+' or '-'. The latter is retained
+ * */
+ if (name[i] == '+') {
+ i++;
+ }
+ else if (name[i] == '-') {
+ lookup_name[j++] = '-';
+ i++;
+ }
+
+ /* Skip leading zeros including single underscores separating the
+ * zeros, or between the final leading zero and the first other
+ * digit */
+ for (; i < name_len - 1; i++) {
+ if ( name[i] != '0'
+ && (name[i] != '_' || ! isDIGIT_A(name[i+1])))
+ {
+ break;
+ }
+ }
+ }
+ }
+ else { /* No '=' */
+
+ /* We are now in a position to determine if this property should have
+ * been parsed using stricter rules. Only a few are like that, and
+ * unlikely to change. */
+ if ( memBEGINPs(lookup_name, j, "perl")
+ && memNEs(lookup_name + 4, j - 4, "space")
+ && memNEs(lookup_name + 4, j - 4, "word"))
+ {
+ stricter = TRUE;
+
+ /* We set the inputs back to 0 and the code below will reparse,
+ * using strict */
+ i = j = 0;
+ }
+ }
+
+ /* Here, we have either finished the property, or are positioned to parse
+ * the remainder, and we know if stricter rules apply. Finish out, if not
+ * already done */
+ for (; i < name_len; i++) {
+ char cur = name[i];
+
+ /* In all instances, case differences are ignored, and we normalize to
+ * lowercase */
+ if (isUPPER_A(cur)) {
+ lookup_name[j++] = toLOWER(cur);
+ continue;
+ }
+
+ /* An underscore is skipped, but not under strict rules unless it
+ * separates two digits */
+ if (cur == '_') {
+ if ( stricter
+ && ( i == 0 || (int) i == equals_pos || i == name_len- 1
+ || ! isDIGIT_A(name[i-1]) || ! isDIGIT_A(name[i+1])))
+ {
+ lookup_name[j++] = '_';
+ }
+ continue;
+ }
+
+ /* Hyphens are skipped except under strict */
+ if (cur == '-' && ! stricter) {
+ continue;
+ }
+
+ /* XXX Bug in documentation. It says white space skipped adjacent to
+ * non-word char. Maybe we should, but shouldn't skip it next to a dot
+ * in a number */
+ if (isSPACE_A(cur) && ! stricter) {
+ continue;
+ }
+
+ lookup_name[j++] = cur;
+
+ /* Unless this is a non-trailing slash, we are done with it */
+ if (i >= name_len - 1 || cur != '/') {
+ continue;
+ }
+
+ slash_pos = j;
+
+ /* A slash in the 'numeric value' property indicates that what follows
+ * is a denominator. It can have a leading '+' and '0's that should be
+ * skipped. But we have never allowed a negative denominator, so treat
+ * a minus like every other character. (No need to rule out a second
+ * '/', as that won't match anything anyway */
+ if (is_nv_type) {
+ i++;
+ if (i < name_len && name[i] == '+') {
+ i++;
+ }
+
+ /* Skip leading zeros including underscores separating digits */
+ for (; i < name_len - 1; i++) {
+ if ( name[i] != '0'
+ && (name[i] != '_' || ! isDIGIT_A(name[i+1])))
+ {
+ break;
+ }
+ }
+
+ /* Store the first real character in the denominator */
+ lookup_name[j++] = name[i];
+ }
+ }
+
+ /* Here are completely done parsing the input 'name', and 'lookup_name'
+ * contains a copy, normalized.
+ *
+ * This special case is grandfathered in: 'L_' and 'GC=L_' are accepted and
+ * different from without the underscores. */
+ if ( ( UNLIKELY(memEQs(lookup_name, j, "l"))
+ || UNLIKELY(memEQs(lookup_name, j, "gc=l")))
+ && UNLIKELY(name[name_len-1] == '_'))
+ {
+ lookup_name[j++] = '&';
+ }
+ else if (name_len > 2 && name[0] == 'I' && ( name[1] == 'n'
+ || name[1] == 's'))
+ {
+
+ /* Also, if the original input began with 'In' or 'Is', it could be a
+ * subroutine call instead of a property names, which currently isn't
+ * handled by this function. Subroutine calls can't happen if there is
+ * an '=' in the name */
+ if (equals_pos < 0 && get_cvn_flags(name, name_len, GV_NOTQUAL) != NULL)
+ {
+ return NULL;
+ }
+
+ starts_with_In_or_Is = TRUE;
+ }
+
+ lookup_len = j; /* Use a more mnemonic name starting here */
+
+ /* Get the index into our pointer table of the inversion list corresponding
+ * to the property */
+ table_index = match_uniprop((U8 *) lookup_name, lookup_len);
+
+ /* If it didn't find the property */
+ if (table_index == 0) {
+
+ /* If didn't find the property, we try again stripping off any initial
+ * 'In' or 'Is' */
+ if (starts_with_In_or_Is) {
+ lookup_name += 2;
+ lookup_len -= 2;
+ equals_pos -= 2;
+ slash_pos -= 2;
+
+ table_index = match_uniprop((U8 *) lookup_name, lookup_len);
+ }
+
+ if (table_index == 0) {
+ char * canonical;
+
+ /* If not found, and not a numeric type property, isn't a legal
+ * property */
+ if (! is_nv_type) {
+ return NULL;
+ }
+
+ /* But the numeric type properties need more work to decide. What
+ * we do is make sure we have the number in canonical form and look
+ * that up. */
+
+ if (slash_pos < 0) { /* No slash */
+
+ /* When it isn't a rational, take the input, convert it to a
+ * NV, then create a canonical string representation of that
+ * NV. */
+
+ NV value;
+
+ /* Get the value */
+ if (my_atof3(lookup_name + equals_pos, &value,
+ lookup_len - equals_pos)
+ != lookup_name + lookup_len)
+ {
+ return NULL;
+ }
+
+ /* If the value is an integer, the canonical value is integral */
+ if (Perl_ceil(value) == value) {
+ canonical = Perl_form(aTHX_ "%.*s%.0" NVff,
+ equals_pos, lookup_name, value);
+ }
+ else { /* Otherwise, it is %e with a known precision */
+ char * exp_ptr;
+
+ canonical = Perl_form(aTHX_ "%.*s%.*" NVef,
+ equals_pos, lookup_name,
+ PL_E_FORMAT_PRECISION, value);
+
+ /* The exponent generated is expecting two digits, whereas
+ * %e on some systems will generate three. Remove leading
+ * zeros in excess of 2 from the exponent. We start
+ * looking for them after the '=' */
+ exp_ptr = strchr(canonical + equals_pos, 'e');
+ if (exp_ptr) {
+ char * cur_ptr = exp_ptr + 2; /* past the 'e[+-]' */
+ SSize_t excess_exponent_len = strlen(cur_ptr) - 2;
+
+ assert(*(cur_ptr - 1) == '-' || *(cur_ptr - 1) == '+');
+
+ if (excess_exponent_len > 0) {
+ SSize_t leading_zeros = strspn(cur_ptr, "0");
+ SSize_t excess_leading_zeros
+ = MIN(leading_zeros, excess_exponent_len);
+ if (excess_leading_zeros > 0) {
+ Move(cur_ptr + excess_leading_zeros,
+ cur_ptr,
+ strlen(cur_ptr) - excess_leading_zeros
+ + 1, /* Copy the NUL as well */
+ char);
+ }
+ }
+ }
+ }
+ }
+ else { /* Has a slash. Create a rational in canonical form */
+ UV numerator, denominator, gcd, trial;
+ const char * end_ptr;
+ const char * sign = "";
+
+ /* We can't just find the numerator, denominator, and do the
+ * division, then use the method above, because that is
+ * inexact. And the input could be a rational that is within
+ * epsilon (given our precision) of a valid rational, and would
+ * then incorrectly compare valid.
+ *
+ * We're only interested in the part after the '=' */
+ const char * this_lookup_name = lookup_name + equals_pos;
+ lookup_len -= equals_pos;
+ slash_pos -= equals_pos;
+
+ /* Handle any leading minus */
+ if (this_lookup_name[0] == '-') {
+ sign = "-";
+ this_lookup_name++;
+ lookup_len--;
+ slash_pos--;
+ }
+
+ /* Convert the numerator to numeric */
+ end_ptr = this_lookup_name + slash_pos;
+ if (! grok_atoUV(this_lookup_name, &numerator, &end_ptr)) {
+ return NULL;
+ }
+
+ /* It better have included all characters before the slash */
+ if (*end_ptr != '/') {
+ return NULL;
+ }
+
+ /* Set to look at just the denominator */
+ this_lookup_name += slash_pos;
+ lookup_len -= slash_pos;
+ end_ptr = this_lookup_name + lookup_len;
+
+ /* Convert the denominator to numeric */
+ if (! grok_atoUV(this_lookup_name, &denominator, &end_ptr)) {
+ return NULL;
+ }
+
+ /* It better be the rest of the characters, and don't divide by
+ * 0 */
+ if ( end_ptr != this_lookup_name + lookup_len
+ || denominator == 0)
+ {
+ return NULL;
+ }
+
+ /* Get the greatest common denominator using
+ http://en.wikipedia.org/wiki/Euclidean_algorithm */
+ gcd = numerator;
+ trial = denominator;
+ while (trial != 0) {
+ UV temp = trial;
+ trial = gcd % trial;
+ gcd = temp;
+ }
+
+ /* If already in lowest possible terms, we have already tried
+ * looking this up */
+ if (gcd == 1) {
+ return NULL;
+ }
+
+ /* Reduce the rational, which should put it in canonical form.
+ * Then look it up */
+ numerator /= gcd;
+ denominator /= gcd;
+
+ canonical = Perl_form(aTHX_ "%.*s%s%" UVuf "/%" UVuf,
+ equals_pos, lookup_name, sign, numerator, denominator);
+ }
+
+ /* Here, we have the number in canonical form. Try that */
+ table_index = match_uniprop((U8 *) canonical, strlen(canonical));
+ if (table_index == 0) {
+ return NULL;
+ }
+ }
+ }
+
+ /* The return is an index into a table of ptrs. A negative return
+ * signifies that the real index is the absolute value, but the result
+ * needs to be inverted */
+ if (table_index < 0) {
+ *invert = TRUE;
+ table_index = -table_index;
+ }
+ else {
+ *invert = FALSE;
+ }
+
+ /* Out-of band indices indicate a deprecated property. The proper index is
+ * modulo it with the table size. And dividing by the table size yields
+ * an offset into a table constructed to contain the corresponding warning
+ * message */
+ if (table_index > MAX_UNI_KEYWORD_INDEX) {
+ Size_t warning_offset = table_index / MAX_UNI_KEYWORD_INDEX;
+ table_index %= MAX_UNI_KEYWORD_INDEX;
+ Perl_ck_warner_d(aTHX_ packWARN(WARN_DEPRECATED),
+ "Use of '%.*s' in \\p{} or \\P{} is deprecated because: %s",
+ (int) name_len, name, deprecated_property_msgs[warning_offset]);
+ }
+
+ /* In a few properties, a different property is used under /i. These are
+ * unlikely to change, so are hard-coded here. */
+ if (to_fold) {
+ if ( table_index == UNI_XPOSIXUPPER
+ || table_index == UNI_XPOSIXLOWER
+ || table_index == UNI_TITLE)
+ {
+ table_index = UNI_CASED;
+ }
+ else if ( table_index == UNI_UPPERCASELETTER
+ || table_index == UNI_LOWERCASELETTER
+# ifdef UNI_TITLECASELETTER /* Missing from early Unicodes */
+ || table_index == UNI_TITLECASELETTER
+# endif
+ ) {
+ table_index = UNI_CASEDLETTER;
+ }
+ else if ( table_index == UNI_POSIXUPPER
+ || table_index == UNI_POSIXLOWER)
+ {
+ table_index = UNI_POSIXALPHA;
+ }
+ }
+
+ /* Create and return the inversion list */
+ return _new_invlist_C_array(uni_prop_ptrs[table_index]);
+}
+
+#endif
+
/*
* ex: set ts=8 sts=4 sw=4 et:
*/