6 join " ", map { sprintf "%04X", $_ } unpack "U*", $_[0];
10 my ($base, $spec, $func) = @_;
11 my $file = File::Spec->catfile(File::Spec->catdir(File::Spec->updir,
12 "lib", "unicore", "To"),
14 my $simple = do $file;
16 for my $i (split(/\n/, $simple)) {
17 my ($k, $v) = split(' ', $i);
22 for my $i (sort keys %simple) {
25 print "# ", scalar keys %simple, " simple mappings\n";
29 for my $i (sort keys %$spec) {
30 if (++$seen{$i} == 2) {
31 warn sprintf "$base: $i seen twice\n";
35 print "# ", scalar keys %$spec, " special mappings\n";
40 for my $i (map { ord } split //,
41 "\e !\"#\$%&'()+,-./0123456789:;<=>?\@[\\]^_{|}~\b") {
42 next if pack("U0U", $i) =~ /\w/;
43 $none{$i}++ unless $seen{$i};
45 print "# ", scalar keys %none, " noncase mappings\n";
48 (scalar keys %simple) +
49 (scalar keys %$spec) +
55 for my $i (sort keys %simple) {
57 my $c = pack "U0U", hex $i;
60 print $d eq pack("U0U", hex $simple{$i}) ?
61 "ok $test # $i -> $w\n" : "not ok $test # $i -> $e ($w)\n";
65 for my $i (sort keys %$spec) {
66 my $w = unidump($spec->{$i});
67 my $u = unpack "U0U", $i;
68 my $h = sprintf "%04X", $u;
69 my $c = chr($u); $c .= chr(0x100); chop $c;
72 if (ord "A" == 193) { # EBCDIC
73 # We need to a little bit of remapping.
75 # For example, in titlecase (ucfirst) mapping
76 # of U+0149 the Unicode mapping is U+02BC U+004E.
77 # The 4E is N, which in EBCDIC is 2B--
78 # and the ucfirst() does that right.
79 # The problem is that our reference
80 # data is in Unicode code points.
82 # The Right Way here would be to use, say,
83 # Encode, to remap the less-than 0x100 code points,
84 # but let's try to be Encode-independent here.
86 # These are the titlecase exceptions:
88 # Unicode Unicode+EBCDIC
90 # 0149 -> 02BC 004E (02BC 002B)
91 # 01F0 -> 004A 030C (00A2 030C)
92 # 1E96 -> 0048 0331 (00E7 0331)
93 # 1E97 -> 0054 0308 (00E8 0308)
94 # 1E98 -> 0057 030A (00EF 030A)
95 # 1E99 -> 0059 030A (00DF 030A)
96 # 1E9A -> 0041 02BE (00A0 02BE)
98 # The uppercase exceptions are identical.
100 # The lowercase has one more:
102 # Unicode Unicode+EBCDIC
104 # 0130 -> 0069 0307 (00D1 0307)
106 if ($i =~ /^(0130|0149|01F0|1E96|1E97|1E98|1E99|1E9A)$/) {
107 $e =~ s/004E/002B/; # N
108 $e =~ s/004A/00A2/; # J
109 $e =~ s/0048/00E7/; # H
110 $e =~ s/0054/00E8/; # T
111 $e =~ s/0057/00EF/; # W
112 $e =~ s/0059/00DF/; # Y
113 $e =~ s/0041/00A0/; # A
114 $e =~ s/0069/00D1/; # i
116 # We have to map the output, not the input, because
117 # pack/unpack U has been EBCDICified, too, it would
118 # just undo our remapping.
121 "ok $test # $i -> $w\n" : "not ok $test # $h -> $e ($w)\n";
125 for my $i (sort { $a <=> $b } keys %none) {
126 my $w = $i = sprintf "%04X", $i;
127 my $c = pack "U0U", hex $i;
131 "ok $test # $i -> $w\n" : "not ok $test # $i -> $e ($w)\n";