From 9b3b2b295e3ec1cd7970810050b3e11d00bfd2d0 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Sat, 8 Apr 2017 03:06:05 +0200 Subject: [PATCH] charset: length not derived from table --- charset.plp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/charset.plp b/charset.plp index f80a250..16a49e9 100644 --- a/charset.plp +++ b/charset.plp @@ -137,10 +137,11 @@ sub tabinput { my $end = $2 ? hex($2) << 4 : $start + 240; $row{table} = join '', map { chr } $start .. $end+15; utf8::upgrade($row{table}); # prevent latin1 output + $row{len} = length $row{table}; $row{set} = sprintf 'Unicode block U+%02Xxx', $start >> 8; } elsif ($input eq 'U') { - $row{table} = ' ' x 1024; + $row{len} = 1024; $row{set} = 'Unicode planes'; $row{cell} = do 'charset-ucplanes.inc.pl' or Alert('Table data could not be read', $@ || $!); @@ -148,18 +149,19 @@ sub tabinput { } elsif ($row{set} = Encode::resolve_alias($input)) { if ($row{set} eq 'Internal') { - $row{table} = ' ' x ($endpoint < 255 ? 640 : 8192); + $row{len} = $endpoint < 255 ? 640 : 8192; $row{set} = 'Unicode BMP'; $row{cell} = do 'charset-unicode.inc.pl' or Alert('Table data could not be read', $@ || $!); } elsif ($row{set} eq 'utf-8-strict') { - $row{table} = undef; + $row{len} = 256; $row{set} = 'UTF-8'; $row{cell} = do 'charset-utf8.inc.pl' or Alert('Table data could not be read', $@ || $!); } else { + $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) @@ -247,7 +249,7 @@ for my $row (@request) { my $rowdiv = 16 ** $coldigits; # row divide for column digits $rowdiv = 1 if $rowdiv != $cols * $colsize; # divide only if all columns are matched my $offset = 0; - my $endpoint = $offset + (length($row->{table}) || 256) * $colsize; + my $endpoint = $offset + $row->{len} * $colsize; printf '
', !$row->{cell} && ' charmap'; my $title = $row->{set}; -- 2.30.0