-<:
-use utf8;
-use strict;
-use warnings;
-use open IO => ':utf8';
-
-our $VERSION = '1.0';
+<(common.inc.plp)><:
-$header{content_type} = 'text/html; charset=utf-8';
+my $mode = exists $get{compare};
+my @tablist = split m{/+}, $Request || 'default';
-:><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
- "http://www.w3.org/TR/html4/loose.dtd">
-<html>
+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-encoding.inc.pl
+ charset-unicode.inc.pl charset-ucplanes.inc.pl charset-utf8.inc.pl
+ )],
+});
-<head>
-<title>charset cheat sheet</title>
-<meta http-equiv="content-type" content="utf-8">
-<link rel="stylesheet" type="text/css" media="all" href="/base.css">
-</head>
+use List::Util qw( first pairmap pairfirst pairs );
-<body>
-<h1>Character encoding</h1>
+:>
+<h1>Character encodings</h1>
+<p>
<:
-my $diinfo = do 'digraphs.inc.pl';
-my %di = map { $diinfo->{$_}->[0] => $_ } grep { ref $diinfo->{$_} }
- keys %$diinfo;
-
-use Encode qw(decode resolve_alias);
-# generate character table(s)
-# (~16x faster than decoding in loop;
-# substr strings is twice as fast as splitting to an array)
-my %ALIAS = (
-# default => [qw(unicode utf-8 iso-8859-1 cp437 -cp1252- --iso-8859-15- -koi8-f)],
- default => [qw(unicode- utf-8 iso-8859-1 -cp1252- --iso-8859-15- cp437 -cp850)],
- 0 => [qw(cp437 cp863)],
- 1 => [qw(iso-8859-1 cp1252 MacRoman cp850)],
- 2 => [qw(iso-8859-2 cp1250 cp852 MacCentralEurRoman MacCroatian MacRumanian)],
- 5 => [qw(koi8-f iso-8859-5 cp1251 MacCyrillic cp855 cp866)],
- 7 => [qw(iso-8859-7 cp1253 MacGreek cp737 cp869)],
- 8 => [qw(iso-8859-8 cp1255 MacHebrew cp862)],
+if ($tablist[0] eq 'default') {
+ say "Overview of Unicode allocation and common latin code pages.";
+ say "Compare alternate charsets:";
+}
+else {
+ say "Charset comparison:";
+}
+
+print join " •\n", (
+ map {
+ join " ·\n", pairmap {
+ showlink($b || ucfirst $a, '/charset'.($a && "/$a?compare"), $a eq $Request);
+ } @{$_}
+ }
+ [
+ iso => 'ISO',
+ win => 'Windows',
+ dos => 'DOS',
+ mac => 'Apple',
+ ebcdic => 'EBCDIC',
+ $tablist[0] eq 'default' ? () : ('' => 'common'),
+ ],
+ [
+ westeur => 'West',
+ centeur => 'Central',
+ norteur => 'North European',
+ turkish => 0,
+ greek => 0,
+ cyrillic => 0,
+ hebrew => 0,
+ ],
);
-my @request = map {
- if (my $input = $_) {
- my %row = (offset => 0);
- my $endpoint = 255;
- if ($input =~ s/^--//) {
- $row{offset} = $endpoint > 160 ? 160 : 48;
+:>.
+</p>
+
+<:
+use POSIX qw( ceil );
+use Shiar_Sheet::FormatChar;
+my $glyphs = Shiar_Sheet::FormatChar->new;
+my @request;
+
+my $charsets = do 'charset-encoding.inc.pl'
+ or Alert('Encoding metadata could not be read', $@ || $!);
+
+sub tabinput {
+ # generate character table(s)
+ my $input = shift or return;
+ my $params = $input =~ s/[+](.*)\z// ? $1 : undef;
+ my $charset = $charsets->{lc $input} || {};
+
+ if (ref $charset ne 'HASH') {
+ $params and Alert("Parameters ignored for $input",
+ "Cannot apply <q>$params</q> to multiple charsets.",
+ );
+ tabinput($_) for ref $charset ? @{$charset} : $charset;
+ return;
+ }
+
+ state $visible = {'' => 1}; # all present tables
+ my %row = (offset => 0, cols => 16);
+
+ if (not defined $params) {
+ my @parents = @{ $charset->{inherit} || [] };
+
+ if (my ($parent, $part) = pairfirst { defined $visible->{$a} } @parents) {
+ $row{parent} = $parent;
+ $params = $part;
+ $params = 80 unless $visible->{$parent}
+ or ($input eq 'MacCroatian' and defined $visible->{MacRomanian});
}
- elsif ($input =~ s/^-//) {
- $row{offset} = $endpoint > 128 ? 128 : 32;
+ elsif (defined $visible->{ascii}) {
+ $row{parent} = $parents[0];
+ $params = $parents[1] // 80;
+ $params = 80 if hex $params >= 0x80; # ascii offset at most
}
- if ($input =~ s/-$//) {
- $endpoint = $row{offset} ? $row{offset} < 160 ? 159 : 191 : 127;
+ elsif (@parents) {
+ $row{parent} = $parents[0];
+ $params = $parents[1] if hex $parents[1] == 0; # apply ascii end
}
- if ($row{set} = resolve_alias($input)) {
- if ($row{set} eq 'Internal') {
- $row{table} = ' ' x ($endpoint < 255 ? 640 : 4096);
- $row{set} = 'Unicode BMP';
- }
- elsif ($row{set} eq 'utf-8-strict') {
- $row{table} = undef;
- $row{set} = 'UTF-8';
+ $visible->{$_} //= 0 for $row{parent} || ();
+ }
+
+ for my $param (split /[+]+/, $params // '') {
+ if ($param eq 'realsize') {
+ $row{realsize}++;
+ }
+ elsif ($param =~ m{ \A cols = (\d+) \z }x) {
+ $row{cols} = $1;
+ }
+ elsif ($param =~ m{ \A (?<start> \p{AHex}+) (?: [-] (?<end> \p{AHex}+) )? \z }x) {
+ if (defined $row{endpoint}) {
+ # extend earlier range
+ my $skip = int(($row{endpoint} || $row{startpoint}) / $row{cols});
+ for ($skip + 1 .. (hex($+{start}) / $row{cols}) - 1) {
+ $row{skip}->{ $_ * $row{cols} - $row{startpoint} }++;
+ }
}
else {
- $row{table} = decode($row{set}, pack 'C*', $row{offset} .. $endpoint);
+ $row{startpoint} = hex $+{start};
}
+ $row{endpoint} = hex($+{end} || 0);
}
else {
- print "<p>Encoding $input unknown</p>\n";
+ Alert("Unknown option <q>$param</q> for charset $input");
}
- \%row;
}
- else {
- ();
- }
-} map { defined $ALIAS{$_} ? @{ $ALIAS{$_} } : $_ }
- $ENV{PATH_INFO} =~ /\w/ ? split(m{[/+\s]}, $ENV{PATH_INFO}) : 'default';
-my $NOCHAR = chr 0xFFFD;
-for my $cp437 (grep {$request[$_]->{set} eq 'cp437'} 0 .. $#request) {
- substr($request[$cp437]->{table}, 237, 1) = pack 'U*', 0x3D5; # phi sign
- substr($request[$cp437]->{table}, 0, 32) = pack 'U*', map {hex} qw(
- 2007 263A 263B 2665 2666 2663 2660 2022 25D8 25CB 25D9 2642 2640 266A 266B 263C
- 25BA 25C4 2195 203C 00B6 00A7 25AC 21A8 2191 2193 2192 2190 221F 2194 25B2 25BC
- );
-}
+ if ($charset->{setup}) {
+ eval { $charset->{setup}->(\%row) }
+ or Alert("Incomplete setup of $input", $@);
+ }
+ $row{endpoint} ||= 0xFF;
-sub quote {
- local $_ = shift;
- s/"/"/g;
- s/</</g;
- s/>/>/g;
- return $_;
-}
+ if (defined $row{table} or defined $row{cell}) {
+ $row{set} //= $input;
+ }
+ elsif ($row{set} = Encode::resolve_alias($input)) {
+ $row{offset} = delete $row{startpoint};
+ if ($charset->{varchar}) {
+ # array of possibly multiple characters per code point
+ $row{table} = [
+ 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} .. $row{endpoint});
+ }
-sub printcell_unicode {
- my ($value) = @_;
- if ($value > 0xFFF) {
- print "\n".'<td class="X">?';
- }
- elsif ($value == 0) {
- print '<td colspan="2" class="X Cc" style="border-right:none">control';
- }
- elsif ($value == 2) {
- print '<td colspan="2" class="X L Po" style="border-left:none; border-right:none">comn';
- }
- elsif ($value == 4) {
- print '<td colspan="4" class="X L Latin" style="border-left:none">basic latin';
- }
- elsif ($value == 8) {
- print '<td colspan="2" class="X Cc" style="border-right:none">control';
- }
- elsif ($value == 10) {
- print '<td colspan="2" class="X L So" style="border-left:none; border-right:none">comn';
- }
- elsif ($value == 12) {
- print '<td colspan="4" class="X L Latin" style="border-left:none">latin1';
- }
- elsif ($value == 0x10) {
- print '<td colspan="8" class="X L Latin">latin extended-A';
- }
- elsif ($value == 0x18) {
- print '<td colspan="8" class="X L Latin">latin extended-B';
- }
- elsif ($value == 0x20) {
- print '<td colspan="5" class="X L Latin">latin ext-B';
- }
- elsif ($value == 0x25) {
- print '<td colspan="6" class="X L Latin">IPA';
- }
- elsif ($value == 0x2B) {
- print '<td colspan="5" class="X Sk">spacing modifier';
- }
- elsif ($value == 0x30) {
- print '<td colspan="8" class="X Mn">diacritics';
- }
- elsif ($value == 0x38) {
- print '<td colspan="8" class="X L Greek">greek';
- }
- elsif ($value == 0x40) {
- print '<td colspan="16" class="X L Cyrillic">cyrillic';
- }
- elsif ($value == 0x50) {
- print '<td colspan="3" class="X L Cyrillic">cyrillic+';
- }
- elsif ($value == 0x53) {
- print '<td colspan="5" class="X L Armenian">armenian';
- }
- elsif ($value == 0x58) {
- print '<td colspan="8" class="X L Hebrew">hebrew';
- }
- elsif ($value == 0x60) {
- print '<td colspan="16" class="X L Arabic">arabic';
- }
- elsif ($value == 0x70) {
- print '<td colspan="5" class="X L Aramaic">syriac';
- }
- elsif ($value == 0x75) {
- print '<td colspan="3" class="X L Arabic">arabic+';
- }
- elsif ($value == 0x78) {
- print '<td colspan="4" class="X L African">thaana';
- }
- elsif ($value == 0x7C) {
- print '<td colspan="4" class="X L African">n\'ko';
- }
- elsif ($value == 0x80) {
- print '<td colspan="4" class="X Xr L Hebrew">samaritan';
- }
- elsif ($value == 0x84) {
- print '<td colspan="2" class="X Xr L Aramaic">manda';
- }
- elsif ($value == 0x86) {
- print '<td colspan="12" class="">reserved';
- }
- elsif ($value == 0x90) {
- print '<td colspan="8" class="X L Brahmic">devanagari';
- }
- elsif ($value == 0x98) {
- print '<td colspan="8" class="X L Brahmic">bengali';
- }
- elsif ($value == 0xA0) {
- print '<td colspan="8" class="X L Brahmic">gurmukhi';
- }
- elsif ($value == 0xA8) {
- print '<td colspan="8" class="X L Brahmic">gujarati';
- }
- elsif ($value == 0xB0) {
- print '<td colspan="8" class="X L Brahmic">oriya';
- }
- elsif ($value == 0xB8) {
- print '<td colspan="8" class="X L Brahmic">tamil';
- }
- elsif ($value == 0xC0) {
- print '<td colspan="8" class="X L Brahmic">telugu';
- }
- elsif ($value == 0xC8) {
- print '<td colspan="8" class="X L Brahmic">kannada';
- }
- elsif ($value == 0xD0) {
- print '<td colspan="8" class="X L Brahmic">malayalam';
- }
- elsif ($value == 0xD8) {
- print '<td colspan="8" class="X L Brahmic">sinhala';
- }
- elsif ($value == 0xE0) {
- print '<td colspan="8" class="X L Brahmic Khmer">thai';
- }
- elsif ($value == 0xE8) {
- print '<td colspan="8" class="X L Brahmic Khmer">lao';
- }
- elsif ($value == 0xF0) {
- print '<td colspan="16" class="X L Brahmic">tibetan';
- }
- elsif ($value == 0x100) {
- print '<td colspan="10" class="X L Brahmic">myanmar';
- }
- elsif ($value == 0x10A) {
- print '<td colspan="6" class="X L Aramaic">georgian';
- }
- elsif ($value == 0x110) {
- print '<td colspan="16" class="X L Hangul">hangeul jamo';
- }
- elsif ($value == 0x120) {
- print '<td colspan="16" class="X L African">ethiopic';
- }
- elsif ($value == 0x130) {
- print '<td colspan="8" class="X L African">ethiopic';
- }
- elsif ($value == 0x138) {
- print '<td colspan="2" class="X L African">eth+';
- }
- elsif ($value == 0x13A) {
- print '<td colspan="6" class="X L Syllabic">cherokee';
- }
- elsif ($value == 0x140) {
- print '<td colspan="16" rowspan="2" class="X L Syllabic">unified canadian aboriginal syllabics';
- }
- elsif ($value == 0x160) {
- print '<td colspan="8" class="X L Syllabic">unified canadian syllabics';
- }
- elsif ($value == 0x168) {
- print '<td colspan="2" class="X L Alpha">ogham';
- }
- elsif ($value == 0x16A) {
- print '<td colspan="6" class="X L Alpha">runic';
- }
- elsif ($value == 0x170) {
- print '<td colspan="2" class="X L Brahmic">tagalog';
- }
- elsif ($value == 0x172) {
- print '<td colspan="2" class="X L Brahmic">hanun';
- }
- elsif ($value == 0x174) {
- print '<td colspan="2" class="X L Brahmic">buhid';
- }
- elsif ($value == 0x176) {
- print '<td colspan="2" class="X L Brahmic" title="tagbanwa">tagb';
- }
- elsif ($value == 0x178) {
- print '<td colspan="8" class="X L Brahmic Khmer">khmer';
- }
- elsif ($value == 0x180) {
- print '<td colspan="11" class="X L Aramaic">mongolian';
- }
- elsif ($value == 0x18B) {
- print '<td colspan="5" class="X Xr L Syllabic">canadian+';
- }
- elsif ($value == 0x190) {
- print '<td colspan="5" class="X L Brahmic">limbu';
- }
- elsif ($value == 0x195) {
- print '<td colspan="4" class="X L Brahmic">tai le';
- }
- elsif ($value == 0x198) {
- print '<td colspan="6" class="X L Brahmic">new tai lue';
- }
- elsif ($value == 0x19E) {
- print '<td colspan="2" class="X L Brahmic Khmer" title="khmer symbols">km';
- }
- elsif ($value == 0x1A0) {
- print '<td colspan="2" class="X L Brahmic">lontara';
- }
- elsif ($value == 0x1A2) {
- print '<td colspan="9" class="X Xr L Brahmic">tai tham';
- }
- elsif ($value == 0x1AB) {
- print '<td colspan="5" class="">reserved';
- }
- elsif ($value == 0x1B0) {
- print '<td colspan="8" class="X L Brahmic">balinese';
- }
- elsif ($value == 0x1B8) {
- print '<td colspan="4" class="X L Brahmic">sundanese';
- }
- elsif ($value == 0x1BC) {
- print '<td colspan="4" class="X Xr L Brahmic">batak';
- }
- elsif ($value == 0x1C0) {
- print '<td colspan="5" class="X L Brahmic">lepcha';
- }
- elsif ($value == 0x1C5) {
- print '<td colspan="3" class="X L Alpha">ol chiki';
- }
- elsif ($value == 0x1C8) {
- print '<td colspan="5" class="">reserved';
- }
- elsif ($value == 0x1CD) {
- print '<td colspan="3" class="X Xr Brahmic">vedic';
- }
- elsif ($value == 0x1D0) {
- print '<td colspan="8" class="X L Latin">phonetic';
- }
- elsif ($value == 0x1D8) {
- print '<td colspan="4" class="X L Latin">phonetic+';
- }
- elsif ($value == 0x1DC) {
- print '<td colspan="4" class="X Mn">combining';
- }
- elsif ($value == 0x1E0) {
- print '<td colspan="16" class="X L Latin">latin extended additional';
- }
- elsif ($value == 0x1F0) {
- print '<td colspan="16" class="X L Greek">greek+';
- }
- elsif ($value == 0x200) {
- print '<td colspan="7" class="X Po">general punctuation';
- }
- elsif ($value == 0x207) {
- print '<td colspan="3" class="X Latin">suþscript'; # suth now means "sub and/or sup"
- }
- elsif ($value == 0x20A) {
- print '<td colspan="3" class="X Sc">currency';
- }
- elsif ($value == 0x20D) {
- print '<td colspan="3" class="X Mn">overlay';
- }
- elsif ($value == 0x210) {
- print '<td colspan="5" class="X So">letterlike';
- }
- elsif ($value == 0x215) {
- print '<td colspan="4" class="X Latin">number';
- }
- elsif ($value == 0x219) {
- print '<td colspan="7" class="X So">arrows';
- }
- elsif ($value == 0x220) {
- print '<td colspan="16" class="X Sm">mathematical symbols';
- }
- elsif ($value == 0x230) {
- print '<td colspan="16" class="X So">miscellaneous technical';
- }
- elsif ($value == 0x240) {
- print '<td colspan="4" class="X So">control';
- }
- elsif ($value == 0x244) {
- print '<td colspan="2" class="X So">OCR';
- }
- elsif ($value == 0x246) {
- print '<td colspan="10" class="X Latin">enclosed alphanumerics';
- }
- elsif ($value == 0x250) {
- print '<td colspan="8" class="X So">box drawing';
- }
- elsif ($value == 0x258) {
- print '<td colspan="2" class="X So">blocks';
- }
- elsif ($value == 0x25A) {
- print '<td colspan="6" class="X So">geometric shapes';
- }
- elsif ($value == 0x260) {
- print '<td colspan="16" class="X So">miscellaneous symbols';
- }
- elsif ($value == 0x270) {
- print '<td colspan="12" class="X So">dingbats';
- }
- elsif ($value == 0x27C) {
- print '<td colspan="3" class="X So">maths-A';
- }
- elsif ($value == 0x27F) {
- print '<td colspan="1" class="X So" title="supplemental arrows-A">arr';
- }
- elsif ($value == 0x280) {
- print '<td colspan="16" class="X L Alpha">braille';
- }
- elsif ($value == 0x290) {
- print '<td colspan="8" class="X So">supplemental arrows-B';
- }
- elsif ($value == 0x298) {
- print '<td colspan="8" class="X Sm">mathematical symbols-B';
- }
- elsif ($value == 0x2A0) {
- print '<td colspan="16" class="X Sm">supplemental mathematical operators';
- }
- elsif ($value == 0x2B0) {
- print '<td colspan="16" class="X So">miscellaneous symbols and arrows';
+ $row{endpoint} -= $row{offset};
+ $visible->{ascii}++; # assume common base
}
- elsif ($value == 0x2C0) {
- print '<td colspan="6" class="X L Cyrillic">glagolitic';
- }
- elsif ($value == 0x2C6) {
- print '<td colspan="2" class="X L Latin">latin-C';
- }
- elsif ($value == 0x2C8) {
- print '<td colspan="8" class="X L Greek">coptic';
- }
- elsif ($value == 0x2D0) {
- print '<td colspan="3" class="X L Aramaic">georgian+';
- }
- elsif ($value == 0x2D3) {
- print '<td colspan="5" class="X L Alpha">tifinagh'; #TODO: proto-canaanite
- }
- elsif ($value == 0x2D8) {
- print '<td colspan="6" class="X L African">ethiopic+';
- }
- elsif ($value == 0x2DE) {
- print '<td colspan="2" class="X L Cyrillic">cyrl-A';
- }
- elsif ($value == 0x2E0) {
- print '<td colspan="8" class="X Po">punctuation+';
- }
- elsif ($value == 0x2E8) {
- print '<td colspan="8" class="X L Han">cjk radicals';
- }
- elsif ($value == 0x2F0) {
- print '<td colspan="14" class="X L Han">kangxi radicals';
- }
- elsif ($value == 0x2FE) {
- print '<td colspan="1" class="">';
- }
- elsif ($value == 0x2FF) {
- print '<td colspan="1" class="X So Han">idc';
- }
- elsif ($value == 0x300) {
- print '<td colspan="4" class="X Po Han">cjk misc';
- }
- elsif ($value == 0x304) {
- print '<td colspan="6" class="X L Hiragana">hiragana';
- }
- elsif ($value == 0x30A) {
- print '<td colspan="6" class="X L Katakana">katakana';
- }
- elsif ($value == 0x310) {
- print '<td colspan="3" class="X L Bopomofo">bopomofo';
- }
- elsif ($value == 0x313) {
- print '<td colspan="6" class="X L Katakana">hangeul compat';
- }
- elsif ($value == 0x319) {
- print '<td colspan="1" class="X L Han" title="kanbun">kbn';
- }
- elsif ($value == 0x31A) {
- print '<td colspan="2" class="X L Bopomofo" title="bopomofo extended">bpmf';
- }
- elsif ($value == 0x31C) {
- print '<td colspan="3" class="X L Han" title="CJK strokes">strokes';
- }
- elsif ($value == 0x31F) {
- print '<td colspan="1" class="X L Katakana" title="katakana phonetic extensions">k+';
- }
- elsif ($value == 0x320) {
- print '<td colspan="16" class="X L Han">enclosed cjk characters';
- }
- elsif ($value == 0x330) {
- print '<td colspan="16" class="X Xd L Han">cjk compatibility';
- }
- elsif ($value == 0x340) {
- print '<td colspan="16" rowspan="25" class="X L Han">cjk unified ideographs extension A';
- }
- elsif ($value == 0x4D0) {
- print '<td colspan="12" class="X L Han" style="border-top:none">cjk unified ideographs extension A';
- }
- elsif ($value == 0x4DC) {
- print '<td colspan="4" class="X So">hexagrams';
- }
- elsif ($value == 0x4E0) {
- print '<td colspan="16" rowspan="82" class="X L Han">cjk unified ideographs';
- }
- elsif ($value == 0xA00) {
- print '<td colspan="16" rowspan="4" class="X L Syllabic">yi';
- }
- elsif ($value == 0xA40) {
- print '<td colspan="9" class="X L Syllabic" style="border-top:none">yi';
- }
- elsif ($value == 0xA49) {
- print '<td colspan="4" class="X L Syllabic">yi radicals';
- }
- elsif ($value == 0xA4D) {
- print '<td colspan="3" class="X Xr L Latin">lisu';
- }
- elsif ($value == 0xA50) {
- print '<td colspan="16" class="X L Syllabic">vai';
- }
- elsif ($value == 0xA60) {
- print '<td colspan="4" class="X L Syllabic" style="border-top:none">vai';
- }
- elsif ($value == 0xA64) {
- print '<td colspan="6" class="X L Cyrillic">cyrillic extended-B';
- }
- elsif ($value == 0xA6A) {
- print '<td colspan="6" class="X Xr L Syllabic">bamum';
- }
- elsif ($value == 0xA70) {
- print '<td colspan="2" class="X L Mn">tones';
- }
- elsif ($value == 0xA72) {
- print '<td colspan="14" class="X L Latin">latin extended-D';
- }
- elsif ($value == 0xA80) {
- print '<td colspan="3" class="X L Brahmic">sylheti';
- }
- elsif ($value == 0xA83) {
- print '<td colspan="1" class="X Xr No">in';
- }
- elsif ($value == 0xA84) {
- print '<td colspan="4" class="X L Brahmic">phags-pa';
- }
- elsif ($value == 0xA88) {
- print '<td colspan="6" class="X L Brahmic">saurashtra';
- }
- elsif ($value == 0xA8E) {
- print '<td colspan="2" class="X Xr L Brahmic">deva+';
- }
- elsif ($value == 0xA90) {
- print '<td colspan="3" class="X L Brahmic">kayah li';
- }
- elsif ($value == 0xA93) {
- print '<td colspan="3" class="X L Brahmic">rejang';
- }
- elsif ($value == 0xA96) {
- print '<td colspan="2" class="X Xr L Hangul">jamo-A';
- }
- elsif ($value == 0xA98) {
- print '<td colspan="6" class="X Xr L Brahmic">javanese';
- }
- elsif ($value == 0xA9E) {
- print '<td colspan="2" class="">res';
- }
- elsif ($value == 0xAA0) {
- print '<td colspan="6" class="X L Brahmic">cham';
- }
- elsif ($value == 0xAA6) {
- print '<td colspan="2" class="X Xr L Brahmic" title="myanmar extended-A">mym-A';
- }
- elsif ($value == 0xAA8) {
- print '<td colspan="6" class="X Xr L Brahmic Khmer">tai viet';
- }
- elsif ($value == 0xAAE) {
- print '<td colspan="2" class="X Xr L Brahmic" title="meetei mayek extended">mtei+';
- }
- elsif ($value == 0xAB0) {
- print '<td colspan="12" class="">reserved';
- }
- elsif ($value == 0xABC) {
- print '<td colspan="4" class="X Xr L Brahmic" title="meetei mayek">manipuri';
- }
- elsif ($value == 0xAC0) {
- print '<td colspan="16" rowspan="43" class="X L Hangul">hangeul syllables';
- }
- elsif ($value == 0xD70) {
- print '<td colspan="11" class="X L Hangul" style="border-top:none">hangeul syllables';
- }
- elsif ($value == 0xD7B) {
- print '<td colspan="5" class="X L Hangul">haungeul jamo-B';
- }
- elsif ($value == 0xD80) {
- print '<td colspan="16" rowspan="4" class="X Cs">high surrogates';
- }
- elsif ($value == 0xDC0) {
- print '<td colspan="16" rowspan="4" class="X Cs">low surrogates';
- }
- elsif ($value == 0xE00) {
- print '<td colspan="16" rowspan="25" class="X Co">private use';
- }
- elsif ($value == 0xF90) {
- print '<td colspan="16" rowspan="2" class="X L Han">cjk compatibility ideographs';
- }
- elsif ($value == 0xFB0) {
- print '<td colspan="5" class="X Xd L">presentation';
- }
- elsif ($value == 0xFB5) {
- print '<td colspan="11" class="X Xd L Arabic" style="border-bottom:none">';
- }
- elsif ($value == 0xFC0) {
- print '<td colspan="16" class="X Xd L Arabic" style="border-top:none; border-bottom:none">arabic presentation forms A';
- }
- elsif ($value == 0xFD0) {
- print '<td colspan="13" class="X Xd L Arabic" style="border-top:none">';
- }
- elsif ($value == 0xFDD) {
- print '<td colspan="2" class="Xi">?';
- }
- elsif ($value == 0xFDF) {
- print '<td colspan="1" class="X Xd L Arabic" style="border-top:none">';
- }
- elsif ($value == 0xFE0) {
- print '<td colspan="1" class="X Cc">var';
- }
- elsif ($value == 0xFE1) {
- print '<td colspan="1" class="X L Pd">ver';
- }
- elsif ($value == 0xFE2) {
- print '<td colspan="1" class="X L Mn">½';
- }
- elsif ($value == 0xFE3) {
- print '<td colspan="2" class="X Xd Pd Han">comp';
- }
- elsif ($value == 0xFE5) {
- print '<td colspan="2" class="X Xd L Latin">small';
- }
- elsif ($value == 0xFE7) {
- print '<td colspan="9" class="X Xd L Arabic">arabic presentation B';
- }
- elsif ($value == 0xFF0) {
- print '<td colspan="15" class="X L Latin">halfwidth & fullwidth forms';
+ else {
+ Alert("Encoding <q>$input</q> unknown");
+ return;
}
- elsif ($value == 0xFFF) {
- print '<td colspan="1" class="X Cc">sp';
+
+ if (my $replace = $charset->{replace}) {
+ while (my ($offset, $sub) = each %{$replace}) {
+ $offset -= $row{offset};
+
+ if (ref $row{table} eq 'ARRAY') {
+ $row{table}->[$offset] = $sub
+ if $offset >= 0 and $offset <= $row{endpoint};
+ next;
+ }
+
+ my $length = length $sub;
+
+ if ($offset < 0) {
+ $offset > -$length or next; # at least one character after start
+ # trim leftmost part to start at offset
+ substr($sub, 0, -$offset) = '';
+ $length += $offset;
+ $offset = 0;
+ }
+
+ if ((my $excess = $row{endpoint} - $offset - $length + 1) < 0) {
+ $excess > -$length or next;
+ # trim rightmost part to prevent overflow
+ substr($sub, $excess) = '';
+ $length += $excess;
+ }
+
+ substr($row{table}, $offset, $length) = $sub;
+ }
}
+
+ push @request, \%row;
+ $visible->{ $row{set} } = 1 if $row{table};
}
+tabinput($_) for @tablist;
-sub printcell_utf8 {
- my ($value) = @_;
- if ($value <= 0x7F) {
- print '<td rowspan="8" colspan="16" class="X di-a"',
- ' title="U+0000 – U+007F">single byte ASCII'
- if $value == 0;
- }
- elsif ($value <= 0xBF) {
- print '<td rowspan="4" colspan="16" class="X di-d"',
- '>multi-byte continuation'
- if $value == 0x80;
- }
- elsif ($value <= 0xC1) {
- print '<td colspan="2" class="X di-b" style="border-right:none; border-bottom:none"',
- ' title="U+0000 – U+007F">(overl.)'
- if $value == 0xC0;
- }
- elsif ($value <= 0xDF) {
- print '<td rowspan="2" colspan="14" class="X di-prop" style="border-left:none"',
- ' title="U+0080 – U+03FF">2-byte sequence start'
- if $value == 0xC2;
- print '<td rowspan="1" colspan="16" class="X di-prop" style="border-top:none"',
- ' title="U+0400 – U+07FF">'
- if $value == 0xD0;
- }
- elsif ($value <= 0xEF) {
- print '<td colspan="16" class="X di-prop"',
- ' title="U+0800 – U+FFFF">3-byte sequence start'
- if $value == 0xE0;
- }
- elsif ($value <= 0xF4) {
- print '<td colspan="5" class="X di-prop" style="border-right:none"',
- ' title="U+1·0000 – U+10·FFFF">4-byte sequence'
- if $value == 0xF0;
- }
- elsif ($value <= 0xF7) {
- print '<td colspan="3" class="X di-b" style="border-left:none"',
- ' title="U+11·0000 – U+1FF·FFFF">(overflow)'
- if $value == 0xF5;
- }
- elsif ($value <= 0xFB) {
- print '<td colspan="4" class="X di-b"',
- ' title="U+200·0000 – U+3FFF·FFFF">5-byte'
- if $value == 0xF8;
- }
- elsif ($value <= 0xFD) {
- print '<td colspan="2" class="X di-b"',
- ' title="U+4000·0000 – 7FFFF·FFFF">6-byte'
- if $value == 0xFC;
- }
- elsif ($value <= 0xFF) {
- print '<td colspan="2" class="di-invalid">invalid'
- if $value == 0xFE;
- }
- else {
- print "\n".'<td class="X">?';
+my $NOCHAR = chr 0xFFFD;
+
+sub range_cell {
+ my ($info, $offset) = @_;
+ my $table = $info->{cell} or return;
+ my $def = $table->{$offset} or return;
+ my ($len, $class, $name, $title) = @{$def};
+
+ my $cols = $info->{cols};
+ my $colsize = $table->{colsize} || 1;
+ my $attr = '';
+ $len /= $colsize;
+ $name //= $len <= 2 ? 'res' : 'reserved';
+
+ if (my $part = ($offset/$colsize - $info->{startpoint}) % $cols) {
+ # continued row
+ my $rest = $cols - $part; # remaining
+ $rest = $len if $len < $rest; #TODO: optimise
+ if ($len -= $rest) {
+ # continued on new row
+ my @next = ($len * $colsize, "$class joinu");
+ my $separate = $cols - $len > $rest; # columns not on next row
+ if ($len > $rest) {
+ # minority remains
+ push @next, $name, $title;
+ $title ||= $name;
+ $name = $separate && '…';
+ }
+ else {
+ # minority on next row
+ push @next, $separate && '"', $title || $name;
+ }
+ $table->{$offset + $colsize*$rest} //= \@next;
+ $class .= ' joind';
+ }
+ $len = $rest;
+ }
+ elsif (my $rows = int($len / $cols)) {
+ # multiple full rows
+ my $rowsize = $colsize * $cols;
+ if ($len -= $rows * $cols) {
+ # partial row remains
+ $table->{$offset + $rowsize * $rows} //= [$len*$colsize, "$class joinu", '', $title];
+ $class .= ' joind';
+ }
+
+ unless ($info->{realsize}) {
+ # 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;
}
-}
-print "<ul>\n";
+ $attr .= sprintf ' colspan=%d', $len unless $len == 1;
+ $attr .= $1 if $class and $class =~ s/( \w+="[^"]*")//;
+ $attr .= sprintf ' class="%s"', $class if $class;
+ $attr .= sprintf ' title="%s"', EscapeHTML($title) if $title;
+ return "<td$attr>$name\n";
+}
-my @nibble = (0..9, 'A'..'F');
for my $row (@request) {
- print '<li><table class="glyphs">';
- printf '<caption>%s</caption>', $row->{set};
- print '<col>';
+ my $cols = $row->{cols};
+ my $colsize = $row->{cell} && $row->{cell}->{colsize} || 1;
+ 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 = $row->{startpoint} * $colsize || 0;
+
+ printf '<div class="section"><table class="glyphs%s">', !$row->{cell} && ' charmap';
+ my $title = $row->{set};
+ $title .= " <aside>(over $_)</aside>"
+ for $row->{parent} || ();
+ printf '<caption>%s</caption>', $title;
+ print '<col>' x ($cols + 1);
for my $section (qw{thead}) {
- print "<$section><tr><th>↱";
- print '<th>', $_ for @nibble;
+ print "<$section><tr><th>", $rowdiv == 1 ? '+' : '↱';
+ printf '<th>%0*X', $coldigits, $_ * $colsize for 0 .. $cols - 1;
print "\n";
}
+
print '<tbody>';
- for my $msb (0 .. (length($row->{table}) || 256) - 1 >> 4) {
- printf '<tr><th>%X', $msb + ($row->{offset} >> 4);
- for my $lsb (0 .. $#nibble) {
- if ($row->{set} eq 'UTF-8') {
- printcell_utf8(($msb<<4) + $lsb);
- next;
+ while ($offset <= $row->{endpoint} * $colsize) {
+ if ($row->{skip}->{$offset}) {
+ $offset += $cols * $colsize;
+ next;
+ }
+
+ print '<tr><th>';
+ if (defined $row->{skip}->{$offset}) {
+ print '⋮';
+ }
+ else {
+ if (my $rowmod = $offset % $rowdiv) {
+ # offset in column units
+ printf '<small>+%X</small>', $rowmod;
}
- elsif ($row->{set} eq 'Unicode BMP') {
- printcell_unicode(($msb<<4) + $lsb);
- next;
+ else {
+ # divided row offset
+ printf '%X', ($offset + $row->{offset}) / $rowdiv;
}
+ }
+ say '';
- my $glyph = substr $row->{table}, ($msb<<4) + $lsb, 1;
- if ($glyph eq $NOCHAR) {
- print '<td>';
+ for (1 .. $cols) {
+ if ($row->{cell}) {
+ print range_cell($row, $offset);
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);
+ my $cp = $offset + $row->{offset};
+ my $glyph = ref $row->{table} eq 'ARRAY' ? $row->{table}->[$offset] :
+ substr $row->{table}, $offset, 1;
+ my ($cell, $name, $class) = !defined $glyph || $glyph eq $NOCHAR ? () :
+ $glyphs->glyph_html($glyph);
- $glyph = "<span>$glyph</span>" if $prop eq 'Zs';
+ if ($mode) {
+ state $visible = {};
+ $class = (
+ $cp == ord $glyph ? 'l4' :
+ $row->{parent} && $glyph eq
+ Encode::decode($row->{parent}, pack 'C', $cp) ? 'l3' :
+ !$class ? undef :
+ $visible->{$glyph} ? 'l2' :
+ 'l1'
+ );
+ $visible->{$glyph}++;
+ }
- printf "\n".'<td class="%s" title="%s">%s',
- join(' ', @class), quote($desc), $glyph;
+ say sprintf $class ? '<td title="%s" class="X %s">%s' : '<td title="%s">',
+ $name, $class, $cell;
+ }
+ continue {
+ $offset += $colsize;
}
- print "\n";
}
- print "</table>\n";
+ say '</table></div>';
}
-print "</ul>\n";
-
:>
<hr>
-<p class="footer">
- <a href="http://sheet.shiar.nl/" rel="home">sheet.shiar.nl</a>/charset
- <a href="git://git.shiar.nl/sheet" rel="vcs-git" title="Git repository"><:= "v$VERSION" :></a>
- created by <a href="http://shiar.nl/" rel="author">Shiar</a> •
- <a title="Licensed under the GNU Affero General Public License, version 3" rel="copyright"
- href="http://www.fsf.org/licensing/licenses/agpl-3.0.html">AGPLv3</a> •
- last update <:
- use Time::Format qw(time_format);
- print time_format('yyyy-mm-dd', (stat $ENV{SCRIPT_FILENAME})[9]);
- :>
-</p>
+<div class="legend">
+ <table class="glyphs"><tr><: if ($mode) { :>
+ <td class="X l4">unicode
+ <td class="X l3">inherited
+ <td class="X l2">existing
+ <td class="X l1">original
+ <td class="">unassigned
+<: } else { :>
+ <td class="X Cc">control
+ <td class="X Zs"><span>whitespace</span>
+ <td class="X Mn">diacritic<table class="glyphs"><tr>
+ <td class="X Sk">letter
+ </table>
+ <td class="X Po">punctuation<table class="glyphs"><tr>
+ <td class="X Pf">quote
+ </table>
+ <td class="X So">symbol<table class="glyphs"><tr>
+ <td class="X Sm">math
+ <td class="X Sc">currency
+ </table>
+ <td class="X No">numeric
+ <td class="X Greek">greek<table class="glyphs"><tr>
+ <td class="X Latin">latin
+ <td class="X Cyrillic">cyrillic
+ </table>
+ <td class="X Aramaic">aramaic<table class="glyphs"><tr>
+ <td class="X Brahmic">brahmic
+ <td class="X Arabic">arabic
+ </table>
+ <td class="X Syllabic">syllabic<table class="glyphs"><tr>
+ <td class="X African">african
+ <td class="X Hiragana">japanese
+ <td class="X Han">cjk
+ <td class="X Bopomofo">chinese
+ </table>
+ <td class="X Alpha">alphabetic
+ </table>
+
+ <table class="glyphs"><tr>
+ <td class="X">unicode 7.0
+ <td class="X Xr">proposed
+ <td class="X Xd">deprecated
+ <td class="">unassigned
+ <td class="X Xi">invalid
+<: } :> </table>
+</div>
-</html>