5 ## mktables -- create the runtime Perl Unicode files (lib/unicore/**/*.pl)
6 ## from the Unicode database files (lib/unicore/*.txt).
20 my $arg = shift @ARGV;
23 } elsif ($arg eq '-q') {
26 die "usage: $0 [-v|-q]";
30 my $LastUnicodeCodepoint = 0x10FFFF; # As of Unicode 3.1.1.
34 # !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
35 # This file is built by $0 from e.g. Unicode.txt.
36 # Any changes made here will be lost!
42 ## The main datastructure (a "Table") represents a set of code points that
43 ## are part of a particular quality (that are part of \pL, \p{InGreek},
44 ## etc.). They are kept as ranges of code points (starting and ending of
47 ## For example, a range ASCII LETTERS would be represented as:
48 ## [ [ 0x41 => 0x5A, 'UPPER' ],
49 ## [ 0x61 => 0x7A, 'LOWER, ] ]
51 sub RANGE_START() { 0 } ## index into range element
52 sub RANGE_END() { 1 } ## index into range element
53 sub RANGE_NAME() { 2 } ## index into range element
60 ## Associates a property ("Greek", "Lu", "Assigned",...) with a Table.
63 ## New_Prop(In => 'Greek', $Table, AllowFuzzy => 1);
65 ## Normally, these parameters are set when the Table is created (when the
66 ## Table->New constructor is called), but there are times when it needs to
67 ## be done after-the-fact...)
71 my $Type = shift; ## "Is" or "In";
75 ## remaining args are optional key/val
78 my $AllowFuzzy = delete $Args{AllowFuzzy};
80 ## sanity check a few args
81 if (%Args or ($Type ne 'Is' and $Type ne 'In') or not ref $Table) {
82 confess "$0: bad args to New_Prop"
85 if (not $TableInfo{$Type}->{$Name})
87 $TableInfo{$Type}->{$Name} = $Table;
89 $FuzzyNames{$Type}->{$Name} = $Name;
96 ## Creates a new Table object.
98 ## Args are key/value pairs:
99 ## In => Name -- Name of "In" property to be associated with
100 ## Is => Name -- Name of "Is" property to be associated with
101 ## AllowFuzzy => Boolean -- True if name can be accessed "fuzzily"
103 ## No args are required.
110 my $Table = bless [], $class;
112 my $AllowFuzzy = delete $Args{AllowFuzzy};
114 for my $Type ('Is', 'In')
116 if (my $Name = delete $Args{$Type}) {
117 New_Prop($Type => $Name, $Table, AllowFuzzy => $AllowFuzzy);
121 ## shouldn't have any left over
123 confess "$0: bad args to Table->New"
130 ## Returns true if the Table has no code points
134 my $Table = shift; #self
139 ## Returns true if the Table has code points
143 my $Table = shift; #self
148 ## Returns the maximum code point currently in the table.
152 my $Table = shift; #self
153 confess "oops" if $Table->IsEmpty; ## must have code points to have a max
154 return $Table->[-1]->[RANGE_END];
158 ## Replaces the codepoints in the Table with those in the Table given
159 ## as an arg. (NOTE: this is not a "deep copy").
161 sub Table::Replace($$)
163 my $Table = shift; #self
170 ## Given a new code point, make the last range of the Table extend to
171 ## include the new (and all intervening) code points.
175 my $Table = shift; #self
176 my $codepoint = shift;
178 my $PrevMax = $Table->Max;
180 confess "oops ($codepoint <= $PrevMax)" if $codepoint <= $PrevMax;
182 $Table->[-1]->[RANGE_END] = $codepoint;
186 ## Given a code point range start and end (and optional name), blindly
187 ## append them to the list of ranges for the Table.
189 ## NOTE: Code points must be added in strictly ascending numeric order.
191 sub Table::RawAppendRange
193 my $Table = shift; #self
197 $name = "" if not defined $name; ## warning: $name can be "0"
199 push @$Table, [ $start, # RANGE_START
201 $name ]; # RANGE_NAME
205 ## Given a code point (and optional name), add it to the Table.
207 ## NOTE: Code points must be added in strictly ascending numeric order.
211 my $Table = shift; #self
212 my $codepoint = shift;
214 $name = "" if not defined $name; ## warning: $name can be "0"
217 ## If we've already got a range working, and this code point is the next
218 ## one in line, and if the name is the same, just extend the current range.
222 $Table->Max == $codepoint - 1
224 $Table->[-1]->[RANGE_NAME] eq $name)
226 $Table->Extend($codepoint);
230 $Table->RawAppendRange($codepoint, $codepoint, $name);
235 ## Given a code point range starting value and ending value (and name),
236 ## Add the range to teh Table.
238 ## NOTE: Code points must be added in strictly ascending numeric order.
240 sub Table::AppendRange
242 my $Table = shift; #self
246 $name = "" if not defined $name; ## warning: $name can be "0"
248 $Table->Append($start, $name);
249 $Table->Extend($end) if $end > $start;
253 ## Return a new Table that represents all code points not in the Table.
257 my $Table = shift; #self
259 my $New = Table->New();
261 for my $range (@$Table)
263 my $start = $range->[RANGE_START];
264 my $end = $range->[RANGE_END];
265 if ($start-1 >= $max+1) {
266 $New->AppendRange($max+1, $start-1, "");
270 if ($max+1 < $LastUnicodeCodepoint) {
271 $New->AppendRange($max+1, $LastUnicodeCodepoint);
277 ## Merges any number of other tables with $self, returning the new table.
278 ## (existing tables are not modified)
280 ## Can be called as either a constructor or a method.
284 shift(@_) if not ref $_[0]; ## if called as a constructor, lose the class
287 ## Accumulate all records from all tables
289 for my $Table (@Tables) {
290 push @Records, @$Table;
293 ## sort by range start, with longer ranges coming first.
294 my ($first, @Rest) = sort {
295 ($a->[RANGE_START] <=> $b->[RANGE_START])
297 ($b->[RANGE_END] <=> $b->[RANGE_END])
300 my $New = Table->New();
302 ## Ensuring the first range is there makes the subsequent loop easier
303 $New->AppendRange($first->[RANGE_START],
304 $first->[RANGE_END]);
306 ## Fold in records so long as they add new information.
309 my $start = $set->[RANGE_START];
310 my $end = $set->[RANGE_END];
311 if ($start > $New->Max) {
312 $New->AppendRange($start, $end);
313 } elsif ($end > $New->Max) {
322 ## Given a filename, write a representation of the Table to a file.
326 my $Table = shift; #self
327 my $filename = shift;
329 print "$filename\n" if $Verbose;
331 if (not open(OUT, ">$filename")) {
332 die "$0: can't write $filename: $!\n";
336 print OUT "return <<'END';\n";
338 for my $set (@$Table)
340 my $start = $set->[RANGE_START];
341 my $end = $set->[RANGE_END];
342 my $name = $set->[RANGE_NAME];
344 if ($start == $end) {
345 printf OUT "%04X\t\t%s\n", $start, $name;
347 printf OUT "%04X\t%04X\t%s\n", $start, $end, $name;
355 ###########################################################################
356 ###########################################################################
357 ###########################################################################
362 ## New_Alias(Is => 'All', SameAs => 'Any', AllowFuzzy => 1);
364 ## The args must be in that order, although the AllowFuzzy pair may be omitted.
366 ## This creates 'IsAll' as an alias for 'IsAny'
370 my $Type = shift; ## "Is" or "In"
375 ## remaining args are optional key/val
378 my $AllowFuzzy = delete $Args{AllowFuzzy};
380 ## sanity check a few args
381 if (%Args or ($Type ne 'Is' and $Type ne 'In') or $SameAs ne 'SameAs') {
382 confess "$0: bad args to New_Alias"
385 if (not $TableInfo{$Type}->{$Name}) {
386 confess "$0: don't have orignial $Type => $Name to make alias"
388 if ($TableInfo{$Alias}) {
389 confess "$0: already have original $Type => $Alias; can't make alias";
391 $AliasInfo{$Type}->{$Name} = $Alias;
393 $FuzzyNames{$Type}->{$Alias} = $Name;
399 ## Turn something like
408 $name =~ s/(?<![a-z])(\w)/\u$1/g;
413 ## All assigned code points
414 my $Assigned = Table->New(Is => 'Assigned', AllowFuzzy => 1);
416 my $Name = Table->New(); ## all characters, individually by name
417 my $General = Table->New(); ## all characters, grouped by category
422 ## Process Unicode.txt (Categories, etc.)
426 my $Bidi = Table->New();
427 my $Deco = Table->New();
428 my $Comb = Table->New();
429 my $Number = Table->New();
430 my $Mirrored = Table->New(Is => 'Mirrored', AllowFuzzy => 0);
435 $Deco{Canon} = Table->New(Is => 'Canon', AllowFuzzy => 0);
436 $Deco{Compat} = Table->New(Is => 'Compat', AllowFuzzy => 0);
438 ## Initialize Perl-generated categories
439 $Cat{Alnum} = Table->New(Is => 'Alnum', AllowFuzzy => 0);
440 $Cat{Alpha} = Table->New(Is => 'Alpha', AllowFuzzy => 0);
441 $Cat{ASCII} = Table->New(Is => 'ASCII', AllowFuzzy => 0);
442 $Cat{Blank} = Table->New(Is => 'Blank', AllowFuzzy => 0);
443 $Cat{Cntrl} = Table->New(Is => 'Cntrl', AllowFuzzy => 0);
444 $Cat{Digit} = Table->New(Is => 'Digit', AllowFuzzy => 0);
445 $Cat{Graph} = Table->New(Is => 'Graph', AllowFuzzy => 0);
446 $Cat{Lower} = Table->New(Is => 'Lower', AllowFuzzy => 0);
447 $Cat{Print} = Table->New(Is => 'Print', AllowFuzzy => 0);
448 $Cat{Punct} = Table->New(Is => 'Punct', AllowFuzzy => 0);
449 $Cat{SpacePerl} = Table->New(Is => 'SpacePerl', AllowFuzzy => 0);
450 $Cat{Space} = Table->New(Is => 'Space', AllowFuzzy => 0);
451 $Cat{Title} = Table->New(Is => 'Title', AllowFuzzy => 0);
452 $Cat{Upper} = Table->New(Is => 'Upper', AllowFuzzy => 0);
453 $Cat{Word} = Table->New(Is => 'Word' , AllowFuzzy => 0);
454 $Cat{XDigit} = Table->New(Is => 'XDigit', AllowFuzzy => 0);
455 ## Categories from Unicode.txt are auto-initialized in gencat()
458 $To{Upper} = Table->New();
459 $To{Lower} = Table->New();
460 $To{Title} = Table->New();
461 $To{Digit} = Table->New();
465 my ($name, ## Name ("LATIN CAPITAL LETTER A")
466 $cat, ## Category ("Lu", "Zp", "Nd", etc.)
467 $code, ## Code point (as an integer)
470 my $MajorCat = substr($cat, 0, 1); ## L, M, Z, S, etc
472 $Assigned->$op($code);
473 $Name->$op($code, $name);
474 $General->$op($code, $cat);
476 ## add to the sub category (e.g. "Lu", "Nd", "Cf", ..)
477 $Cat{$cat} ||= Table->New(Is => $cat, AllowFuzzy => 0);
478 $Cat{$cat}->$op($code);
480 ## add to the major category (e.g. "L", "N", "C", ...)
481 $Cat{$MajorCat} ||= Table->New(Is => $MajorCat, AllowFuzzy => 0);
482 $Cat{$MajorCat}->$op($code);
484 ($General{$name} ||= Table->New)->$op($code, $name);
486 # 005F: SPACING UNDERSCORE
487 $Cat{Word}->$op($code) if $cat =~ /^[LMN]/ || $code == 0x005F;
488 $Cat{Alnum}->$op($code) if $cat =~ /^[LMN]/;
489 $Cat{Alpha}->$op($code) if $cat =~ /^[LM]/;
493 $Cat{Space}->$op($code) if $cat =~ /^Z/
494 || $code == 0x0009 # 0009: HORIZONTAL TAB
495 || $code == 0x000A # 000A: LINE FEED
496 || $code == 0x000B # 000B: VERTICAL TAB
497 || $code == 0x000C # 000C: FORM FEED
498 || $code == 0x000D; # 000D: CARRIAGE RETURN
501 $Cat{SpacePerl}->$op($code) if $cat =~ /^Z/
502 || $code == 0x0009 # 0009: HORIZONTAL TAB
503 || $code == 0x000A # 000A: LINE FEED
504 || $code == 0x000C # 000C: FORM FEED
505 || $code == 0x000D # 000D: CARRIAGE RETURN
506 || $code == 0x0085 # 0085: <NEXT LINE>
507 || $code == 0x2028 # 2028: LINE SEPARATOR
508 || $code == 0x2029;# 2029: PARAGRAPH SEP.
510 $Cat{Blank}->$op($code) if $cat =~ /^Z[^lp]$/
511 || $code == 0x0009 # 0009: HORIZONTAL TAB
512 || $code == 0x0020; # 0020: SPACE
514 $Cat{Digit}->$op($code) if $cat eq "Nd";
515 $Cat{Upper}->$op($code) if $cat eq "Lu";
516 $Cat{Lower}->$op($code) if $cat eq "Ll";
517 $Cat{Title}->$op($code) if $cat eq "Lt";
518 $Cat{ASCII}->$op($code) if $code <= 0x007F;
519 $Cat{Cntrl}->$op($code) if $cat =~ /^C/;
520 $Cat{Graph}->$op($code) if $cat =~ /^([LMNPS]|Co)/;
521 $Cat{Print}->$op($code) if $cat =~ /^([LMNPS]|Co|Zs)/;
522 $Cat{Punct}->$op($code) if $cat =~ /^P/;
524 $Cat{XDigit}->$op($code) if ($code >= 0x30 && $code <= 0x39) ## 0..9
525 || ($code >= 0x41 && $code <= 0x46) ## A..F
526 || ($code >= 0x61 && $code <= 0x66); ## a..f
529 ## open ane read file.....
530 if (not open IN, "Unicode.txt") {
531 die "$0: Unicode.txt: $!\n";
536 next unless /^[0-9A-Fa-f]+;/;
539 my ($hexcode, ## code point in hex (e.g. "0041")
540 $name, ## character name (e.g. "LATIN CAPITAL LETTER A")
541 $cat, ## category (e.g. "Lu")
542 $comb, ## Canonical combining class (e.t. "230")
543 $bidi, ## directional category (e.g. "L")
544 $deco, ## decomposition mapping
545 $decimal, ## decimal digit value
546 $digit, ## digit value
547 $number, ## numeric value
548 $mirrored, ## mirrored
549 $unicode10, ## name in Unicode 1.0
550 $comment, ## comment field
551 $upper, ## uppercase mapping
552 $lower, ## lowercase mapping
553 $title, ## titlecase mapping
554 ) = split(/\s*;\s*/);
556 my $code = hex($hexcode);
559 ## There are a few pairs of lines like:
560 ## AC00;<Hangul Syllable, First>;Lo;0;L;;;;;N;;;;;
561 ## D7A3;<Hangul Syllable, Last>;Lo;0;L;;;;;N;;;;;
562 ## that define ranges.
564 if ($name =~ /^<(.+), (First|Last)>$/)
567 gencat($name, $cat, $code, $2 eq 'First' ? 'Append' : 'Extend');
568 #New_Prop(In => $name, $General{$name}, AllowFuzzy => 1);
572 ## normal (single-character) lines
573 gencat($name, $cat, $code, 'Append');
575 # No Append() here since since several codes may map into one.
576 $To{Upper}->RawAppendRange($code, $code, $upper) if $upper;
577 $To{Lower}->RawAppendRange($code, $code, $lower) if $lower;
578 $To{Title}->RawAppendRange($code, $code, $title) if $title;
579 $To{Digit}->Append($code, $decimal) if length $decimal;
581 $Bidi->Append($code, $bidi);
582 $Comb->Append($code, $comb) if $comb;
583 $Number->Append($code, $number) if length $number;
585 $Mirrored->Append($code) if $mirrored eq "Y";
587 $Bidi{$bidi} ||= Table->New(Is => "Bidi$bidi", AllowFuzzy => 0);
588 $Bidi{$bidi}->Append($code);
592 $Deco->Append($code, $deco);
593 if ($deco =~/^<(\w+)>/)
595 $Deco{Compat}->Append($code);
597 $DC{$1} ||= Table->New(Is => "DC$1", AllowFuzzy => 0);
598 $DC{$1}->Append($code);
602 $Deco{Canon}->Append($code);
610 ## Tidy up a few special cases....
613 $Cat{Cn} = $Assigned->Invert; ## Cn is everything that doesn't exist
614 New_Prop(Is => 'Cn', $Cat{Cn}, AllowFuzzy => 0);
616 ## Unassigned is the same as 'Cn'
617 New_Alias(Is => 'Unassigned', SameAs => 'Cn', AllowFuzzy => 1);
619 $Cat{C}->Replace($Cat{C}->Merge($Cat{Cn})); ## Now merge in Cn into C
622 # L& is Ll, Lu, and Lt.
624 Table->Merge(@Cat{qw[Ll Lu Lt]}),
627 ## Any and All are all code points.
628 my $Any = Table->New(Is => 'Any', AllowFuzzy => 1);
629 $Any->RawAppendRange(0, $LastUnicodeCodepoint);
631 New_Alias(Is => 'All', SameAs => 'Any', AllowFuzzy => 1);
635 ## Now dump the files.
637 $Name->Write("Name.pl");
638 $Bidi->Write("Bidirectional.pl");
639 $Comb->Write("CombiningClass.pl");
640 $Deco->Write("Decomposition.pl");
641 $Number->Write("Number.pl");
642 $General->Write("Category.pl");
644 for my $to (sort keys %To) {
645 $To{$to}->Write("To/$to.pl");
650 ## Process LineBrk.txt
654 if (not open IN, "LineBrk.txt") {
655 die "$0: LineBrk.txt: $!\n";
658 my $Lbrk = Table->New();
663 next unless /^([0-9A-Fa-f]+)(?:\.\.([0-9A-Fa-f]+))?\s*;\s*(\w+)/;
665 my ($first, $last, $lbrk) = (hex($1), hex($2||""), $3);
667 $Lbrk->Append($first, $lbrk);
669 $Lbrk{$lbrk} ||= Table->New(Is => "Lbrk$lbrk", AllowFuzzy => 0);
670 $Lbrk{$lbrk}->Append($first);
673 $Lbrk->Extend($last);
674 $Lbrk{$lbrk}->Extend($last);
679 $Lbrk->Write("Lbrk.pl");
683 ## Process ArabShap.txt.
687 if (not open IN, "ArabShap.txt") {
688 die "$0: ArabShap.txt: $!\n";
691 my $ArabLink = Table->New();
692 my $ArabLinkGroup = Table->New();
696 next unless /^[0-9A-Fa-f]+;/;
699 my ($hexcode, $name, $link, $linkgroup) = split(/\s*;\s*/);
700 my $code = hex($hexcode);
701 $ArabLink->Append($code, $link);
702 $ArabLinkGroup->Append($code, $linkgroup);
706 $ArabLink->Write("ArabLink.pl");
707 $ArabLinkGroup->Write("ArabLnkGrp.pl");
715 if (not open IN, "Jamo.txt") {
716 die "$0: Jamo.txt: $!\n";
718 my $Short = Table->New();
722 next unless /^([0-9A-Fa-f]+)\s*;\s*(\w*)/;
723 my ($code, $short) = (hex($1), $2);
725 $Short->Append($code, $short);
728 $Short->Write("JamoShort.pl");
732 ## Process Scripts.txt.
738 if (not open(IN, "Scripts.txt")) {
739 die "$0: Scripts.txt: $!\n";
742 next unless /^([0-9A-Fa-f]+)(?:\.\.([0-9A-Fa-f]+))?\s*;\s*(.+?)\s*\#/;
744 # Wait until all the scripts have been read since
745 # they are not listed in numeric order.
746 push @ScriptInfo, [ hex($1), hex($2||""), $3 ];
750 # Now append the scripts properties in their code point order.
753 my $Scripts = Table->New();
755 for my $script (sort { $a->[0] <=> $b->[0] } @ScriptInfo)
757 my ($first, $last, $name) = @$script;
758 $Scripts->Append($first, $name);
760 $Script{$name} ||= Table->New(Is => CanonicalName($name),
762 $Script{$name}->Append($first, $name);
765 $Scripts->Extend($last);
766 $Script{$name}->Extend($last);
770 $Scripts->Write("Scripts.pl");
772 ## Common is everything not explicitly assigned to a Script
774 ## ***shouldn't this be intersected with \p{Assigned}? ******
776 New_Prop(Is => 'Common', $Scripts->Invert, AllowFuzzy => 1);
780 ## Given a name like "Close Punctuation", return a regex (that when applied
781 ## with /i) matches any valid form of that name (e.g. "ClosePunctuation",
782 ## "Close-Punctuation", etc.)
784 ## Accept any space, dash, or underbar where in the official name there is
785 ## space or a dash (or underbar, but there never is).
791 $Name =~ s/[- _]/(?:[-_]|\\s+)?/g;
796 ## Process Blocks.txt.
800 my $Blocks = Table->New();
803 if (not open IN, "Blocks.txt") {
804 die "$0: Blocks.txt: $!\n";
809 #next if not /Private Use$/;
810 next if not /^([0-9A-Fa-f]+)\.\.([0-9A-Fa-f]+)\s*;\s*(.+?)\s*$/;
812 my ($first, $last, $name) = (hex($1), hex($2), $3);
814 $Blocks->Append($first, $name);
816 $Blocks{$name} ||= Table->New(In=>CanonicalName($name), AllowFuzzy=>1);
817 $Blocks{$name}->Append($first, $name);
819 if ($last and $last != $first) {
820 $Blocks->Extend($last);
821 $Blocks{$name}->Extend($last);
826 $Blocks->Write("Blocks.pl");
830 ## Read in the PropList.txt. It contains extended properties not
831 ## listed in the Unicode.txt, such as 'Other_Alphabetic':
832 ## alphabetic but not of the general category L; many modifiers
833 ## belong to this extended property category: while they are not
834 ## alphabets, they are alphabetic in nature.
840 if (not open IN, "PropList.txt") {
841 die "$0: PropList.txt: $!\n";
846 next unless /^([0-9A-Fa-f]+)(?:\.\.([0-9A-Fa-f]+))?\s*;\s*(.+?)\s*\#/;
848 # Wait until all the extended properties have been read since
849 # they are not listed in numeric order.
850 push @PropInfo, [ hex($1), hex($2||""), $3 ];
854 # Now append the extended properties in their code point order.
855 my $Props = Table->New();
858 for my $prop (sort { $a->[0] <=> $b->[0] } @PropInfo)
860 my ($first, $last, $name) = @$prop;
861 $Props->Append($first, $name);
863 $Prop{$name} ||= Table->New(Is => $name, AllowFuzzy => 1);
864 $Prop{$name}->Append($first, $name);
867 $Props->Extend($last);
868 $Prop{$name}->Extend($last);
872 # Alphabetic is L and Other_Alphabetic.
873 New_Prop(Is => 'Alphabetic',
874 Table->Merge($Cat{L}, $Prop{Other_Alphabetic}),
877 # Lowercase is Ll and Other_Lowercase.
878 New_Prop(Is => 'Lowercase',
879 Table->Merge($Cat{Ll}, $Prop{Other_Lowercase}),
882 # Uppercase is Lu and Other_Uppercase.
883 New_Prop(Is => 'Uppercase',
884 Table->Merge($Cat{Lu}, $Prop{Other_Uppercase}),
887 # Math is Sm and Other_Math.
888 New_Prop(Is => 'Math',
889 Table->Merge($Cat{Sm}, $Prop{Other_Math}),
892 # ID_Start is Ll, Lu, Lt, Lm, Lo, and Nl.
893 New_Prop(Is => 'ID_Start',
894 Table->Merge(@Cat{qw[Ll Lu Lt Lm Lo Nl]}),
897 # ID_Continue is ID_Start, Mn, Mc, Nd, and Pc.
898 New_Prop(Is => 'ID_Continue',
899 Table->Merge(@Cat{qw[Ll Lu Lt Lm Lo Nl Mn Mc Nd Pc ]}),
903 sub Make_GC_Aliases()
906 ## The mapping from General Category long forms to short forms is
907 ## currently hardwired here since no simple data file in the UCD
908 ## seems to do that. Unicode 3.2 will assumedly correct this.
912 'Uppercase_Letter' => 'Lu',
913 'Lowercase_Letter' => 'Ll',
914 'Titlecase_Letter' => 'Lt',
915 'Modifier_Letter' => 'Lm',
916 'Other_Letter' => 'Lo',
919 'Non_Spacing_Mark' => 'Mn',
920 'Spacing_Mark' => 'Mc',
921 'Enclosing_Mark' => 'Me',
924 'Space_Separator' => 'Zs',
925 'Line_Separator' => 'Zl',
926 'Paragraph_Separator' => 'Zp',
929 'Decimal_Number' => 'Nd',
930 'Letter_Number' => 'Nl',
931 'Other_Number' => 'No',
933 'Punctuation' => 'P',
934 'Connector_Punctuation' => 'Pc',
935 'Dash_Punctuation' => 'Pd',
936 'Open_Punctuation' => 'Ps',
937 'Close_Punctuation' => 'Pe',
938 'Initial_Punctuation' => 'Pi',
939 'Final_Punctuation' => 'Pf',
940 'Other_Punctuation' => 'Po',
943 'Math_Symbol' => 'Sm',
944 'Currency_Symbol' => 'Sc',
945 'Modifier_Symbol' => 'Sk',
946 'Other_Symbol' => 'So',
952 'Private Use' => 'Co',
953 'Unassigned' => 'Cn',
956 ## make the aliases....
957 while (my ($Alias, $Name) = each %Is) {
958 New_Alias(Is => $Alias, SameAs => $Name, AllowFuzzy => 1);
963 ## Writes the info accumulated in
970 sub WriteAllMappings()
972 for my $Type ('In', 'Is')
977 my %Exact; ## will become %utf8::Is or %utf8::In
978 my %Pat; ## will become %utf8::IsPat or %utf8::InPat
981 ## First write all the files to the $Type/ directory
983 while (my ($Name, $Table) = each %{$TableInfo{$Type}})
985 ## Need an 8.3 safe filename.
986 my $filename = $Name;
987 $filename =~ s/[_\W]+(\w*)/\u$1/g;
988 substr($filename, 8) = '' if length($filename) > 8;
991 ## Make sure the filename doesn't conflict with something we
992 ## might have already written. If we have, say,
999 while (my $num = $Filenames{lc $filename}++)
1001 $num++; ## so filenames with numbers start with '2', which
1002 ## just looks more natural.
1003 substr($filename, -length($num)) = $num;
1007 ## Okay, write the file...
1009 $Exact{$Name} = $filename;
1010 $Table->Write("$Type/$filename.pl");
1016 while (my ($Fuzzy, $Real) = each %{$FuzzyNames{$Type}})
1018 my $File = $Exact{$Real};
1021 die "$0: oops [$Real]";
1024 ## The prefix length of 2 is enough spread,
1025 ## and besides, we have 'Yi' as an In category.
1026 my $Prefix = lc(substr($Fuzzy, 0, 2));
1027 my $Regex = NameToRegex($Fuzzy);
1029 if ($Pat{$Prefix}->{$Regex}) {
1030 warn "WHOA, conflict with /$Regex/: $Pat{$Prefix}->{$Regex} vs $File\n";
1033 $Pat{$Prefix}->{$Regex} = $File;
1037 ## Since the fuzzy method will provide for a way to match $Fuzzy,
1038 ## there's no need for $Fuzzy to be in %Exact as well.
1039 ## This can't be done in the loop above because there could be
1040 ## multiple $Fuzzys pointing at the same $Real, and we don't want
1041 ## the first to delete the exact mapping out from under the second.
1043 for my $Fuzzy (keys %{$FuzzyNames{$Type}})
1045 delete $Exact{$Fuzzy};
1051 ## Now write In.pl / Is.pl
1053 if (not open OUT, ">$Type.pl") {
1054 die "$0: $Type.pl: $!\n";
1058 print OUT "## Data in this file used by ../utf8_heavy.pl\n";
1061 print OUT "## Mapping from name to filename in ./$Type\n";
1062 print OUT "%utf8::$Type = (\n";
1063 for my $Name (sort keys %Exact)
1065 my $File = $Exact{$Name};
1066 printf OUT " %-41s => %s,\n", "'$Name'", "'$File'";
1070 print OUT "## Mappings from regex to filename in ./$Type/\n";
1071 print OUT "%utf8::${Type}Pat = (\n";
1072 for my $Prefix (sort keys %Pat)
1074 print OUT " '$Prefix' => {\n";
1075 while (my ($Regex, $File) = each %{ $Pat{$Prefix} }) {
1076 print OUT "\t'$Regex' => '$File',\n";
1089 # Read in the special cases.
1094 if (not open IN, "SpecCase.txt") {
1095 die "$0: SpecCase.txt: $!\n";
1098 next unless /^[0-9A-Fa-f]+;/;
1102 my ($code, $lower, $title, $upper, $condition) = split(/\s*;\s*/);
1104 if ($condition) { # not implemented yet
1105 print "# SKIPPING $_\n" if $Verbose;
1109 # Wait until all the special cases have been read since
1110 # they are not listed in numeric order.
1111 my $ix = hex($code);
1112 push @{$CaseInfo{Lower}}, [ $ix, $code, $lower ];
1113 push @{$CaseInfo{Title}}, [ $ix, $code, $title ];
1114 push @{$CaseInfo{Upper}}, [ $ix, $code, $upper ];
1118 # Now write out the special cases properties in their code point order.
1119 # Prepend them to the To/{Upper,Lower,Title}.pl.
1121 for my $case (qw(Lower Title Upper))
1123 my $NormalCase = do "To/$case.pl" || die "$0: $@\n";
1124 if (not open OUT, ">To/$case.pl") {
1125 die "$0: To/$case.txt: $!";
1128 print OUT $HEADER, "\n";
1129 print OUT "%utf8::ToSpec$case =\n(\n";
1131 for my $prop (sort { $a->[0] <=> $b->[0] } @{$CaseInfo{$case}}) {
1132 my ($ix, $code, $to) = @$prop;
1134 join "", map { sprintf "\\x{%s}", $_ } split ' ', $to;
1135 printf OUT qq['%04X' => "$tostr",\n], $ix;
1138 print OUT "return <<'END';\n";
1139 print OUT $NormalCase;
1146 # Read in the case foldings.
1148 # We will do full case folding, C + F + I (see CaseFold.txt).
1152 if (not open IN, "CaseFold.txt") {
1153 die "$0: To/Fold.pl: $!\n";
1156 my $Fold = Table->New();
1160 # Skip status 'S', simple case folding
1161 next unless /^([0-9A-Fa-f]+)\s*;\s*([CFI])\s*;\s*([0-9A-Fa-f]+(?: [0-9A-Fa-f]+)*)\s*;/;
1163 my ($code, $status, $fold) = (hex($1), $2, $3);
1165 if ($status eq 'C') { # Common: one-to-one folding
1166 # No append() since several codes may fold into one.
1167 $Fold->RawAppendRange($code, $code, $fold);
1168 } else { # F: full, or I: dotted uppercase I -> dotless lowercase I
1169 $Fold{$code} = $fold;
1174 $Fold->Write("To/Fold.pl");
1177 # Prepend the special foldings to the common foldings.
1180 my $CommonFold = do "To/Fold.pl" || die "$0: To/Fold.pl: $!\n";
1181 if (not open OUT, ">To/Fold.pl") {
1182 die "$0: To/Fold.pl: $!\n";
1184 print OUT $HEADER, "\n";
1185 print OUT "%utf8::ToSpecFold =\n(\n";
1186 for my $code (sort { $a <=> $b } keys %Fold) {
1188 join "", map { sprintf "\\x{%s}", $_ } split ' ', $Fold{$code};
1189 printf OUT qq['%04X' => "$foldstr",\n], $code;
1192 print OUT "return <<'END';\n";
1193 print OUT $CommonFold;
1216 # That's all, folks!