2 require 5.008; # Needs pack "U". Probably safest to run on 5.8.x
8 ## mktables -- create the runtime Perl Unicode files (lib/unicore/**/*.pl)
9 ## from the Unicode database files (lib/unicore/*.txt).
12 ## "Fuzzy" means this section in Unicode TR18:
14 ## The recommended names for UCD properties and property values are in
15 ## PropertyAliases.txt [Prop] and PropertyValueAliases.txt
16 ## [PropValue]. There are both abbreviated names and longer, more
17 ## descriptive names. It is strongly recommended that both names be
18 ## recognized, and that loose matching of property names be used,
19 ## whereby the case distinctions, whitespace, hyphens, and underbar
22 ## Base names already used in lib/gc_sc (for avoiding 8.3 conflicts)
29 my $MakeTestScript = 0;
33 my $arg = shift @ARGV;
36 } elsif ($arg eq '-q') {
38 } elsif ($arg eq '-maketest') {
40 } elsif ($arg eq '-C' && defined (my $dir = shift)) {
41 chdir $dir or die "chdir $_: $!";
43 die "usage: $0 [-v|-q|-C dir] [-maketest]";
47 foreach my $lib ('To', 'lib',
48 map {File::Spec->catdir("lib",$_)}
49 qw(gc_sc dt bc hst ea jt lb nt ccc)) {
51 mkdir $lib, 0755 or die "mkdir '$lib': $!";
54 my $LastUnicodeCodepoint = 0x10FFFF; # As of Unicode 3.1.1.
57 # !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
58 # This file is built by $0 from e.g. UnicodeData.txt.
59 # Any changes made here will be lost!
65 return unless -e $filename;
66 return if CORE::unlink($filename);
67 # We might need write permission
68 chmod 0777, $filename;
69 CORE::unlink($filename) or die "Couldn't unlink $filename: $!\n";
73 ## Given a filename and a reference to an array of lines,
74 ## write the lines to the file only if the contents have not changed.
75 ## Filename can be given as an arrayref of directory names
77 sub WriteIfChanged($\@)
82 $file = File::Spec->catfile(@$file) if ref $file;
84 my $TextToWrite = join '', @$lines;
87 my $PreviousText = <IN>;
89 if ($PreviousText eq $TextToWrite) {
90 print "$file unchanged.\n" if $Verbose;
95 if (not open OUT, ">$file") {
96 die "$0: can't open $file for output: $!\n";
98 print "$file written.\n" if $Verbose;
100 print OUT $TextToWrite;
105 ## The main datastructure (a "Table") represents a set of code points that
106 ## are part of a particular quality (that are part of \pL, \p{InGreek},
107 ## etc.). They are kept as ranges of code points (starting and ending of
110 ## For example, a range ASCII LETTERS would be represented as:
111 ## [ [ 0x41 => 0x5A, 'UPPER' ],
112 ## [ 0x61 => 0x7A, 'LOWER, ] ]
114 sub RANGE_START() { 0 } ## index into range element
115 sub RANGE_END() { 1 } ## index into range element
116 sub RANGE_NAME() { 2 } ## index into range element
118 ## Conceptually, these should really be folded into the 'Table' objects
126 ## Turn something like
135 $name =~ s/(?<![a-z])(\w)/\u$1/g;
136 $name =~ s/[-_\s]+//g;
138 $CanonicalToOrig{$name} = $orig if not $CanonicalToOrig{$name};
144 ## Store the alias definitions for later use.
155 ## Most of the work with aliases doesn't occur here,
156 ## but rather in utf8_heavy.pl, which uses PVA.pl,
158 # Placate the warnings about used only once. (They are used again, but
159 # via a typeglob lookup)
160 %utf8::PropertyAlias = ();
161 %utf8::PA_reverse = ();
162 %utf8::PropValueAlias = ();
163 %utf8::PVA_reverse = ();
164 %utf8::PVA_abbr_map = ();
166 open PA, "< PropertyAliases.txt"
167 or confess "Can't open PropertyAliases.txt: $!";
173 my ($abbrev, $name) = split /\s*;\s*/;
174 next if $abbrev eq "n/a";
175 $PropertyAlias{$abbrev} = $name;
176 $PA_reverse{$name} = $abbrev;
178 # The %utf8::... versions use japhy's code originally from utf8_pva.pl
179 # However, it's moved here so that we build the tables at runtime.
180 tr/ _-//d for $abbrev, $name;
181 $utf8::PropertyAlias{lc $abbrev} = $name;
182 $utf8::PA_reverse{lc $name} = $abbrev;
186 open PVA, "< PropValueAliases.txt"
187 or confess "Can't open PropValueAliases.txt: $!";
193 my ($prop, @data) = split /\s*;\s*/;
195 if ($prop eq 'ccc') {
196 $PropValueAlias{$prop}{$data[1]} = [ @data[0,2] ];
197 $PVA_reverse{$prop}{$data[2]} = [ @data[0,1] ];
200 next if $data[0] eq "n/a";
201 $PropValueAlias{$prop}{$data[0]} = $data[1];
202 $PVA_reverse{$prop}{$data[1]} = $data[0];
205 shift @data if $prop eq 'ccc';
206 next if $data[0] eq "n/a";
208 $data[1] =~ tr/ _-//d;
209 $utf8::PropValueAlias{$prop}{lc $data[0]} = $data[1];
210 $utf8::PVA_reverse{$prop}{lc $data[1]} = $data[0];
212 my $abbr_class = ($prop eq 'gc' or $prop eq 'sc') ? 'gc_sc' : $prop;
213 $utf8::PVA_abbr_map{$abbr_class}{lc $data[0]} = $data[0];
217 # backwards compatibility for L& -> LC
218 $utf8::PropValueAlias{gc}{'l&'} = $utf8::PropValueAlias{gc}{lc};
219 $utf8::PVA_abbr_map{gc_sc}{'l&'} = $utf8::PVA_abbr_map{gc_sc}{lc};
225 ## Associates a property ("Greek", "Lu", "Assigned",...) with a Table.
228 ## New_Prop(In => 'Greek', $Table, Desc => 'Greek Block', Fuzzy => 1);
230 ## Normally, these parameters are set when the Table is created (when the
231 ## Table->New constructor is called), but there are times when it needs to
232 ## be done after-the-fact...)
236 my $Type = shift; ## "Is" or "In";
240 ## remaining args are optional key/val
243 my $Fuzzy = delete $Args{Fuzzy};
244 my $Desc = delete $Args{Desc}; # description
246 $Name = CanonicalName($Name) if $Fuzzy;
248 ## sanity check a few args
249 if (%Args or ($Type ne 'Is' and $Type ne 'In') or not ref $Table) {
250 confess "$0: bad args to New_Prop"
253 if (not $TableInfo{$Type}->{$Name})
255 $TableInfo{$Type}->{$Name} = $Table;
256 $TableDesc{$Type}->{$Name} = $Desc;
258 $FuzzyNames{$Type}->{$Name} = $Name;
265 ## Creates a new Table object.
267 ## Args are key/value pairs:
268 ## In => Name -- Name of "In" property to be associated with
269 ## Is => Name -- Name of "Is" property to be associated with
270 ## Fuzzy => Boolean -- True if name can be accessed "fuzzily"
271 ## Desc => String -- Description of the property
273 ## No args are required.
280 my $Table = bless [], $class;
282 my $Fuzzy = delete $Args{Fuzzy};
283 my $Desc = delete $Args{Desc};
285 for my $Type ('Is', 'In')
287 if (my $Name = delete $Args{$Type}) {
288 New_Prop($Type => $Name, $Table, Desc => $Desc, Fuzzy => $Fuzzy);
292 ## shouldn't have any left over
294 confess "$0: bad args to Table->New"
301 ## Returns true if the Table has no code points
305 my $Table = shift; #self
310 ## Returns true if the Table has code points
314 my $Table = shift; #self
319 ## Returns the maximum code point currently in the table.
323 my $Table = shift; #self
324 confess "oops" if $Table->IsEmpty; ## must have code points to have a max
325 return $Table->[-1]->[RANGE_END];
329 ## Replaces the codepoints in the Table with those in the Table given
330 ## as an arg. (NOTE: this is not a "deep copy").
332 sub Table::Replace($$)
334 my $Table = shift; #self
341 ## Given a new code point, make the last range of the Table extend to
342 ## include the new (and all intervening) code points.
346 my $Table = shift; #self
347 my $codepoint = shift;
349 my $PrevMax = $Table->Max;
351 confess "oops ($codepoint <= $PrevMax)" if $codepoint <= $PrevMax;
353 $Table->[-1]->[RANGE_END] = $codepoint;
357 ## Given a code point range start and end (and optional name), blindly
358 ## append them to the list of ranges for the Table.
360 ## NOTE: Code points must be added in strictly ascending numeric order.
362 sub Table::RawAppendRange
364 my $Table = shift; #self
368 $name = "" if not defined $name; ## warning: $name can be "0"
370 push @$Table, [ $start, # RANGE_START
372 $name ]; # RANGE_NAME
376 ## Given a code point (and optional name), add it to the Table.
378 ## NOTE: Code points must be added in strictly ascending numeric order.
382 my $Table = shift; #self
383 my $codepoint = shift;
385 $name = "" if not defined $name; ## warning: $name can be "0"
388 ## If we've already got a range working, and this code point is the next
389 ## one in line, and if the name is the same, just extend the current range.
393 $Table->Max == $codepoint - 1
395 $Table->[-1]->[RANGE_NAME] eq $name)
397 $Table->Extend($codepoint);
401 $Table->RawAppendRange($codepoint, $codepoint, $name);
406 ## Given a code point range starting value and ending value (and name),
407 ## Add the range to teh Table.
409 ## NOTE: Code points must be added in strictly ascending numeric order.
411 sub Table::AppendRange
413 my $Table = shift; #self
417 $name = "" if not defined $name; ## warning: $name can be "0"
419 $Table->Append($start, $name);
420 $Table->Extend($end) if $end > $start;
424 ## Return a new Table that represents all code points not in the Table.
428 my $Table = shift; #self
430 my $New = Table->New();
432 for my $range (@$Table)
434 my $start = $range->[RANGE_START];
435 my $end = $range->[RANGE_END];
436 if ($start-1 >= $max+1) {
437 $New->AppendRange($max+1, $start-1, "");
441 if ($max+1 < $LastUnicodeCodepoint) {
442 $New->AppendRange($max+1, $LastUnicodeCodepoint);
448 ## Merges any number of other tables with $self, returning the new table.
449 ## (existing tables are not modified)
452 ## Args may be Tables, or individual code points (as integers).
454 ## Can be called as either a constructor or a method.
458 shift(@_) if not ref $_[0]; ## if called as a constructor, lose the class
461 ## Accumulate all records from all tables
463 for my $Arg (@Tables)
466 ## arg is a table -- get its ranges
467 push @Records, @$Arg;
469 ## arg is a codepoint, make a range
470 push @Records, [ $Arg, $Arg ]
474 ## sort by range start, with longer ranges coming first.
475 my ($first, @Rest) = sort {
476 ($a->[RANGE_START] <=> $b->[RANGE_START])
478 ($b->[RANGE_END] <=> $b->[RANGE_END])
481 my $New = Table->New();
483 ## Ensuring the first range is there makes the subsequent loop easier
484 $New->AppendRange($first->[RANGE_START],
485 $first->[RANGE_END]);
487 ## Fold in records so long as they add new information.
490 my $start = $set->[RANGE_START];
491 my $end = $set->[RANGE_END];
492 if ($start > $New->Max) {
493 $New->AppendRange($start, $end);
494 } elsif ($end > $New->Max) {
503 ## Given a filename, write a representation of the Table to a file.
504 ## May have an optional comment as a 2nd arg.
505 ## Filename may actually be an arrayref of directories
509 my $Table = shift; #self
510 my $filename = shift;
514 if (defined $comment) {
515 $comment =~ s/\s+\Z//;
516 $comment =~ s/^/# /gm;
517 push @OUT, "#\n$comment\n#\n";
519 push @OUT, "return <<'END';\n";
521 for my $set (@$Table)
523 my $start = $set->[RANGE_START];
524 my $end = $set->[RANGE_END];
525 my $name = $set->[RANGE_NAME];
527 if ($start == $end) {
528 push @OUT, sprintf "%04X\t\t%s\n", $start, $name;
530 push @OUT, sprintf "%04X\t%04X\t%s\n", $start, $end, $name;
536 WriteIfChanged($filename, @OUT);
539 ## This used only for making the test script.
544 return 0 if $code <= 0x0000; ## don't use null
545 return 0 if $code >= $LastUnicodeCodepoint; ## keep in range
546 return 0 if ($code >= 0xD800 and $code <= 0xDFFF); ## no surrogates
547 return 0 if ($code >= 0xFDD0 and $code <= 0xFDEF); ## utf8.c says no good
548 return 0 if (($code & 0xFFFF) == 0xFFFE); ## utf8.c says no good
549 return 0 if (($code & 0xFFFF) == 0xFFFF); ## utf8.c says no good
553 ## Return a code point that's part of the table.
554 ## Returns nothing if the table is empty (or covers only surrogates).
555 ## This used only for making the test script.
558 my $Table = shift; #self
559 for my $set (@$Table) {
560 return $set->[RANGE_END] if IsUsable($set->[RANGE_END]);
565 ## Return a code point that's not part of the table
566 ## Returns nothing if the table covers all code points.
567 ## This used only for making the test script.
568 sub Table::InvalidCode
570 my $Table = shift; #self
572 return 0x1234 if $Table->IsEmpty();
574 for my $set (@$Table)
576 if (IsUsable($set->[RANGE_END] + 1))
578 return $set->[RANGE_END] + 1;
581 if (IsUsable($set->[RANGE_START] - 1))
583 return $set->[RANGE_START] - 1;
589 ###########################################################################
590 ###########################################################################
591 ###########################################################################
596 ## New_Alias(Is => 'All', SameAs => 'Any', Fuzzy => 1);
598 ## The args must be in that order, although the Fuzzy pair may be omitted.
600 ## This creates 'IsAll' as an alias for 'IsAny'
604 my $Type = shift; ## "Is" or "In"
606 my $SameAs = shift; # expecting "SameAs" -- just ignored
609 ## remaining args are optional key/val
612 my $Fuzzy = delete $Args{Fuzzy};
614 ## sanity check a few args
615 if (%Args or ($Type ne 'Is' and $Type ne 'In') or $SameAs ne 'SameAs') {
616 confess "$0: bad args to New_Alias"
619 $Alias = CanonicalName($Alias) if $Fuzzy;
621 if (not $TableInfo{$Type}->{$Name})
623 my $CName = CanonicalName($Name);
624 if ($TableInfo{$Type}->{$CName}) {
625 confess "$0: Use canonical form '$CName' instead of '$Name' for alias.";
627 confess "$0: don't have original $Type => $Name to make alias\n";
630 if ($TableInfo{$Alias}) {
631 confess "$0: already have original $Type => $Alias; can't make alias";
633 $AliasInfo{$Type}->{$Name} = $Alias;
635 $FuzzyNames{$Type}->{$Alias} = $Name;
641 ## All assigned code points
642 my $Assigned = Table->New(Is => 'Assigned',
643 Desc => "All assigned code points",
646 my $Name = Table->New(); ## all characters, individually by name
647 my $General = Table->New(); ## all characters, grouped by category
651 ## Simple Data::Dumper alike. Good enough for our needs. We can't use the real
652 ## thing as we have to run under miniperl
658 if (ref $item eq 'ARRAY') {
659 push @lines, "[\n", simple_dumper (@$item), "],\n";
660 } elsif (ref $item eq 'HASH') {
661 push @lines, "{\n", simple_dumper (%$item), "},\n";
663 die "Can't cope with $item";
668 $copy =~ s/([\'\\])/\\$1/gs;
669 push @lines, "'$copy',\n";
671 push @lines, "undef,\n";
679 ## Process UnicodeData.txt (Categories, etc.)
681 sub UnicodeData_Txt()
683 my $Bidi = Table->New();
684 my $Deco = Table->New();
685 my $Comb = Table->New();
686 my $Number = Table->New();
687 my $Mirrored = Table->New();#Is => 'Mirrored',
688 #Desc => "Mirrored in bidirectional text",
694 $DC{can} = Table->New();
695 $DC{com} = Table->New();
697 ## Initialize Perl-generated categories
698 ## (Categories from UnicodeData.txt are auto-initialized in gencat)
700 Table->New(Is => 'Alnum', Desc => "[[:Alnum:]]", Fuzzy => 0);
702 Table->New(Is => 'Alpha', Desc => "[[:Alpha:]]", Fuzzy => 0);
704 Table->New(Is => 'ASCII', Desc => "[[:ASCII:]]", Fuzzy => 0);
706 Table->New(Is => 'Blank', Desc => "[[:Blank:]]", Fuzzy => 0);
708 Table->New(Is => 'Cntrl', Desc => "[[:Cntrl:]]", Fuzzy => 0);
710 Table->New(Is => 'Digit', Desc => "[[:Digit:]]", Fuzzy => 0);
712 Table->New(Is => 'Graph', Desc => "[[:Graph:]]", Fuzzy => 0);
714 Table->New(Is => 'Lower', Desc => "[[:Lower:]]", Fuzzy => 0);
716 Table->New(Is => 'Print', Desc => "[[:Print:]]", Fuzzy => 0);
718 Table->New(Is => 'Punct', Desc => "[[:Punct:]]", Fuzzy => 0);
720 Table->New(Is => 'Space', Desc => "[[:Space:]]", Fuzzy => 0);
722 Table->New(Is => 'Title', Desc => "[[:Title:]]", Fuzzy => 0);
724 Table->New(Is => 'Upper', Desc => "[[:Upper:]]", Fuzzy => 0);
726 Table->New(Is => 'XDigit', Desc => "[[:XDigit:]]", Fuzzy => 0);
728 Table->New(Is => 'Word', Desc => "[[:Word:]]", Fuzzy => 0);
730 Table->New(Is => 'SpacePerl', Desc => '\s', Fuzzy => 0);
733 $To{Upper} = Table->New();
734 $To{Lower} = Table->New();
735 $To{Title} = Table->New();
736 $To{Digit} = Table->New();
740 my ($name, ## Name ("LATIN CAPITAL LETTER A")
741 $cat, ## Category ("Lu", "Zp", "Nd", etc.)
742 $code, ## Code point (as an integer)
745 my $MajorCat = substr($cat, 0, 1); ## L, M, Z, S, etc
747 $Assigned->$op($code);
748 $Name->$op($code, $name);
749 $General->$op($code, $cat);
751 ## add to the sub category (e.g. "Lu", "Nd", "Cf", ..)
752 $Cat{$cat} ||= Table->New(Is => $cat,
753 Desc => "General Category '$cat'",
755 $Cat{$cat}->$op($code);
757 ## add to the major category (e.g. "L", "N", "C", ...)
758 $Cat{$MajorCat} ||= Table->New(Is => $MajorCat,
759 Desc => "Major Category '$MajorCat'",
761 $Cat{$MajorCat}->$op($code);
763 ($General{$name} ||= Table->New)->$op($code, $name);
765 # 005F: SPACING UNDERSCORE
766 $Cat{Word}->$op($code) if $cat =~ /^[LMN]|Pc/;
767 $Cat{Alnum}->$op($code) if $cat =~ /^[LM]|Nd/;
768 $Cat{Alpha}->$op($code) if $cat =~ /^[LM]/;
771 ($cat =~ /Zs|Zl|Zp/ &&
772 $code != 0x200B) # 200B is ZWSP which is for line break control
773 # and therefore it is not part of "space" even while it is "Zs".
774 || $code == 0x0009 # 0009: HORIZONTAL TAB
775 || $code == 0x000A # 000A: LINE FEED
776 || $code == 0x000B # 000B: VERTICAL TAB
777 || $code == 0x000C # 000C: FORM FEED
778 || $code == 0x000D # 000D: CARRIAGE RETURN
779 || $code == 0x0085 # 0085: NEL
783 $Cat{Space}->$op($code) if $isspace;
785 $Cat{SpacePerl}->$op($code) if $isspace
786 && $code != 0x000B; # Backward compat.
788 $Cat{Blank}->$op($code) if $isspace
789 && !($code == 0x000A ||
796 $Cat{Digit}->$op($code) if $cat eq "Nd";
797 $Cat{Upper}->$op($code) if $cat eq "Lu";
798 $Cat{Lower}->$op($code) if $cat eq "Ll";
799 $Cat{Title}->$op($code) if $cat eq "Lt";
800 $Cat{ASCII}->$op($code) if $code <= 0x007F;
801 $Cat{Cntrl}->$op($code) if $cat =~ /^C/;
802 my $isgraph = !$isspace && $cat !~ /Cc|Cs|Cn/;
803 $Cat{Graph}->$op($code) if $isgraph;
804 $Cat{Print}->$op($code) if $isgraph || $isspace;
805 $Cat{Punct}->$op($code) if $cat =~ /^P/;
807 $Cat{XDigit}->$op($code) if ($code >= 0x30 && $code <= 0x39) ## 0..9
808 || ($code >= 0x41 && $code <= 0x46) ## A..F
809 || ($code >= 0x61 && $code <= 0x66); ## a..f
812 ## open ane read file.....
813 if (not open IN, "UnicodeData.txt") {
814 die "$0: UnicodeData.txt: $!\n";
818 ## For building \p{_CombAbove} and \p{_CanonDCIJ}
820 my %_Above_HexCodes; ## Hexcodes for chars with $comb == 230 ("ABOVE")
822 my %CodeToDeco; ## Maps code to decomp. list for chars with first
823 ## decomp. char an "i" or "j" (for \p{_CanonDCIJ})
825 ## This is filled in as we go....
826 my $CombAbove = Table->New(Is => '_CombAbove',
827 Desc => '(for internal casefolding use)',
832 next unless /^[0-9A-Fa-f]+;/;
835 my ($hexcode, ## code point in hex (e.g. "0041")
836 $name, ## character name (e.g. "LATIN CAPITAL LETTER A")
837 $cat, ## category (e.g. "Lu")
838 $comb, ## Canonical combining class (e.t. "230")
839 $bidi, ## directional category (e.g. "L")
840 $deco, ## decomposition mapping
841 $decimal, ## decimal digit value
842 $digit, ## digit value
843 $number, ## numeric value
844 $mirrored, ## mirrored
845 $unicode10, ## name in Unicode 1.0
846 $comment, ## comment field
847 $upper, ## uppercase mapping
848 $lower, ## lowercase mapping
849 $title, ## titlecase mapping
850 ) = split(/\s*;\s*/);
852 # Note that in Unicode 3.2 there will be names like
853 # LINE FEED (LF), which probably means that \N{} needs
854 # to cope also with LINE FEED and LF.
855 $name = $unicode10 if $name eq '<control>' && $unicode10 ne '';
857 my $code = hex($hexcode);
859 if ($comb and $comb == 230) {
860 $CombAbove->Append($code);
861 $_Above_HexCodes{$hexcode} = 1;
864 ## Used in building \p{_CanonDCIJ}
865 if ($deco and $deco =~ m/^006[9A]\b/) {
866 $CodeToDeco{$code} = $deco;
870 ## There are a few pairs of lines like:
871 ## AC00;<Hangul Syllable, First>;Lo;0;L;;;;;N;;;;;
872 ## D7A3;<Hangul Syllable, Last>;Lo;0;L;;;;;N;;;;;
873 ## that define ranges.
875 if ($name =~ /^<(.+), (First|Last)>$/)
878 gencat($name, $cat, $code, $2 eq 'First' ? 'Append' : 'Extend');
879 #New_Prop(In => $name, $General{$name}, Fuzzy => 1);
883 ## normal (single-character) lines
884 gencat($name, $cat, $code, 'Append');
886 # No Append() here since since several codes may map into one.
887 $To{Upper}->RawAppendRange($code, $code, $upper) if $upper;
888 $To{Lower}->RawAppendRange($code, $code, $lower) if $lower;
889 $To{Title}->RawAppendRange($code, $code, $title) if $title;
890 $To{Digit}->Append($code, $decimal) if length $decimal;
892 $Bidi->Append($code, $bidi);
893 $Comb->Append($code, $comb) if $comb;
894 $Number->Append($code, $number) if length $number;
896 length($decimal) and ($Number{De} ||= Table->New())->Append($code)
898 length($digit) and ($Number{Di} ||= Table->New())->Append($code)
900 length($number) and ($Number{Nu} ||= Table->New())->Append($code);
902 $Mirrored->Append($code) if $mirrored eq "Y";
904 $Bidi{$bidi} ||= Table->New();#Is => "bt/$bidi",
905 #Desc => "Bi-directional category '$bidi'",
907 $Bidi{$bidi}->Append($code);
911 $Deco->Append($code, $deco);
912 if ($deco =~/^<(\w+)>/)
914 my $dshort = $PVA_reverse{dt}{ucfirst lc $1};
915 $DC{com}->Append($code);
917 $DC{$dshort} ||= Table->New();
918 $DC{$dshort}->Append($code);
922 $DC{can}->Append($code);
930 ## Tidy up a few special cases....
933 $Cat{Cn} = $Assigned->Invert; ## Cn is everything that doesn't exist
936 Desc => "General Category 'Cn' [not functional in Perl]",
939 ## Unassigned is the same as 'Cn'
940 New_Alias(Is => 'Unassigned', SameAs => 'Cn', Fuzzy => 0);
942 $Cat{C}->Replace($Cat{C}->Merge($Cat{Cn})); ## Now merge in Cn into C
945 # LC is Ll, Lu, and Lt.
946 # (used to be L& or L_, but PropValueAliases.txt defines it as LC)
948 Table->Merge(@Cat{qw[Ll Lu Lt]}),
949 Desc => '[\p{Ll}\p{Lu}\p{Lt}]',
952 ## Any and All are all code points.
953 my $Any = Table->New(Is => 'Any',
954 Desc => sprintf("[\\x{0000}-\\x{%X}]",
955 $LastUnicodeCodepoint),
957 $Any->RawAppendRange(0, $LastUnicodeCodepoint);
959 New_Alias(Is => 'All', SameAs => 'Any', Fuzzy => 0);
962 ## Build special properties for Perl's internal case-folding needs:
963 ## \p{_CaseIgnorable}
966 ## _CombAbove was built above. Others are built here....
969 ## \p{_CaseIgnorable} is [\p{Mn}\0x00AD\x2010]
970 New_Prop(Is => '_CaseIgnorable',
971 Table->Merge($Cat{Mn},
974 Desc => '(for internal casefolding use)',
978 ## \p{_CanonDCIJ} is fairly complex...
979 my $CanonCDIJ = Table->New(Is => '_CanonDCIJ',
980 Desc => '(for internal casefolding use)',
982 ## It contains the ASCII 'i' and 'j'....
983 $CanonCDIJ->Append(0x0069); # ASCII ord("i")
984 $CanonCDIJ->Append(0x006A); # ASCII ord("j")
985 ## ...and any character with a decomposition that starts with either of
986 ## those code points, but only if the decomposition does not have any
987 ## combining character with the "ABOVE" canonical combining class.
988 for my $code (sort { $a <=> $b} keys %CodeToDeco)
990 ## Need to ensure that all decomposition characters do not have
991 ## a %HexCodeToComb in %AboveCombClasses.
993 for my $deco_hexcode (split / /, $CodeToDeco{$code})
995 if (exists $_Above_HexCodes{$deco_hexcode}) {
996 ## one of the decmposition chars has an ABOVE combination
997 ## class, so we're not interested in this one
1003 $CanonCDIJ->Append($code);
1010 ## Now dump the files.
1012 $Name->Write("Name.pl");
1016 foreach my $name (qw (PropertyAlias PA_reverse PropValueAlias
1017 PVA_reverse PVA_abbr_map)) {
1018 # Should I really jump through typeglob hoops just to avoid a
1019 # symbolic reference? (%{"utf8::$name})
1020 push @PVA, "\n", "\%utf8::$name = (\n",
1021 simple_dumper (%{$utf8::{$name}}), ");\n";
1023 WriteIfChanged("PVA.pl", @PVA);
1026 # $Bidi->Write("Bidirectional.pl");
1029 ["lib","bc","$_.pl"],
1030 "BidiClass category '$PropValueAlias{bc}{$_}'"
1034 $Comb->Write("CombiningClass.pl");
1035 for (keys %{ $PropValueAlias{ccc} }) {
1036 my ($code, $name) = @{ $PropValueAlias{ccc}{$_} };
1037 (my $c = Table->New())->Append($code);
1039 ["lib","ccc","$_.pl"],
1040 "CombiningClass category '$name'"
1044 $Deco->Write("Decomposition.pl");
1047 ["lib","dt","$_.pl"],
1048 "DecompositionType category '$PropValueAlias{dt}{$_}'"
1052 # $Number->Write("Number.pl");
1053 for (keys %Number) {
1055 ["lib","nt","$_.pl"],
1056 "NumericType category '$PropValueAlias{nt}{$_}'"
1060 # $General->Write("Category.pl");
1062 for my $to (sort keys %To) {
1063 $To{$to}->Write(["To","$to.pl"]);
1066 for (keys %{ $PropValueAlias{gc} }) {
1067 New_Alias(Is => $PropValueAlias{gc}{$_}, SameAs => $_, Fuzzy => 1);
1072 ## Process LineBreak.txt
1076 if (not open IN, "LineBreak.txt") {
1077 die "$0: LineBreak.txt: $!\n";
1080 my $Lbrk = Table->New();
1085 next unless /^([0-9A-Fa-f]+)(?:\.\.([0-9A-Fa-f]+))?\s*;\s*(\w+)/;
1087 my ($first, $last, $lbrk) = (hex($1), hex($2||""), $3);
1089 $Lbrk->Append($first, $lbrk);
1091 $Lbrk{$lbrk} ||= Table->New();
1092 $Lbrk{$lbrk}->Append($first);
1095 $Lbrk->Extend($last);
1096 $Lbrk{$lbrk}->Extend($last);
1101 # $Lbrk->Write("Lbrk.pl");
1106 ["lib","lb","$_.pl"],
1107 "Linebreak category '$PropValueAlias{lb}{$_}'"
1113 ## Process ArabicShaping.txt.
1115 sub ArabicShaping_txt()
1117 if (not open IN, "ArabicShaping.txt") {
1118 die "$0: ArabicShaping.txt: $!\n";
1121 my $ArabLink = Table->New();
1122 my $ArabLinkGroup = Table->New();
1128 next unless /^[0-9A-Fa-f]+;/;
1131 my ($hexcode, $name, $link, $linkgroup) = split(/\s*;\s*/);
1132 my $code = hex($hexcode);
1133 $ArabLink->Append($code, $link);
1134 $ArabLinkGroup->Append($code, $linkgroup);
1136 $JoinType{$link} ||= Table->New(Is => "JoinType$link");
1137 $JoinType{$link}->Append($code);
1141 # $ArabLink->Write("ArabLink.pl");
1142 # $ArabLinkGroup->Write("ArabLnkGrp.pl");
1145 for (keys %JoinType) {
1146 $JoinType{$_}->Write(
1147 ["lib","jt","$_.pl"],
1148 "JoiningType category '$PropValueAlias{jt}{$_}'"
1154 ## Process EastAsianWidth.txt.
1156 sub EastAsianWidth_txt()
1158 if (not open IN, "EastAsianWidth.txt") {
1159 die "$0: EastAsianWidth.txt: $!\n";
1166 next unless /^[0-9A-Fa-f]+;/;
1170 my ($hexcode, $pv) = split(/\s*;\s*/);
1171 my $code = hex($hexcode);
1172 $EAW{$pv} ||= Table->New(Is => "EastAsianWidth$pv");
1173 $EAW{$pv}->Append($code);
1180 ["lib","ea","$_.pl"],
1181 "EastAsianWidth category '$PropValueAlias{ea}{$_}'"
1187 ## Process HangulSyllableType.txt.
1189 sub HangulSyllableType_txt()
1191 if (not open IN, "HangulSyllableType.txt") {
1192 die "$0: HangulSyllableType.txt: $!\n";
1199 next unless /^([0-9A-Fa-f]+)(?:\.\.([0-9A-Fa-f]+))?\s*;\s*(\w+)/;
1200 my ($first, $last, $pv) = (hex($1), hex($2||""), $3);
1202 $HST{$pv} ||= Table->New(Is => "HangulSyllableType$pv");
1203 $HST{$pv}->Append($first);
1205 if ($last) { $HST{$pv}->Extend($last) }
1211 ["lib","hst","$_.pl"],
1212 "HangulSyllableType category '$PropValueAlias{hst}{$_}'"
1218 ## Process Jamo.txt.
1222 if (not open IN, "Jamo.txt") {
1223 die "$0: Jamo.txt: $!\n";
1225 my $Short = Table->New();
1229 next unless /^([0-9A-Fa-f]+)\s*;\s*(\w*)/;
1230 my ($code, $short) = (hex($1), $2);
1232 $Short->Append($code, $short);
1235 # $Short->Write("JamoShort.pl");
1239 ## Process Scripts.txt.
1245 if (not open(IN, "Scripts.txt")) {
1246 die "$0: Scripts.txt: $!\n";
1249 next unless /^([0-9A-Fa-f]+)(?:\.\.([0-9A-Fa-f]+))?\s*;\s*(.+?)\s*\#/;
1251 # Wait until all the scripts have been read since
1252 # they are not listed in numeric order.
1253 push @ScriptInfo, [ hex($1), hex($2||""), $3 ];
1257 # Now append the scripts properties in their code point order.
1260 my $Scripts = Table->New();
1262 for my $script (sort { $a->[0] <=> $b->[0] } @ScriptInfo)
1264 my ($first, $last, $name) = @$script;
1265 $Scripts->Append($first, $name);
1267 $Script{$name} ||= Table->New(Is => $name,
1268 Desc => "Script '$name'",
1270 $Script{$name}->Append($first, $name);
1273 $Scripts->Extend($last);
1274 $Script{$name}->Extend($last);
1278 # $Scripts->Write("Scripts.pl");
1280 ## Common is everything not explicitly assigned to a Script
1282 ## ***shouldn't this be intersected with \p{Assigned}? ******
1284 New_Prop(Is => 'Common',
1286 Desc => 'Pseudo-Script of codepoints not in other Unicode scripts',
1291 ## Given a name like "Close Punctuation", return a regex (that when applied
1292 ## with /i) matches any valid form of that name (e.g. "ClosePunctuation",
1293 ## "Close-Punctuation", etc.)
1295 ## Accept any space, dash, or underbar where in the official name there is
1296 ## space or a dash (or underbar, but there never is).
1302 $Name =~ s/[- _]/(?:[-_]|\\s+)?/g;
1307 ## Process Blocks.txt.
1311 my $Blocks = Table->New();
1314 if (not open IN, "Blocks.txt") {
1315 die "$0: Blocks.txt: $!\n";
1320 #next if not /Private Use$/;
1321 next if not /^([0-9A-Fa-f]+)\.\.([0-9A-Fa-f]+)\s*;\s*(.+?)\s*$/;
1323 my ($first, $last, $name) = (hex($1), hex($2), $3);
1325 $Blocks->Append($first, $name);
1327 $Blocks{$name} ||= Table->New(In => $name,
1328 Desc => "Block '$name'",
1330 $Blocks{$name}->Append($first, $name);
1332 if ($last and $last != $first) {
1333 $Blocks->Extend($last);
1334 $Blocks{$name}->Extend($last);
1339 # $Blocks->Write("Blocks.pl");
1343 ## Read in the PropList.txt. It contains extended properties not
1344 ## listed in the UnicodeData.txt, such as 'Other_Alphabetic':
1345 ## alphabetic but not of the general category L; many modifiers
1346 ## belong to this extended property category: while they are not
1347 ## alphabets, they are alphabetic in nature.
1353 if (not open IN, "PropList.txt") {
1354 die "$0: PropList.txt: $!\n";
1359 next unless /^([0-9A-Fa-f]+)(?:\.\.([0-9A-Fa-f]+))?\s*;\s*(.+?)\s*\#/;
1361 # Wait until all the extended properties have been read since
1362 # they are not listed in numeric order.
1363 push @PropInfo, [ hex($1), hex($2||""), $3 ];
1367 # Now append the extended properties in their code point order.
1368 my $Props = Table->New();
1371 for my $prop (sort { $a->[0] <=> $b->[0] } @PropInfo)
1373 my ($first, $last, $name) = @$prop;
1374 $Props->Append($first, $name);
1376 $Prop{$name} ||= Table->New(Is => $name,
1377 Desc => "Extended property '$name'",
1379 $Prop{$name}->Append($first, $name);
1382 $Props->Extend($last);
1383 $Prop{$name}->Extend($last);
1388 (my $file = $PA_reverse{$_}) =~ tr/_//d;
1389 # XXX I'm assuming that the names from %Prop don't suffer 8.3 clashes.
1390 $BaseNames{lc $file}++;
1392 ["lib","gc_sc","$file.pl"],
1393 "Binary property '$_'"
1397 # Alphabetic is L and Other_Alphabetic.
1398 New_Prop(Is => 'Alphabetic',
1399 Table->Merge($Cat{L}, $Prop{Other_Alphabetic}),
1400 Desc => '[\p{L}\p{OtherAlphabetic}]', # use canonical names here
1403 # Lowercase is Ll and Other_Lowercase.
1404 New_Prop(Is => 'Lowercase',
1405 Table->Merge($Cat{Ll}, $Prop{Other_Lowercase}),
1406 Desc => '[\p{Ll}\p{OtherLowercase}]', # use canonical names here
1409 # Uppercase is Lu and Other_Uppercase.
1410 New_Prop(Is => 'Uppercase',
1411 Table->Merge($Cat{Lu}, $Prop{Other_Uppercase}),
1412 Desc => '[\p{Lu}\p{Other_Uppercase}]', # use canonical names here
1415 # Math is Sm and Other_Math.
1416 New_Prop(Is => 'Math',
1417 Table->Merge($Cat{Sm}, $Prop{Other_Math}),
1418 Desc => '[\p{Sm}\p{OtherMath}]', # use canonical names here
1421 # ID_Start is Ll, Lu, Lt, Lm, Lo, and Nl.
1422 New_Prop(Is => 'ID_Start',
1423 Table->Merge(@Cat{qw[Ll Lu Lt Lm Lo Nl]}),
1424 Desc => '[\p{Ll}\p{Lu}\p{Lt}\p{Lm}\p{Lo}\p{Nl}]',
1427 # ID_Continue is ID_Start, Mn, Mc, Nd, and Pc.
1428 New_Prop(Is => 'ID_Continue',
1429 Table->Merge(@Cat{qw[Ll Lu Lt Lm Lo Nl Mn Mc Nd Pc ]}),
1430 Desc => '[\p{ID_Start}\p{Mn}\p{Mc}\p{Nd}\p{Pc}]',
1436 ## These are used in:
1437 ## MakePropTestScript()
1438 ## WriteAllMappings()
1439 ## for making the test script.
1441 my %FuzzyNameToTest;
1442 my %ExactNameToTest;
1445 ## This used only for making the test script
1450 my $MatchCode = shift;
1451 my $FailCode = shift;
1453 if (defined $MatchCode) {
1454 printf $FH qq/Expect(1, "\\x{%04X}", '\\p{$Prop}' );\n/, $MatchCode;
1455 printf $FH qq/Expect(0, "\\x{%04X}", '\\p{^$Prop}');\n/, $MatchCode;
1456 printf $FH qq/Expect(0, "\\x{%04X}", '\\P{$Prop}' );\n/, $MatchCode;
1457 printf $FH qq/Expect(1, "\\x{%04X}", '\\P{^$Prop}');\n/, $MatchCode;
1459 if (defined $FailCode) {
1460 printf $FH qq/Expect(0, "\\x{%04X}", '\\p{$Prop}' );\n/, $FailCode;
1461 printf $FH qq/Expect(1, "\\x{%04X}", '\\p{^$Prop}');\n/, $FailCode;
1462 printf $FH qq/Expect(1, "\\x{%04X}", '\\P{$Prop}' );\n/, $FailCode;
1463 printf $FH qq/Expect(0, "\\x{%04X}", '\\P{^$Prop}');\n/, $FailCode;
1467 ## This used only for making the test script
1473 print $FH qq/Error('\\p{$prop}');\n/;
1474 print $FH qq/Error('\\P{$prop}');\n/;
1477 ## This used only for making the test script
1493 ## This used only for making the test script
1494 sub RandomlyFuzzifyName($;$)
1497 my $WantError = shift; ## if true, make an error
1500 for my $part (split /[-\s_]+/, $Name)
1503 if ($WantError and rand() < 0.3) {
1504 push @parts, $BadSeps[rand(@BadSeps)];
1507 push @parts, $GoodSeps[rand(@GoodSeps)];
1510 my $switch = int rand(4);
1512 push @parts, uc $part;
1513 } elsif ($switch == 1) {
1514 push @parts, lc $part;
1515 } elsif ($switch == 2) {
1516 push @parts, ucfirst $part;
1521 my $new = join('', @parts);
1524 if (rand() >= 0.5) {
1525 $new .= $BadSeps[rand(@BadSeps)];
1527 $new = $BadSeps[rand(@BadSeps)] . $new;
1533 ## This used only for making the test script
1534 sub MakePropTestScript()
1536 ## this written directly -- it's huge.
1537 force_unlink ("TestProp.pl");
1538 if (not open OUT, ">TestProp.pl") {
1539 die "$0: TestProp.pl: $!\n";
1543 while (my ($Name, $Table) = each %ExactNameToTest)
1545 GenTests(*OUT, $Name, $Table->ValidCode, $Table->InvalidCode);
1546 ExpectError(*OUT, uc $Name) if uc $Name ne $Name;
1547 ExpectError(*OUT, lc $Name) if lc $Name ne $Name;
1551 while (my ($Name, $Table) = each %FuzzyNameToTest)
1553 my $Orig = $CanonicalToOrig{$Name};
1557 RandomlyFuzzifyName($Orig) => 1
1560 for my $N (keys %Names) {
1561 GenTests(*OUT, $N, $Table->ValidCode, $Table->InvalidCode);
1564 ExpectError(*OUT, RandomlyFuzzifyName($Orig, 'ERROR'));
1567 print OUT "Finished();\n";
1573 ## These are used only in:
1574 ## RegisterFileForName()
1575 ## WriteAllMappings()
1577 my %Exact; ## will become %utf8::Exact;
1578 my %Canonical; ## will become %utf8::Canonical;
1579 my %CaComment; ## Comment for %Canonical entry of same key
1582 ## Given info about a name and a datafile that it should be associated with,
1583 ## register that assocation in %Exact and %Canonical.
1584 sub RegisterFileForName($$$$)
1588 my $IsFuzzy = shift;
1589 my $filename = shift;
1592 ## Now in details for the mapping. $Type eq 'Is' has the
1593 ## Is removed, as it will be removed in utf8_heavy when this
1594 ## data is being checked. In keeps its "In", but a second
1595 ## sans-In record is written if it doesn't conflict with
1596 ## anything already there.
1600 if ($Type eq 'Is') {
1601 die "oops[$Name]" if $Exact{$Name};
1602 $Exact{$Name} = $filename;
1604 die "oops[$Type$Name]" if $Exact{"$Type$Name"};
1605 $Exact{"$Type$Name"} = $filename;
1606 $Exact{$Name} = $filename if not $Exact{$Name};
1611 my $CName = lc $Name;
1612 if ($Type eq 'Is') {
1613 die "oops[$CName]" if $Canonical{$CName};
1614 $Canonical{$CName} = $filename;
1615 $CaComment{$CName} = $Name if $Name =~ tr/A-Z// >= 2;
1617 die "oops[$Type$CName]" if $Canonical{lc "$Type$CName"};
1618 $Canonical{lc "$Type$CName"} = $filename;
1619 $CaComment{lc "$Type$CName"} = "$Type$Name";
1620 if (not $Canonical{$CName}) {
1621 $Canonical{$CName} = $filename;
1622 $CaComment{$CName} = "$Type$Name";
1629 ## Writes the info accumulated in
1636 sub WriteAllMappings()
1640 ## 'Is' *MUST* come first, so its names have precidence over 'In's
1641 for my $Type ('Is', 'In')
1643 my %RawNameToFile; ## a per-$Type cache
1645 for my $Name (sort {length $a <=> length $b} keys %{$TableInfo{$Type}})
1647 ## Note: $Name is already canonical
1648 my $Table = $TableInfo{$Type}->{$Name};
1649 my $IsFuzzy = $FuzzyNames{$Type}->{$Name};
1651 ## Need an 8.3 safe filename (which means "an 8 safe" $filename)
1654 ## 'Is' items lose 'Is' from the basename.
1655 $filename = $Type eq 'Is' ?
1656 ($PVA_reverse{sc}{$Name} || $Name) :
1659 $filename =~ s/[^\w_]+/_/g; # "L&" -> "L_"
1660 substr($filename, 8) = '' if length($filename) > 8;
1663 ## Make sure the basename doesn't conflict with something we
1664 ## might have already written. If we have, say,
1671 while (my $num = $BaseNames{lc $filename}++)
1673 $num++; ## so basenames with numbers start with '2', which
1674 ## just looks more natural.
1675 ## Want to append $num, but if it'll make the basename longer
1676 ## than 8 characters, pre-truncate $filename so that the result
1678 my $delta = length($filename) + length($num) - 8;
1680 substr($filename, -$delta) = $num;
1688 ## Construct a nice comment to add to the file, and build data
1689 ## for the "./Properties" file along the way.
1693 my $Desc = $TableDesc{$Type}->{$Name} || "";
1694 ## get list of names this table is reference by
1695 my @Supported = $Name;
1696 while (my ($Orig, $Alias) = each %{ $AliasInfo{$Type} })
1698 if ($Orig eq $Name) {
1699 push @Supported, $Alias;
1703 my $TypeToShow = $Type eq 'Is' ? "" : $Type;
1706 $Comment = "This file supports:\n";
1707 for my $N (@Supported)
1709 my $IsFuzzy = $FuzzyNames{$Type}->{$N};
1710 my $Prop = "\\p{$TypeToShow$Name}";
1711 $OrigProp = $Prop if not $OrigProp; #cache for aliases
1713 $Comment .= "\t$Prop (and fuzzy permutations)\n";
1715 $Comment .= "\t$Prop\n";
1717 my $MyDesc = ($N eq $Name) ? $Desc : "Alias for $OrigProp ($Desc)";
1719 push @MAP, sprintf("%s %-42s %s\n",
1720 $IsFuzzy ? '*' : ' ', $Prop, $MyDesc);
1723 $Comment .= "\nMeaning: $Desc\n";
1728 ## Okay, write the file...
1730 $Table->Write(["lib","gc_sc","$filename.pl"], $Comment);
1733 $RawNameToFile{$Name} = $filename;
1734 RegisterFileForName($Type => $Name, $IsFuzzy, $filename);
1738 my $CName = CanonicalName($Type . '_'. $Name);
1739 $FuzzyNameToTest{$Name} = $Table if !$FuzzyNameToTest{$Name};
1740 $FuzzyNameToTest{$CName} = $Table if !$FuzzyNameToTest{$CName};
1742 $ExactNameToTest{$Name} = $Table;
1747 ## Register aliase info
1748 for my $Name (sort {length $a <=> length $b} keys %{$AliasInfo{$Type}})
1750 my $Alias = $AliasInfo{$Type}->{$Name};
1751 my $IsFuzzy = $FuzzyNames{$Type}->{$Alias};
1752 my $filename = $RawNameToFile{$Name};
1753 die "oops [$Alias]->[$Name]" if not $filename;
1754 RegisterFileForName($Type => $Alias, $IsFuzzy, $filename);
1756 my $Table = $TableInfo{$Type}->{$Name};
1757 die "oops" if not $Table;
1760 my $CName = CanonicalName($Type .'_'. $Alias);
1761 $FuzzyNameToTest{$Alias} = $Table if !$FuzzyNameToTest{$Alias};
1762 $FuzzyNameToTest{$CName} = $Table if !$FuzzyNameToTest{$CName};
1764 $ExactNameToTest{$Alias} = $Table;
1770 ## Write out the property list
1775 "## This file created by $0\n",
1776 "## List of built-in \\p{...}/\\P{...} properties.\n",
1778 "## '*' means name may be 'fuzzy'\n",
1780 sort { substr($a,2) cmp substr($b, 2) } @MAP,
1782 WriteIfChanged('Properties', @OUT);
1785 use Text::Tabs (); ## using this makes the files about half the size
1792 "## Data in this file used by ../utf8_heavy.pl\n",
1794 "## Mapping from name to filename in ./lib/gc_sc\n",
1795 "%utf8::Exact = (\n",
1798 $Exact{InGreek} = 'InGreekA'; # this is evil kludge
1799 for my $Name (sort keys %Exact)
1801 my $File = $Exact{$Name};
1802 $Name = $Name =~ m/\W/ ? qq/'$Name'/ : " $Name ";
1803 my $Text = sprintf("%-15s => %s,\n", $Name, qq/'$File'/);
1804 push @OUT, Text::Tabs::unexpand($Text);
1806 push @OUT, ");\n1;\n";
1808 WriteIfChanged('Exact.pl', @OUT);
1811 ## Write Canonical.pl
1816 "## Data in this file used by ../utf8_heavy.pl\n",
1818 "## Mapping from lc(canonical name) to filename in ./lib\n",
1819 "%utf8::Canonical = (\n",
1821 my $Trail = ""; ## used just to keep the spacing pretty
1822 for my $Name (sort keys %Canonical)
1824 my $File = $Canonical{$Name};
1825 if ($CaComment{$Name}) {
1826 push @OUT, "\n" if not $Trail;
1827 push @OUT, " # $CaComment{$Name}\n";
1832 $Name = $Name =~ m/\W/ ? qq/'$Name'/ : " $Name ";
1833 my $Text = sprintf(" %-41s => %s,\n$Trail", $Name, qq/'$File'/);
1834 push @OUT, Text::Tabs::unexpand($Text);
1836 push @OUT, ");\n1\n";
1837 WriteIfChanged('Canonical.pl', @OUT);
1840 MakePropTestScript() if $MakeTestScript;
1844 sub SpecialCasing_txt()
1847 # Read in the special cases.
1852 if (not open IN, "SpecialCasing.txt") {
1853 die "$0: SpecialCasing.txt: $!\n";
1856 next unless /^[0-9A-Fa-f]+;/;
1860 my ($code, $lower, $title, $upper, $condition) = split(/\s*;\s*/);
1862 if ($condition) { # not implemented yet
1863 print "# SKIPPING $_\n" if $Verbose;
1867 # Wait until all the special cases have been read since
1868 # they are not listed in numeric order.
1869 my $ix = hex($code);
1870 push @{$CaseInfo{Lower}}, [ $ix, $code, $lower ]
1871 unless $code eq $lower;
1872 push @{$CaseInfo{Title}}, [ $ix, $code, $title ]
1873 unless $code eq $title;
1874 push @{$CaseInfo{Upper}}, [ $ix, $code, $upper ]
1875 unless $code eq $upper;
1879 # Now write out the special cases properties in their code point order.
1880 # Prepend them to the To/{Upper,Lower,Title}.pl.
1882 for my $case (qw(Lower Title Upper))
1884 my $NormalCase = do "To/$case.pl" || die "$0: $@\n";
1889 "# The key UTF-8 _bytes_, the value UTF-8 (speed hack)\n",
1890 "%utf8::ToSpec$case =\n(\n",
1893 for my $prop (sort { $a->[0] <=> $b->[0] } @{$CaseInfo{$case}}) {
1894 my ($ix, $code, $to) = @$prop;
1896 join "", map { sprintf "\\x{%s}", $_ } split ' ', $to;
1897 push @OUT, sprintf qq["%s" => "$tostr",\n], join("", map { sprintf "\\x%02X", $_ } unpack("U0C*", pack("U", $ix)));
1898 # Remove any single-character mappings for
1899 # the same character since we are going for
1900 # the special casing rules.
1901 $NormalCase =~ s/^$code\t\t\w+\n//m;
1905 "return <<'END';\n",
1909 WriteIfChanged(["To","$case.pl"], @OUT);
1914 # Read in the case foldings.
1916 # We will do full case folding, C + F + I (see CaseFolding.txt).
1918 sub CaseFolding_txt()
1920 if (not open IN, "CaseFolding.txt") {
1921 die "$0: CaseFolding.txt: $!\n";
1924 my $Fold = Table->New();
1928 # Skip status 'S', simple case folding
1929 next unless /^([0-9A-Fa-f]+)\s*;\s*([CFI])\s*;\s*([0-9A-Fa-f]+(?: [0-9A-Fa-f]+)*)\s*;/;
1931 my ($code, $status, $fold) = (hex($1), $2, $3);
1933 if ($status eq 'C') { # Common: one-to-one folding
1934 # No append() since several codes may fold into one.
1935 $Fold->RawAppendRange($code, $code, $fold);
1936 } else { # F: full, or I: dotted uppercase I -> dotless lowercase I
1937 $Fold{$code} = $fold;
1942 $Fold->Write("To/Fold.pl");
1945 # Prepend the special foldings to the common foldings.
1947 my $CommonFold = do "To/Fold.pl" || die "$0: To/Fold.pl: $!\n";
1952 "# The ke UTF-8 _bytes_, the value UTF-8 (speed hack)\n",
1953 "%utf8::ToSpecFold =\n(\n",
1955 for my $code (sort { $a <=> $b } keys %Fold) {
1957 join "", map { sprintf "\\x{%s}", $_ } split ' ', $Fold{$code};
1958 push @OUT, sprintf qq["%s" => "$foldstr",\n], join("", map { sprintf "\\x%02X", $_ } unpack("U0C*", pack("U", $code)));
1962 "return <<'END';\n",
1967 WriteIfChanged(["To","Fold.pl"], @OUT);
1982 ArabicShaping_txt();
1983 EastAsianWidth_txt();
1984 HangulSyllableType_txt();
1986 SpecialCasing_txt();
1991 ## TRAILING CODE IS USED BY MakePropTestScript()
2004 my $Line = (caller)[2];
2009 $RegObj = qr/$Regex/;
2010 $String =~ $RegObj ? 1 : 0
2013 if (not defined $result) {
2014 print "couldn't compile /$Regex/ on $0 line $Line: $@\n";
2016 } elsif ($result ^ $Expect) {
2017 print "bad result (expected $Expect) on $0 line $Line: $@\n";
2026 if (eval { 'x' =~ qr/$Regex/; 1 }) {
2028 my $Line = (caller)[2];
2029 print "expected error for /$Regex/ on $0 line $Line: $@\n";
2036 print "All $Tests tests passed.\n";
2039 print "$Tests tests, $Fails failed!\n";