X-Git-Url: http://git.shiar.net/sheet.git/blobdiff_plain/a0ba9298856b2426c5c66b6d2f2b284d98cee594..65ee755208200729b5754d38aa35dc168251c3e7:/charset.plp?ds=sidebyside diff --git a/charset.plp b/charset.plp index c9ef2b6..3bf294e 100644 --- a/charset.plp +++ b/charset.plp @@ -1,185 +1,231 @@ -<: -use utf8; -use strict; -use warnings; -use open IO => ':utf8'; - -our $VERSION = '1.0'; - -$header{content_type} = 'text/html; charset=utf-8'; - -:> - +<(common.inc.plp)><: + +Html({ + title => 'charset cheat sheet', + version => '1.0', + description => [ + "Reference sheet with all glyphs in common character encoding tables,", + "and an overview of Unicode ranges and UTF-8 bytes.", + ], + keywords => [qw' + charset codepage unicode ascii utf8 latin glyph character encoding + reference common overview table + '], + stylesheet => [qw'light'], + data => [qw'charset-unicode.inc.pl charset-utf8.inc.pl'], +}); -
-Table data could not be read: %s.
\n", $@ || $!; + @nibble = (map { $_.0, $_.8 } 0 .. 7); + $nibsize = 8; + } + elsif ($row{set} = resolve_alias($input)) { + if ($row{set} eq 'Internal') { + $row{table} = ' ' x ($endpoint < 255 ? 640 : 8192); + $row{set} = 'Unicode BMP'; + $row{cell} = do 'charset-unicode.inc.pl' + or printf "Table data could not be read: %s.
\n", $@ || $!; + } + elsif ($row{set} eq 'utf-8-strict') { + $row{table} = undef; + $row{set} = 'UTF-8'; + $row{cell} = do 'charset-utf8.inc.pl' + or printf "Table data could not be read: %s.
\n", $@ || $!; + } + else { + $row{table} = decode($row{set}, pack 'C*', $row{offset} .. $endpoint); + } + } + else { + say "Encoding $input
unknown
â±"; - print ' | ', $_ for @nibble; - print "\n"; +sub range_cell { + my ($table, $offset) = @_; + my $def = $table->{$offset} or return; + my ($len, $class, $name, $title) = @{$def}; + + my $attr = ''; + $len /= $nibsize; + $name //= $len <= 2 ? 'res' : 'reserved'; + + if (my $part = $offset/$nibsize % 16) { + # continued row + my $cols = 16 - $part; # remaining + $cols = $len if $len < $cols; #TODO: optimise + if ($len -= $cols) { + # continued on new row + $table->{$offset + $nibsize*$cols} //= [$len*$nibsize, "$class joinu", $name, $title]; + $name = ''; + $class .= ' joind'; + } + $len = $cols; } - print ' | |
---|---|---|
', $nibble[$msb]; - for my $lsb (0 .. $#nibble) { - my $glyph = substr $tables[$tablenum], ($msb<<4) + $lsb, 1; - if ($glyph eq $NOCHAR) { - print ' | '; - next; - } - my $info = [ord $glyph]; - if (defined (my $mnem = $di{ord $glyph})) { - $info = $diinfo->{$mnem}; - } - my ($codepoint, $name, $prop, $script, $string) = @$info; - - $glyph = quote($string || $glyph); - my $desc = sprintf 'U+%04X%s', $codepoint, $name && " ($name)"; - my @class = ('X', grep {$_} $prop, $script); - - $glyph = "$glyph" if $prop eq 'Zs'; - - printf "\n".' | %s', - join(' ', @class), quote($desc), $glyph; + elsif (my $rows = $len >> 4) { + # multiple full rows + if ($len -= $rows << 4) { + # partial row remains + $table->{$offset + $nibsize*$rows * 16} //= [$len*$nibsize, "$class joinu", '', $title]; + $class .= ' joind'; } - print "\n"; + $attr .= sprintf ' rowspan=%d', $rows; + $len = 16; } - print " |
â±"; print ' | ', $_ for @nibble; print "\n"; } print ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
', $nibble[$msb]; + for my $msb (0 .. (length($row->{table}) || 256) - 1 >> 4) { + printf ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
%X', ($msb + ($row->{offset} >> 4)) * $nibsize; for my $lsb (0 .. $#nibble) { - my $value = ($msb<<4) + $lsb; - if ($value <= 0x7F) { - print ' | Single byte ASCII' - if $value == 0; - } - elsif ($value <= 0xBF) { - print ' | Multi-byte continuation' - if $value == 0x80; - } - elsif ($value <= 0xC1) { - print ' | (Overl.)' - if $value == 0xC0; - } - elsif ($value <= 0xDF) { - print ' | 2-byte sequence start' - if $value == 0xC2; - print ' | ' - if $value == 0xD0; - } - elsif ($value <= 0xEF) { - print ' | 3-byte sequence start' - if $value == 0xE0; - } - elsif ($value <= 0xF4) { - print ' | 4-byte sequence' - if $value == 0xF0; - } - elsif ($value <= 0xF7) { - print ' | (Overflow)' - if $value == 0xF5; - } - elsif ($value <= 0xFB) { - print ' | 5-byte' - if $value == 0xF8; - } - elsif ($value <= 0xFD) { - print ' | 6-byte' - if $value == 0xFC; - } - elsif ($value <= 0xFF) { - print ' | Invalid' - if $value == 0xFE; + my $val = ( ($msb<<4) + $lsb ) * $nibsize; + if ($row->{cell}) { + if (ref $row->{cell} eq 'CODE') { + print $row->{cell}->($val); + next; + } + print range_cell($row->{cell}, $val); + next; } - else { - print "\n".' | ?'; + + my $glyph = substr $row->{table}, $val, 1; + if ($glyph eq $NOCHAR) { + print ' | '; + next; } + + print "\n".$glyphs->glyph_cell($glyph); } print "\n"; } - print " |
control + | whitespace + | diacritic
| punctuation
| symbol
| numeric + | greek
| aramaic
| syllabic
| alphabetic + |
unicode 7.0 + | proposed + | deprecated + | unassigned + | invalid + |