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)
30 my $MakeTestScript = 0;
34 my $arg = shift @ARGV;
37 } elsif ($arg eq '-q') {
39 } elsif ($arg eq '-maketest') {
41 } elsif ($arg eq '-C' && defined (my $dir = shift)) {
42 chdir $dir or die "chdir $_: $!";
44 die "usage: $0 [-v|-q|-C dir] [-maketest]";
48 foreach my $lib ('To', 'lib',
49 map {File::Spec->catdir("lib",$_)}
50 qw(gc_sc dt bc hst ea jt lb nt ccc)) {
52 mkdir $lib, 0755 or die "mkdir '$lib': $!";
55 my $LastUnicodeCodepoint = 0x10FFFF; # As of Unicode 3.1.1.
58 # !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
59 # This file is built by $0 from e.g. UnicodeData.txt.
60 # Any changes made here will be lost!
66 return unless -e $filename;
67 return if CORE::unlink($filename);
68 # We might need write permission
69 chmod 0777, $filename;
70 CORE::unlink($filename) or die "Couldn't unlink $filename: $!\n";
74 ## Given a filename and a reference to an array of lines,
75 ## write the lines to the file only if the contents have not changed.
76 ## Filename can be given as an arrayref of directory names
78 sub WriteIfChanged($\@)
83 $file = File::Spec->catfile(@$file) if ref $file;
85 my $TextToWrite = join '', @$lines;
88 my $PreviousText = <IN>;
90 if ($PreviousText eq $TextToWrite) {
91 print "$file unchanged.\n" if $Verbose;
96 if (not open OUT, ">$file") {
97 die "$0: can't open $file for output: $!\n";
99 print "$file written.\n" if $Verbose;
101 print OUT $TextToWrite;
106 ## The main datastructure (a "Table") represents a set of code points that
107 ## are part of a particular quality (that are part of \pL, \p{InGreek},
108 ## etc.). They are kept as ranges of code points (starting and ending of
111 ## For example, a range ASCII LETTERS would be represented as:
112 ## [ [ 0x41 => 0x5A, 'UPPER' ],
113 ## [ 0x61 => 0x7A, 'LOWER, ] ]
115 sub RANGE_START() { 0 } ## index into range element
116 sub RANGE_END() { 1 } ## index into range element
117 sub RANGE_NAME() { 2 } ## index into range element
119 ## Conceptually, these should really be folded into the 'Table' objects
127 ## Turn something like
136 $name =~ s/(?<![a-z])(\w)/\u$1/g;
137 $name =~ s/[-_\s]+//g;
139 $CanonicalToOrig{$name} = $orig if not $CanonicalToOrig{$name};
145 ## Store the alias definitions for later use.
156 ## Most of the work with aliases doesn't occur here,
157 ## but rather in utf8_heavy.pl, which uses utf8_pva.pl,
158 ## which contains just this function. However, this one
160 ## -- japhy (2004/04/13)
162 open PA, "< PropertyAliases.txt"
163 or confess "Can't open PropertyAliases.txt: $!";
169 my ($abbrev, $name) = split /\s*;\s*/;
170 next if $abbrev eq "n/a";
171 $PropertyAlias{$abbrev} = $name;
172 $PA_reverse{$name} = $abbrev;
176 open PVA, "< PropValueAliases.txt"
177 or confess "Can't open PropValueAliases.txt: $!";
183 my ($prop, @data) = split /\s*;\s*/;
185 if ($prop eq 'ccc') {
186 $PropValueAlias{$prop}{$data[1]} = [ @data[0,2] ];
187 $PVA_reverse{$prop}{$data[2]} = [ @data[0,1] ];
190 next if $data[0] eq "n/a";
191 $PropValueAlias{$prop}{$data[0]} = $data[1];
192 $PVA_reverse{$prop}{$data[1]} = $data[0];
200 ## Associates a property ("Greek", "Lu", "Assigned",...) with a Table.
203 ## New_Prop(In => 'Greek', $Table, Desc => 'Greek Block', Fuzzy => 1);
205 ## Normally, these parameters are set when the Table is created (when the
206 ## Table->New constructor is called), but there are times when it needs to
207 ## be done after-the-fact...)
211 my $Type = shift; ## "Is" or "In";
215 ## remaining args are optional key/val
218 my $Fuzzy = delete $Args{Fuzzy};
219 my $Desc = delete $Args{Desc}; # description
221 $Name = CanonicalName($Name) if $Fuzzy;
223 ## sanity check a few args
224 if (%Args or ($Type ne 'Is' and $Type ne 'In') or not ref $Table) {
225 confess "$0: bad args to New_Prop"
228 if (not $TableInfo{$Type}->{$Name})
230 $TableInfo{$Type}->{$Name} = $Table;
231 $TableDesc{$Type}->{$Name} = $Desc;
233 $FuzzyNames{$Type}->{$Name} = $Name;
240 ## Creates a new Table object.
242 ## Args are key/value pairs:
243 ## In => Name -- Name of "In" property to be associated with
244 ## Is => Name -- Name of "Is" property to be associated with
245 ## Fuzzy => Boolean -- True if name can be accessed "fuzzily"
246 ## Desc => String -- Description of the property
248 ## No args are required.
255 my $Table = bless [], $class;
257 my $Fuzzy = delete $Args{Fuzzy};
258 my $Desc = delete $Args{Desc};
260 for my $Type ('Is', 'In')
262 if (my $Name = delete $Args{$Type}) {
263 New_Prop($Type => $Name, $Table, Desc => $Desc, Fuzzy => $Fuzzy);
267 ## shouldn't have any left over
269 confess "$0: bad args to Table->New"
276 ## Returns true if the Table has no code points
280 my $Table = shift; #self
285 ## Returns true if the Table has code points
289 my $Table = shift; #self
294 ## Returns the maximum code point currently in the table.
298 my $Table = shift; #self
299 confess "oops" if $Table->IsEmpty; ## must have code points to have a max
300 return $Table->[-1]->[RANGE_END];
304 ## Replaces the codepoints in the Table with those in the Table given
305 ## as an arg. (NOTE: this is not a "deep copy").
307 sub Table::Replace($$)
309 my $Table = shift; #self
316 ## Given a new code point, make the last range of the Table extend to
317 ## include the new (and all intervening) code points.
321 my $Table = shift; #self
322 my $codepoint = shift;
324 my $PrevMax = $Table->Max;
326 confess "oops ($codepoint <= $PrevMax)" if $codepoint <= $PrevMax;
328 $Table->[-1]->[RANGE_END] = $codepoint;
332 ## Given a code point range start and end (and optional name), blindly
333 ## append them to the list of ranges for the Table.
335 ## NOTE: Code points must be added in strictly ascending numeric order.
337 sub Table::RawAppendRange
339 my $Table = shift; #self
343 $name = "" if not defined $name; ## warning: $name can be "0"
345 push @$Table, [ $start, # RANGE_START
347 $name ]; # RANGE_NAME
351 ## Given a code point (and optional name), add it to the Table.
353 ## NOTE: Code points must be added in strictly ascending numeric order.
357 my $Table = shift; #self
358 my $codepoint = shift;
360 $name = "" if not defined $name; ## warning: $name can be "0"
363 ## If we've already got a range working, and this code point is the next
364 ## one in line, and if the name is the same, just extend the current range.
368 $Table->Max == $codepoint - 1
370 $Table->[-1]->[RANGE_NAME] eq $name)
372 $Table->Extend($codepoint);
376 $Table->RawAppendRange($codepoint, $codepoint, $name);
381 ## Given a code point range starting value and ending value (and name),
382 ## Add the range to teh Table.
384 ## NOTE: Code points must be added in strictly ascending numeric order.
386 sub Table::AppendRange
388 my $Table = shift; #self
392 $name = "" if not defined $name; ## warning: $name can be "0"
394 $Table->Append($start, $name);
395 $Table->Extend($end) if $end > $start;
399 ## Return a new Table that represents all code points not in the Table.
403 my $Table = shift; #self
405 my $New = Table->New();
407 for my $range (@$Table)
409 my $start = $range->[RANGE_START];
410 my $end = $range->[RANGE_END];
411 if ($start-1 >= $max+1) {
412 $New->AppendRange($max+1, $start-1, "");
416 if ($max+1 < $LastUnicodeCodepoint) {
417 $New->AppendRange($max+1, $LastUnicodeCodepoint);
423 ## Merges any number of other tables with $self, returning the new table.
424 ## (existing tables are not modified)
427 ## Args may be Tables, or individual code points (as integers).
429 ## Can be called as either a constructor or a method.
433 shift(@_) if not ref $_[0]; ## if called as a constructor, lose the class
436 ## Accumulate all records from all tables
438 for my $Arg (@Tables)
441 ## arg is a table -- get its ranges
442 push @Records, @$Arg;
444 ## arg is a codepoint, make a range
445 push @Records, [ $Arg, $Arg ]
449 ## sort by range start, with longer ranges coming first.
450 my ($first, @Rest) = sort {
451 ($a->[RANGE_START] <=> $b->[RANGE_START])
453 ($b->[RANGE_END] <=> $b->[RANGE_END])
456 my $New = Table->New();
458 ## Ensuring the first range is there makes the subsequent loop easier
459 $New->AppendRange($first->[RANGE_START],
460 $first->[RANGE_END]);
462 ## Fold in records so long as they add new information.
465 my $start = $set->[RANGE_START];
466 my $end = $set->[RANGE_END];
467 if ($start > $New->Max) {
468 $New->AppendRange($start, $end);
469 } elsif ($end > $New->Max) {
478 ## Given a filename, write a representation of the Table to a file.
479 ## May have an optional comment as a 2nd arg.
480 ## Filename may actually be an arrayref of directories
484 my $Table = shift; #self
485 my $filename = shift;
489 if (defined $comment) {
490 $comment =~ s/\s+\Z//;
491 $comment =~ s/^/# /gm;
492 push @OUT, "#\n$comment\n#\n";
494 push @OUT, "return <<'END';\n";
496 for my $set (@$Table)
498 my $start = $set->[RANGE_START];
499 my $end = $set->[RANGE_END];
500 my $name = $set->[RANGE_NAME];
502 if ($start == $end) {
503 push @OUT, sprintf "%04X\t\t%s\n", $start, $name;
505 push @OUT, sprintf "%04X\t%04X\t%s\n", $start, $end, $name;
511 WriteIfChanged($filename, @OUT);
514 ## This used only for making the test script.
519 return 0 if $code <= 0x0000; ## don't use null
520 return 0 if $code >= $LastUnicodeCodepoint; ## keep in range
521 return 0 if ($code >= 0xD800 and $code <= 0xDFFF); ## no surrogates
522 return 0 if ($code >= 0xFDD0 and $code <= 0xFDEF); ## utf8.c says no good
523 return 0 if (($code & 0xFFFF) == 0xFFFE); ## utf8.c says no good
524 return 0 if (($code & 0xFFFF) == 0xFFFF); ## utf8.c says no good
528 ## Return a code point that's part of the table.
529 ## Returns nothing if the table is empty (or covers only surrogates).
530 ## This used only for making the test script.
533 my $Table = shift; #self
534 for my $set (@$Table) {
535 return $set->[RANGE_END] if IsUsable($set->[RANGE_END]);
540 ## Return a code point that's not part of the table
541 ## Returns nothing if the table covers all code points.
542 ## This used only for making the test script.
543 sub Table::InvalidCode
545 my $Table = shift; #self
547 return 0x1234 if $Table->IsEmpty();
549 for my $set (@$Table)
551 if (IsUsable($set->[RANGE_END] + 1))
553 return $set->[RANGE_END] + 1;
556 if (IsUsable($set->[RANGE_START] - 1))
558 return $set->[RANGE_START] - 1;
564 ###########################################################################
565 ###########################################################################
566 ###########################################################################
571 ## New_Alias(Is => 'All', SameAs => 'Any', Fuzzy => 1);
573 ## The args must be in that order, although the Fuzzy pair may be omitted.
575 ## This creates 'IsAll' as an alias for 'IsAny'
579 my $Type = shift; ## "Is" or "In"
581 my $SameAs = shift; # expecting "SameAs" -- just ignored
584 ## remaining args are optional key/val
587 my $Fuzzy = delete $Args{Fuzzy};
589 ## sanity check a few args
590 if (%Args or ($Type ne 'Is' and $Type ne 'In') or $SameAs ne 'SameAs') {
591 confess "$0: bad args to New_Alias"
594 $Alias = CanonicalName($Alias) if $Fuzzy;
596 if (not $TableInfo{$Type}->{$Name})
598 my $CName = CanonicalName($Name);
599 if ($TableInfo{$Type}->{$CName}) {
600 confess "$0: Use canonical form '$CName' instead of '$Name' for alias.";
602 confess "$0: don't have original $Type => $Name to make alias\n";
605 if ($TableInfo{$Alias}) {
606 confess "$0: already have original $Type => $Alias; can't make alias";
608 $AliasInfo{$Type}->{$Name} = $Alias;
610 $FuzzyNames{$Type}->{$Alias} = $Name;
616 ## All assigned code points
617 my $Assigned = Table->New(Is => 'Assigned',
618 Desc => "All assigned code points",
621 my $Name = Table->New(); ## all characters, individually by name
622 my $General = Table->New(); ## all characters, grouped by category
627 ## Process UnicodeData.txt (Categories, etc.)
629 sub UnicodeData_Txt()
631 my $Bidi = Table->New();
632 my $Deco = Table->New();
633 my $Comb = Table->New();
634 my $Number = Table->New();
635 my $Mirrored = Table->New();#Is => 'Mirrored',
636 #Desc => "Mirrored in bidirectional text",
642 $DC{can} = Table->New();
643 $DC{com} = Table->New();
645 ## Initialize Perl-generated categories
646 ## (Categories from UnicodeData.txt are auto-initialized in gencat)
648 Table->New(Is => 'Alnum', Desc => "[[:Alnum:]]", Fuzzy => 0);
650 Table->New(Is => 'Alpha', Desc => "[[:Alpha:]]", Fuzzy => 0);
652 Table->New(Is => 'ASCII', Desc => "[[:ASCII:]]", Fuzzy => 0);
654 Table->New(Is => 'Blank', Desc => "[[:Blank:]]", Fuzzy => 0);
656 Table->New(Is => 'Cntrl', Desc => "[[:Cntrl:]]", Fuzzy => 0);
658 Table->New(Is => 'Digit', Desc => "[[:Digit:]]", Fuzzy => 0);
660 Table->New(Is => 'Graph', Desc => "[[:Graph:]]", Fuzzy => 0);
662 Table->New(Is => 'Lower', Desc => "[[:Lower:]]", Fuzzy => 0);
664 Table->New(Is => 'Print', Desc => "[[:Print:]]", Fuzzy => 0);
666 Table->New(Is => 'Punct', Desc => "[[:Punct:]]", Fuzzy => 0);
668 Table->New(Is => 'Space', Desc => "[[:Space:]]", Fuzzy => 0);
670 Table->New(Is => 'Title', Desc => "[[:Title:]]", Fuzzy => 0);
672 Table->New(Is => 'Upper', Desc => "[[:Upper:]]", Fuzzy => 0);
674 Table->New(Is => 'XDigit', Desc => "[[:XDigit:]]", Fuzzy => 0);
676 Table->New(Is => 'Word', Desc => "[[:Word:]]", Fuzzy => 0);
678 Table->New(Is => 'SpacePerl', Desc => '\s', Fuzzy => 0);
681 $To{Upper} = Table->New();
682 $To{Lower} = Table->New();
683 $To{Title} = Table->New();
684 $To{Digit} = Table->New();
688 my ($name, ## Name ("LATIN CAPITAL LETTER A")
689 $cat, ## Category ("Lu", "Zp", "Nd", etc.)
690 $code, ## Code point (as an integer)
693 my $MajorCat = substr($cat, 0, 1); ## L, M, Z, S, etc
695 $Assigned->$op($code);
696 $Name->$op($code, $name);
697 $General->$op($code, $cat);
699 ## add to the sub category (e.g. "Lu", "Nd", "Cf", ..)
700 $Cat{$cat} ||= Table->New(Is => $cat,
701 Desc => "General Category '$cat'",
703 $Cat{$cat}->$op($code);
705 ## add to the major category (e.g. "L", "N", "C", ...)
706 $Cat{$MajorCat} ||= Table->New(Is => $MajorCat,
707 Desc => "Major Category '$MajorCat'",
709 $Cat{$MajorCat}->$op($code);
711 ($General{$name} ||= Table->New)->$op($code, $name);
713 # 005F: SPACING UNDERSCORE
714 $Cat{Word}->$op($code) if $cat =~ /^[LMN]|Pc/;
715 $Cat{Alnum}->$op($code) if $cat =~ /^[LM]|Nd/;
716 $Cat{Alpha}->$op($code) if $cat =~ /^[LM]/;
719 ($cat =~ /Zs|Zl|Zp/ &&
720 $code != 0x200B) # 200B is ZWSP which is for line break control
721 # and therefore it is not part of "space" even while it is "Zs".
722 || $code == 0x0009 # 0009: HORIZONTAL TAB
723 || $code == 0x000A # 000A: LINE FEED
724 || $code == 0x000B # 000B: VERTICAL TAB
725 || $code == 0x000C # 000C: FORM FEED
726 || $code == 0x000D # 000D: CARRIAGE RETURN
727 || $code == 0x0085 # 0085: NEL
731 $Cat{Space}->$op($code) if $isspace;
733 $Cat{SpacePerl}->$op($code) if $isspace
734 && $code != 0x000B; # Backward compat.
736 $Cat{Blank}->$op($code) if $isspace
737 && !($code == 0x000A ||
744 $Cat{Digit}->$op($code) if $cat eq "Nd";
745 $Cat{Upper}->$op($code) if $cat eq "Lu";
746 $Cat{Lower}->$op($code) if $cat eq "Ll";
747 $Cat{Title}->$op($code) if $cat eq "Lt";
748 $Cat{ASCII}->$op($code) if $code <= 0x007F;
749 $Cat{Cntrl}->$op($code) if $cat =~ /^C/;
750 my $isgraph = !$isspace && $cat !~ /Cc|Cs|Cn/;
751 $Cat{Graph}->$op($code) if $isgraph;
752 $Cat{Print}->$op($code) if $isgraph || $isspace;
753 $Cat{Punct}->$op($code) if $cat =~ /^P/;
755 $Cat{XDigit}->$op($code) if ($code >= 0x30 && $code <= 0x39) ## 0..9
756 || ($code >= 0x41 && $code <= 0x46) ## A..F
757 || ($code >= 0x61 && $code <= 0x66); ## a..f
760 ## open ane read file.....
761 if (not open IN, "UnicodeData.txt") {
762 die "$0: UnicodeData.txt: $!\n";
766 ## For building \p{_CombAbove} and \p{_CanonDCIJ}
768 my %_Above_HexCodes; ## Hexcodes for chars with $comb == 230 ("ABOVE")
770 my %CodeToDeco; ## Maps code to decomp. list for chars with first
771 ## decomp. char an "i" or "j" (for \p{_CanonDCIJ})
773 ## This is filled in as we go....
774 my $CombAbove = Table->New(Is => '_CombAbove',
775 Desc => '(for internal casefolding use)',
780 next unless /^[0-9A-Fa-f]+;/;
783 my ($hexcode, ## code point in hex (e.g. "0041")
784 $name, ## character name (e.g. "LATIN CAPITAL LETTER A")
785 $cat, ## category (e.g. "Lu")
786 $comb, ## Canonical combining class (e.t. "230")
787 $bidi, ## directional category (e.g. "L")
788 $deco, ## decomposition mapping
789 $decimal, ## decimal digit value
790 $digit, ## digit value
791 $number, ## numeric value
792 $mirrored, ## mirrored
793 $unicode10, ## name in Unicode 1.0
794 $comment, ## comment field
795 $upper, ## uppercase mapping
796 $lower, ## lowercase mapping
797 $title, ## titlecase mapping
798 ) = split(/\s*;\s*/);
800 # Note that in Unicode 3.2 there will be names like
801 # LINE FEED (LF), which probably means that \N{} needs
802 # to cope also with LINE FEED and LF.
803 $name = $unicode10 if $name eq '<control>' && $unicode10 ne '';
805 my $code = hex($hexcode);
807 if ($comb and $comb == 230) {
808 $CombAbove->Append($code);
809 $_Above_HexCodes{$hexcode} = 1;
812 ## Used in building \p{_CanonDCIJ}
813 if ($deco and $deco =~ m/^006[9A]\b/) {
814 $CodeToDeco{$code} = $deco;
818 ## There are a few pairs of lines like:
819 ## AC00;<Hangul Syllable, First>;Lo;0;L;;;;;N;;;;;
820 ## D7A3;<Hangul Syllable, Last>;Lo;0;L;;;;;N;;;;;
821 ## that define ranges.
823 if ($name =~ /^<(.+), (First|Last)>$/)
826 gencat($name, $cat, $code, $2 eq 'First' ? 'Append' : 'Extend');
827 #New_Prop(In => $name, $General{$name}, Fuzzy => 1);
831 ## normal (single-character) lines
832 gencat($name, $cat, $code, 'Append');
834 # No Append() here since since several codes may map into one.
835 $To{Upper}->RawAppendRange($code, $code, $upper) if $upper;
836 $To{Lower}->RawAppendRange($code, $code, $lower) if $lower;
837 $To{Title}->RawAppendRange($code, $code, $title) if $title;
838 $To{Digit}->Append($code, $decimal) if length $decimal;
840 $Bidi->Append($code, $bidi);
841 $Comb->Append($code, $comb) if $comb;
842 $Number->Append($code, $number) if length $number;
844 length($decimal) and ($Number{De} ||= Table->New())->Append($code)
846 length($digit) and ($Number{Di} ||= Table->New())->Append($code)
848 length($number) and ($Number{Nu} ||= Table->New())->Append($code);
850 $Mirrored->Append($code) if $mirrored eq "Y";
852 $Bidi{$bidi} ||= Table->New();#Is => "bt/$bidi",
853 #Desc => "Bi-directional category '$bidi'",
855 $Bidi{$bidi}->Append($code);
859 $Deco->Append($code, $deco);
860 if ($deco =~/^<(\w+)>/)
862 my $dshort = $PVA_reverse{dt}{ucfirst lc $1};
863 $DC{com}->Append($code);
865 $DC{$dshort} ||= Table->New();
866 $DC{$dshort}->Append($code);
870 $DC{can}->Append($code);
878 ## Tidy up a few special cases....
881 $Cat{Cn} = $Assigned->Invert; ## Cn is everything that doesn't exist
884 Desc => "General Category 'Cn' [not functional in Perl]",
887 ## Unassigned is the same as 'Cn'
888 New_Alias(Is => 'Unassigned', SameAs => 'Cn', Fuzzy => 0);
890 $Cat{C}->Replace($Cat{C}->Merge($Cat{Cn})); ## Now merge in Cn into C
893 # LC is Ll, Lu, and Lt.
894 # (used to be L& or L_, but PropValueAliases.txt defines it as LC)
896 Table->Merge(@Cat{qw[Ll Lu Lt]}),
897 Desc => '[\p{Ll}\p{Lu}\p{Lt}]',
900 ## Any and All are all code points.
901 my $Any = Table->New(Is => 'Any',
902 Desc => sprintf("[\\x{0000}-\\x{%X}]",
903 $LastUnicodeCodepoint),
905 $Any->RawAppendRange(0, $LastUnicodeCodepoint);
907 New_Alias(Is => 'All', SameAs => 'Any', Fuzzy => 0);
910 ## Build special properties for Perl's internal case-folding needs:
911 ## \p{_CaseIgnorable}
914 ## _CombAbove was built above. Others are built here....
917 ## \p{_CaseIgnorable} is [\p{Mn}\0x00AD\x2010]
918 New_Prop(Is => '_CaseIgnorable',
919 Table->Merge($Cat{Mn},
922 Desc => '(for internal casefolding use)',
926 ## \p{_CanonDCIJ} is fairly complex...
927 my $CanonCDIJ = Table->New(Is => '_CanonDCIJ',
928 Desc => '(for internal casefolding use)',
930 ## It contains the ASCII 'i' and 'j'....
931 $CanonCDIJ->Append(0x0069); # ASCII ord("i")
932 $CanonCDIJ->Append(0x006A); # ASCII ord("j")
933 ## ...and any character with a decomposition that starts with either of
934 ## those code points, but only if the decomposition does not have any
935 ## combining character with the "ABOVE" canonical combining class.
936 for my $code (sort { $a <=> $b} keys %CodeToDeco)
938 ## Need to ensure that all decomposition characters do not have
939 ## a %HexCodeToComb in %AboveCombClasses.
941 for my $deco_hexcode (split / /, $CodeToDeco{$code})
943 if (exists $_Above_HexCodes{$deco_hexcode}) {
944 ## one of the decmposition chars has an ABOVE combination
945 ## class, so we're not interested in this one
951 $CanonCDIJ->Append($code);
958 ## Now dump the files.
960 $Name->Write("Name.pl");
962 # $Bidi->Write("Bidirectional.pl");
965 ["lib","bc","$_.pl"],
966 "BidiClass category '$PropValueAlias{bc}{$_}'"
970 $Comb->Write("CombiningClass.pl");
971 for (keys %{ $PropValueAlias{ccc} }) {
972 my ($code, $name) = @{ $PropValueAlias{ccc}{$_} };
973 (my $c = Table->New())->Append($code);
975 ["lib","ccc","$_.pl"],
976 "CombiningClass category '$name'"
980 $Deco->Write("Decomposition.pl");
983 ["lib","dt","$_.pl"],
984 "DecompositionType category '$PropValueAlias{dt}{$_}'"
988 # $Number->Write("Number.pl");
991 ["lib","nt","$_.pl"],
992 "NumericType category '$PropValueAlias{nt}{$_}'"
996 # $General->Write("Category.pl");
998 for my $to (sort keys %To) {
999 $To{$to}->Write(["To","$to.pl"]);
1002 for (keys %{ $PropValueAlias{gc} }) {
1003 New_Alias(Is => $PropValueAlias{gc}{$_}, SameAs => $_, Fuzzy => 1);
1008 ## Process LineBreak.txt
1012 if (not open IN, "LineBreak.txt") {
1013 die "$0: LineBreak.txt: $!\n";
1016 my $Lbrk = Table->New();
1021 next unless /^([0-9A-Fa-f]+)(?:\.\.([0-9A-Fa-f]+))?\s*;\s*(\w+)/;
1023 my ($first, $last, $lbrk) = (hex($1), hex($2||""), $3);
1025 $Lbrk->Append($first, $lbrk);
1027 $Lbrk{$lbrk} ||= Table->New();
1028 $Lbrk{$lbrk}->Append($first);
1031 $Lbrk->Extend($last);
1032 $Lbrk{$lbrk}->Extend($last);
1037 # $Lbrk->Write("Lbrk.pl");
1042 ["lib","lb","$_.pl"],
1043 "Linebreak category '$PropValueAlias{lb}{$_}'"
1049 ## Process ArabicShaping.txt.
1051 sub ArabicShaping_txt()
1053 if (not open IN, "ArabicShaping.txt") {
1054 die "$0: ArabicShaping.txt: $!\n";
1057 my $ArabLink = Table->New();
1058 my $ArabLinkGroup = Table->New();
1064 next unless /^[0-9A-Fa-f]+;/;
1067 my ($hexcode, $name, $link, $linkgroup) = split(/\s*;\s*/);
1068 my $code = hex($hexcode);
1069 $ArabLink->Append($code, $link);
1070 $ArabLinkGroup->Append($code, $linkgroup);
1072 $JoinType{$link} ||= Table->New(Is => "JoinType$link");
1073 $JoinType{$link}->Append($code);
1077 # $ArabLink->Write("ArabLink.pl");
1078 # $ArabLinkGroup->Write("ArabLnkGrp.pl");
1081 for (keys %JoinType) {
1082 $JoinType{$_}->Write(
1083 ["lib","jt","$_.pl"],
1084 "JoiningType category '$PropValueAlias{jt}{$_}'"
1090 ## Process EastAsianWidth.txt.
1092 sub EastAsianWidth_txt()
1094 if (not open IN, "EastAsianWidth.txt") {
1095 die "$0: EastAsianWidth.txt: $!\n";
1102 next unless /^[0-9A-Fa-f]+;/;
1106 my ($hexcode, $pv) = split(/\s*;\s*/);
1107 my $code = hex($hexcode);
1108 $EAW{$pv} ||= Table->New(Is => "EastAsianWidth$pv");
1109 $EAW{$pv}->Append($code);
1116 ["lib","ea","$_.pl"],
1117 "EastAsianWidth category '$PropValueAlias{ea}{$_}'"
1123 ## Process HangulSyllableType.txt.
1125 sub HangulSyllableType_txt()
1127 if (not open IN, "HangulSyllableType.txt") {
1128 die "$0: HangulSyllableType.txt: $!\n";
1135 next unless /^([0-9A-Fa-f]+)(?:\.\.([0-9A-Fa-f]+))?\s*;\s*(\w+)/;
1136 my ($first, $last, $pv) = (hex($1), hex($2||""), $3);
1138 $HST{$pv} ||= Table->New(Is => "HangulSyllableType$pv");
1139 $HST{$pv}->Append($first);
1141 if ($last) { $HST{$pv}->Extend($last) }
1147 ["lib","hst","$_.pl"],
1148 "HangulSyllableType category '$PropValueAlias{hst}{$_}'"
1154 ## Process Jamo.txt.
1158 if (not open IN, "Jamo.txt") {
1159 die "$0: Jamo.txt: $!\n";
1161 my $Short = Table->New();
1165 next unless /^([0-9A-Fa-f]+)\s*;\s*(\w*)/;
1166 my ($code, $short) = (hex($1), $2);
1168 $Short->Append($code, $short);
1171 # $Short->Write("JamoShort.pl");
1175 ## Process Scripts.txt.
1181 if (not open(IN, "Scripts.txt")) {
1182 die "$0: Scripts.txt: $!\n";
1185 next unless /^([0-9A-Fa-f]+)(?:\.\.([0-9A-Fa-f]+))?\s*;\s*(.+?)\s*\#/;
1187 # Wait until all the scripts have been read since
1188 # they are not listed in numeric order.
1189 push @ScriptInfo, [ hex($1), hex($2||""), $3 ];
1193 # Now append the scripts properties in their code point order.
1196 my $Scripts = Table->New();
1198 for my $script (sort { $a->[0] <=> $b->[0] } @ScriptInfo)
1200 my ($first, $last, $name) = @$script;
1201 $Scripts->Append($first, $name);
1203 $Script{$name} ||= Table->New(Is => $name,
1204 Desc => "Script '$name'",
1206 $Script{$name}->Append($first, $name);
1209 $Scripts->Extend($last);
1210 $Script{$name}->Extend($last);
1214 # $Scripts->Write("Scripts.pl");
1216 ## Common is everything not explicitly assigned to a Script
1218 ## ***shouldn't this be intersected with \p{Assigned}? ******
1220 New_Prop(Is => 'Common',
1222 Desc => 'Pseudo-Script of codepoints not in other Unicode scripts',
1227 ## Given a name like "Close Punctuation", return a regex (that when applied
1228 ## with /i) matches any valid form of that name (e.g. "ClosePunctuation",
1229 ## "Close-Punctuation", etc.)
1231 ## Accept any space, dash, or underbar where in the official name there is
1232 ## space or a dash (or underbar, but there never is).
1238 $Name =~ s/[- _]/(?:[-_]|\\s+)?/g;
1243 ## Process Blocks.txt.
1247 my $Blocks = Table->New();
1250 if (not open IN, "Blocks.txt") {
1251 die "$0: Blocks.txt: $!\n";
1256 #next if not /Private Use$/;
1257 next if not /^([0-9A-Fa-f]+)\.\.([0-9A-Fa-f]+)\s*;\s*(.+?)\s*$/;
1259 my ($first, $last, $name) = (hex($1), hex($2), $3);
1261 $Blocks->Append($first, $name);
1263 $Blocks{$name} ||= Table->New(In => $name,
1264 Desc => "Block '$name'",
1266 $Blocks{$name}->Append($first, $name);
1268 if ($last and $last != $first) {
1269 $Blocks->Extend($last);
1270 $Blocks{$name}->Extend($last);
1275 # $Blocks->Write("Blocks.pl");
1279 ## Read in the PropList.txt. It contains extended properties not
1280 ## listed in the UnicodeData.txt, such as 'Other_Alphabetic':
1281 ## alphabetic but not of the general category L; many modifiers
1282 ## belong to this extended property category: while they are not
1283 ## alphabets, they are alphabetic in nature.
1289 if (not open IN, "PropList.txt") {
1290 die "$0: PropList.txt: $!\n";
1295 next unless /^([0-9A-Fa-f]+)(?:\.\.([0-9A-Fa-f]+))?\s*;\s*(.+?)\s*\#/;
1297 # Wait until all the extended properties have been read since
1298 # they are not listed in numeric order.
1299 push @PropInfo, [ hex($1), hex($2||""), $3 ];
1303 # Now append the extended properties in their code point order.
1304 my $Props = Table->New();
1307 for my $prop (sort { $a->[0] <=> $b->[0] } @PropInfo)
1309 my ($first, $last, $name) = @$prop;
1310 $Props->Append($first, $name);
1312 $Prop{$name} ||= Table->New(Is => $name,
1313 Desc => "Extended property '$name'",
1315 $Prop{$name}->Append($first, $name);
1318 $Props->Extend($last);
1319 $Prop{$name}->Extend($last);
1324 (my $file = $PA_reverse{$_}) =~ tr/_//d;
1325 # XXX I'm assuming that the names from %Prop don't suffer 8.3 clashes.
1326 $BaseNames{lc $file}++;
1328 ["lib","gc_sc","$file.pl"],
1329 "Binary property '$_'"
1333 # Alphabetic is L and Other_Alphabetic.
1334 New_Prop(Is => 'Alphabetic',
1335 Table->Merge($Cat{L}, $Prop{Other_Alphabetic}),
1336 Desc => '[\p{L}\p{OtherAlphabetic}]', # use canonical names here
1339 # Lowercase is Ll and Other_Lowercase.
1340 New_Prop(Is => 'Lowercase',
1341 Table->Merge($Cat{Ll}, $Prop{Other_Lowercase}),
1342 Desc => '[\p{Ll}\p{OtherLowercase}]', # use canonical names here
1345 # Uppercase is Lu and Other_Uppercase.
1346 New_Prop(Is => 'Uppercase',
1347 Table->Merge($Cat{Lu}, $Prop{Other_Uppercase}),
1348 Desc => '[\p{Lu}\p{Other_Uppercase}]', # use canonical names here
1351 # Math is Sm and Other_Math.
1352 New_Prop(Is => 'Math',
1353 Table->Merge($Cat{Sm}, $Prop{Other_Math}),
1354 Desc => '[\p{Sm}\p{OtherMath}]', # use canonical names here
1357 # ID_Start is Ll, Lu, Lt, Lm, Lo, and Nl.
1358 New_Prop(Is => 'ID_Start',
1359 Table->Merge(@Cat{qw[Ll Lu Lt Lm Lo Nl]}),
1360 Desc => '[\p{Ll}\p{Lu}\p{Lt}\p{Lm}\p{Lo}\p{Nl}]',
1363 # ID_Continue is ID_Start, Mn, Mc, Nd, and Pc.
1364 New_Prop(Is => 'ID_Continue',
1365 Table->Merge(@Cat{qw[Ll Lu Lt Lm Lo Nl Mn Mc Nd Pc ]}),
1366 Desc => '[\p{ID_Start}\p{Mn}\p{Mc}\p{Nd}\p{Pc}]',
1372 ## These are used in:
1373 ## MakePropTestScript()
1374 ## WriteAllMappings()
1375 ## for making the test script.
1377 my %FuzzyNameToTest;
1378 my %ExactNameToTest;
1381 ## This used only for making the test script
1386 my $MatchCode = shift;
1387 my $FailCode = shift;
1389 if (defined $MatchCode) {
1390 printf $FH qq/Expect(1, "\\x{%04X}", '\\p{$Prop}' );\n/, $MatchCode;
1391 printf $FH qq/Expect(0, "\\x{%04X}", '\\p{^$Prop}');\n/, $MatchCode;
1392 printf $FH qq/Expect(0, "\\x{%04X}", '\\P{$Prop}' );\n/, $MatchCode;
1393 printf $FH qq/Expect(1, "\\x{%04X}", '\\P{^$Prop}');\n/, $MatchCode;
1395 if (defined $FailCode) {
1396 printf $FH qq/Expect(0, "\\x{%04X}", '\\p{$Prop}' );\n/, $FailCode;
1397 printf $FH qq/Expect(1, "\\x{%04X}", '\\p{^$Prop}');\n/, $FailCode;
1398 printf $FH qq/Expect(1, "\\x{%04X}", '\\P{$Prop}' );\n/, $FailCode;
1399 printf $FH qq/Expect(0, "\\x{%04X}", '\\P{^$Prop}');\n/, $FailCode;
1403 ## This used only for making the test script
1409 print $FH qq/Error('\\p{$prop}');\n/;
1410 print $FH qq/Error('\\P{$prop}');\n/;
1413 ## This used only for making the test script
1429 ## This used only for making the test script
1430 sub RandomlyFuzzifyName($;$)
1433 my $WantError = shift; ## if true, make an error
1436 for my $part (split /[-\s_]+/, $Name)
1439 if ($WantError and rand() < 0.3) {
1440 push @parts, $BadSeps[rand(@BadSeps)];
1443 push @parts, $GoodSeps[rand(@GoodSeps)];
1446 my $switch = int rand(4);
1448 push @parts, uc $part;
1449 } elsif ($switch == 1) {
1450 push @parts, lc $part;
1451 } elsif ($switch == 2) {
1452 push @parts, ucfirst $part;
1457 my $new = join('', @parts);
1460 if (rand() >= 0.5) {
1461 $new .= $BadSeps[rand(@BadSeps)];
1463 $new = $BadSeps[rand(@BadSeps)] . $new;
1469 ## This used only for making the test script
1470 sub MakePropTestScript()
1472 ## this written directly -- it's huge.
1473 force_unlink ("TestProp.pl");
1474 if (not open OUT, ">TestProp.pl") {
1475 die "$0: TestProp.pl: $!\n";
1479 while (my ($Name, $Table) = each %ExactNameToTest)
1481 GenTests(*OUT, $Name, $Table->ValidCode, $Table->InvalidCode);
1482 ExpectError(*OUT, uc $Name) if uc $Name ne $Name;
1483 ExpectError(*OUT, lc $Name) if lc $Name ne $Name;
1487 while (my ($Name, $Table) = each %FuzzyNameToTest)
1489 my $Orig = $CanonicalToOrig{$Name};
1493 RandomlyFuzzifyName($Orig) => 1
1496 for my $N (keys %Names) {
1497 GenTests(*OUT, $N, $Table->ValidCode, $Table->InvalidCode);
1500 ExpectError(*OUT, RandomlyFuzzifyName($Orig, 'ERROR'));
1503 print OUT "Finished();\n";
1509 ## These are used only in:
1510 ## RegisterFileForName()
1511 ## WriteAllMappings()
1513 my %Exact; ## will become %utf8::Exact;
1514 my %Canonical; ## will become %utf8::Canonical;
1515 my %CaComment; ## Comment for %Canonical entry of same key
1518 ## Given info about a name and a datafile that it should be associated with,
1519 ## register that assocation in %Exact and %Canonical.
1520 sub RegisterFileForName($$$$)
1524 my $IsFuzzy = shift;
1525 my $filename = shift;
1528 ## Now in details for the mapping. $Type eq 'Is' has the
1529 ## Is removed, as it will be removed in utf8_heavy when this
1530 ## data is being checked. In keeps its "In", but a second
1531 ## sans-In record is written if it doesn't conflict with
1532 ## anything already there.
1536 if ($Type eq 'Is') {
1537 die "oops[$Name]" if $Exact{$Name};
1538 $Exact{$Name} = $filename;
1540 die "oops[$Type$Name]" if $Exact{"$Type$Name"};
1541 $Exact{"$Type$Name"} = $filename;
1542 $Exact{$Name} = $filename if not $Exact{$Name};
1547 my $CName = lc $Name;
1548 if ($Type eq 'Is') {
1549 die "oops[$CName]" if $Canonical{$CName};
1550 $Canonical{$CName} = $filename;
1551 $CaComment{$CName} = $Name if $Name =~ tr/A-Z// >= 2;
1553 die "oops[$Type$CName]" if $Canonical{lc "$Type$CName"};
1554 $Canonical{lc "$Type$CName"} = $filename;
1555 $CaComment{lc "$Type$CName"} = "$Type$Name";
1556 if (not $Canonical{$CName}) {
1557 $Canonical{$CName} = $filename;
1558 $CaComment{$CName} = "$Type$Name";
1565 ## Writes the info accumulated in
1572 sub WriteAllMappings()
1576 ## 'Is' *MUST* come first, so its names have precidence over 'In's
1577 for my $Type ('Is', 'In')
1579 my %RawNameToFile; ## a per-$Type cache
1581 for my $Name (sort {length $a <=> length $b} keys %{$TableInfo{$Type}})
1583 ## Note: $Name is already canonical
1584 my $Table = $TableInfo{$Type}->{$Name};
1585 my $IsFuzzy = $FuzzyNames{$Type}->{$Name};
1587 ## Need an 8.3 safe filename (which means "an 8 safe" $filename)
1590 ## 'Is' items lose 'Is' from the basename.
1591 $filename = $Type eq 'Is' ?
1592 ($PVA_reverse{sc}{$Name} || $Name) :
1595 $filename =~ s/[^\w_]+/_/g; # "L&" -> "L_"
1596 substr($filename, 8) = '' if length($filename) > 8;
1599 ## Make sure the basename doesn't conflict with something we
1600 ## might have already written. If we have, say,
1607 while (my $num = $BaseNames{lc $filename}++)
1609 $num++; ## so basenames with numbers start with '2', which
1610 ## just looks more natural.
1611 ## Want to append $num, but if it'll make the basename longer
1612 ## than 8 characters, pre-truncate $filename so that the result
1614 my $delta = length($filename) + length($num) - 8;
1616 substr($filename, -$delta) = $num;
1624 ## Construct a nice comment to add to the file, and build data
1625 ## for the "./Properties" file along the way.
1629 my $Desc = $TableDesc{$Type}->{$Name} || "";
1630 ## get list of names this table is reference by
1631 my @Supported = $Name;
1632 while (my ($Orig, $Alias) = each %{ $AliasInfo{$Type} })
1634 if ($Orig eq $Name) {
1635 push @Supported, $Alias;
1639 my $TypeToShow = $Type eq 'Is' ? "" : $Type;
1642 $Comment = "This file supports:\n";
1643 for my $N (@Supported)
1645 my $IsFuzzy = $FuzzyNames{$Type}->{$N};
1646 my $Prop = "\\p{$TypeToShow$Name}";
1647 $OrigProp = $Prop if not $OrigProp; #cache for aliases
1649 $Comment .= "\t$Prop (and fuzzy permutations)\n";
1651 $Comment .= "\t$Prop\n";
1653 my $MyDesc = ($N eq $Name) ? $Desc : "Alias for $OrigProp ($Desc)";
1655 push @MAP, sprintf("%s %-42s %s\n",
1656 $IsFuzzy ? '*' : ' ', $Prop, $MyDesc);
1659 $Comment .= "\nMeaning: $Desc\n";
1664 ## Okay, write the file...
1666 $Table->Write(["lib","gc_sc","$filename.pl"], $Comment);
1669 $RawNameToFile{$Name} = $filename;
1670 RegisterFileForName($Type => $Name, $IsFuzzy, $filename);
1674 my $CName = CanonicalName($Type . '_'. $Name);
1675 $FuzzyNameToTest{$Name} = $Table if !$FuzzyNameToTest{$Name};
1676 $FuzzyNameToTest{$CName} = $Table if !$FuzzyNameToTest{$CName};
1678 $ExactNameToTest{$Name} = $Table;
1683 ## Register aliase info
1684 for my $Name (sort {length $a <=> length $b} keys %{$AliasInfo{$Type}})
1686 my $Alias = $AliasInfo{$Type}->{$Name};
1687 my $IsFuzzy = $FuzzyNames{$Type}->{$Alias};
1688 my $filename = $RawNameToFile{$Name};
1689 die "oops [$Alias]->[$Name]" if not $filename;
1690 RegisterFileForName($Type => $Alias, $IsFuzzy, $filename);
1692 my $Table = $TableInfo{$Type}->{$Name};
1693 die "oops" if not $Table;
1696 my $CName = CanonicalName($Type .'_'. $Alias);
1697 $FuzzyNameToTest{$Alias} = $Table if !$FuzzyNameToTest{$Alias};
1698 $FuzzyNameToTest{$CName} = $Table if !$FuzzyNameToTest{$CName};
1700 $ExactNameToTest{$Alias} = $Table;
1706 ## Write out the property list
1711 "## This file created by $0\n",
1712 "## List of built-in \\p{...}/\\P{...} properties.\n",
1714 "## '*' means name may be 'fuzzy'\n",
1716 sort { substr($a,2) cmp substr($b, 2) } @MAP,
1718 WriteIfChanged('Properties', @OUT);
1721 use Text::Tabs (); ## using this makes the files about half the size
1728 "## Data in this file used by ../utf8_heavy.pl\n",
1730 "## Mapping from name to filename in ./lib/gc_sc\n",
1731 "%utf8::Exact = (\n",
1734 $Exact{InGreek} = 'InGreekA'; # this is evil kludge
1735 for my $Name (sort keys %Exact)
1737 my $File = $Exact{$Name};
1738 $Name = $Name =~ m/\W/ ? qq/'$Name'/ : " $Name ";
1739 my $Text = sprintf("%-15s => %s,\n", $Name, qq/'$File'/);
1740 push @OUT, Text::Tabs::unexpand($Text);
1742 push @OUT, ");\n1;\n";
1744 WriteIfChanged('Exact.pl', @OUT);
1747 ## Write Canonical.pl
1752 "## Data in this file used by ../utf8_heavy.pl\n",
1754 "## Mapping from lc(canonical name) to filename in ./lib\n",
1755 "%utf8::Canonical = (\n",
1757 my $Trail = ""; ## used just to keep the spacing pretty
1758 for my $Name (sort keys %Canonical)
1760 my $File = $Canonical{$Name};
1761 if ($CaComment{$Name}) {
1762 push @OUT, "\n" if not $Trail;
1763 push @OUT, " # $CaComment{$Name}\n";
1768 $Name = $Name =~ m/\W/ ? qq/'$Name'/ : " $Name ";
1769 my $Text = sprintf(" %-41s => %s,\n$Trail", $Name, qq/'$File'/);
1770 push @OUT, Text::Tabs::unexpand($Text);
1772 push @OUT, ");\n1\n";
1773 WriteIfChanged('Canonical.pl', @OUT);
1776 MakePropTestScript() if $MakeTestScript;
1780 sub SpecialCasing_txt()
1783 # Read in the special cases.
1788 if (not open IN, "SpecialCasing.txt") {
1789 die "$0: SpecialCasing.txt: $!\n";
1792 next unless /^[0-9A-Fa-f]+;/;
1796 my ($code, $lower, $title, $upper, $condition) = split(/\s*;\s*/);
1798 if ($condition) { # not implemented yet
1799 print "# SKIPPING $_\n" if $Verbose;
1803 # Wait until all the special cases have been read since
1804 # they are not listed in numeric order.
1805 my $ix = hex($code);
1806 push @{$CaseInfo{Lower}}, [ $ix, $code, $lower ]
1807 unless $code eq $lower;
1808 push @{$CaseInfo{Title}}, [ $ix, $code, $title ]
1809 unless $code eq $title;
1810 push @{$CaseInfo{Upper}}, [ $ix, $code, $upper ]
1811 unless $code eq $upper;
1815 # Now write out the special cases properties in their code point order.
1816 # Prepend them to the To/{Upper,Lower,Title}.pl.
1818 for my $case (qw(Lower Title Upper))
1820 my $NormalCase = do "To/$case.pl" || die "$0: $@\n";
1825 "# The key UTF-8 _bytes_, the value UTF-8 (speed hack)\n",
1826 "%utf8::ToSpec$case =\n(\n",
1829 for my $prop (sort { $a->[0] <=> $b->[0] } @{$CaseInfo{$case}}) {
1830 my ($ix, $code, $to) = @$prop;
1832 join "", map { sprintf "\\x{%s}", $_ } split ' ', $to;
1833 push @OUT, sprintf qq["%s" => "$tostr",\n], join("", map { sprintf "\\x%02X", $_ } unpack("U0C*", pack("U", $ix)));
1834 # Remove any single-character mappings for
1835 # the same character since we are going for
1836 # the special casing rules.
1837 $NormalCase =~ s/^$code\t\t\w+\n//m;
1841 "return <<'END';\n",
1845 WriteIfChanged(["To","$case.pl"], @OUT);
1850 # Read in the case foldings.
1852 # We will do full case folding, C + F + I (see CaseFolding.txt).
1854 sub CaseFolding_txt()
1856 if (not open IN, "CaseFolding.txt") {
1857 die "$0: CaseFolding.txt: $!\n";
1860 my $Fold = Table->New();
1864 # Skip status 'S', simple case folding
1865 next unless /^([0-9A-Fa-f]+)\s*;\s*([CFI])\s*;\s*([0-9A-Fa-f]+(?: [0-9A-Fa-f]+)*)\s*;/;
1867 my ($code, $status, $fold) = (hex($1), $2, $3);
1869 if ($status eq 'C') { # Common: one-to-one folding
1870 # No append() since several codes may fold into one.
1871 $Fold->RawAppendRange($code, $code, $fold);
1872 } else { # F: full, or I: dotted uppercase I -> dotless lowercase I
1873 $Fold{$code} = $fold;
1878 $Fold->Write("To/Fold.pl");
1881 # Prepend the special foldings to the common foldings.
1883 my $CommonFold = do "To/Fold.pl" || die "$0: To/Fold.pl: $!\n";
1888 "# The ke UTF-8 _bytes_, the value UTF-8 (speed hack)\n",
1889 "%utf8::ToSpecFold =\n(\n",
1891 for my $code (sort { $a <=> $b } keys %Fold) {
1893 join "", map { sprintf "\\x{%s}", $_ } split ' ', $Fold{$code};
1894 push @OUT, sprintf qq["%s" => "$foldstr",\n], join("", map { sprintf "\\x%02X", $_ } unpack("U0C*", pack("U", $code)));
1898 "return <<'END';\n",
1903 WriteIfChanged(["To","Fold.pl"], @OUT);
1918 ArabicShaping_txt();
1919 EastAsianWidth_txt();
1920 HangulSyllableType_txt();
1922 SpecialCasing_txt();
1927 ## TRAILING CODE IS USED BY MakePropTestScript()
1940 my $Line = (caller)[2];
1945 $RegObj = qr/$Regex/;
1946 $String =~ $RegObj ? 1 : 0
1949 if (not defined $result) {
1950 print "couldn't compile /$Regex/ on $0 line $Line: $@\n";
1952 } elsif ($result ^ $Expect) {
1953 print "bad result (expected $Expect) on $0 line $Line: $@\n";
1962 if (eval { 'x' =~ qr/$Regex/; 1 }) {
1964 my $Line = (caller)[2];
1965 print "expected error for /$Regex/ on $0 line $Line: $@\n";
1972 print "All $Tests tests passed.\n";
1975 print "$Tests tests, $Fails failed!\n";