2 require 5.008; # Needs pack "U". Probably safest to run on 5.8.x
7 ## mktables -- create the runtime Perl Unicode files (lib/unicore/**/*.pl)
8 ## from the Unicode database files (lib/unicore/*.txt).
12 mkdir("lib/gc_sc", 0755);
19 my $MakeTestScript = 0;
23 my $arg = shift @ARGV;
26 } elsif ($arg eq '-q') {
28 } elsif ($arg eq '-maketest') {
31 die "usage: $0 [-v|-q] [-maketest]";
35 my $LastUnicodeCodepoint = 0x10FFFF; # As of Unicode 3.1.1.
38 # !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
39 # This file is built by $0 from e.g. UnicodeData.txt.
40 # Any changes made here will be lost!
46 ## Given a filename and a reference to an array of lines,
47 ## write the lines to the file only if the contents have not changed.
49 sub WriteIfChanged($\@)
54 my $TextToWrite = join '', @$lines;
57 my $PreviousText = <IN>;
59 if ($PreviousText eq $TextToWrite) {
60 print "$file unchanged.\n" if $Verbose;
64 if (not open OUT, ">$file") {
65 die "$0: can't open $file for output: $!\n";
67 print "$file written.\n" if $Verbose;
69 print OUT $TextToWrite;
74 ## The main datastructure (a "Table") represents a set of code points that
75 ## are part of a particular quality (that are part of \pL, \p{InGreek},
76 ## etc.). They are kept as ranges of code points (starting and ending of
79 ## For example, a range ASCII LETTERS would be represented as:
80 ## [ [ 0x41 => 0x5A, 'UPPER' ],
81 ## [ 0x61 => 0x7A, 'LOWER, ] ]
83 sub RANGE_START() { 0 } ## index into range element
84 sub RANGE_END() { 1 } ## index into range element
85 sub RANGE_NAME() { 2 } ## index into range element
87 ## Conceptually, these should really be folded into the 'Table' objects
95 ## Turn something like
104 $name =~ s/(?<![a-z])(\w)/\u$1/g;
105 $name =~ s/[-_\s]+//g;
107 $CanonicalToOrig{$name} = $orig if not $CanonicalToOrig{$name};
113 ## Store the alias definitions for later use.
124 ## Most of the work with aliases doesn't occur here,
125 ## but rather in utf8_heavy.pl, which uses utf8_pva.pl,
126 ## which contains just this function. However, this one
128 ## -- japhy (2004/04/13)
130 open PA, "< PropertyAliases.txt"
131 or confess "Can't open PropertyAliases.txt: $!";
137 my ($abbrev, $name) = split /\s*;\s*/;
138 next if $abbrev eq "n/a";
139 $PropertyAlias{$abbrev} = $name;
140 $PA_reverse{$name} = $abbrev;
144 open PVA, "< PropValueAliases.txt"
145 or confess "Can't open PropValueAliases.txt: $!";
151 my ($prop, @data) = split /\s*;\s*/;
153 if ($prop eq 'ccc') {
154 $PropValueAlias{$prop}{$data[1]} = [ @data[0,2] ];
155 $PVA_reverse{$prop}{$data[2]} = [ @data[0,1] ];
158 next if $data[0] eq "n/a";
159 $PropValueAlias{$prop}{$data[0]} = $data[1];
160 $PVA_reverse{$prop}{$data[1]} = $data[0];
168 ## Associates a property ("Greek", "Lu", "Assigned",...) with a Table.
171 ## New_Prop(In => 'Greek', $Table, Desc => 'Greek Block', Fuzzy => 1);
173 ## Normally, these parameters are set when the Table is created (when the
174 ## Table->New constructor is called), but there are times when it needs to
175 ## be done after-the-fact...)
179 my $Type = shift; ## "Is" or "In";
183 ## remaining args are optional key/val
186 my $Fuzzy = delete $Args{Fuzzy};
187 my $Desc = delete $Args{Desc}; # description
189 $Name = CanonicalName($Name) if $Fuzzy;
191 ## sanity check a few args
192 if (%Args or ($Type ne 'Is' and $Type ne 'In') or not ref $Table) {
193 confess "$0: bad args to New_Prop"
196 if (not $TableInfo{$Type}->{$Name})
198 $TableInfo{$Type}->{$Name} = $Table;
199 $TableDesc{$Type}->{$Name} = $Desc;
201 $FuzzyNames{$Type}->{$Name} = $Name;
208 ## Creates a new Table object.
210 ## Args are key/value pairs:
211 ## In => Name -- Name of "In" property to be associated with
212 ## Is => Name -- Name of "Is" property to be associated with
213 ## Fuzzy => Boolean -- True if name can be accessed "fuzzily"
214 ## Desc => String -- Description of the property
216 ## No args are required.
223 my $Table = bless [], $class;
225 my $Fuzzy = delete $Args{Fuzzy};
226 my $Desc = delete $Args{Desc};
228 for my $Type ('Is', 'In')
230 if (my $Name = delete $Args{$Type}) {
231 New_Prop($Type => $Name, $Table, Desc => $Desc, Fuzzy => $Fuzzy);
235 ## shouldn't have any left over
237 confess "$0: bad args to Table->New"
244 ## Returns true if the Table has no code points
248 my $Table = shift; #self
253 ## Returns true if the Table has code points
257 my $Table = shift; #self
262 ## Returns the maximum code point currently in the table.
266 my $Table = shift; #self
267 confess "oops" if $Table->IsEmpty; ## must have code points to have a max
268 return $Table->[-1]->[RANGE_END];
272 ## Replaces the codepoints in the Table with those in the Table given
273 ## as an arg. (NOTE: this is not a "deep copy").
275 sub Table::Replace($$)
277 my $Table = shift; #self
284 ## Given a new code point, make the last range of the Table extend to
285 ## include the new (and all intervening) code points.
289 my $Table = shift; #self
290 my $codepoint = shift;
292 my $PrevMax = $Table->Max;
294 confess "oops ($codepoint <= $PrevMax)" if $codepoint <= $PrevMax;
296 $Table->[-1]->[RANGE_END] = $codepoint;
300 ## Given a code point range start and end (and optional name), blindly
301 ## append them to the list of ranges for the Table.
303 ## NOTE: Code points must be added in strictly ascending numeric order.
305 sub Table::RawAppendRange
307 my $Table = shift; #self
311 $name = "" if not defined $name; ## warning: $name can be "0"
313 push @$Table, [ $start, # RANGE_START
315 $name ]; # RANGE_NAME
319 ## Given a code point (and optional name), add it to the Table.
321 ## NOTE: Code points must be added in strictly ascending numeric order.
325 my $Table = shift; #self
326 my $codepoint = shift;
328 $name = "" if not defined $name; ## warning: $name can be "0"
331 ## If we've already got a range working, and this code point is the next
332 ## one in line, and if the name is the same, just extend the current range.
336 $Table->Max == $codepoint - 1
338 $Table->[-1]->[RANGE_NAME] eq $name)
340 $Table->Extend($codepoint);
344 $Table->RawAppendRange($codepoint, $codepoint, $name);
349 ## Given a code point range starting value and ending value (and name),
350 ## Add the range to teh Table.
352 ## NOTE: Code points must be added in strictly ascending numeric order.
354 sub Table::AppendRange
356 my $Table = shift; #self
360 $name = "" if not defined $name; ## warning: $name can be "0"
362 $Table->Append($start, $name);
363 $Table->Extend($end) if $end > $start;
367 ## Return a new Table that represents all code points not in the Table.
371 my $Table = shift; #self
373 my $New = Table->New();
375 for my $range (@$Table)
377 my $start = $range->[RANGE_START];
378 my $end = $range->[RANGE_END];
379 if ($start-1 >= $max+1) {
380 $New->AppendRange($max+1, $start-1, "");
384 if ($max+1 < $LastUnicodeCodepoint) {
385 $New->AppendRange($max+1, $LastUnicodeCodepoint);
391 ## Merges any number of other tables with $self, returning the new table.
392 ## (existing tables are not modified)
395 ## Args may be Tables, or individual code points (as integers).
397 ## Can be called as either a constructor or a method.
401 shift(@_) if not ref $_[0]; ## if called as a constructor, lose the class
404 ## Accumulate all records from all tables
406 for my $Arg (@Tables)
409 ## arg is a table -- get its ranges
410 push @Records, @$Arg;
412 ## arg is a codepoint, make a range
413 push @Records, [ $Arg, $Arg ]
417 ## sort by range start, with longer ranges coming first.
418 my ($first, @Rest) = sort {
419 ($a->[RANGE_START] <=> $b->[RANGE_START])
421 ($b->[RANGE_END] <=> $b->[RANGE_END])
424 my $New = Table->New();
426 ## Ensuring the first range is there makes the subsequent loop easier
427 $New->AppendRange($first->[RANGE_START],
428 $first->[RANGE_END]);
430 ## Fold in records so long as they add new information.
433 my $start = $set->[RANGE_START];
434 my $end = $set->[RANGE_END];
435 if ($start > $New->Max) {
436 $New->AppendRange($start, $end);
437 } elsif ($end > $New->Max) {
446 ## Given a filename, write a representation of the Table to a file.
447 ## May have an optional comment as a 2nd arg.
451 my $Table = shift; #self
452 my $filename = shift;
456 if (defined $comment) {
457 $comment =~ s/\s+\Z//;
458 $comment =~ s/^/# /gm;
459 push @OUT, "#\n$comment\n#\n";
461 push @OUT, "return <<'END';\n";
463 for my $set (@$Table)
465 my $start = $set->[RANGE_START];
466 my $end = $set->[RANGE_END];
467 my $name = $set->[RANGE_NAME];
469 if ($start == $end) {
470 push @OUT, sprintf "%04X\t\t%s\n", $start, $name;
472 push @OUT, sprintf "%04X\t%04X\t%s\n", $start, $end, $name;
478 WriteIfChanged($filename, @OUT);
481 ## This used only for making the test script.
486 return 0 if $code <= 0x0000; ## don't use null
487 return 0 if $code >= $LastUnicodeCodepoint; ## keep in range
488 return 0 if ($code >= 0xD800 and $code <= 0xDFFF); ## no surrogates
489 return 0 if ($code >= 0xFDD0 and $code <= 0xFDEF); ## utf8.c says no good
490 return 0 if (($code & 0xFFFF) == 0xFFFE); ## utf8.c says no good
491 return 0 if (($code & 0xFFFF) == 0xFFFF); ## utf8.c says no good
495 ## Return a code point that's part of the table.
496 ## Returns nothing if the table is empty (or covers only surrogates).
497 ## This used only for making the test script.
500 my $Table = shift; #self
501 for my $set (@$Table) {
502 return $set->[RANGE_END] if IsUsable($set->[RANGE_END]);
507 ## Return a code point that's not part of the table
508 ## Returns nothing if the table covers all code points.
509 ## This used only for making the test script.
510 sub Table::InvalidCode
512 my $Table = shift; #self
514 return 0x1234 if $Table->IsEmpty();
516 for my $set (@$Table)
518 if (IsUsable($set->[RANGE_END] + 1))
520 return $set->[RANGE_END] + 1;
523 if (IsUsable($set->[RANGE_START] - 1))
525 return $set->[RANGE_START] - 1;
531 ###########################################################################
532 ###########################################################################
533 ###########################################################################
538 ## New_Alias(Is => 'All', SameAs => 'Any', Fuzzy => 1);
540 ## The args must be in that order, although the Fuzzy pair may be omitted.
542 ## This creates 'IsAll' as an alias for 'IsAny'
546 my $Type = shift; ## "Is" or "In"
548 my $SameAs = shift; # expecting "SameAs" -- just ignored
551 ## remaining args are optional key/val
554 my $Fuzzy = delete $Args{Fuzzy};
556 ## sanity check a few args
557 if (%Args or ($Type ne 'Is' and $Type ne 'In') or $SameAs ne 'SameAs') {
558 confess "$0: bad args to New_Alias"
561 $Alias = CanonicalName($Alias) if $Fuzzy;
563 if (not $TableInfo{$Type}->{$Name})
565 my $CName = CanonicalName($Name);
566 if ($TableInfo{$Type}->{$CName}) {
567 confess "$0: Use canonical form '$CName' instead of '$Name' for alias.";
569 confess "$0: don't have original $Type => $Name to make alias\n";
572 if ($TableInfo{$Alias}) {
573 confess "$0: already have original $Type => $Alias; can't make alias";
575 $AliasInfo{$Type}->{$Name} = $Alias;
577 $FuzzyNames{$Type}->{$Alias} = $Name;
583 ## All assigned code points
584 my $Assigned = Table->New(Is => 'Assigned',
585 Desc => "All assigned code points",
588 my $Name = Table->New(); ## all characters, individually by name
589 my $General = Table->New(); ## all characters, grouped by category
594 ## Process UnicodeData.txt (Categories, etc.)
596 sub UnicodeData_Txt()
598 my $Bidi = Table->New();
599 my $Deco = Table->New();
600 my $Comb = Table->New();
601 my $Number = Table->New();
602 my $Mirrored = Table->New();#Is => 'Mirrored',
603 #Desc => "Mirrored in bidirectional text",
609 $DC{can} = Table->New();
610 $DC{com} = Table->New();
612 ## Initialize Perl-generated categories
613 ## (Categories from UnicodeData.txt are auto-initialized in gencat)
615 Table->New(Is => 'Alnum', Desc => "[[:Alnum:]]", Fuzzy => 0);
617 Table->New(Is => 'Alpha', Desc => "[[:Alpha:]]", Fuzzy => 0);
619 Table->New(Is => 'ASCII', Desc => "[[:ASCII:]]", Fuzzy => 0);
621 Table->New(Is => 'Blank', Desc => "[[:Blank:]]", Fuzzy => 0);
623 Table->New(Is => 'Cntrl', Desc => "[[:Cntrl:]]", Fuzzy => 0);
625 Table->New(Is => 'Digit', Desc => "[[:Digit:]]", Fuzzy => 0);
627 Table->New(Is => 'Graph', Desc => "[[:Graph:]]", Fuzzy => 0);
629 Table->New(Is => 'Lower', Desc => "[[:Lower:]]", Fuzzy => 0);
631 Table->New(Is => 'Print', Desc => "[[:Print:]]", Fuzzy => 0);
633 Table->New(Is => 'Punct', Desc => "[[:Punct:]]", Fuzzy => 0);
635 Table->New(Is => 'Space', Desc => "[[:Space:]]", Fuzzy => 0);
637 Table->New(Is => 'Title', Desc => "[[:Title:]]", Fuzzy => 0);
639 Table->New(Is => 'Upper', Desc => "[[:Upper:]]", Fuzzy => 0);
641 Table->New(Is => 'XDigit', Desc => "[[:XDigit:]]", Fuzzy => 0);
643 Table->New(Is => 'Word', Desc => "[[:Word:]]", Fuzzy => 0);
645 Table->New(Is => 'SpacePerl', Desc => '\s', Fuzzy => 0);
648 $To{Upper} = Table->New();
649 $To{Lower} = Table->New();
650 $To{Title} = Table->New();
651 $To{Digit} = Table->New();
655 my ($name, ## Name ("LATIN CAPITAL LETTER A")
656 $cat, ## Category ("Lu", "Zp", "Nd", etc.)
657 $code, ## Code point (as an integer)
660 my $MajorCat = substr($cat, 0, 1); ## L, M, Z, S, etc
662 $Assigned->$op($code);
663 $Name->$op($code, $name);
664 $General->$op($code, $cat);
666 ## add to the sub category (e.g. "Lu", "Nd", "Cf", ..)
667 $Cat{$cat} ||= Table->New(Is => $cat,
668 Desc => "General Category '$cat'",
670 $Cat{$cat}->$op($code);
672 ## add to the major category (e.g. "L", "N", "C", ...)
673 $Cat{$MajorCat} ||= Table->New(Is => $MajorCat,
674 Desc => "Major Category '$MajorCat'",
676 $Cat{$MajorCat}->$op($code);
678 ($General{$name} ||= Table->New)->$op($code, $name);
680 # 005F: SPACING UNDERSCORE
681 $Cat{Word}->$op($code) if $cat =~ /^[LMN]|Pc/;
682 $Cat{Alnum}->$op($code) if $cat =~ /^[LM]|Nd/;
683 $Cat{Alpha}->$op($code) if $cat =~ /^[LM]/;
686 ($cat =~ /Zs|Zl|Zp/ &&
687 $code != 0x200B) # 200B is ZWSP which is for line break control
688 # and therefore it is not part of "space" even while it is "Zs".
689 || $code == 0x0009 # 0009: HORIZONTAL TAB
690 || $code == 0x000A # 000A: LINE FEED
691 || $code == 0x000B # 000B: VERTICAL TAB
692 || $code == 0x000C # 000C: FORM FEED
693 || $code == 0x000D # 000D: CARRIAGE RETURN
694 || $code == 0x0085 # 0085: NEL
698 $Cat{Space}->$op($code) if $isspace;
700 $Cat{SpacePerl}->$op($code) if $isspace
701 && $code != 0x000B; # Backward compat.
703 $Cat{Blank}->$op($code) if $isspace
704 && !($code == 0x000A ||
711 $Cat{Digit}->$op($code) if $cat eq "Nd";
712 $Cat{Upper}->$op($code) if $cat eq "Lu";
713 $Cat{Lower}->$op($code) if $cat eq "Ll";
714 $Cat{Title}->$op($code) if $cat eq "Lt";
715 $Cat{ASCII}->$op($code) if $code <= 0x007F;
716 $Cat{Cntrl}->$op($code) if $cat =~ /^C/;
717 my $isgraph = !$isspace && $cat !~ /Cc|Cs|Cn/;
718 $Cat{Graph}->$op($code) if $isgraph;
719 $Cat{Print}->$op($code) if $isgraph || $isspace;
720 $Cat{Punct}->$op($code) if $cat =~ /^P/;
722 $Cat{XDigit}->$op($code) if ($code >= 0x30 && $code <= 0x39) ## 0..9
723 || ($code >= 0x41 && $code <= 0x46) ## A..F
724 || ($code >= 0x61 && $code <= 0x66); ## a..f
727 ## open ane read file.....
728 if (not open IN, "UnicodeData.txt") {
729 die "$0: UnicodeData.txt: $!\n";
733 ## For building \p{_CombAbove} and \p{_CanonDCIJ}
735 my %_Above_HexCodes; ## Hexcodes for chars with $comb == 230 ("ABOVE")
737 my %CodeToDeco; ## Maps code to decomp. list for chars with first
738 ## decomp. char an "i" or "j" (for \p{_CanonDCIJ})
740 ## This is filled in as we go....
741 my $CombAbove = Table->New(Is => '_CombAbove',
742 Desc => '(for internal casefolding use)',
747 next unless /^[0-9A-Fa-f]+;/;
750 my ($hexcode, ## code point in hex (e.g. "0041")
751 $name, ## character name (e.g. "LATIN CAPITAL LETTER A")
752 $cat, ## category (e.g. "Lu")
753 $comb, ## Canonical combining class (e.t. "230")
754 $bidi, ## directional category (e.g. "L")
755 $deco, ## decomposition mapping
756 $decimal, ## decimal digit value
757 $digit, ## digit value
758 $number, ## numeric value
759 $mirrored, ## mirrored
760 $unicode10, ## name in Unicode 1.0
761 $comment, ## comment field
762 $upper, ## uppercase mapping
763 $lower, ## lowercase mapping
764 $title, ## titlecase mapping
765 ) = split(/\s*;\s*/);
767 # Note that in Unicode 3.2 there will be names like
768 # LINE FEED (LF), which probably means that \N{} needs
769 # to cope also with LINE FEED and LF.
770 $name = $unicode10 if $name eq '<control>' && $unicode10 ne '';
772 my $code = hex($hexcode);
774 if ($comb and $comb == 230) {
775 $CombAbove->Append($code);
776 $_Above_HexCodes{$hexcode} = 1;
779 ## Used in building \p{_CanonDCIJ}
780 if ($deco and $deco =~ m/^006[9A]\b/) {
781 $CodeToDeco{$code} = $deco;
785 ## There are a few pairs of lines like:
786 ## AC00;<Hangul Syllable, First>;Lo;0;L;;;;;N;;;;;
787 ## D7A3;<Hangul Syllable, Last>;Lo;0;L;;;;;N;;;;;
788 ## that define ranges.
790 if ($name =~ /^<(.+), (First|Last)>$/)
793 gencat($name, $cat, $code, $2 eq 'First' ? 'Append' : 'Extend');
794 #New_Prop(In => $name, $General{$name}, Fuzzy => 1);
798 ## normal (single-character) lines
799 gencat($name, $cat, $code, 'Append');
801 # No Append() here since since several codes may map into one.
802 $To{Upper}->RawAppendRange($code, $code, $upper) if $upper;
803 $To{Lower}->RawAppendRange($code, $code, $lower) if $lower;
804 $To{Title}->RawAppendRange($code, $code, $title) if $title;
805 $To{Digit}->Append($code, $decimal) if length $decimal;
807 $Bidi->Append($code, $bidi);
808 $Comb->Append($code, $comb) if $comb;
809 $Number->Append($code, $number) if length $number;
811 length($decimal) and ($Number{De} ||= Table->New())->Append($code)
813 length($digit) and ($Number{Di} ||= Table->New())->Append($code)
815 length($number) and ($Number{Nu} ||= Table->New())->Append($code);
817 $Mirrored->Append($code) if $mirrored eq "Y";
819 $Bidi{$bidi} ||= Table->New();#Is => "bt/$bidi",
820 #Desc => "Bi-directional category '$bidi'",
822 $Bidi{$bidi}->Append($code);
826 $Deco->Append($code, $deco);
827 if ($deco =~/^<(\w+)>/)
829 my $dshort = $PVA_reverse{dt}{ucfirst lc $1};
830 $DC{com}->Append($code);
832 $DC{$dshort} ||= Table->New();
833 $DC{$dshort}->Append($code);
837 $DC{can}->Append($code);
845 ## Tidy up a few special cases....
848 $Cat{Cn} = $Assigned->Invert; ## Cn is everything that doesn't exist
851 Desc => "General Category 'Cn' [not functional in Perl]",
854 ## Unassigned is the same as 'Cn'
855 New_Alias(Is => 'Unassigned', SameAs => 'Cn', Fuzzy => 0);
857 $Cat{C}->Replace($Cat{C}->Merge($Cat{Cn})); ## Now merge in Cn into C
860 # LC is Ll, Lu, and Lt.
861 # (used to be L& or L_, but PropValueAliases.txt defines it as LC)
863 Table->Merge(@Cat{qw[Ll Lu Lt]}),
864 Desc => '[\p{Ll}\p{Lu}\p{Lt}]',
867 ## Any and All are all code points.
868 my $Any = Table->New(Is => 'Any',
869 Desc => sprintf("[\\x{0000}-\\x{%X}]",
870 $LastUnicodeCodepoint),
872 $Any->RawAppendRange(0, $LastUnicodeCodepoint);
874 New_Alias(Is => 'All', SameAs => 'Any', Fuzzy => 0);
877 ## Build special properties for Perl's internal case-folding needs:
878 ## \p{_CaseIgnorable}
881 ## _CombAbove was built above. Others are built here....
884 ## \p{_CaseIgnorable} is [\p{Mn}\0x00AD\x2010]
885 New_Prop(Is => '_CaseIgnorable',
886 Table->Merge($Cat{Mn},
889 Desc => '(for internal casefolding use)',
893 ## \p{_CanonDCIJ} is fairly complex...
894 my $CanonCDIJ = Table->New(Is => '_CanonDCIJ',
895 Desc => '(for internal casefolding use)',
897 ## It contains the ASCII 'i' and 'j'....
898 $CanonCDIJ->Append(0x0069); # ASCII ord("i")
899 $CanonCDIJ->Append(0x006A); # ASCII ord("j")
900 ## ...and any character with a decomposition that starts with either of
901 ## those code points, but only if the decomposition does not have any
902 ## combining character with the "ABOVE" canonical combining class.
903 for my $code (sort { $a <=> $b} keys %CodeToDeco)
905 ## Need to ensure that all decomposition characters do not have
906 ## a %HexCodeToComb in %AboveCombClasses.
908 for my $deco_hexcode (split / /, $CodeToDeco{$code})
910 if (exists $_Above_HexCodes{$deco_hexcode}) {
911 ## one of the decmposition chars has an ABOVE combination
912 ## class, so we're not interested in this one
918 $CanonCDIJ->Append($code);
925 ## Now dump the files.
927 $Name->Write("Name.pl");
929 # $Bidi->Write("Bidirectional.pl");
930 mkdir("lib/bc", 0755);
934 "BidiClass category '$PropValueAlias{bc}{$_}'"
938 $Comb->Write("CombiningClass.pl");
939 mkdir("lib/ccc", 0755);
940 for (keys %{ $PropValueAlias{ccc} }) {
941 my ($code, $name) = @{ $PropValueAlias{ccc}{$_} };
942 (my $c = Table->New())->Append($code);
945 "CombiningClass category '$name'"
949 $Deco->Write("Decomposition.pl");
950 mkdir("lib/dt", 0755);
954 "DecompositionType category '$PropValueAlias{dt}{$_}'"
958 # $Number->Write("Number.pl");
959 mkdir("lib/nt", 0755);
963 "NumericType category '$PropValueAlias{nt}{$_}'"
967 # $General->Write("Category.pl");
969 for my $to (sort keys %To) {
970 $To{$to}->Write("To/$to.pl");
973 for (keys %{ $PropValueAlias{gc} }) {
974 New_Alias(Is => $PropValueAlias{gc}{$_}, SameAs => $_, Fuzzy => 1);
979 ## Process LineBreak.txt
983 if (not open IN, "LineBreak.txt") {
984 die "$0: LineBreak.txt: $!\n";
987 my $Lbrk = Table->New();
992 next unless /^([0-9A-Fa-f]+)(?:\.\.([0-9A-Fa-f]+))?\s*;\s*(\w+)/;
994 my ($first, $last, $lbrk) = (hex($1), hex($2||""), $3);
996 $Lbrk->Append($first, $lbrk);
998 $Lbrk{$lbrk} ||= Table->New();
999 $Lbrk{$lbrk}->Append($first);
1002 $Lbrk->Extend($last);
1003 $Lbrk{$lbrk}->Extend($last);
1008 # $Lbrk->Write("Lbrk.pl");
1010 mkdir("lib/lb", 0755);
1015 "Linebreak category '$PropValueAlias{lb}{$_}'"
1021 ## Process ArabicShaping.txt.
1023 sub ArabicShaping_txt()
1025 if (not open IN, "ArabicShaping.txt") {
1026 die "$0: ArabicShaping.txt: $!\n";
1029 my $ArabLink = Table->New();
1030 my $ArabLinkGroup = Table->New();
1036 next unless /^[0-9A-Fa-f]+;/;
1039 my ($hexcode, $name, $link, $linkgroup) = split(/\s*;\s*/);
1040 my $code = hex($hexcode);
1041 $ArabLink->Append($code, $link);
1042 $ArabLinkGroup->Append($code, $linkgroup);
1044 $JoinType{$link} ||= Table->New(Is => "JoinType$link");
1045 $JoinType{$link}->Append($code);
1049 # $ArabLink->Write("ArabLink.pl");
1050 # $ArabLinkGroup->Write("ArabLnkGrp.pl");
1052 mkdir("lib/jt", 0755);
1054 for (keys %JoinType) {
1055 $JoinType{$_}->Write(
1057 "JoiningType category '$PropValueAlias{jt}{$_}'"
1063 ## Process EastAsianWidth.txt.
1065 sub EastAsianWidth_txt()
1067 if (not open IN, "EastAsianWidth.txt") {
1068 die "$0: EastAsianWidth.txt: $!\n";
1075 next unless /^[0-9A-Fa-f]+;/;
1079 my ($hexcode, $pv) = split(/\s*;\s*/);
1080 my $code = hex($hexcode);
1081 $EAW{$pv} ||= Table->New(Is => "EastAsianWidth$pv");
1082 $EAW{$pv}->Append($code);
1086 mkdir("lib/ea", 0755);
1091 "EastAsianWidth category '$PropValueAlias{ea}{$_}'"
1097 ## Process HangulSyllableType.txt.
1099 sub HangulSyllableType_txt()
1101 if (not open IN, "HangulSyllableType.txt") {
1102 die "$0: HangulSyllableType.txt: $!\n";
1109 next unless /^([0-9A-Fa-f]+)(?:\.\.([0-9A-Fa-f]+))?\s*;\s*(\w+)/;
1110 my ($first, $last, $pv) = (hex($1), hex($2||""), $3);
1112 $HST{$pv} ||= Table->New(Is => "HangulSyllableType$pv");
1113 $HST{$pv}->Append($first);
1115 if ($last) { $HST{$pv}->Extend($last) }
1119 mkdir("lib/hst", 0755);
1124 "HangulSyllableType category '$PropValueAlias{hst}{$_}'"
1130 ## Process Jamo.txt.
1134 if (not open IN, "Jamo.txt") {
1135 die "$0: Jamo.txt: $!\n";
1137 my $Short = Table->New();
1141 next unless /^([0-9A-Fa-f]+)\s*;\s*(\w*)/;
1142 my ($code, $short) = (hex($1), $2);
1144 $Short->Append($code, $short);
1147 # $Short->Write("JamoShort.pl");
1151 ## Process Scripts.txt.
1157 if (not open(IN, "Scripts.txt")) {
1158 die "$0: Scripts.txt: $!\n";
1161 next unless /^([0-9A-Fa-f]+)(?:\.\.([0-9A-Fa-f]+))?\s*;\s*(.+?)\s*\#/;
1163 # Wait until all the scripts have been read since
1164 # they are not listed in numeric order.
1165 push @ScriptInfo, [ hex($1), hex($2||""), $3 ];
1169 # Now append the scripts properties in their code point order.
1172 my $Scripts = Table->New();
1174 for my $script (sort { $a->[0] <=> $b->[0] } @ScriptInfo)
1176 my ($first, $last, $name) = @$script;
1177 $Scripts->Append($first, $name);
1179 $Script{$name} ||= Table->New(Is => $name,
1180 Desc => "Script '$name'",
1182 $Script{$name}->Append($first, $name);
1185 $Scripts->Extend($last);
1186 $Script{$name}->Extend($last);
1190 # $Scripts->Write("Scripts.pl");
1192 ## Common is everything not explicitly assigned to a Script
1194 ## ***shouldn't this be intersected with \p{Assigned}? ******
1196 New_Prop(Is => 'Common',
1198 Desc => 'Pseudo-Script of codepoints not in other Unicode scripts',
1203 ## Given a name like "Close Punctuation", return a regex (that when applied
1204 ## with /i) matches any valid form of that name (e.g. "ClosePunctuation",
1205 ## "Close-Punctuation", etc.)
1207 ## Accept any space, dash, or underbar where in the official name there is
1208 ## space or a dash (or underbar, but there never is).
1214 $Name =~ s/[- _]/(?:[-_]|\\s+)?/g;
1219 ## Process Blocks.txt.
1223 my $Blocks = Table->New();
1226 if (not open IN, "Blocks.txt") {
1227 die "$0: Blocks.txt: $!\n";
1232 #next if not /Private Use$/;
1233 next if not /^([0-9A-Fa-f]+)\.\.([0-9A-Fa-f]+)\s*;\s*(.+?)\s*$/;
1235 my ($first, $last, $name) = (hex($1), hex($2), $3);
1237 $Blocks->Append($first, $name);
1239 $Blocks{$name} ||= Table->New(In => $name,
1240 Desc => "Block '$name'",
1242 $Blocks{$name}->Append($first, $name);
1244 if ($last and $last != $first) {
1245 $Blocks->Extend($last);
1246 $Blocks{$name}->Extend($last);
1251 # $Blocks->Write("Blocks.pl");
1255 ## Read in the PropList.txt. It contains extended properties not
1256 ## listed in the UnicodeData.txt, such as 'Other_Alphabetic':
1257 ## alphabetic but not of the general category L; many modifiers
1258 ## belong to this extended property category: while they are not
1259 ## alphabets, they are alphabetic in nature.
1265 if (not open IN, "PropList.txt") {
1266 die "$0: PropList.txt: $!\n";
1271 next unless /^([0-9A-Fa-f]+)(?:\.\.([0-9A-Fa-f]+))?\s*;\s*(.+?)\s*\#/;
1273 # Wait until all the extended properties have been read since
1274 # they are not listed in numeric order.
1275 push @PropInfo, [ hex($1), hex($2||""), $3 ];
1279 # Now append the extended properties in their code point order.
1280 my $Props = Table->New();
1283 for my $prop (sort { $a->[0] <=> $b->[0] } @PropInfo)
1285 my ($first, $last, $name) = @$prop;
1286 $Props->Append($first, $name);
1288 $Prop{$name} ||= Table->New(Is => $name,
1289 Desc => "Extended property '$name'",
1291 $Prop{$name}->Append($first, $name);
1294 $Props->Extend($last);
1295 $Prop{$name}->Extend($last);
1300 (my $file = $PA_reverse{$_}) =~ tr/_//d;
1302 "lib/gc_sc/$file.pl",
1303 "Binary property '$_'"
1307 # Alphabetic is L and Other_Alphabetic.
1308 New_Prop(Is => 'Alphabetic',
1309 Table->Merge($Cat{L}, $Prop{Other_Alphabetic}),
1310 Desc => '[\p{L}\p{OtherAlphabetic}]', # use canonical names here
1313 # Lowercase is Ll and Other_Lowercase.
1314 New_Prop(Is => 'Lowercase',
1315 Table->Merge($Cat{Ll}, $Prop{Other_Lowercase}),
1316 Desc => '[\p{Ll}\p{OtherLowercase}]', # use canonical names here
1319 # Uppercase is Lu and Other_Uppercase.
1320 New_Prop(Is => 'Uppercase',
1321 Table->Merge($Cat{Lu}, $Prop{Other_Uppercase}),
1322 Desc => '[\p{Lu}\p{Other_Uppercase}]', # use canonical names here
1325 # Math is Sm and Other_Math.
1326 New_Prop(Is => 'Math',
1327 Table->Merge($Cat{Sm}, $Prop{Other_Math}),
1328 Desc => '[\p{Sm}\p{OtherMath}]', # use canonical names here
1331 # ID_Start is Ll, Lu, Lt, Lm, Lo, and Nl.
1332 New_Prop(Is => 'ID_Start',
1333 Table->Merge(@Cat{qw[Ll Lu Lt Lm Lo Nl]}),
1334 Desc => '[\p{Ll}\p{Lu}\p{Lt}\p{Lm}\p{Lo}\p{Nl}]',
1337 # ID_Continue is ID_Start, Mn, Mc, Nd, and Pc.
1338 New_Prop(Is => 'ID_Continue',
1339 Table->Merge(@Cat{qw[Ll Lu Lt Lm Lo Nl Mn Mc Nd Pc ]}),
1340 Desc => '[\p{ID_Start}\p{Mn}\p{Mc}\p{Nd}\p{Pc}]',
1346 ## These are used in:
1347 ## MakePropTestScript()
1348 ## WriteAllMappings()
1349 ## for making the test script.
1351 my %FuzzyNameToTest;
1352 my %ExactNameToTest;
1355 ## This used only for making the test script
1360 my $MatchCode = shift;
1361 my $FailCode = shift;
1363 if (defined $MatchCode) {
1364 printf $FH qq/Expect(1, "\\x{%04X}", '\\p{$Prop}' );\n/, $MatchCode;
1365 printf $FH qq/Expect(0, "\\x{%04X}", '\\p{^$Prop}');\n/, $MatchCode;
1366 printf $FH qq/Expect(0, "\\x{%04X}", '\\P{$Prop}' );\n/, $MatchCode;
1367 printf $FH qq/Expect(1, "\\x{%04X}", '\\P{^$Prop}');\n/, $MatchCode;
1369 if (defined $FailCode) {
1370 printf $FH qq/Expect(0, "\\x{%04X}", '\\p{$Prop}' );\n/, $FailCode;
1371 printf $FH qq/Expect(1, "\\x{%04X}", '\\p{^$Prop}');\n/, $FailCode;
1372 printf $FH qq/Expect(1, "\\x{%04X}", '\\P{$Prop}' );\n/, $FailCode;
1373 printf $FH qq/Expect(0, "\\x{%04X}", '\\P{^$Prop}');\n/, $FailCode;
1377 ## This used only for making the test script
1383 print $FH qq/Error('\\p{$prop}');\n/;
1384 print $FH qq/Error('\\P{$prop}');\n/;
1387 ## This used only for making the test script
1403 ## This used only for making the test script
1404 sub RandomlyFuzzifyName($;$)
1407 my $WantError = shift; ## if true, make an error
1410 for my $part (split /[-\s_]+/, $Name)
1413 if ($WantError and rand() < 0.3) {
1414 push @parts, $BadSeps[rand(@BadSeps)];
1417 push @parts, $GoodSeps[rand(@GoodSeps)];
1420 my $switch = int rand(4);
1422 push @parts, uc $part;
1423 } elsif ($switch == 1) {
1424 push @parts, lc $part;
1425 } elsif ($switch == 2) {
1426 push @parts, ucfirst $part;
1431 my $new = join('', @parts);
1434 if (rand() >= 0.5) {
1435 $new .= $BadSeps[rand(@BadSeps)];
1437 $new = $BadSeps[rand(@BadSeps)] . $new;
1443 ## This used only for making the test script
1444 sub MakePropTestScript()
1446 ## this written directly -- it's huge.
1447 if (not open OUT, ">TestProp.pl") {
1448 die "$0: TestProp.pl: $!\n";
1452 while (my ($Name, $Table) = each %ExactNameToTest)
1454 GenTests(*OUT, $Name, $Table->ValidCode, $Table->InvalidCode);
1455 ExpectError(*OUT, uc $Name) if uc $Name ne $Name;
1456 ExpectError(*OUT, lc $Name) if lc $Name ne $Name;
1460 while (my ($Name, $Table) = each %FuzzyNameToTest)
1462 my $Orig = $CanonicalToOrig{$Name};
1466 RandomlyFuzzifyName($Orig) => 1
1469 for my $N (keys %Names) {
1470 GenTests(*OUT, $N, $Table->ValidCode, $Table->InvalidCode);
1473 ExpectError(*OUT, RandomlyFuzzifyName($Orig, 'ERROR'));
1476 print OUT "Finished();\n";
1482 ## These are used only in:
1483 ## RegisterFileForName()
1484 ## WriteAllMappings()
1486 my %Exact; ## will become %utf8::Exact;
1487 my %Canonical; ## will become %utf8::Canonical;
1488 my %CaComment; ## Comment for %Canonical entry of same key
1491 ## Given info about a name and a datafile that it should be associated with,
1492 ## register that assocation in %Exact and %Canonical.
1493 sub RegisterFileForName($$$$)
1497 my $IsFuzzy = shift;
1498 my $filename = shift;
1501 ## Now in details for the mapping. $Type eq 'Is' has the
1502 ## Is removed, as it will be removed in utf8_heavy when this
1503 ## data is being checked. In keeps its "In", but a second
1504 ## sans-In record is written if it doesn't conflict with
1505 ## anything already there.
1509 if ($Type eq 'Is') {
1510 die "oops[$Name]" if $Exact{$Name};
1511 $Exact{$Name} = $filename;
1513 die "oops[$Type$Name]" if $Exact{"$Type$Name"};
1514 $Exact{"$Type$Name"} = $filename;
1515 $Exact{$Name} = $filename if not $Exact{$Name};
1520 my $CName = lc $Name;
1521 if ($Type eq 'Is') {
1522 die "oops[$CName]" if $Canonical{$CName};
1523 $Canonical{$CName} = $filename;
1524 $CaComment{$CName} = $Name if $Name =~ tr/A-Z// >= 2;
1526 die "oops[$Type$CName]" if $Canonical{lc "$Type$CName"};
1527 $Canonical{lc "$Type$CName"} = $filename;
1528 $CaComment{lc "$Type$CName"} = "$Type$Name";
1529 if (not $Canonical{$CName}) {
1530 $Canonical{$CName} = $filename;
1531 $CaComment{$CName} = "$Type$Name";
1538 ## Writes the info accumulated in
1545 sub WriteAllMappings()
1549 my %BaseNames; ## Base names already used (for avoiding 8.3 conflicts)
1551 ## 'Is' *MUST* come first, so its names have precidence over 'In's
1552 for my $Type ('Is', 'In')
1554 my %RawNameToFile; ## a per-$Type cache
1556 for my $Name (sort {length $a <=> length $b} keys %{$TableInfo{$Type}})
1558 ## Note: $Name is already canonical
1559 my $Table = $TableInfo{$Type}->{$Name};
1560 my $IsFuzzy = $FuzzyNames{$Type}->{$Name};
1562 ## Need an 8.3 safe filename (which means "an 8 safe" $filename)
1565 ## 'Is' items lose 'Is' from the basename.
1566 $filename = $Type eq 'Is' ?
1567 ($PVA_reverse{sc}{$Name} || $Name) :
1570 $filename =~ s/[^\w_]+/_/g; # "L&" -> "L_"
1571 substr($filename, 8) = '' if length($filename) > 8;
1574 ## Make sure the basename doesn't conflict with something we
1575 ## might have already written. If we have, say,
1582 while (my $num = $BaseNames{lc $filename}++)
1584 $num++; ## so basenames with numbers start with '2', which
1585 ## just looks more natural.
1586 ## Want to append $num, but if it'll make the basename longer
1587 ## than 8 characters, pre-truncate $filename so that the result
1589 my $delta = length($filename) + length($num) - 8;
1591 substr($filename, -$delta) = $num;
1599 ## Construct a nice comment to add to the file, and build data
1600 ## for the "./Properties" file along the way.
1604 my $Desc = $TableDesc{$Type}->{$Name} || "";
1605 ## get list of names this table is reference by
1606 my @Supported = $Name;
1607 while (my ($Orig, $Alias) = each %{ $AliasInfo{$Type} })
1609 if ($Orig eq $Name) {
1610 push @Supported, $Alias;
1614 my $TypeToShow = $Type eq 'Is' ? "" : $Type;
1617 $Comment = "This file supports:\n";
1618 for my $N (@Supported)
1620 my $IsFuzzy = $FuzzyNames{$Type}->{$N};
1621 my $Prop = "\\p{$TypeToShow$Name}";
1622 $OrigProp = $Prop if not $OrigProp; #cache for aliases
1624 $Comment .= "\t$Prop (and fuzzy permutations)\n";
1626 $Comment .= "\t$Prop\n";
1628 my $MyDesc = ($N eq $Name) ? $Desc : "Alias for $OrigProp ($Desc)";
1630 push @MAP, sprintf("%s %-42s %s\n",
1631 $IsFuzzy ? '*' : ' ', $Prop, $MyDesc);
1634 $Comment .= "\nMeaning: $Desc\n";
1639 ## Okay, write the file...
1641 $Table->Write("lib/gc_sc/$filename.pl", $Comment);
1644 $RawNameToFile{$Name} = $filename;
1645 RegisterFileForName($Type => $Name, $IsFuzzy, $filename);
1649 my $CName = CanonicalName($Type . '_'. $Name);
1650 $FuzzyNameToTest{$Name} = $Table if !$FuzzyNameToTest{$Name};
1651 $FuzzyNameToTest{$CName} = $Table if !$FuzzyNameToTest{$CName};
1653 $ExactNameToTest{$Name} = $Table;
1658 ## Register aliase info
1659 for my $Name (sort {length $a <=> length $b} keys %{$AliasInfo{$Type}})
1661 my $Alias = $AliasInfo{$Type}->{$Name};
1662 my $IsFuzzy = $FuzzyNames{$Type}->{$Alias};
1663 my $filename = $RawNameToFile{$Name};
1664 die "oops [$Alias]->[$Name]" if not $filename;
1665 RegisterFileForName($Type => $Alias, $IsFuzzy, $filename);
1667 my $Table = $TableInfo{$Type}->{$Name};
1668 die "oops" if not $Table;
1671 my $CName = CanonicalName($Type .'_'. $Alias);
1672 $FuzzyNameToTest{$Alias} = $Table if !$FuzzyNameToTest{$Alias};
1673 $FuzzyNameToTest{$CName} = $Table if !$FuzzyNameToTest{$CName};
1675 $ExactNameToTest{$Alias} = $Table;
1681 ## Write out the property list
1686 "## This file created by $0\n",
1687 "## List of built-in \\p{...}/\\P{...} properties.\n",
1689 "## '*' means name may be 'fuzzy'\n",
1691 sort { substr($a,2) cmp substr($b, 2) } @MAP,
1693 WriteIfChanged('Properties', @OUT);
1696 use Text::Tabs (); ## using this makes the files about half the size
1703 "## Data in this file used by ../utf8_heavy.pl\n",
1705 "## Mapping from name to filename in ./lib/gc_sc\n",
1706 "%utf8::Exact = (\n",
1709 $Exact{InGreek} = 'InGreekA'; # this is evil kludge
1710 for my $Name (sort keys %Exact)
1712 my $File = $Exact{$Name};
1713 $Name = $Name =~ m/\W/ ? qq/'$Name'/ : " $Name ";
1714 my $Text = sprintf("%-15s => %s,\n", $Name, qq/'$File'/);
1715 push @OUT, Text::Tabs::unexpand($Text);
1717 push @OUT, ");\n1;\n";
1719 WriteIfChanged('Exact.pl', @OUT);
1722 ## Write Canonical.pl
1727 "## Data in this file used by ../utf8_heavy.pl\n",
1729 "## Mapping from lc(canonical name) to filename in ./lib\n",
1730 "%utf8::Canonical = (\n",
1732 my $Trail = ""; ## used just to keep the spacing pretty
1733 for my $Name (sort keys %Canonical)
1735 my $File = $Canonical{$Name};
1736 if ($CaComment{$Name}) {
1737 push @OUT, "\n" if not $Trail;
1738 push @OUT, " # $CaComment{$Name}\n";
1743 $Name = $Name =~ m/\W/ ? qq/'$Name'/ : " $Name ";
1744 my $Text = sprintf(" %-41s => %s,\n$Trail", $Name, qq/'$File'/);
1745 push @OUT, Text::Tabs::unexpand($Text);
1747 push @OUT, ");\n1\n";
1748 WriteIfChanged('Canonical.pl', @OUT);
1751 MakePropTestScript() if $MakeTestScript;
1755 sub SpecialCasing_txt()
1758 # Read in the special cases.
1763 if (not open IN, "SpecialCasing.txt") {
1764 die "$0: SpecialCasing.txt: $!\n";
1767 next unless /^[0-9A-Fa-f]+;/;
1771 my ($code, $lower, $title, $upper, $condition) = split(/\s*;\s*/);
1773 if ($condition) { # not implemented yet
1774 print "# SKIPPING $_\n" if $Verbose;
1778 # Wait until all the special cases have been read since
1779 # they are not listed in numeric order.
1780 my $ix = hex($code);
1781 push @{$CaseInfo{Lower}}, [ $ix, $code, $lower ]
1782 unless $code eq $lower;
1783 push @{$CaseInfo{Title}}, [ $ix, $code, $title ]
1784 unless $code eq $title;
1785 push @{$CaseInfo{Upper}}, [ $ix, $code, $upper ]
1786 unless $code eq $upper;
1790 # Now write out the special cases properties in their code point order.
1791 # Prepend them to the To/{Upper,Lower,Title}.pl.
1793 for my $case (qw(Lower Title Upper))
1795 my $NormalCase = do "To/$case.pl" || die "$0: $@\n";
1800 "# The key UTF-8 _bytes_, the value UTF-8 (speed hack)\n",
1801 "%utf8::ToSpec$case =\n(\n",
1804 for my $prop (sort { $a->[0] <=> $b->[0] } @{$CaseInfo{$case}}) {
1805 my ($ix, $code, $to) = @$prop;
1807 join "", map { sprintf "\\x{%s}", $_ } split ' ', $to;
1808 push @OUT, sprintf qq["%s" => "$tostr",\n], join("", map { sprintf "\\x%02X", $_ } unpack("U0C*", pack("U", $ix)));
1809 # Remove any single-character mappings for
1810 # the same character since we are going for
1811 # the special casing rules.
1812 $NormalCase =~ s/^$code\t\t\w+\n//m;
1816 "return <<'END';\n",
1820 WriteIfChanged("To/$case.pl", @OUT);
1825 # Read in the case foldings.
1827 # We will do full case folding, C + F + I (see CaseFolding.txt).
1829 sub CaseFolding_txt()
1831 if (not open IN, "CaseFolding.txt") {
1832 die "$0: CaseFolding.txt: $!\n";
1835 my $Fold = Table->New();
1839 # Skip status 'S', simple case folding
1840 next unless /^([0-9A-Fa-f]+)\s*;\s*([CFI])\s*;\s*([0-9A-Fa-f]+(?: [0-9A-Fa-f]+)*)\s*;/;
1842 my ($code, $status, $fold) = (hex($1), $2, $3);
1844 if ($status eq 'C') { # Common: one-to-one folding
1845 # No append() since several codes may fold into one.
1846 $Fold->RawAppendRange($code, $code, $fold);
1847 } else { # F: full, or I: dotted uppercase I -> dotless lowercase I
1848 $Fold{$code} = $fold;
1853 $Fold->Write("To/Fold.pl");
1856 # Prepend the special foldings to the common foldings.
1858 my $CommonFold = do "To/Fold.pl" || die "$0: To/Fold.pl: $!\n";
1863 "# The ke UTF-8 _bytes_, the value UTF-8 (speed hack)\n",
1864 "%utf8::ToSpecFold =\n(\n",
1866 for my $code (sort { $a <=> $b } keys %Fold) {
1868 join "", map { sprintf "\\x{%s}", $_ } split ' ', $Fold{$code};
1869 push @OUT, sprintf qq["%s" => "$foldstr",\n], join("", map { sprintf "\\x%02X", $_ } unpack("U0C*", pack("U", $code)));
1873 "return <<'END';\n",
1878 WriteIfChanged("To/Fold.pl", @OUT);
1893 ArabicShaping_txt();
1894 EastAsianWidth_txt();
1895 HangulSyllableType_txt();
1897 SpecialCasing_txt();
1902 ## TRAILING CODE IS USED BY MakePropTestScript()
1915 my $Line = (caller)[2];
1920 $RegObj = qr/$Regex/;
1921 $String =~ $RegObj ? 1 : 0
1924 if (not defined $result) {
1925 print "couldn't compile /$Regex/ on $0 line $Line: $@\n";
1927 } elsif ($result ^ $Expect) {
1928 print "bad result (expected $Expect) on $0 line $Line: $@\n";
1937 if (eval { 'x' =~ qr/$Regex/; 1 }) {
1939 my $Line = (caller)[2];
1940 print "expected error for /$Regex/ on $0 line $Line: $@\n";
1947 print "All $Tests tests passed.\n";
1950 print "$Tests tests, $Fails failed!\n";