else {
eptr = SvPVx_const(argsv, elen);
if (DO_UTF8(argsv)) {
+ I32 old_precis = precis;
if (has_precis && precis < elen) {
I32 p = precis;
sv_pos_u2b(argsv, &p, 0); /* sticks at end */
precis = p;
}
if (width) { /* fudge width (can't fudge elen) */
- width += elen - sv_len_utf8(argsv);
+ if (has_precis && precis < elen)
+ width += precis - old_precis;
+ else
+ width += elen - sv_len_utf8(argsv);
}
is_utf8 = TRUE;
}
require './test.pl';
}
-plan tests => 280;
+plan tests => 284;
is(
sprintf("%.40g ",0.01),
"width calculation under utf8 upgrade, length=$i");
}
+# check simultaneous width & precision with wide characters
+for my $i (1, 3, 5, 10) {
+ my $string = "\x{0410}"x($i+10); # cyrillic capital A
+ my $expect = "\x{0410}"x$i; # cut down to exactly $i characters
+ my $format = "%$i.${i}s";
+ is(sprintf($format, $string), $expect,
+ "width & precision interplay with utf8 strings, length=$i");
+}
+
# Used to mangle PL_sv_undef
fresh_perl_is(
'print sprintf "xxx%n\n"; print undef',