6 join " ", map { sprintf "%04X", $_ } unpack "U*", $_[0];
10 my ($base, $spec, @funcs) = @_;
11 # For each provided function run it, and run a version with some extra
12 # characters afterwards. Use a recycling symbol, as it doesn't change case.
13 my $ballast = chr (0x2672) x 3;
14 @funcs = map {my $f = $_;
16 sub {my $r = $f->($_[0] . $ballast); # Add it before
17 $r =~ s/$ballast\z//so # Remove it afterwards
18 or die "'$_[0]' to '$r' mangled";
19 $r; # Result with $ballast removed.
23 my $file = File::Spec->catfile(File::Spec->catdir(File::Spec->updir,
24 "lib", "unicore", "To"),
26 my $simple = do $file or die $@;
28 for my $i (split(/\n/, $simple)) {
29 my ($k, $v) = split(' ', $i);
34 for my $i (sort keys %simple) {
37 print "# ", scalar keys %simple, " simple mappings\n";
41 for my $i (sort keys %$spec) {
42 if (++$seen{$i} == 2) {
43 warn sprintf "$base: $i seen twice\n";
47 print "# ", scalar keys %$spec, " special mappings\n";
52 for my $i (map { ord } split //,
53 "\e !\"#\$%&'()+,-./0123456789:;<=>?\@[\\]^_{|}~\b") {
54 next if pack("U0U", $i) =~ /\w/;
55 $none{$i}++ unless $seen{$i};
57 print "# ", scalar keys %none, " noncase mappings\n";
60 ((scalar keys %simple) +
61 (scalar keys %$spec) +
62 (scalar keys %none)) * @funcs;
67 for my $i (sort keys %simple) {
69 my $c = pack "U0U", hex $i;
70 foreach my $func (@funcs) {
73 print $d eq pack("U0U", hex $simple{$i}) ?
74 "ok $test # $i -> $w\n" : "not ok $test # $i -> $e ($w)\n";
79 for my $i (sort keys %$spec) {
80 my $w = unidump($spec->{$i});
81 if (ord('A') == 193 && $i eq "\x8A\x73") {
82 $w = '0178'; # It's a Latin small Y with diaeresis and not a Latin small letter sharp 's'.
84 my $u = unpack "C0U", $i;
85 my $h = sprintf "%04X", $u;
86 my $c = chr($u); $c .= chr(0x100); chop $c;
87 foreach my $func (@funcs) {
90 if (ord "A" == 193) { # EBCDIC
91 # We need to a little bit of remapping.
93 # For example, in titlecase (ucfirst) mapping
94 # of U+0149 the Unicode mapping is U+02BC U+004E.
95 # The 4E is N, which in EBCDIC is 2B--
96 # and the ucfirst() does that right.
97 # The problem is that our reference
98 # data is in Unicode code points.
100 # The Right Way here would be to use, say,
101 # Encode, to remap the less-than 0x100 code points,
102 # but let's try to be Encode-independent here.
104 # These are the titlecase exceptions:
106 # Unicode Unicode+EBCDIC
108 # 0149 -> 02BC 004E (02BC 002B)
109 # 01F0 -> 004A 030C (00A2 030C)
110 # 1E96 -> 0048 0331 (00E7 0331)
111 # 1E97 -> 0054 0308 (00E8 0308)
112 # 1E98 -> 0057 030A (00EF 030A)
113 # 1E99 -> 0059 030A (00DF 030A)
114 # 1E9A -> 0041 02BE (00A0 02BE)
116 # The uppercase exceptions are identical.
118 # The lowercase has one more:
120 # Unicode Unicode+EBCDIC
122 # 0130 -> 0069 0307 (00D1 0307)
124 if ($h =~ /^(0130|0149|01F0|1E96|1E97|1E98|1E99|1E9A)$/) {
125 $e =~ s/004E/002B/; # N
126 $e =~ s/004A/00A2/; # J
127 $e =~ s/0048/00E7/; # H
128 $e =~ s/0054/00E8/; # T
129 $e =~ s/0057/00EF/; # W
130 $e =~ s/0059/00DF/; # Y
131 $e =~ s/0041/00A0/; # A
132 $e =~ s/0069/00D1/; # i
134 # We have to map the output, not the input, because
135 # pack/unpack U has been EBCDICified, too, it would
136 # just undo our remapping.
139 "ok $test # $i -> $w\n" : "not ok $test # $h -> $e ($w)\n";
144 for my $i (sort { $a <=> $b } keys %none) {
145 my $w = $i = sprintf "%04X", $i;
146 my $c = pack "U0U", hex $i;
147 foreach my $func (@funcs) {
151 "ok $test # $i -> $w\n" : "not ok $test # $i -> $e ($w)\n";