我有一个应用程序正在扩展到英国,我需要添加对 Latin-9 Unicode 的支持。我做了一些谷歌搜索,但没有发现任何关于该过程所涉及的内容的可靠信息。有什么建议吗?
这是一些代码(只是 Unicode 内容的位)
use Unicode::String qw(utf8 latin1 utf16);
# How to call
$encoded_txt = $self->unicode_encode($item->{value});
# Function part
sub unicode_encode {
shift() if ref($_[0]);
my $toencode = shift();
return undef unless defined($toencode);
Unicode::String->stringify_as("utf8");
my $unicode_str = Unicode::String->new();
# encode Perl UTF-8 string into latin1 Unicode::String
# - currently only Basic Latin and Latin 1 Supplement
# are supported here due to issues with Unicode::String .
$unicode_str->latin1( $toencode );
...
任何帮助都会很棒,谢谢。
编辑: 我确实找到了这篇文章:http://czyborra.com/charsets/iso8859.html
最佳答案
Unicode::String是古老的,旨在为旧的 Perls 添加 Unicode 支持。现代版本的 Perl(5.8.0 及更高版本)具有 native Unicode 支持。看Encode模块和 :encoding层。您可以使用 perldoc Encode::Supported
获取 Perl 中支持的编码列表。
基本上,您只需在输入和输出上解码/编码为 Latin-9 即可。其余时间,您应该使用 Perl 的 native UTF-8 字符串。
# Read a Latin-9 file:
open(my $in, '<:encoding(Latin9)', 'some/file');
my $line = <$in>; # Automatically converts Latin9 to UTF-8
# Write a Latin-9 file:
open(my $out, '>:encoding(Latin9)', 'other/file');
print $out $line; # Automatically converts UTF-8 to Latin9
关于Perl 拉丁语 9? Unicode - 需要添加支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3039600/