What if sv_utf8_upgrade() used heuristic encoding?
Heuristic: decode as native unless is well-formed UTF-X:
sub heuristic_utf8_upgrade {
utf8::upgrade($_[0])
unless utf8::decode($_[0]);
return !!0;
}
Here is some code to play with:
#!/usr/bin/perl
use strict;
use warnings;
{
package encoding::heuristic;
our $Encoding;
BEGIN {
require Encode;
$Encoding = Encode::find_encoding('utf8');
}
sub import {
${^ENCODING} = bless \my $x, __PACKAGE__;…