charset: array table for multibyte MacHebrew
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 8 Apr 2017 01:06:59 +0000 (03:06 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 24 Apr 2017 23:51:41 +0000 (01:51 +0200)
charset.plp

index 16a49e92cd132dbf2220cd37cd404955628b8703..e2dac1a67a7307655934a44e5d5a76c50c6a532c 100644 (file)
@@ -161,10 +161,18 @@ sub tabinput {
                                or Alert('Table data could not be read', $@ || $!);
                }
                else {
+                       if ($row{set} eq 'MacHebrew') {
+                               # array of possibly multiple characters per code point
+                               $row{table} = [
+                                       map { Encode::decode($row{set}, pack 'C*', $_) } $row{offset} .. $endpoint
+                               ];
+                       }
+                       else {
+                               # ~16x faster than decoding in loop;
+                               # substr strings is twice as fast as splitting to an array
+                               $row{table} = Encode::decode($row{set}, pack 'C*', $row{offset} .. $endpoint);
+                       }
                        $row{len} = $endpoint - $row{offset};
-                       $row{table} = Encode::decode($row{set}, pack 'C*', $row{offset} .. $endpoint);
-                               # (~16x faster than decoding in loop;
-                               #  substr strings is twice as fast as splitting to an array)
 
                        if ($row{set} eq 'cp437' and !$row{offset}) {
                                substr($row{table}, 237, 1) = pack 'U*', 0x3D5; # phi sign
@@ -281,7 +289,8 @@ for my $row (@request) {
                                next;
                        }
 
-                       my $glyph = substr $row->{table}, $offset, 1;
+                       my $glyph = ref $row->{table} eq 'ARRAY' ? $row->{table}->[$offset] :
+                               substr $row->{table}, $offset, 1;
                        if ($glyph eq $NOCHAR) {
                                print '<td>';
                                next;