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 $type = 'Assigned' if $type =~ /^(?:Is)?Assigned$/i;
59 $type = 'Unassigned' if $type =~ /^(?:Is)?Unassigned$/i;
60 if ($type =~ /^(In|(?:Script|Block)\s*=\s*)?[- _]?(?!herited$)(.+)/i) {
63 print "incat = $incat, intype = $intype\n" if DEBUG;
64 if (exists $utf8::In{$intype}) {
65 $file = "unicore/In/$utf8::In{$intype}";
67 my $inprefix = substr(lc($intype), 0, 2);
68 print "inprefix = $inprefix\n" if DEBUG;
69 if (exists $utf8::InPat{$inprefix}) {
71 print "inprefix = $inprefix, In = $In\n" if DEBUG;
72 for my $k (keys %{$utf8::InPat{$inprefix}}) {
73 print "inprefix = $inprefix, In = $In, k = $k\n" if DEBUG;
75 my $i = $utf8::InPat{$inprefix}->{$k};
76 print "inprefix = $inprefix, In = $In, k = $k, i = $i\n" if DEBUG;
77 next if $incat =~ /^S/ &&
78 !exists $utf8::InScript{$i};
79 next if $incat =~ /^B/ &&
80 !exists $utf8::InBlock{$i};
81 $file = "unicore/In/$i";
82 print "inprefix = $inprefix, In = $In, k = $k, file = $file\n" if DEBUG;
91 unless (defined $file) {
92 if ($type =~ /^To([A-Z][A-Za-z]+)$/) {
93 $file = "unicore/To/$1";
99 $list = do "$file.pl";
102 croak("Can't find Unicode character property \"$type\"")
110 my @tmp = split(/^/m, $list);
113 $extras = join '', grep /^[^0-9a-fA-F]/, @tmp;
115 sort { hex $a <=> hex $b }
116 grep {/^([0-9a-fA-F]+)/ and not $seen{$1}++} @tmp; # XXX doesn't do ranges right
120 my $hextra = sprintf "%04x", $none + 1;
121 $list =~ s/\tXXXX$/\t$hextra/mg;
126 while ($list =~ /^([0-9a-fA-F]+)(?:\t([0-9a-fA-F]+)?)(?:\t([0-9a-fA-F]+))?/mg) {
128 my $max = hex(defined $2 ? $2 : $1);
129 my $val = hex(defined $3 ? $3 : "");
130 $val += $max - $min if defined $3;
131 $top = $val if $val > $top;
138 $bits = $minbits if $bits < $minbits;
141 for my $x ($extras) {
143 while ($x =~ /^([^0-9a-fA-F\n])(.*)/mg) {
146 print STDERR "$1 => $2\n" if DEBUG;
147 if ($char =~ /[-+!]/) {
148 my ($c,$t) = split(/::/, $name, 2); # bogus use of ::, really
149 my $subobj = $c->SWASHNEW($t, "", 0, 0, 0);
150 push @extras, $name => $subobj;
151 $bits = $subobj->{BITS} if $bits < $subobj->{BITS};
156 print STDERR "CLASS = $class, TYPE => $type, BITS => $bits, NONE => $none\nEXTRAS =>\n$extras\nLIST =>\n$list\n" if DEBUG;
158 ${"${class}::{$type}"} = bless {
168 # NOTE: utf8.c:swash_init() assumes entries are never modified once generated.
171 # See utf8.c:Perl_swash_fetch for problems with this interface.
172 my ($self, $start, $len) = @_;
173 local $^D = 0 if $^D;
174 my $type = $self->{TYPE};
175 my $bits = $self->{BITS};
176 my $none = $self->{NONE};
177 print STDERR "SWASHGET @_ [$type/$bits/$none]\n" if DEBUG;
178 my $end = $start + $len;
181 vec($swatch, $len - 1, $bits) = 0; # Extend to correct length.
183 for $key (0 .. $len - 1) { vec($swatch, $key, $bits) = $none }
186 for ($self->{LIST}) {
190 while (/^([0-9a-fA-F]+)(?:\t([0-9a-fA-F]+)?)(?:\t([0-9a-fA-F]+))?/mg) {
192 my $max = (defined $2 ? hex $2 : $min);
194 next if $max < $start;
195 print "$min $max $val\n" if DEBUG;
198 $val += $start - $min if $val < $none;
201 for ($key = $min; $key <= $max; $key++) {
202 last LINE if $key >= $end;
203 print STDERR "$key => $val\n" if DEBUG;
204 vec($swatch, $key - $start, $bits) = $val;
205 ++$val if $val < $none;
210 $val += $start - $min;
213 for ($key = $min; $key <= $max; $key++, $val++) {
214 last LINE if $key >= $end;
215 print STDERR "$key => $val\n" if DEBUG;
216 vec($swatch, $key - $start, $bits) = $val;
223 while (/^([0-9a-fA-F]+)(?:\t([0-9a-fA-F]+))?/mg) {
225 my $max = (defined $2 ? hex $2 : $min);
226 next if $max < $start;
230 for ($key = $min; $key <= $max; $key++) {
231 last LINE if $key >= $end;
232 print STDERR "$key => 1\n" if DEBUG;
233 vec($swatch, $key - $start, 1) = 1;
238 for my $x ($self->{EXTRAS}) {
240 while ($x =~ /^([-+!])(.*)/mg) {
243 print STDERR "INDIRECT $1 $2\n" if DEBUG;
244 my $otherbits = $self->{$name}->{BITS};
245 croak("SWASHGET size mismatch") if $bits < $otherbits;
246 my $other = $self->{$name}->SWASHGET($start, $len);
248 if ($bits == 1 and $otherbits == 1) {
252 for ($key = 0; $key < $len; $key++) {
253 vec($swatch, $key, $bits) = vec($other, $key, $otherbits);
257 elsif ($char eq '!') {
258 if ($bits == 1 and $otherbits == 1) {
262 for ($key = 0; $key < $len; $key++) {
263 if (!vec($other, $key, $otherbits)) {
264 vec($swatch, $key, $bits) = 1;
269 elsif ($char eq '-') {
270 if ($bits == 1 and $otherbits == 1) {
274 for ($key = 0; $key < $len; $key++) {
275 if (vec($other, $key, $otherbits)) {
276 vec($swatch, $key, $bits) = 0;
284 print STDERR "CELLS ";
285 for ($key = 0; $key < $len; $key++) {
286 print STDERR vec($swatch, $key, $bits), " ";