7 sub croak { require Carp; Carp::croak(@_) }
10 my ($class, $type, $list, $minbits, $none) = @_;
13 print STDERR "SWASHNEW @_\n" if DEBUG;
15 if ($type and ref ${"${class}::{$type}"} eq $class) {
16 warn qq/Found \${"${class}::{$type}"}\n/ if DEBUG;
17 return ${"${class}::{$type}"}; # Already there...
24 print "type = $type\n" if DEBUG;
28 unless (defined $file) {
29 defined %utf8::Is || do "unicore/Is.pl";
30 if ($type =~ /^(?:Is|Category\s*=\s*)?[- _]?([A-Z].*)$/i) {
32 print "istype = $istype\n" if DEBUG;
33 unless ($list = do "unicore/Is/$istype.pl") {
34 if (exists $utf8::Is{$istype}) {
35 $file = "unicore/Is/$utf8::Is{$istype}";
37 my $isprefix = substr(lc($istype), 0, 2);
38 print "isprefix = $isprefix\n" if DEBUG;
39 if (exists $utf8::IsPat{$isprefix}) {
41 print "isprefix = $isprefix, Is = $Is\n" if DEBUG;
42 for my $k (keys %{$utf8::IsPat{$isprefix}}) {
43 print "isprefix = $isprefix, Is = $Is, k = $k\n" if DEBUG;
45 $file = "unicore/Is/$utf8::IsPat{$isprefix}->{$k}";
46 print "isprefix = $isprefix, Is = $Is, k = $k, file = $file\n" if DEBUG;
55 unless (defined $file) {
56 defined %utf8::In || do "unicore/In.pl";
57 $type = 'Lampersand' if $type =~ /^(?:Is)?L&$/;
58 if ($type =~ /^(In|(?:Script|Block)\s*=\s*)?[- _]?(?!herited$)(.+)/i) {
61 print "incat = $incat, intype = $intype\n" if DEBUG;
62 if (exists $utf8::In{$intype}) {
63 $file = "unicore/In/$utf8::In{$intype}";
65 my $inprefix = substr(lc($intype), 0, 2);
66 print "inprefix = $inprefix\n" if DEBUG;
67 if (exists $utf8::InPat{$inprefix}) {
69 print "inprefix = $inprefix, In = $In\n" if DEBUG;
70 for my $k (keys %{$utf8::InPat{$inprefix}}) {
71 print "inprefix = $inprefix, In = $In, k = $k\n" if DEBUG;
73 my $i = $utf8::InPat{$inprefix}->{$k};
74 print "inprefix = $inprefix, In = $In, k = $k, i = $i\n" if DEBUG;
75 next if $incat =~ /^S/ &&
76 !exists $utf8::InScript{$i};
77 next if $incat =~ /^B/ &&
78 !exists $utf8::InBlock{$i};
79 $file = "unicore/In/$i";
80 print "inprefix = $inprefix, In = $In, k = $k, file = $file\n" if DEBUG;
89 unless (defined $file) {
90 if ($type =~ /^To([A-Z][A-Za-z]+)$/) {
91 $file = "unicore/To/$1";
97 $list = do "$file.pl";
100 croak("Can't find Unicode character property \"$type\"")
108 my @tmp = split(/^/m, $list);
111 $extras = join '', grep /^[^0-9a-fA-F]/, @tmp;
113 sort { hex $a <=> hex $b }
114 grep {/^([0-9a-fA-F]+)/ and not $seen{$1}++} @tmp; # XXX doesn't do ranges right
118 my $hextra = sprintf "%04x", $none + 1;
119 $list =~ s/\tXXXX$/\t$hextra/mg;
124 while ($list =~ /^([0-9a-fA-F]+)(?:\t([0-9a-fA-F]+)?)(?:\t([0-9a-fA-F]+))?/mg) {
126 my $max = hex(defined $2 ? $2 : $1);
127 my $val = hex(defined $3 ? $3 : "");
128 $val += $max - $min if defined $3;
129 $top = $val if $val > $top;
136 $bits = $minbits if $bits < $minbits;
139 for my $x ($extras) {
141 while ($x =~ /^([^0-9a-fA-F\n])(.*)/mg) {
144 print STDERR "$1 => $2\n" if DEBUG;
145 if ($char =~ /[-+!]/) {
146 my ($c,$t) = split(/::/, $name, 2); # bogus use of ::, really
147 my $subobj = $c->SWASHNEW($t, "", 0, 0, 0);
148 push @extras, $name => $subobj;
149 $bits = $subobj->{BITS} if $bits < $subobj->{BITS};
154 print STDERR "CLASS = $class, TYPE => $type, BITS => $bits, NONE => $none\nEXTRAS =>\n$extras\nLIST =>\n$list\n" if DEBUG;
156 ${"${class}::{$type}"} = bless {
166 # NOTE: utf8.c:swash_init() assumes entries are never modified once generated.
169 # See utf8.c:Perl_swash_fetch for problems with this interface.
170 my ($self, $start, $len) = @_;
171 local $^D = 0 if $^D;
172 my $type = $self->{TYPE};
173 my $bits = $self->{BITS};
174 my $none = $self->{NONE};
175 print STDERR "SWASHGET @_ [$type/$bits/$none]\n" if DEBUG;
176 my $end = $start + $len;
179 vec($swatch, $len - 1, $bits) = 0; # Extend to correct length.
181 for $key (0 .. $len - 1) { vec($swatch, $key, $bits) = $none }
184 for ($self->{LIST}) {
188 while (/^([0-9a-fA-F]+)(?:\t([0-9a-fA-F]+)?)(?:\t([0-9a-fA-F]+))?/mg) {
190 my $max = (defined $2 ? hex $2 : $min);
192 next if $max < $start;
193 print "$min $max $val\n" if DEBUG;
196 $val += $start - $min if $val < $none;
199 for ($key = $min; $key <= $max; $key++) {
200 last LINE if $key >= $end;
201 print STDERR "$key => $val\n" if DEBUG;
202 vec($swatch, $key - $start, $bits) = $val;
203 ++$val if $val < $none;
208 $val += $start - $min;
211 for ($key = $min; $key <= $max; $key++, $val++) {
212 last LINE if $key >= $end;
213 print STDERR "$key => $val\n" if DEBUG;
214 vec($swatch, $key - $start, $bits) = $val;
221 while (/^([0-9a-fA-F]+)(?:\t([0-9a-fA-F]+))?/mg) {
223 my $max = (defined $2 ? hex $2 : $min);
224 next if $max < $start;
228 for ($key = $min; $key <= $max; $key++) {
229 last LINE if $key >= $end;
230 print STDERR "$key => 1\n" if DEBUG;
231 vec($swatch, $key - $start, 1) = 1;
236 for my $x ($self->{EXTRAS}) {
238 while ($x =~ /^([-+!])(.*)/mg) {
241 print STDERR "INDIRECT $1 $2\n" if DEBUG;
242 my $otherbits = $self->{$name}->{BITS};
243 croak("SWASHGET size mismatch") if $bits < $otherbits;
244 my $other = $self->{$name}->SWASHGET($start, $len);
246 if ($bits == 1 and $otherbits == 1) {
250 for ($key = 0; $key < $len; $key++) {
251 vec($swatch, $key, $bits) = vec($other, $key, $otherbits);
255 elsif ($char eq '!') {
256 if ($bits == 1 and $otherbits == 1) {
260 for ($key = 0; $key < $len; $key++) {
261 if (!vec($other, $key, $otherbits)) {
262 vec($swatch, $key, $bits) = 1;
267 elsif ($char eq '-') {
268 if ($bits == 1 and $otherbits == 1) {
272 for ($key = 0; $key < $len; $key++) {
273 if (vec($other, $key, $otherbits)) {
274 vec($swatch, $key, $bits) = 0;
282 print STDERR "CELLS ";
283 for ($key = 0; $key < $len; $key++) {
284 print STDERR vec($swatch, $key, $bits), " ";