【发布时间】:2011-10-09 22:57:22
【问题描述】:
#!/usr/local/bin/perl
use warnings;
use 5.014;
use Unicode::Normalize qw(NFD NFC compose);
my $string1 = "\x{f5}";
my $NFD_string1 = NFD( $string1 );
# PV = 0x831150 "o\314\203"\0 [UTF8 "o\x{303}"] *
my $composed_NFD_string1 = compose( $NFD_string1 );
# PV = 0x77bc40 "\303\265"\0 [UTF8 "\x{f5}"] *
my $NFC_string1 = NFC( $string1 );
# PV = 0x836e30 "\303\265"\0 [UTF8 "\x{f5}"] *
my $string2 = "o\x{303}";
my $NFD_string2 = NFD( $string2 );
# PV = 0x780da0 "o\314\203"\0 [UTF8 "o\x{303}"] *
my $composed_NFD_string2 = compose( $NFD_string2 );
# PV = 0x782dc0 "\303\265"\0 [UTF8 "\x{f5}"] *
my $NFC_string2 = NFC( $string2 );
# PV = 0x7acba0 "\303\265"\0 [UTF8 "\x{f5}"] *
# * from Devel::Peek::Dump output
say 'OK' if $NFD_string1 eq $NFD_string2;
say 'OK' if $NFC_string1 eq $NFC_string2;
输出:
好的
好的
尝试后我问我:
是否有理由使用Normalization Form D 而不是Normalization Form C?
【问题讨论】:
-
TR15: »有关 Unicode 字符串等价序列主题和规范化需求的一般介绍,请参阅Section 2.12, Equivalent Sequences and Normalization in Unicode。«
标签: perl unicode normalization unicode-normalization