7 sub croak { require Carp; Carp::croak(@_) }
10 my ($class, $type, $list, $minbits, $none) = @_;
13 print STDERR "SWASHNEW @_\n" if DEBUG;
17 if ($type and ref ${"${class}::{$type}"} eq $class) {
18 warn qq/Found \${"${class}::{$type}"}\n/ if DEBUG;
19 return ${"${class}::{$type}"}; # Already there...
24 defined %utf8::In || do "unicore/In.pl";
26 $type =~ s/^In(?:[-_]|\s+)?(?!herited$)//i;
29 $type = 'Lampersand' if $type =~ /^(?:Is)?L&$/;
31 my $inprefix = substr(lc($type), 0, 2);
32 if (exists $utf8::InPat{$inprefix}) {
34 for my $k (keys %{$utf8::InPat{$inprefix}}) {
36 $In = $utf8::InPat{$inprefix}->{$k};
37 if (exists $utf8::In{$In}) {
38 $file = "unicore/In/$utf8::In{$In}";
39 print "inprefix = $inprefix, In = $In, k = $k, file = $file\n" if DEBUG;
46 unless (defined $file) {
47 # This is separate from 'To' in preparation of Is.pl (a la In.pl).
48 if ($type =~ /^Is([A-Z][A-Za-z]*)$/) {
49 $file = "unicore/Is/$1";
50 } elsif ((not defined $file) && $type =~ /^To([A-Z][A-Za-z]*)$/) {
51 $file = "unicore/To/$1";
57 $list ||= do "$file.pl"
58 || do "unicore/Is/$type.pl"
59 || croak("Can't find Unicode character property \"$type\"");
66 my @tmp = split(/^/m, $list);
69 $extras = join '', grep /^[^0-9a-fA-F]/, @tmp;
71 sort { hex $a <=> hex $b }
72 grep {/^([0-9a-fA-F]+)/ and not $seen{$1}++} @tmp; # XXX doesn't do ranges right
76 my $hextra = sprintf "%04x", $none + 1;
77 $list =~ s/\tXXXX$/\t$hextra/mg;
82 while ($list =~ /^([0-9a-fA-F]+)(?:\t([0-9a-fA-F]+)?)(?:\t([0-9a-fA-F]+))?/mg) {
84 my $max = hex(defined $2 ? $2 : $1);
85 my $val = hex(defined $3 ? $3 : "");
86 $val += $max - $min if defined $3;
87 $top = $val if $val > $top;
94 $bits = $minbits if $bits < $minbits;
99 while ($x =~ /^([^0-9a-fA-F\n])(.*)/mg) {
102 # print STDERR "$1 => $2\n" if DEBUG;
103 if ($char =~ /[-+!]/) {
104 my ($c,$t) = split(/::/, $name, 2); # bogus use of ::, really
105 my $subobj = $c->SWASHNEW($t, "", 0, 0, 0);
106 push @extras, $name => $subobj;
107 $bits = $subobj->{BITS} if $bits < $subobj->{BITS};
112 print STDERR "CLASS = $class, TYPE => $type, BITS => $bits, NONE => $none\nEXTRAS =>\n$extras\nLIST =>\n$list\n" if DEBUG;
114 ${"${class}::{$type}"} = bless {
124 # NOTE: utf8.c:swash_init() assumes entries are never modified once generated.
127 my ($self, $start, $len) = @_;
128 local $^D = 0 if $^D;
129 my $type = $self->{TYPE};
130 my $bits = $self->{BITS};
131 my $none = $self->{NONE};
132 print STDERR "SWASHGET @_ [$type/$bits/$none]\n" if DEBUG;
133 my $end = $start + $len;
136 vec($swatch, $len - 1, $bits) = 0; # Extend to correct length.
138 for $key (0 .. $len - 1) { vec($swatch, $key, $bits) = $none }
141 for ($self->{LIST}) {
145 while (/^([0-9a-fA-F]+)(?:\t([0-9a-fA-F]+)?)(?:\t([0-9a-fA-F]+))?/mg) {
147 my $max = (defined $2 ? hex $2 : $min);
149 next if $max < $start;
150 # print "$min $max $val\n";
153 $val += $start - $min if $val < $none;
156 for ($key = $min; $key <= $max; $key++) {
157 last LINE if $key >= $end;
158 # print STDERR "$key => $val\n" if DEBUG;
159 vec($swatch, $key - $start, $bits) = $val;
160 ++$val if $val < $none;
165 $val += $start - $min;
168 for ($key = $min; $key <= $max; $key++, $val++) {
169 last LINE if $key >= $end;
170 # print STDERR "$key => $val\n" if DEBUG;
171 vec($swatch, $key - $start, $bits) = $val;
178 while (/^([0-9a-fA-F]+)(?:\t([0-9a-fA-F]+))?/mg) {
180 my $max = (defined $2 ? hex $2 : $min);
181 next if $max < $start;
185 for ($key = $min; $key <= $max; $key++) {
186 last LINE if $key >= $end;
187 # print STDERR "$key => 1\n" if DEBUG;
188 vec($swatch, $key - $start, 1) = 1;
193 for my $x ($self->{EXTRAS}) {
195 while ($x =~ /^([-+!])(.*)/mg) {
198 print STDERR "INDIRECT $1 $2\n" if DEBUG;
199 my $otherbits = $self->{$name}->{BITS};
200 croak("SWASHGET size mismatch") if $bits < $otherbits;
201 my $other = $self->{$name}->SWASHGET($start, $len);
203 if ($bits == 1 and $otherbits == 1) {
207 for ($key = 0; $key < $len; $key++) {
208 vec($swatch, $key, $bits) = vec($other, $key, $otherbits);
212 elsif ($char eq '!') {
213 if ($bits == 1 and $otherbits == 1) {
217 for ($key = 0; $key < $len; $key++) {
218 if (!vec($other, $key, $otherbits)) {
219 vec($swatch, $key, $bits) = 1;
224 elsif ($char eq '-') {
225 if ($bits == 1 and $otherbits == 1) {
229 for ($key = 0; $key < $len; $key++) {
230 if (vec($other, $key, $otherbits)) {
231 vec($swatch, $key, $bits) = 0;
239 print STDERR "CELLS ";
240 for ($key = 0; $key < $len; $key++) {
241 print STDERR vec($swatch, $key, $bits), " ";