Subject: | Handling of Unicode characters |
Data::JavaScript currently has no support for characters above codepoint
0xff. For example, the script
use Data::JavaScript;
print join("\n", jsdump("unicode", "\x{20ac}")), "\n";
would return a string with three bytes, the utf-8 representation of 0x20ac.
However, it would be safer if \u20ac would be used instead. Here's a
possible solution:
sub quotemeta {
my $text = shift;
$text =~ s/([^\x20\x21\x23-\x26\x28\x7E\x{0100}-\x{fffd}])/sprintf("\\%03o", ord($1))/ge;
$text =~ s/([\x{0100}-\x{fffd}])/sprintf("\\u%04x", ord($1))/ge;
$text;
}
Regards,
Slaven