charset: page with latin1 character table
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 19 Apr 2009 00:06:42 +0000 (00:06 +0000)
committerMischa POSLAWSKY <perl@shiar.org>
Wed, 22 Apr 2009 00:01:21 +0000 (00:01 +0000)
A 16x16 table with each iso-8859-1 byte in order.  Rather than simply
using chr(code point), it converts the byte range using Encode::decode,
so it can just as easily display any other charset known by Perl.

Uses the digraphs include for character details.  While this may lack
some characters, it is faster and easier.  Plug the most glaring gaps by
adding the entire ASCII range as single-character "digraphs".

Linked from vi i^v (as code points can be entered there), but mostly
useful as reference (not necessarily limited to vim).

charset.plp [new file with mode: 0644]
rfc1345convert
vim.inc.pl

diff --git a/charset.plp b/charset.plp
new file mode 100644 (file)
index 0000000..d3ddea7
--- /dev/null
@@ -0,0 +1,80 @@
+<:
+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>
+
+<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 Encode qw(decode);
+# generate character table(s)
+# (~16x faster than decoding in loop;
+#  substr strings is twice as fast as splitting to an array)
+my @tables = map { decode($_, pack 'C*', 0..255) } 'iso-8859-1';
+my $NOCHAR = chr 0xFFFD;
+
+sub quote {
+       local $_ = shift;
+       s/"/&quot;/g;
+       s/</&lt;/g;
+       s/>/&gt;/g;
+       return $_;
+}
+
+my @nibble = (0..9, 'A'..'F');
+for my $table (@tables) {
+       print '<table class="glyphs"><col>';
+       for my $section (qw{thead tfoot}) {
+               print "<$section><tr><th>↳";
+               print '<th>', $_ for @nibble;
+               print "<th>&nbsp;\n";
+       }
+       print '<tbody>';
+       for my $msb (0 .. $#nibble) {
+               print '<tr><th>', $nibble[$msb];
+               for my $lsb (0 .. $#nibble) {
+                       my $glyph = substr $table, ($msb<<4) + $lsb, 1;
+                       if ($glyph eq $NOCHAR) {
+                               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<th>", $nibble[$msb], "\n";
+       }
+       print "</table>\n";
+}
+
index cae6d47b9014d2a67ecd32955a1f3fb15e868a14..f93275348360e0970948d38a731513efc64dea17 100755 (executable)
@@ -117,6 +117,9 @@ if (-r 'shiar.inc.txt') {
 }
 warn $@ if $@;
 
+$di{chr $_} = $_ for 32 .. 126;
+$di{'\\'.$_} = delete $di{$_} for '{', '}', '\\';
+
 # optionally get unicode character information
 my %info = eval {
        require Unicode::UCD;
index 98abbc63be822c2da8835d301ccda338e5acb554..b73b2540b0c373be19e1dda9d06c6a06f863180d 100644 (file)
@@ -504,7 +504,7 @@ i => {
        '^h' => ["back$sign{_}space", "co"],
        '^i' => ["tab", "co"],
        '^j' => ["enter", "co"],
-       '^k' => ["di$sign{_}graph", "co arg arg vim linkdigraphs.plp", "Key code"],
+       '^k' => ["di$sign{_}graph", 'co arg arg vim linkdigraphs', "Key code"],
        '^l' => ["<em>im</em> leave ins mode", "mo mode vim"],  # insertmode only
        '^m' => ["enter", "co"],
        '^n' => ["find next keyword", "pm vim"],
@@ -515,7 +515,7 @@ i => {
        '^s' => "^s",
        '^t' => ["indent", "co"],
        '^u' => ["delete line", "co"],
-       '^v' => ["literal or ch$sign{_}ar$sign{_}cod$sign{_}e", 'co', "Verbatim or by Value"],
+       '^v' => ["literal or ch$sign{_}ar$sign{_}cod$sign{_}e", 'co linkcharset', "Verbatim or by Value"],
        '^w' => ["delete word back", "co"],
        '^x' => ["ex$sign{_}pand mode", 'me arg modei^x vim'],
        '^y' => ["ins char above", "co vim"],