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 if ($file =~ /^In(.+)/) {
30 defined %utf8::In || do "$encoding/In.pl";
31 if (exists $utf8::In{$1}) {
32 $file = "$enconding/In/$utf8::In{$1}";
35 $file =~ s#^(Is|To)([A-Z].*)#$1/$2#;
40 ( exists &{"${caller}::${type}"} &&
41 eval { $caller->$type() } )
43 || do "$encoding/$file.pl"
44 || do "$encoding/Is/${type}.pl"
45 || croak("Can't find $encoding character property \"$type\"");
51 my @tmp = split(/^/m, $list);
54 $extras = join '', grep /^[^0-9a-fA-F]/, @tmp;
56 sort { hex $a <=> hex $b }
57 grep {/^([0-9a-fA-F]+)/ and not $seen{$1}++} @tmp; # XXX doesn't do ranges right
61 my $hextra = sprintf "%04x", $none + 1;
62 $list =~ s/\tXXXX$/\t$hextra/mg;
67 while ($list =~ /^([0-9a-fA-F]+)(?:\t([0-9a-fA-F]+)?)(?:\t([0-9a-fA-F]+))?/mg) {
69 my $max = hex(defined $2 ? $2 : $1);
70 my $val = hex(defined $3 ? $3 : "");
71 $val += $max - $min if defined $3;
72 $top = $val if $val > $top;
79 $bits = $minbits if $bits < $minbits;
84 while ($x =~ /^([^0-9a-fA-F\n])(.*)/mg) {
87 # print STDERR "$1 => $2\n" if $DEBUG;
88 if ($char =~ /[-+!]/) {
89 my ($c,$t) = split(/::/, $name, 2); # bogus use of ::, really
90 my $subobj = $c->SWASHNEW($t, "", 0, 0, 0);
91 push @extras, $name => $subobj;
92 $bits = $subobj->{BITS} if $bits < $subobj->{BITS};
97 print STDERR "CLASS = $class, TYPE => $type, BITS => $bits, NONE => $none\nEXTRAS =>\n$extras\nLIST =>\n$list\n" if $DEBUG;
99 ${"${class}::{$type}"} = bless {
109 # NOTE: utf8.c:swash_init() assumes entries are never modified once generated.
112 my ($self, $start, $len) = @_;
113 local $^D = 0 if $^D;
114 my $type = $self->{TYPE};
115 my $bits = $self->{BITS};
116 my $none = $self->{NONE};
117 print STDERR "SWASHGET @_ [$type/$bits/$none]\n" if $DEBUG;
118 my $end = $start + $len;
121 vec($swatch, $len - 1, $bits) = 0; # Extend to correct length.
123 for $key (0 .. $len - 1) { vec($swatch, $key, $bits) = $none }
126 for ($self->{LIST}) {
130 while (/^([0-9a-fA-F]+)(?:\t([0-9a-fA-F]+)?)(?:\t([0-9a-fA-F]+))?/mg) {
132 my $max = (defined $2 ? hex $2 : $min);
134 next if $max < $start;
135 # print "$min $max $val\n";
138 $val += $start - $min if $val < $none;
141 for ($key = $min; $key <= $max; $key++) {
142 last LINE if $key >= $end;
143 # print STDERR "$key => $val\n" if $DEBUG;
144 vec($swatch, $key - $start, $bits) = $val;
145 ++$val if $val < $none;
150 $val += $start - $min;
153 for ($key = $min; $key <= $max; $key++, $val++) {
154 last LINE if $key >= $end;
155 # print STDERR "$key => $val\n" if $DEBUG;
156 vec($swatch, $key - $start, $bits) = $val;
163 while (/^([0-9a-fA-F]+)(?:\t([0-9a-fA-F]+))?/mg) {
165 my $max = (defined $2 ? hex $2 : $min);
166 next if $max < $start;
170 for ($key = $min; $key <= $max; $key++) {
171 last LINE if $key >= $end;
172 # print STDERR "$key => 1\n" if $DEBUG;
173 vec($swatch, $key - $start, 1) = 1;
178 for my $x ($self->{EXTRAS}) {
180 while ($x =~ /^([-+!])(.*)/mg) {
183 print STDERR "INDIRECT $1 $2\n" if $DEBUG;
184 my $otherbits = $self->{$name}->{BITS};
185 croak("SWASHGET size mismatch") if $bits < $otherbits;
186 my $other = $self->{$name}->SWASHGET($start, $len);
188 if ($bits == 1 and $otherbits == 1) {
192 for ($key = 0; $key < $len; $key++) {
193 vec($swatch, $key, $bits) = vec($other, $key, $otherbits);
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) = 1;
209 elsif ($char eq '-') {
210 if ($bits == 1 and $otherbits == 1) {
214 for ($key = 0; $key < $len; $key++) {
215 if (vec($other, $key, $otherbits)) {
216 vec($swatch, $key, $bits) = 0;
224 print STDERR "CELLS ";
225 for ($key = 0; $key < $len; $key++) {
226 print STDERR vec($swatch, $key, $bits), " ";