X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/d5ddd90537e6910cf1b2fd1c6181b98b59d39bd0..2dbf5ea33ec8ea148e1859f90d1ced4abef05045:/charset.plp diff --git a/charset.plp b/charset.plp index f26b7bd..b1167ea 100644 --- a/charset.plp +++ b/charset.plp @@ -61,6 +61,7 @@ print join " •\n", ( cyrillic => 0, hebrew => 0, ], + [ uc => 'Unicode' ], ); :>.

@@ -77,6 +78,7 @@ sub tabinput { state $ALIAS = { default => [qw( unicode+0-639 utf-8 iso-8859-1 iso-8859-15 cp1252 cp437 cp850 )], + uc => [qw( U++ unicode+0-4095 unicode+4096-6319 unicode+6320-8191 )], us => [qw( cp437 cp863 gsm0338 AdobeStandardEncoding )], ebcdic => [qw( cp37 cp500 cp1047 posix-bc cp1026 cp875 )], iso => [map {"iso-8859-$_"} 1 .. 11, 13 .. 16], @@ -124,7 +126,6 @@ sub tabinput { state $visible = {}; # all present tables my %row = (offset => 0, cols => 16); - my $endpoint = 255; my $params = $input =~ s/[+](.*)\z// ? $1 : undef; if (not defined $params) { @@ -219,7 +220,8 @@ sub tabinput { } $visible->{$_} //= 0 for $row{parent} || (); } - else { + + if (length $params) { # manual option to double table width $row{cols} *= 2 if $params =~ s/[+]\z//; } @@ -235,7 +237,7 @@ sub tabinput { ]); $row{offset} = $+{offset}; - $endpoint = $+{endpoint} if $+{endpoint}; + $row{endpoint} = $+{endpoint} if $+{endpoint}; if (my $restart = $+{restart}) { my $skip = int(($+{stop} || $row{offset}) / $row{cols}); for ($skip + 1 .. ($restart / $row{cols}) - 1) { @@ -257,15 +259,22 @@ sub tabinput { $row{set} = 'Unicode planes'; $row{cell} = do 'charset-ucplanes.inc.pl' or Alert('Table data could not be read', $@ || $!); - $row{cols} *= 2; $row{endpoint} = 1023 * $row{cell}->{colsize}; } elsif ($row{set} = Encode::resolve_alias($input)) { if ($row{set} eq 'Internal') { - $row{set} = 'Unicode BMP'; $row{cell} = do 'charset-unicode.inc.pl' or Alert('Table data could not be read', $@ || $!); - $row{endpoint} = ($endpoint || 8191) * $row{cell}->{colsize}; + + $row{endpoint} ||= 8191; + $row{endpoint} *= $row{cell}->{colsize}; + $row{startpoint} = $row{cell}->{colsize} * $row{offset}; + $row{offset} = 0; + $row{set} = 'Unicode ' . ( + $row{startpoint} < 0x10000 && $row{endpoint} < 0x10000 ? 'BMP' : + $row{startpoint} >= 0x10000 && $row{endpoint} < 0x20000 ? 'SMP' : + 'allocations' + ); } elsif ($row{set} eq 'utf-8-strict') { $row{set} = 'UTF-8'; @@ -274,18 +283,19 @@ sub tabinput { $row{endpoint} = 255; } else { + $row{endpoint} ||= 255; if ($row{set} eq 'MacHebrew' or $row{set} eq 'MacThai') { # array of possibly multiple characters per code point $row{table} = [ - map { Encode::decode($row{set}, pack 'C*', $_) } $row{offset} .. $endpoint + map { Encode::decode($row{set}, pack 'C*', $_) } $row{offset} .. $row{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{table} = Encode::decode($row{set}, pack 'C*', $row{offset} .. $row{endpoint}); } - $row{endpoint} = $endpoint - $row{offset}; + $row{endpoint} -= $row{offset}; if ($row{set} eq 'cp437' and !$row{offset}) { substr($row{table}, 237, 1) = pack 'U*', 0x3D5; # phi sign @@ -380,7 +390,7 @@ for my $row (@request) { my $coldigits = ceil(log($colsize * $cols) / log(16)); # uniform length of hexadecimal header 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 $offset = $row->{startpoint} || 0; printf '
', !$row->{cell} && ' charmap'; my $title = $row->{set};