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 @tables = map { decode($_, pack 'C*', 0..255) } 'iso-8859-1';
34 my $NOCHAR = chr 0xFFFD;
44 my @nibble = (0..9, 'A'..'F');
45 for my $table (@tables) {
46 print '<table class="glyphs"><col>';
47 for my $section (qw{thead tfoot}) {
48 print "<$section><tr><th>↳";
49 print '<th>', $_ for @nibble;
53 for my $msb (0 .. $#nibble) {
54 print '<tr><th>', $nibble[$msb];
55 for my $lsb (0 .. $#nibble) {
56 my $glyph = substr $table, ($msb<<4) + $lsb, 1;
57 if ($glyph eq $NOCHAR) {
61 my $info = [ord $glyph];
62 if (defined (my $mnem = $di{ord $glyph})) {
63 $info = $diinfo->{$mnem};
65 my ($codepoint, $name, $prop, $script, $string) = @$info;
67 $glyph = quote($string || $glyph);
68 my $desc = sprintf 'U+%04X%s', $codepoint, $name && " ($name)";
69 my @class = ('X', grep {$_} $prop, $script);
71 $glyph = "<span>$glyph</span>" if $prop eq 'Zs';
73 printf "\n".'<td class="%s" title="%s">%s',
74 join(' ', @class), quote($desc), $glyph;
76 print "\n<th>", $nibble[$msb], "\n";