【问题标题】:Perl latin-9? Unicode - need to add supportPerl latin-9? Unicode - 需要添加支持
【发布时间】:2011-03-03 15:32:48
【问题描述】:

我有一个正在扩展到英国的应用程序,我需要添加对 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

【问题讨论】:

  • 为什么需要支持 Latin-9?对于您将收到的数据,该格式是否有特定的内容?如果您需要支持某些字符而不是特定字符集,我建议您使用完整的 Unicode 和 UTF-8。
  • Latin-9 就像带有欧元符号的 Latin-1,如果您不想或不能跳转到 Unicode,它是一个受欢迎的选择。
  • Latin-9 是业务需求

标签: perl unicode character-encoding latin9


【解决方案1】:

Unicode::String 是古老的,旨在为旧的 Perls 添加 Unicode 支持。 Perl 的现代版本(5.8.0 及更高版本)具有原生 Unicode 支持。查看Encode 模块和:encoding 层。您可以使用 perldoc Encode::Supported 获取 Perl 中支持的编码列表。

基本上,您只需要在输入和输出上解码/编码为 Latin-9。其余时间,您应该使用 Perl 的原生 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

【讨论】:

  • 谢谢,我确实看过您提供的参考资料,但没有看到 Latin-9。还有其他参考/建议吗?
  • 再次感谢,我还有另一个问题,因为一些运行旧软件的客户端可能无法升级到新版本的 Perl。使用 Unicode::String 方式而不是 :encoding 是否支持 Latin-9?只是想让客户尽可能轻松地升级。
  • 尝试perldoc Encode::Supported 获取支持的编码列表。 search.cpan.org 似乎没有找到当前版本(因为它被移到了 tarball 中的不同位置)。
  • Perl 5.6.1 现在已经 9 岁了。 (甚至 5.6.2 也快 7 了。)是时候让他们升级了。我怀疑将 Latin9 支持添加到 Unicode::String 会很困难,但你可能必须自己做。
  • hmm 试图为此使用编码,但它不起作用。英国欧元代码:encode("iso-8859-15", "UK €") 有什么想法吗?
【解决方案2】:

在 perldoc Encode::Supported 中,它被称为 ISO-8859-15 (!)。以下是 perldoc 的一些大幅缩减的输出:

           Lang/Regions  ISO/Other Std.  DOS     Windows Macintosh  Others
       ----------------------------------------------------------------
       Latin9 [4]    iso-8859-15
       ----------------------------------------------------------------

       [4] Nicknamed Latin0; the Euro sign as well as French and Finnish
           letters that are missing from 8859-1 were added.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-16
    • 2011-03-10
    • 2012-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多