U8 * const send = s+len;
PERL_ARGS_ASSERT_DO_TRANS_SIMPLE;
+ DEBUG_y(PerlIO_printf(Perl_debug_log, "%s: %d: entering do_trans_simple:"
+ " input sv:\n",
+ __FILE__, __LINE__));
+ DEBUG_y(sv_dump(sv));
/* First, take care of non-UTF-8 input strings, because they're easy */
if (!SvUTF8(sv)) {
SvUTF8_on(sv);
SvSETMAGIC(sv);
}
+ DEBUG_y(PerlIO_printf(Perl_debug_log, "%s: %d: returning %zu\n",
+ __FILE__, __LINE__, matches));
+ DEBUG_y(sv_dump(sv));
return matches;
}
PERL_ARGS_ASSERT_DO_TRANS_COUNT;
+ DEBUG_y(PerlIO_printf(Perl_debug_log, "%s: %d: entering do_trans_count:"
+ " input sv:\n",
+ __FILE__, __LINE__));
+ DEBUG_y(sv_dump(sv));
+
if (!SvUTF8(sv)) {
while (s < send) {
if (tbl->map[*s++] >= 0)
}
}
+ DEBUG_y(PerlIO_printf(Perl_debug_log, "%s: %d: count returning %zu\n",
+ __FILE__, __LINE__, matches));
return matches;
}
PERL_ARGS_ASSERT_DO_TRANS_COMPLEX;
+ DEBUG_y(PerlIO_printf(Perl_debug_log, "%s: %d: entering do_trans_complex:"
+ " input sv:\n",
+ __FILE__, __LINE__));
+ DEBUG_y(sv_dump(sv));
+
if (!SvUTF8(sv)) {
U8 *d = s;
U8 * const dstart = d;
}
}
else {
- if (this_map == (short) TR_UNMAPPED)
+ if (this_map == (short) TR_UNMAPPED) {
*d++ = *s;
+ previous_map = (short) TR_OOB;
+ }
else {
assert(this_map == (short) TR_DELETE);
matches++;
}
- previous_map = (short) TR_OOB;
}
s++;
else if (sch == (short) TR_UNMAPPED) {
Move(s, d, len, U8);
d += len;
+ pch = TR_OOB;
}
else if (sch == (short) TR_DELETE)
matches++;
}
s += len;
- pch = TR_OOB;
}
if (grows) {
SvUTF8_on(sv);
}
SvSETMAGIC(sv);
+ DEBUG_y(PerlIO_printf(Perl_debug_log, "%s: %d: returning %zu\n",
+ __FILE__, __LINE__, matches));
+ DEBUG_y(sv_dump(sv));
return matches;
}
PERL_ARGS_ASSERT_DO_TRANS_COUNT_INVMAP;
+ DEBUG_y(PerlIO_printf(Perl_debug_log, "%s: %d:"
+ "entering do_trans_count_invmap:"
+ " input sv:\n",
+ __FILE__, __LINE__));
+ DEBUG_y(sv_dump(sv));
+ DEBUG_y(PerlIO_printf(Perl_debug_log, "mapping:\n"));
+ DEBUG_y(invmap_dump(from_invlist, (UV *) SvPVX(to_invmap_sv)));
+
s = (U8*)SvPV_nomg(sv, len);
send = s + len;
s += s_len;
}
+ DEBUG_y(PerlIO_printf(Perl_debug_log, "%s: %d: returning %zu\n",
+ __FILE__, __LINE__, matches));
return matches;
}
-
/* Helper function for do_trans().
* Handles cases where an inversion map implementation is to be used and the
* search and replacement charlists are either not identical or flags are
const bool delete_unfound = cBOOL(PL_op->op_private & OPpTRANS_DELETE);
bool inplace = ! cBOOL(PL_op->op_private & OPpTRANS_GROWS);
const UV* from_array = invlist_array(from_invlist);
- UV final_map;
+ UV final_map = TR_OOB;
bool out_is_utf8 = cBOOL(SvUTF8(sv));
STRLEN s_len;
* assume cannot */
if (! out_is_utf8 && (PL_op->op_private & OPpTRANS_CAN_FORCE_UTF8)) {
inplace = FALSE;
- if (max_expansion < 2) {
- max_expansion = 2;
- }
}
s = (U8*)SvPV_nomg(sv, len);
+ DEBUG_y(PerlIO_printf(Perl_debug_log, "%s: %d: entering do_trans_invmap:"
+ " input sv:\n",
+ __FILE__, __LINE__));
+ DEBUG_y(sv_dump(sv));
+ DEBUG_y(PerlIO_printf(Perl_debug_log, "mapping:\n"));
+ DEBUG_y(invmap_dump(from_invlist, map));
+
send = s + len;
s0 = s;
else {
/* Here, we can't edit in place. We have no idea how much, if any,
* this particular input string will grow. However, the compilation
- * calculated the maximum expansion possible. Use that to allocale
- * based on the worst case scenario. */
- Newx(d, len * max_expansion + 1, U8);
+ * calculated the maximum expansion possible. Use that to allocate
+ * based on the worst case scenario. (First +1 is to round up; 2nd is
+ * for \0) */
+ Newx(d, (STRLEN) (len * max_expansion + 1 + 1), U8);
d0 = d;
}
if (to == (UV) TR_UNLISTED) { /* Just copy the unreplaced character */
if (UVCHR_IS_INVARIANT(from) || ! out_is_utf8) {
- *d++ = from;
+ *d++ = (U8) from;
}
else if (SvUTF8(sv)) {
Move(s, d, s_len, U8);
if (to == (UV) TR_SPECIAL_HANDLING) {
if (delete_unfound) {
- previous_map = to;
s += s_len;
continue;
}
matches = 0;
goto restart;
}
- *d++ = to;
+ *d++ = (U8) to;
}
}
s += s_len;
if (! inplace) {
sv_setpvn(sv, (char*)d0, d - d0);
+ Safefree(d0);
}
else {
*d = '\0';
}
SvSETMAGIC(sv);
+ DEBUG_y(PerlIO_printf(Perl_debug_log, "%s: %d: returning %zu\n",
+ __FILE__, __LINE__, matches));
+ DEBUG_y(sv_dump(sv));
return matches;
}
-
/* Execute a tr//. sv is the value to be translated, while PL_op
* should be an OP_TRANS or OP_TRANSR op, whose op_pv field contains a
* translation table or whose op_sv field contains an inversion map.
}
}
else if (size < 8)
- retnum = (s[uoffset] >> bitoffs) & ((1 << size) - 1);
+ retnum = (s[uoffset] >> bitoffs) & nBIT_MASK(size);
else {
if (size == 8)
retnum = s[uoffset];
}
if (size < 8) {
- mask = (1 << size) - 1;
+ mask = nBIT_MASK(size);
lval &= mask;
s[offset] &= ~(mask << bitoffs);
s[offset] |= lval << bitoffs;