First, it's important to note that Encode::FB_XMLCREF doesn't work on from_to when using 5.8.8's Encode 2.12.
$ perl -MEncode=encode,from_to -wle'$s = encode("UTF-8", chr(0x2660)); + from_to($s, "UTF-8", "ascii", Encode::FB_XMLCREF); print $s' | od -c 0000000 342 231 240 \n 0000004
The problem appears to be fixed in 2.13. Using Encode 2.33:
$ perl -MEncode=encode,from_to -wle'$s = encode("UTF-8", chr(0x2660)); + from_to($s, "UTF-8", "ascii", Encode::FB_XMLCREF); print $s' | od -c 0000000 & # x 2 6 6 0 ; \n 0000011
So it's not a solid solution to being with. (You'd have to use decode+encode instead of from_to.) But it's buggy even with a bug-free version of Encode.
1..1 not ok 1 - With XML/HTML 4 digit hex entity # Failed test 'With XML/HTML 4 digit hex entity' # at a.pl line 24. # got: '\u2660\u2660' # expected: '♠\u2660' # Looks like you failed 1 test of 1.
#!/usr/bin/perl -T use strict; use warnings; # 2.13 has a necessary bug fix in from_to use Encode 2.13 qw( encode ); my @tests; BEGIN { @tests = ( [ encode('UTF-8', "♠\x{2660}"), "♠\\u2660", 'Wit +h XML/HTML 4 digit hex entity' ], ); } use Test::More tests => 0+@tests; sub escape_with_encode { return $_[0] unless $_[0] =~ /[\x80-\xff]/; my $s = shift; Encode::from_to($s, "utf-8", "ascii", Encode::FB_XMLCREF); $s =~ s/&#x(....);/\\u$1/g; return $s; } is( escape_with_encode($_->[0]), $_->[1], $_->[2] ) for @tests;
In reply to Re^2: Faster utf8 escaping.
by ikegami
in thread Faster utf8 escaping.
by kyle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |