2013-05-03 14 views
2

使用這些Unicode範圍Unicode::GCStringcolumns返回打印列的數量,而mbswidthText::CharWidth沒有。
他們的行爲不同,因爲他們使用不同的數據庫?爲什麼這兩種方法確定打印列數的行爲有所不同?

#!/usr/bin/env perl 
use warnings; 
use strict; 
use open qw(:std :utf8); 
use Text::CharWidth qw(mbswidth); # 0.04 
use Unicode::GCString;    # 2012.10 

for my $hex (0x0378 .. 0xd7ff, 0xfa2e .. 0xfdcf, 0xfdfe .. 0xfff8) { 
    my $chr = chr $hex; 
    if (mbswidth($chr) == -1) { # -1 invalid data 
     my $gcs = Unicode::GCString->new($chr); 
     my $width = $gcs->columns; 
     printf "%04x - %d : %s\n", $hex, $width, $chr; 
    } 
} 

回答

1

Text::CharWidth使用C庫函數wcwidth取決於操作系統和當前區域上。 Unicode::GCString使用sombok庫。後者似乎會定期更新到最新的Unicode版本,所以我認爲它是準確的。

相關問題