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} || "unicore";
28 (my $file = $type) =~ s!::!/!g;
29 if ($file =~ /^(In|in|IN|iN)[- _]?(.+?)\s*$/) { # /i would cause recursion.
31 defined %utf8::In || do "$encoding/In.pl";
32 my $prefix = substr(lc($In), 0, 3);
33 if (exists $utf8::InPat{$prefix}) {
34 for my $k (keys %{$utf8::InPat{$prefix}}) {
36 $In = $utf8::InPat{$prefix}->{$k};
37 if (exists $utf8::In{$In}) {
38 $file = "$encoding/In/$utf8::In{$In}";
45 $file =~ s#^(Is|To)([A-Z].*)#$1/$2#;
50 ( exists &{"${caller}::${type}"} &&
51 eval { $caller->$type() } )
53 || do "$encoding/$file.pl"
54 || do "$encoding/Is/${type}.pl"
55 || croak("Can't find Unicode character property \"$type\"");
61 my @tmp = split(/^/m, $list);
64 $extras = join '', grep /^[^0-9a-fA-F]/, @tmp;
66 sort { hex $a <=> hex $b }
67 grep {/^([0-9a-fA-F]+)/ and not $seen{$1}++} @tmp; # XXX doesn't do ranges right
71 my $hextra = sprintf "%04x", $none + 1;
72 $list =~ s/\tXXXX$/\t$hextra/mg;
77 while ($list =~ /^([0-9a-fA-F]+)(?:\t([0-9a-fA-F]+)?)(?:\t([0-9a-fA-F]+))?/mg) {
79 my $max = hex(defined $2 ? $2 : $1);
80 my $val = hex(defined $3 ? $3 : "");
81 $val += $max - $min if defined $3;
82 $top = $val if $val > $top;
89 $bits = $minbits if $bits < $minbits;
94 while ($x =~ /^([^0-9a-fA-F\n])(.*)/mg) {
97 # print STDERR "$1 => $2\n" if $DEBUG;
98 if ($char =~ /[-+!]/) {
99 my ($c,$t) = split(/::/, $name, 2); # bogus use of ::, really
100 my $subobj = $c->SWASHNEW($t, "", 0, 0, 0);
101 push @extras, $name => $subobj;
102 $bits = $subobj->{BITS} if $bits < $subobj->{BITS};
107 print STDERR "CLASS = $class, TYPE => $type, BITS => $bits, NONE => $none\nEXTRAS =>\n$extras\nLIST =>\n$list\n" if $DEBUG;
109 ${"${class}::{$type}"} = bless {
119 # NOTE: utf8.c:swash_init() assumes entries are never modified once generated.
122 my ($self, $start, $len) = @_;
123 local $^D = 0 if $^D;
124 my $type = $self->{TYPE};
125 my $bits = $self->{BITS};
126 my $none = $self->{NONE};
127 print STDERR "SWASHGET @_ [$type/$bits/$none]\n" if $DEBUG;
128 my $end = $start + $len;
131 vec($swatch, $len - 1, $bits) = 0; # Extend to correct length.
133 for $key (0 .. $len - 1) { vec($swatch, $key, $bits) = $none }
136 for ($self->{LIST}) {
140 while (/^([0-9a-fA-F]+)(?:\t([0-9a-fA-F]+)?)(?:\t([0-9a-fA-F]+))?/mg) {
142 my $max = (defined $2 ? hex $2 : $min);
144 next if $max < $start;
145 # print "$min $max $val\n";
148 $val += $start - $min if $val < $none;
151 for ($key = $min; $key <= $max; $key++) {
152 last LINE if $key >= $end;
153 # print STDERR "$key => $val\n" if $DEBUG;
154 vec($swatch, $key - $start, $bits) = $val;
155 ++$val if $val < $none;
160 $val += $start - $min;
163 for ($key = $min; $key <= $max; $key++, $val++) {
164 last LINE if $key >= $end;
165 # print STDERR "$key => $val\n" if $DEBUG;
166 vec($swatch, $key - $start, $bits) = $val;
173 while (/^([0-9a-fA-F]+)(?:\t([0-9a-fA-F]+))?/mg) {
175 my $max = (defined $2 ? hex $2 : $min);
176 next if $max < $start;
180 for ($key = $min; $key <= $max; $key++) {
181 last LINE if $key >= $end;
182 # print STDERR "$key => 1\n" if $DEBUG;
183 vec($swatch, $key - $start, 1) = 1;
188 for my $x ($self->{EXTRAS}) {
190 while ($x =~ /^([-+!])(.*)/mg) {
193 print STDERR "INDIRECT $1 $2\n" if $DEBUG;
194 my $otherbits = $self->{$name}->{BITS};
195 croak("SWASHGET size mismatch") if $bits < $otherbits;
196 my $other = $self->{$name}->SWASHGET($start, $len);
198 if ($bits == 1 and $otherbits == 1) {
202 for ($key = 0; $key < $len; $key++) {
203 vec($swatch, $key, $bits) = vec($other, $key, $otherbits);
207 elsif ($char eq '!') {
208 if ($bits == 1 and $otherbits == 1) {
212 for ($key = 0; $key < $len; $key++) {
213 if (!vec($other, $key, $otherbits)) {
214 vec($swatch, $key, $bits) = 1;
219 elsif ($char eq '-') {
220 if ($bits == 1 and $otherbits == 1) {
224 for ($key = 0; $key < $len; $key++) {
225 if (vec($other, $key, $otherbits)) {
226 vec($swatch, $key, $bits) = 0;
234 print STDERR "CELLS ";
235 for ($key = 0; $key < $len; $key++) {
236 print STDERR vec($swatch, $key, $bits), " ";