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(.+)/) {
31 defined %utf8::In || do "$encoding/In.pl";
32 if (exists $utf8::In{$In}) {
33 $file = "$encoding/In/$utf8::In{$In}";
36 $file =~ s#^(Is|To)([A-Z].*)#$1/$2#;
41 ( exists &{"${caller}::${type}"} &&
42 eval { $caller->$type() } )
44 || do "$encoding/$file.pl"
45 || do "$encoding/Is/${type}.pl"
46 || croak("Can't find $encoding character property \"$type\"");
52 my @tmp = split(/^/m, $list);
55 $extras = join '', grep /^[^0-9a-fA-F]/, @tmp;
57 sort { hex $a <=> hex $b }
58 grep {/^([0-9a-fA-F]+)/ and not $seen{$1}++} @tmp; # XXX doesn't do ranges right
62 my $hextra = sprintf "%04x", $none + 1;
63 $list =~ s/\tXXXX$/\t$hextra/mg;
68 while ($list =~ /^([0-9a-fA-F]+)(?:\t([0-9a-fA-F]+)?)(?:\t([0-9a-fA-F]+))?/mg) {
70 my $max = hex(defined $2 ? $2 : $1);
71 my $val = hex(defined $3 ? $3 : "");
72 $val += $max - $min if defined $3;
73 $top = $val if $val > $top;
80 $bits = $minbits if $bits < $minbits;
85 while ($x =~ /^([^0-9a-fA-F\n])(.*)/mg) {
88 # print STDERR "$1 => $2\n" if $DEBUG;
89 if ($char =~ /[-+!]/) {
90 my ($c,$t) = split(/::/, $name, 2); # bogus use of ::, really
91 my $subobj = $c->SWASHNEW($t, "", 0, 0, 0);
92 push @extras, $name => $subobj;
93 $bits = $subobj->{BITS} if $bits < $subobj->{BITS};
98 print STDERR "CLASS = $class, TYPE => $type, BITS => $bits, NONE => $none\nEXTRAS =>\n$extras\nLIST =>\n$list\n" if $DEBUG;
100 ${"${class}::{$type}"} = bless {
110 # NOTE: utf8.c:swash_init() assumes entries are never modified once generated.
113 my ($self, $start, $len) = @_;
114 local $^D = 0 if $^D;
115 my $type = $self->{TYPE};
116 my $bits = $self->{BITS};
117 my $none = $self->{NONE};
118 print STDERR "SWASHGET @_ [$type/$bits/$none]\n" if $DEBUG;
119 my $end = $start + $len;
122 vec($swatch, $len - 1, $bits) = 0; # Extend to correct length.
124 for $key (0 .. $len - 1) { vec($swatch, $key, $bits) = $none }
127 for ($self->{LIST}) {
131 while (/^([0-9a-fA-F]+)(?:\t([0-9a-fA-F]+)?)(?:\t([0-9a-fA-F]+))?/mg) {
133 my $max = (defined $2 ? hex $2 : $min);
135 next if $max < $start;
136 # print "$min $max $val\n";
139 $val += $start - $min if $val < $none;
142 for ($key = $min; $key <= $max; $key++) {
143 last LINE if $key >= $end;
144 # print STDERR "$key => $val\n" if $DEBUG;
145 vec($swatch, $key - $start, $bits) = $val;
146 ++$val if $val < $none;
151 $val += $start - $min;
154 for ($key = $min; $key <= $max; $key++, $val++) {
155 last LINE if $key >= $end;
156 # print STDERR "$key => $val\n" if $DEBUG;
157 vec($swatch, $key - $start, $bits) = $val;
164 while (/^([0-9a-fA-F]+)(?:\t([0-9a-fA-F]+))?/mg) {
166 my $max = (defined $2 ? hex $2 : $min);
167 next if $max < $start;
171 for ($key = $min; $key <= $max; $key++) {
172 last LINE if $key >= $end;
173 # print STDERR "$key => 1\n" if $DEBUG;
174 vec($swatch, $key - $start, 1) = 1;
179 for my $x ($self->{EXTRAS}) {
181 while ($x =~ /^([-+!])(.*)/mg) {
184 print STDERR "INDIRECT $1 $2\n" if $DEBUG;
185 my $otherbits = $self->{$name}->{BITS};
186 croak("SWASHGET size mismatch") if $bits < $otherbits;
187 my $other = $self->{$name}->SWASHGET($start, $len);
189 if ($bits == 1 and $otherbits == 1) {
193 for ($key = 0; $key < $len; $key++) {
194 vec($swatch, $key, $bits) = vec($other, $key, $otherbits);
198 elsif ($char eq '!') {
199 if ($bits == 1 and $otherbits == 1) {
203 for ($key = 0; $key < $len; $key++) {
204 if (!vec($other, $key, $otherbits)) {
205 vec($swatch, $key, $bits) = 1;
210 elsif ($char eq '-') {
211 if ($bits == 1 and $otherbits == 1) {
215 for ($key = 0; $key < $len; $key++) {
216 if (vec($other, $key, $otherbits)) {
217 vec($swatch, $key, $bits) = 0;
225 print STDERR "CELLS ";
226 for ($key = 0; $key < $len; $key++) {
227 print STDERR vec($swatch, $key, $bits), " ";