2010-06-14 90 views
2

我有一個正在擴展到英國的應用程序,我需要添加對Latin-9 Unicode的支持。我做了一些谷歌搜索,但沒有發現什麼固定的過程中涉及什麼。有小費嗎?Perl 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

+3

爲什麼你需要支持Latin-9?對於您將要收到的數據,是否有特定的格式?如果您需要支持的某些字符而不是特定的字符集,我建議您使用Unicode和UTF-8。 – mpeters 2010-06-14 19:23:07

+0

Latin-9就像帶有歐元符號的Latin-1,如果你不想或不能跳轉到Unicode,它是一種流行的選擇。 – leonbloy 2010-06-15 00:06:28

+0

Latin-9是業務需求 – 2010-06-15 12:21:49

回答

5

Unicode::String是古老的,並設計爲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 
+0

謝謝,我看過你給的參考資料,但沒有看到Latin-9。任何其他參考/建議? – 2010-06-14 18:39:12

+0

再次感謝,我還有一個問題,因爲運行舊軟件的某些客戶端可能無法升級到新版本的Perl。有沒有支持拉丁語-9使用Unicode :: String的方式,而不是:編碼?只是想讓客戶儘可能簡單地升級。 – 2010-06-14 18:48:39

+0

嘗試使用'perldoc Encode :: Supported'來獲取支持的編碼列表。 search.cpan.org似乎沒有找到當前版本(因爲它被移到了tarball中的不同位置)。 – cjm 2010-06-14 18:51:33

0

在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.