#!/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;
输出:
好的
好的
在尝试了这个之后,我问我:有没有理由使用 theNormalization Form D
而不是Normalization Form C
?