5 use open IO => ':utf8';
9 $header{content_type} = 'text/html; charset=utf-8';
11 :><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
12 "http://www.w3.org/TR/html4/loose.dtd">
16 <title>charset cheat sheet</title>
17 <meta http-equiv="content-type" content="utf-8">
18 <link rel="stylesheet" type="text/css" media="all" href="/base.css">
22 <h1>Character encoding</h1>
25 my $diinfo = do 'digraphs.inc.pl';
26 my %di = map { $diinfo->{$_}->[0] => $_ } grep { ref $diinfo->{$_} }
29 use Encode qw(decode);
30 # generate character table(s)
31 # (~16x faster than decoding in loop;
32 # substr strings is twice as fast as splitting to an array)
33 my @request = ('iso-8859-1', 'cp437');
34 my @tables = map { decode($_, pack 'C*', 0..255) } @request;
35 my $NOCHAR = chr 0xFFFD;
37 for my $cp437 (grep {$request[$_] eq 'cp437'} 0 .. $#request) {
38 substr($tables[$cp437], 237, 1) = pack 'U*', 0x3D5; # phi sign
39 substr($tables[$cp437], 0, 32) = pack 'U*', map {hex} qw(
40 2007 263A 263B 2665 2666 2663 2660 2022 25D8 25CB 25D9 2642 2640 266A 266B 263C
41 25BA 25C4 2195 203C 00B6 00A7 25AC 21A8 2191 2193 2192 2190 221F 2194 25B2 25BC
55 my @nibble = (0..9, 'A'..'F');
56 for my $tablenum (0 .. $#tables) {
57 print '<li><table class="glyphs">';
58 printf '<caption>%s</caption>', $request[$tablenum];
60 for my $section (qw{thead}) {
61 print "<$section><tr><th>↱";
62 print '<th>', $_ for @nibble;
66 for my $msb (0 .. $#nibble) {
67 print '<tr><th>', $nibble[$msb];
68 for my $lsb (0 .. $#nibble) {
69 my $glyph = substr $tables[$tablenum], ($msb<<4) + $lsb, 1;
70 if ($glyph eq $NOCHAR) {
74 my $info = [ord $glyph];
75 if (defined (my $mnem = $di{ord $glyph})) {
76 $info = $diinfo->{$mnem};
78 my ($codepoint, $name, $prop, $script, $string) = @$info;
80 $glyph = quote($string || $glyph);
81 my $desc = sprintf 'U+%04X%s', $codepoint, $name && " ($name)";
82 my @class = ('X', grep {$_} $prop, $script);
84 $glyph = "<span>$glyph</span>" if $prop eq 'Zs';
86 printf "\n".'<td class="%s" title="%s">%s',
87 join(' ', @class), quote($desc), $glyph;
100 <a href="http://sheet.shiar.nl/" rel="home">sheet.shiar.nl</a>/charset
101 <a href="git://git.shiar.nl/sheet" rel="vcs-git" title="Git repository"><:= "v$VERSION" :></a>
102 created by <a href="http://shiar.nl/" rel="author">Shiar</a> •
103 <a title="Licensed under the GNU Affero General Public License, version 3" rel="copyright"
104 href="http://www.fsf.org/licensing/licenses/agpl-3.0.html">AGPLv3</a> •
106 use Time::Format qw(time_format);
107 print time_format('yyyy-mm-dd', (stat $ENV{SCRIPT_FILENAME})[9]);