6 join " ", map { sprintf "%04X", $_ } unpack "U*", $_[0];
10 my ($already_run, $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 # $already_run is the number of extra tests the caller has run before this
15 my $ballast = chr (0x2672) x 3;
16 @funcs = map {my $f = $_;
18 sub {my $r = $f->($_[0] . $ballast); # Add it before
19 $r =~ s/$ballast\z//so # Remove it afterwards
20 or die "'$_[0]' to '$r' mangled";
21 $r; # Result with $ballast removed.
25 my $file = File::Spec->catfile(File::Spec->catdir(File::Spec->updir,
26 "lib", "unicore", "To"),
28 my $simple = do $file or die $@;
30 for my $i (split(/\n/, $simple)) {
31 my ($k, $v) = split(' ', $i);
36 for my $i (sort keys %simple) {
39 print "# ", scalar keys %simple, " simple mappings\n";
43 for my $i (sort keys %$spec) {
44 if (++$seen{$i} == 2) {
45 warn sprintf "$base: $i seen twice\n";
49 print "# ", scalar keys %$spec, " special mappings\n";
54 for my $i (map { ord } split //,
55 "\e !\"#\$%&'()+,-./0123456789:;<=>?\@[\\]^_{|}~\b") {
56 next if pack("U0U", $i) =~ /\w/;
57 $none{$i}++ unless $seen{$i};
59 print "# ", scalar keys %none, " noncase mappings\n";
63 ((scalar keys %simple) +
64 (scalar keys %$spec) +
65 (scalar keys %none)) * @funcs;
67 my $test = $already_run + 1;
69 for my $i (sort keys %simple) {
71 my $c = pack "U0U", hex $i;
72 foreach my $func (@funcs) {
75 print $d eq pack("U0U", hex $simple{$i}) ?
76 "ok $test # $i -> $w\n" : "not ok $test # $i -> $e ($w)\n";
81 for my $i (sort keys %$spec) {
82 my $w = unidump($spec->{$i});
83 if (ord('A') == 193 && $i eq "\x8A\x73") {
84 $w = '0178'; # It's a Latin small Y with diaeresis and not a Latin small letter sharp 's'.
86 my $u = unpack "C0U", $i;
87 my $h = sprintf "%04X", $u;
88 my $c = chr($u); $c .= chr(0x100); chop $c;
89 foreach my $func (@funcs) {
92 if (ord "A" == 193) { # EBCDIC
93 # We need to a little bit of remapping.
95 # For example, in titlecase (ucfirst) mapping
96 # of U+0149 the Unicode mapping is U+02BC U+004E.
97 # The 4E is N, which in EBCDIC is 2B--
98 # and the ucfirst() does that right.
99 # The problem is that our reference
100 # data is in Unicode code points.
102 # The Right Way here would be to use, say,
103 # Encode, to remap the less-than 0x100 code points,
104 # but let's try to be Encode-independent here.
106 # These are the titlecase exceptions:
108 # Unicode Unicode+EBCDIC
110 # 0149 -> 02BC 004E (02BC 002B)
111 # 01F0 -> 004A 030C (00A2 030C)
112 # 1E96 -> 0048 0331 (00E7 0331)
113 # 1E97 -> 0054 0308 (00E8 0308)
114 # 1E98 -> 0057 030A (00EF 030A)
115 # 1E99 -> 0059 030A (00DF 030A)
116 # 1E9A -> 0041 02BE (00A0 02BE)
118 # The uppercase exceptions are identical.
120 # The lowercase has one more:
122 # Unicode Unicode+EBCDIC
124 # 0130 -> 0069 0307 (00D1 0307)
126 if ($h =~ /^(0130|0149|01F0|1E96|1E97|1E98|1E99|1E9A)$/) {
127 $e =~ s/004E/002B/; # N
128 $e =~ s/004A/00A2/; # J
129 $e =~ s/0048/00E7/; # H
130 $e =~ s/0054/00E8/; # T
131 $e =~ s/0057/00EF/; # W
132 $e =~ s/0059/00DF/; # Y
133 $e =~ s/0041/00A0/; # A
134 $e =~ s/0069/00D1/; # i
136 # We have to map the output, not the input, because
137 # pack/unpack U has been EBCDICified, too, it would
138 # just undo our remapping.
141 "ok $test # $i -> $w\n" : "not ok $test # $h -> $e ($w)\n";
146 for my $i (sort { $a <=> $b } keys %none) {
147 my $w = $i = sprintf "%04X", $i;
148 my $c = pack "U0U", hex $i;
149 foreach my $func (@funcs) {
153 "ok $test # $i -> $w\n" : "not ok $test # $i -> $e ($w)\n";