countries: change antarctica class to .an
[sheet.git] / charset.plp
index e5ca8bf..e5fdd45 100644 (file)
@@ -1,30 +1,25 @@
-<:
-use utf8;
-use strict;
-use warnings;
-use open IO => ':utf8';
-
-our $VERSION = '1.0';
-
-$header{content_type} = 'text/html; charset=utf-8';
-
-:><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
- "http://www.w3.org/TR/html4/loose.dtd">
-<html>
+<(common.inc.plp)><:
+
+Html({
+       title => 'charset cheat sheet',
+       version => 'v1.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'],
+});
 
-<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>
-
-<body>
+:>
 <h1>Character encoding</h1>
 
 <:
-my $diinfo = do 'digraphs.inc.pl';
-my %di = map { $diinfo->{$_}->[0] => $_ } grep { ref $diinfo->{$_} }
-       keys %$diinfo;
+use Shiar_Sheet::FormatChar;
+my $glyphs = Shiar_Sheet::FormatChar->new;
 
 use Encode qw(decode resolve_alias);
 # generate character table(s)
@@ -32,7 +27,7 @@ use Encode qw(decode resolve_alias);
 #  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)],
+       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)],
@@ -53,14 +48,29 @@ my @request = map {
                if ($input =~ s/-$//) {
                        $endpoint = $row{offset} ? $row{offset} < 160 ? 159 : 191 : 127;
                }
-               if ($row{set} = resolve_alias($input)) {
+
+               if ($input =~ /^U([0-9a-f]+)(?:-([0-9a-f]+))?/) {
+                       my $start = hex($1) << ($2 ? 4 : 8);
+                       my $end = $2 ? hex($2) << 4 : $start + 240;
+                       $row{table} = join '', map { chr } $start .. $end+15;
+                       utf8::upgrade($row{table});  # prevent latin1 output
+                       $row{set} = sprintf 'Unicode block U+%02Xxx', $start >> 8;
+               }
+               elsif ($input eq 'U') {
+                       $row{table} = ' ' x 512;
+                       $row{set} = 'Unicode planes';
+                       $row{cell} = do 'charset-ucplanes.inc.pl';
+               }
+               elsif ($row{set} = resolve_alias($input)) {
                        if ($row{set} eq 'Internal') {
-                               $row{table} = ' 'x512;
+                               $row{table} = ' ' x ($endpoint < 255 ? 640 : 4096);
                                $row{set} = 'Unicode BMP';
+                               $row{cell} = do 'charset-unicode.inc.pl';
                        }
                        elsif ($row{set} eq 'utf-8-strict') {
                                $row{table} = undef;
                                $row{set} = 'UTF-8';
+                               $row{cell} = do 'charset-utf8.inc.pl';
                        }
                        else {
                                $row{table} = decode($row{set}, pack 'C*', $row{offset} .. $endpoint);
@@ -86,306 +96,11 @@ for my $cp437 (grep {$request[$_]->{set} eq 'cp437'} 0 .. $#request) {
        );
 }
 
-sub quote {
-       local $_ = shift;
-       s/"/&quot;/g;
-       s/</&lt;/g;
-       s/>/&gt;/g;
-       return $_;
-}
-
-sub printcell_unicode {
-       my ($value) = @_;
-       if ($value > 0x1FF) {
-               print "\n".'<td class="X">?';
-       }
-       elsif ($value == 0) {
-               print '<td colspan="2" class="X Cc">control';
-       }
-       elsif ($value == 2) {
-               print '<td colspan="6" class="X Ll Latin">latin';
-       }
-       elsif ($value == 8) {
-               print '<td colspan="2" class="X Cc">control';
-       }
-       elsif ($value == 10) {
-               print '<td colspan="6" class="X Ll Latin">latin supplement';
-       }
-       elsif ($value == 0x10) {
-               print '<td colspan="8" class="X Ll Latin">latin ext-A';
-       }
-       elsif ($value == 0x18) {
-               print '<td colspan="8" class="X Ll Latin">latin ext-B';
-       }
-       elsif ($value == 0x20) {
-               print '<td colspan="5" class="X Ll Latin">latin ext-B';
-       }
-       elsif ($value == 0x25) {
-               print '<td colspan="6" class="X Ll 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 Ll Greek">greek';
-       }
-       elsif ($value == 0x40) {
-               print '<td colspan="16" class="X Ll Cyrillic">cyrillic';
-       }
-       elsif ($value == 0x50) {
-               print '<td colspan="3" class="X Ll Cyrillic">cyrillic+';
-       }
-       elsif ($value == 0x53) {
-               print '<td colspan="5" class="X Ll Armenian">armenian';
-       }
-       elsif ($value == 0x58) {
-               print '<td colspan="8" class="X Ll Hebrew">hebrew';
-       }
-       elsif ($value == 0x60) {
-               print '<td colspan="16" class="X Ll Arabic">arabic';
-       }
-       elsif ($value == 0x70) {
-               print '<td colspan="5" class="X Ll Aramaic">syriac';
-       }
-       elsif ($value == 0x75) {
-               print '<td colspan="3" class="X Ll Arabic">arabic+';
-       }
-       elsif ($value == 0x78) {
-               print '<td colspan="4" class="X Ll African">thaana';
-       }
-       elsif ($value == 0x7C) {
-               print '<td colspan="4" class="X Ll African">nko';
-       }
-       elsif ($value == 0x80) {
-               print '<td colspan="4" class="X di-rare">samaritan';
-       }
-       elsif ($value == 0x84) {
-               print '<td colspan="2" class="X di-rare Ll Aramaic">manda';
-       }
-       elsif ($value == 0x86) {
-               print '<td colspan="12" class="di-invalid">reserved';
-       }
-       elsif ($value == 0x90) {
-               print '<td colspan="8" class="X Ll Brahmic">devanagari';
-       }
-       elsif ($value == 0x98) {
-               print '<td colspan="8" class="X Ll Brahmic">bengali';
-       }
-       elsif ($value == 0xA0) {
-               print '<td colspan="8" class="X Ll Brahmic">gurmukhi';
-       }
-       elsif ($value == 0xA8) {
-               print '<td colspan="8" class="X Ll Brahmic">gujarati';
-       }
-       elsif ($value == 0xB0) {
-               print '<td colspan="8" class="X Ll Brahmic">oriya';
-       }
-       elsif ($value == 0xB8) {
-               print '<td colspan="8" class="X Ll Brahmic">tamil';
-       }
-       elsif ($value == 0xC0) {
-               print '<td colspan="8" class="X Ll Brahmic">telugu';
-       }
-       elsif ($value == 0xC8) {
-               print '<td colspan="8" class="X Ll Brahmic">kannada';
-       }
-       elsif ($value == 0xD0) {
-               print '<td colspan="8" class="X Ll Brahmic">malayalam';
-       }
-       elsif ($value == 0xD8) {
-               print '<td colspan="8" class="X Ll Brahmic">sinhala';
-       }
-       elsif ($value == 0xE0) {
-               print '<td colspan="8" class="X Ll Brahmic Khmer">thai';
-       }
-       elsif ($value == 0xE8) {
-               print '<td colspan="8" class="X Ll Brahmic Khmer">lao';
-       }
-       elsif ($value == 0xF0) {
-               print '<td colspan="16" class="X Ll Brahmic">tibetan';
-       }
-       elsif ($value == 0x100) {
-               print '<td colspan="10" class="X Ll Brahmic">myanmar';
-       }
-       elsif ($value == 0x10A) {
-               print '<td colspan="6" class="X Ll Aramaic">georgian';
-       }
-       elsif ($value == 0x110) {
-               print '<td colspan="16" class="X Ll Hangul">hangeul jamo';
-       }
-       elsif ($value == 0x120) {
-               print '<td colspan="16" class="X Ll African">ethiopic';
-       }
-       elsif ($value == 0x130) {
-               print '<td colspan="8" class="X Ll African">ethiopic';
-       }
-       elsif ($value == 0x138) {
-               print '<td colspan="2" class="X Ll African">eth+';
-       }
-       elsif ($value == 0x13A) {
-               print '<td colspan="6" class="X Ll X">cherokee';
-       }
-       elsif ($value == 0x140) {
-               print '<td colspan="16" rowspan="2" class="X Ll Syllabic">unified canadian aboriginal syllabics';
-       }
-       elsif ($value == 0x160) {
-               print '<td colspan="8" class="X Ll Syllabic">unified canadian syllabics';
-       }
-       elsif ($value == 0x168) {
-               print '<td colspan="2" class="X Ll X">ogham';
-       }
-       elsif ($value == 0x16A) {
-               print '<td colspan="6" class="X Ll X">runic';
-       }
-       elsif ($value == 0x170) {
-               print '<td colspan="2" class="X Ll Brahmic">tagalog';
-       }
-       elsif ($value == 0x172) {
-               print '<td colspan="2" class="X Ll Brahmic">hanun';
-       }
-       elsif ($value == 0x174) {
-               print '<td colspan="2" class="X Ll Brahmic">buhid';
-       }
-       elsif ($value == 0x176) {
-               print '<td colspan="2" class="X Ll Brahmic" title="tagbanwa">tagb';
-       }
-       elsif ($value == 0x178) {
-               print '<td colspan="8" class="X Ll Brahmic Khmer">khmer';
-       }
-       elsif ($value == 0x180) {
-               print '<td colspan="11" class="X Ll Aramaic">mongolian';
-       }
-       elsif ($value == 0x18B) {
-               print '<td colspan="5" class="X Ll Syllabic di-rare">canadian+';
-       }
-       elsif ($value == 0x190) {
-               print '<td colspan="5" class="X Ll Brahmic">limbu';
-       }
-       elsif ($value == 0x195) {
-               print '<td colspan="4" class="X Ll Brahmic">tai le';
-       }
-       elsif ($value == 0x198) {
-               print '<td colspan="6" class="X Ll Brahmic">new tai lue';
-       }
-       elsif ($value == 0x19E) {
-               print '<td colspan="2" class="X Ll Brahmic Khmer" title="khmer symbols">km';
-       }
-       elsif ($value == 0x1A0) {
-               print '<td colspan="2" class="X Ll Brahmic">lontara';
-       }
-       elsif ($value == 0x1A2) {
-               print '<td colspan="9" class="X Ll Brahmic di-rare">tai tham';
-       }
-       elsif ($value == 0x1AB) {
-               print '<td colspan="5" class="di-invalid">reserved';
-       }
-       elsif ($value == 0x1B0) {
-               print '<td colspan="8" class="X Ll ">balinese';
-       }
-       elsif ($value == 0x1B8) {
-               print '<td colspan="4" class="X Ll ">sundanese';
-       }
-       elsif ($value == 0x1BC) {
-               print '<td colspan="4" class="X Ll di-rare">batak';
-       }
-       elsif ($value == 0x1C0) {
-               print '<td colspan="5" class="X Ll ">lepcha';
-       }
-       elsif ($value == 0x1C5) {
-               print '<td colspan="3" class="X Ll ">ol chiki';
-       }
-       elsif ($value == 0x1C8) {
-               print '<td colspan="5" class="di-invalid">reserved';
-       }
-       elsif ($value == 0x1CD) {
-               print '<td colspan="3" class="X Ll di-rare">vedic';
-       }
-       elsif ($value == 0x1D0) {
-               print '<td colspan="8" class="X Ll Latin">phonetic';
-       }
-       elsif ($value == 0x1D8) {
-               print '<td colspan="4" class="X Ll Latin">phonetic+';
-       }
-       elsif ($value == 0x1DC) {
-               print '<td colspan="4" class="X Mn">combining';
-       }
-       elsif ($value == 0x1E0) {
-               print '<td colspan="16" class="X Ll Latin">latin extended additional';
-       }
-       elsif ($value == 0x1F0) {
-               print '<td colspan="16" class="X Ll Greek">greek+';
-       }
-}
-
-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">?';
-       }
-}
-
-print "<ul>\n";
-
 my @nibble = (0..9, 'A'..'F');
 for my $row (@request) {
-       print '<li><table class="glyphs">';
+       printf '<div class="section"><table class="glyphs%s">', !$row->{cell} && ' charmap';
        printf '<caption>%s</caption>', $row->{set};
-       print '<col>';
+       print '<col>' x 17;
        for my $section (qw{thead}) {
                print "<$section><tr><th>↱";
                print '<th>', $_ for @nibble;
@@ -395,12 +110,8 @@ for my $row (@request) {
        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;
-                       }
-                       elsif ($row->{set} eq 'Unicode BMP') {
-                               printcell_unicode(($msb<<4) + $lsb);
+                       if ($row->{cell}) {
+                               print $row->{cell}->(($msb<<4) + $lsb);
                                next;
                        }
 
@@ -409,41 +120,55 @@ for my $row (@request) {
                                print '<td>';
                                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 = "<span>$glyph</span>" if $prop eq 'Zs';
-
-                       printf "\n".'<td class="%s" title="%s">%s',
-                               join(' ', @class), quote($desc), $glyph;
+                       print "\n".$glyphs->glyph_cell($glyph);
                }
                print "\n";
        }
-       print "</table>\n";
+       print "</table></div>\n";
 }
 
-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>
+       <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 5.0
+       <td class="X Xr">proposed
+       <td class="X Xd">deprecated
+       <td class="">unassigned
+       <td class="X Xi">invalid
+       </table>
+</div>
 
-</html>