ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/util/gen_uts46data
Revision: 1.3
Committed: Wed Dec 16 01:22:36 2009 UTC (14 years, 6 months ago) by root
Branch: MAIN
CVS Tags: rel-5_28, rel-5_29, rel-5_24, rel-5_26, rel-5_27, rel-5_3, rel-5_261, rel-5_23, rel-5_31, rel-5_271, rel-5_251
Changes since 1.2: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #!/opt/bin/perl
2
3 # creates lib/AnyEvent/Util/uts46.pl - better do not run it!
4
5 use common::sense;
6 use utf8;
7 no warnings 'utf8';
8
9 binmode STDOUT, ":utf8";
10
11 open my $fh, "GET http://www.unicode.org/Public/idna/5.2.0/IdnaMappingTable.txt |"
12 or die;
13
14 my $valid;
15 my $imap; # index map \x00 char replacement
16
17 while (<$fh>) {
18 next unless /^[0-9A-F]/;
19
20 /^
21 ([0-9A-F]{4,}) (?: \.\.([0-9A-F]{4,}) )?
22 \s*;\s*(\S+)
23 (?: \s*;\s*([0-9A-F ]+?) )?
24 \s*
25 (?: \#.* )?
26 $
27 /x or die "$_: unparsable";
28
29 my ($r1, $r2, $type, $map) = (hex $1, hex $2, $3, $4);
30
31 my $R1 = chr $r1;
32 my $R2 = chr $r2;
33
34 $map = join "", map chr hex, split ' ', $map;
35
36 given ($type) {
37 when ("disallowed") {
38 # nop
39 }
40 when (/mapped|deviation|ignored/) {
41 $map = "\x01$map" if $type eq "deviation";
42
43 $imap .= "\x00" . chr . $map
44 for $r1 .. $r2 || $r1;
45 }
46 when ("valid") {
47 (vec $valid, $_, 1) = 1
48 for $r1 .. $r2 || $r1;
49 }
50 default {
51 die "default: $R1,$R2,$type,$map;\n";
52 }
53 }
54 }
55
56 open my $fh, ">lib/AnyEvent/Util/uts46data.pl"
57 or die;
58 binmode $fh, ":perlio";
59 print $fh "# autogenerated by util/gen_uts46data\n";
60
61 utf8::encode $imap;
62 0 > index $imap, "\x02" # it's not supposed to be anywhere in there
63 or die "imap contains \\x02";
64 print $fh "\$uts46_imap = q\x02$imap\x00\x02;\n";
65
66 # try to find a valid quoting character - there usually are many legal combos
67 for (1..127) { # stay out of utf-8 range
68 if (0 >= index $valid, chr) {
69 print $fh "\$uts46_valid = q", chr, $valid, chr, ";\n";
70 goto valid_ok;
71 }
72 }
73 die "unable to found valid quoting character";
74 valid_ok:;
75
76 print $fh "1;\n";
77 close $fh;
78