6 # This program outputs the 256 lines that form the guts of the PL_charclass
7 # table. The output should be used to manually replace the table contents in
8 # perl.h. Each line is a bit map of properties that the Unicode code point at
9 # the corresponding position in the table array has. The first line
10 # corresponds to code point U+0000, NULL, the last line to U=00FF. For an
11 # application to see if the code point "i" has a particular property, it just
13 # 'PL_charclass[i] & BIT'
14 # The bit names are of the form '_CC_property_suffix', where 'CC' stands for
15 # character class, and 'property' is the corresponding property, and 'suffix'
16 # is one of '_A' to mean the property is true only if the corresponding code
17 # point is ASCII, and '_L1' means that the range includes any Latin1
18 # character (ISO-8859-1 including the C0 and C1 controls). A property without
19 # these suffixes does not have different forms for both ranges.
21 # The data in the table is pretty well set in stone, so that this program need
22 # be run only when adding new properties to it.
57 my @bits; # Bit map for each code point
59 for my $ord (0..255) {
61 utf8::upgrade($char); # Important to use Unicode semantics!
62 for my $property (@properties) {
65 # The property name that corresponds to this doesn't have a suffix.
66 # If is a latin1 version, no further checking is needed.
67 if (! ($name =~ s/_L1$//)) {
69 # Here, isn't an L1. It's either a special one or the suffix ends
70 # in _A. In the latter case, it's automatically false for
71 # non-ascii. The one current special is valid over the whole range.
72 next if $name =~ s/_A$// && $ord >= 128;
76 if ($name eq 'PUNCT') {;
78 # Sadly, this is inconsistent: \pP and \pS for the ascii range,
79 # just \pP outside it.
80 $re = qr/\p{Punct}|[^\P{Symbol}\P{ASCII}]/;
81 } elsif ($name eq 'CHARNAME_CONT') {;
82 $re = qr/[-\w ():\xa0]/;
83 } elsif ($name eq 'SPACE') {;
85 } elsif ($name eq 'IDFIRST') {
86 $re = qr/[_\p{Alpha}]/;
87 } elsif ($name eq 'PSXSPC') {
88 $re = qr/[\v\p{Space}]/;
89 } elsif ($name eq 'WORDCHAR') {
91 } elsif ($name eq 'ALNUMC') {
92 # Like \w, but no underscore
94 } elsif ($name eq 'OCTAL') {
96 } else { # The remainder have the same name and values as Unicode
97 $re = eval "qr/\\p{$name}/";
99 carp $@ if ! defined $re;
101 #print "$ord, $name $property, $re\n";
102 if ($char =~ $re) { # Add this property if matches
103 $bits[$ord] .= '|' if $bits[$ord];
104 $bits[$ord] .= "_CC_$property";
107 #print __LINE__, " $ord $char $bits[$ord]\n";
110 # Names of C0 controls
146 # Names of C1 controls, plus the adjacent DEL
183 # Output the table using fairly short names for each char.
184 for my $ord (0..255) {
186 if ($ord < 32) { # A C0 control
188 } elsif ($ord > 32 && $ord < 127) { # Graphic
189 $name = "'" . chr($ord) . "'";
190 } elsif ($ord >= 127 && $ord <= 0x9f) {
191 $name = $C1[$ord - 127]; # A C1 control + DEL
192 } else { # SPACE, or, if Latin1, shorten the name */
194 $name = charnames::viacode($ord);
195 $name =~ s/LATIN CAPITAL LETTER //
196 || $name =~ s/LATIN SMALL LETTER (.*)/\L$1/;
198 printf "/* U+%02X %s */ %s,\n", $ord, $name, $bits[$ord];