X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/bf64871d2554e77756e10b896bb63589d15b4f73..2dbf5ea33ec8ea148e1859f90d1ced4abef05045:/charset.plp diff --git a/charset.plp b/charset.plp index b1c680e..b1167ea 100644 --- a/charset.plp +++ b/charset.plp @@ -17,8 +17,54 @@ Html({ my @tablist = split m{/+}, $Request || 'default'; +use List::Util qw( first pairmap pairfirst pairs ); + :> -

Character encoding

+

Character encodings

+ +

+<: +if ($tablist[0] eq 'default') { + say "Overview of Unicode allocation and common latin code pages."; + say "Compare alternate charsets:"; +} +else { + say "Charset comparison:"; +} + +sub optionlink { + my ($title, $href, $selected) = @_; + return sprintf( + $selected ? '%s' : '%s', + EscapeHTML($title), $href + ); +} + +print join " •\n", ( + map { + join " ·\n", pairmap { + optionlink($b || ucfirst $a, "/charset/$a?compare", $a eq $Request); + } @{$_} + } + [ + iso => 'ISO', + dos => 'DOS', + mac => 'Apple', + ebcdic => 'EBCDIC', + ], + [ + westeur => 'West', + centeur => 'Central', + norteur => 'North European', + turkish => 0, + greek => 0, + cyrillic => 0, + hebrew => 0, + ], + [ uc => 'Unicode' ], +); +:>. +

<: use POSIX qw( ceil ); @@ -32,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], @@ -46,6 +93,7 @@ sub tabinput { westeur => [qw( iso-8859-1 iso-8859-15 cp1252 iso-8859-14 cp850 hp-roman8 nextstep MacRoman )], centeur => [qw( iso-8859-2 iso-8859-16 cp1250 cp852 MacRomanian MacCroatian MacCentralEurRoman )], # MacRumanian only for DB turkish => [qw( iso-8859-9 iso-8859-3 cp1254 cp857 MacTurkish )], + norteur => [qw( baltic nordic )], baltic => [qw( iso-8859-4 iso-8859-13 cp1257 cp775 )], nordic => [qw( iso-8859-10 cp865 cp861 MacIcelandic MacSami )], cyrillic => [qw( koi8-r koi8-u koi8-f iso-8859-5 cp1251 MacCyrillic cp866 cp855 @@ -78,12 +126,9 @@ 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) { - use List::Util qw( first pairfirst pairs ); - state $INHERIT = { 'cp437' => ['cp850' => 0, 'ascii' => '0-31+128'], # ascii range overridden later 'gsm0338' => ['ascii' => '0-127'], @@ -175,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//; } @@ -191,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) { @@ -213,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'; @@ -230,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 @@ -303,11 +357,22 @@ sub range_cell { } elsif (my $rows = int($len / $cols)) { # multiple full rows + my $rowsize = $colsize * $cols; if ($len -= $rows * $cols) { # partial row remains - $table->{$offset + $colsize*$rows * $cols} //= [$len*$colsize, "$class joinu", '', $title]; + $table->{$offset + $rowsize * $rows} //= [$len*$colsize, "$class joinu", '', $title]; $class .= ' joind'; } + + # coalesce multiple rows + while ($rows > 3) { + $info->{skip}->{$offset += $rowsize}++; + $rows--; + } + if ($rows > 2) { + $info->{skip}->{$offset += $rowsize} = 0; + } + $attr .= sprintf ' rowspan=%d', $rows; $len = $cols; } @@ -325,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}; @@ -346,7 +411,10 @@ for my $row (@request) { } print '
'; - { + if (defined $row->{skip}->{$offset}) { + print '⋮'; + } + else { if (my $rowmod = $offset % $rowdiv) { # offset in column units printf '+%X', $rowmod;