8 sub croak
{ require Carp
; Carp
::croak
(@_) }
11 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...
26 while (($caller = caller($i)) eq __PACKAGE__
) { $i++ }
27 my $encoding = $enc{$caller} || "unicode";
28 (my $file = $type) =~ s!::!/!g;
29 $file =~ s
#^(I[sn]|To)([A-Z].*)#$1/$2#;
30 $list ||= eval { $caller->$type(); }
32 || do "$encoding/$file.pl"
33 || do "$encoding/Is/${type}.pl"
34 || croak
("Can't find $encoding character property definition via $caller->$type or $file.pl");
39 my @tmp = split(/^/m, $list);
42 $extras = join '', grep /^[^0-9a-fA-F]/, @tmp;
44 sort { hex $a <=> hex $b }
45 grep {/^([0-9a-fA-F]+)/ and not $seen{$1}++} @tmp; # XXX doesn't do ranges right
49 my $hextra = sprintf "%04x", $none + 1;
50 $list =~ s/\tXXXX$/\t$hextra/mg;
55 while ($list =~ /^([0-9a-fA-F]+)(?:\t([0-9a-fA-F]+)?)(?:\t([0-9a-fA-F]+))?/mg) {
57 my $max = hex(defined $2 ?
$2 : $1);
58 my $val = hex(defined $3 ?
$3 : "");
59 $val += $max - $min if defined $3;
60 $top = $val if $val > $top;
67 $bits = $minbits if $bits < $minbits;
72 while ($x =~ /^([^0-9a-fA-F\n])(.*)/mg) {
75 # print STDERR "$1 => $2\n" if $DEBUG;
76 if ($char =~ /[-+!]/) {
77 my ($c,$t) = split(/::/, $name, 2); # bogus use of ::, really
78 my $subobj = $c->SWASHNEW($t, "", 0, 0, 0);
79 push @extras, $name => $subobj;
80 $bits = $subobj->{BITS
} if $bits < $subobj->{BITS
};
85 print STDERR
"CLASS = $class, TYPE => $type, BITS => $bits, NONE => $none\nEXTRAS =>\n$extras\nLIST =>\n$list\n" if $DEBUG;
87 ${"${class}::{$type}"} = bless {
97 # NOTE: utf8.c:swash_init() assumes entries are never modified once generated.
100 my ($self, $start, $len) = @_;
101 local $^D
= 0 if $^D
;
102 my $type = $self->{TYPE
};
103 my $bits = $self->{BITS
};
104 my $none = $self->{NONE
};
105 print STDERR
"SWASHGET @_ [$type/$bits/$none]\n" if $DEBUG;
106 my $end = $start + $len;
109 vec($swatch, $len - 1, $bits) = 0; # Extend to correct length.
111 for $key (0 .. $len - 1) { vec($swatch, $key, $bits) = $none }
114 for ($self->{LIST
}) {
118 while (/^([0-9a-fA-F]+)(?:\t([0-9a-fA-F]+)?)(?:\t([0-9a-fA-F]+))?/mg) {
120 my $max = (defined $2 ?
hex $2 : $min);
122 next if $max < $start;
123 # print "$min $max $val\n";
126 $val += $start - $min if $val < $none;
129 for ($key = $min; $key <= $max; $key++) {
130 last LINE
if $key >= $end;
131 # print STDERR "$key => $val\n" if $DEBUG;
132 vec($swatch, $key - $start, $bits) = $val;
133 ++$val if $val < $none;
138 $val += $start - $min;
141 for ($key = $min; $key <= $max; $key++, $val++) {
142 last LINE
if $key >= $end;
143 # print STDERR "$key => $val\n" if $DEBUG;
144 vec($swatch, $key - $start, $bits) = $val;
151 while (/^([0-9a-fA-F]+)(?:\t([0-9a-fA-F]+))?/mg) {
153 my $max = (defined $2 ?
hex $2 : $min);
154 next if $max < $start;
158 for ($key = $min; $key <= $max; $key++) {
159 last LINE
if $key >= $end;
160 # print STDERR "$key => 1\n" if $DEBUG;
161 vec($swatch, $key - $start, 1) = 1;
166 for my $x ($self->{EXTRAS
}) {
168 while ($x =~ /^([-+!])(.*)/mg) {
171 print STDERR
"INDIRECT $1 $2\n" if $DEBUG;
172 my $otherbits = $self->{$name}->{BITS
};
173 croak
("SWASHGET size mismatch") if $bits < $otherbits;
174 my $other = $self->{$name}->SWASHGET($start, $len);
176 if ($bits == 1 and $otherbits == 1) {
180 for ($key = 0; $key < $len; $key++) {
181 vec($swatch, $key, $bits) = vec($other, $key, $otherbits);
185 elsif ($char eq '!') {
186 if ($bits == 1 and $otherbits == 1) {
190 for ($key = 0; $key < $len; $key++) {
191 if (!vec($other, $key, $otherbits)) {
192 vec($swatch, $key, $bits) = 1;
197 elsif ($char eq '-') {
198 if ($bits == 1 and $otherbits == 1) {
202 for ($key = 0; $key < $len; $key++) {
203 if (vec($other, $key, $otherbits)) {
204 vec($swatch, $key, $bits) = 0;
212 print STDERR
"CELLS ";
213 for ($key = 0; $key < $len; $key++) {
214 print STDERR
vec($swatch, $key, $bits), " ";