From 8ed454fdd94aae38d04fcd96cab15ef3b86b9cc5 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Tue, 9 Mar 2010 22:59:55 +0000 Subject: [PATCH 1/1] formatchar: annotation options, print method --- Shiar_Sheet/FormatChar.pm | 24 ++++++++++++++++++------ unicode.plp | 13 ++++--------- writing.plp | 16 +++++----------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/Shiar_Sheet/FormatChar.pm b/Shiar_Sheet/FormatChar.pm index a501b94..ba38035 100644 --- a/Shiar_Sheet/FormatChar.pm +++ b/Shiar_Sheet/FormatChar.pm @@ -6,7 +6,7 @@ use warnings; use Data::Dump 'pp'; use PLP::Functions 'EscapeHTML'; -our $VERSION = '1.00'; +our $VERSION = '1.01'; our $diinfo = do 'digraphs.inc.pl'; our %di = map { $diinfo->{$_}->[0] => $_ } grep { ref $diinfo->{$_} } @@ -14,7 +14,7 @@ our %di = map { $diinfo->{$_}->[0] => $_ } grep { ref $diinfo->{$_} } sub new { my ($class) = @_; - bless {}, $class; + bless { digraph => 1, unicode => 0 }, $class; } sub glyph_info { @@ -38,7 +38,7 @@ sub glyph_html { my $title = sprintf 'U+%04X%s', $codepoint, $name && " ($name)"; my @class = ('X', grep {$_} $prop, $script); - $cell = "$cell" if $prop eq 'Zs'; + $cell = "$cell" if $prop and $prop eq 'Zs'; $cell = ' ' if $cell eq ''; return ($cell, EscapeHTML($title), join(' ', @class), $mnem); @@ -101,9 +101,9 @@ sub cell { @class ? sprintf(' class="%s"', join ' ', @class) : '', $html || '', $cell eq '' ? ' ' : $cell, - defined $mnem && length $mnem + $self->{digraph} && defined $mnem && length $mnem ? sprintf(' %s', EscapeHTML($mnem)) - : $cell =~ /^[^a-zA-Z]$/ + : $self->{unicode} + $cell =~ /^[^a-zA-Z]$/ > 0 ? sprintf(' %04X', 'value', ord $cell) : '', ); @@ -151,9 +151,21 @@ sub table { $colspan = 1; } - return sprintf qq{\n%s
\n}, + return sprintf qq{\n%s
\n}, + $self->{digraph} || $self->{unicode} >= 0 ? ' dilabel' : '', join '', map {"$_\n"} @rows; } +sub print { + my $self = shift; + while (@_) { + printf '

%s

'."\n\n", shift; + while (ref $_[0] and $_ = shift) { + print $self->table($_); + } + print '
'; + } +} + 1; diff --git a/unicode.plp b/unicode.plp index fb5ee03..f506fb5 100644 --- a/unicode.plp +++ b/unicode.plp @@ -28,19 +28,14 @@ i^k or i^vu respectively in Vim. use Shiar_Sheet::FormatChar; my $glyphs = Shiar_Sheet::FormatChar->new; -sub print_glyph_tables { - while (@_) { - printf '

%s

'."\n\n", shift; - while (ref $_[0] and $_ = shift) { - print $glyphs->table($_); - } - print '
'; - } +if (exists $get{q}) { + $glyphs->{unicode}--; + $glyphs->{digraph}--; } our $verbose = exists $get{v}; -print_glyph_tables( +$glyphs->print( 'Popular', [qw{. « » . ‹ › . ‘ ’ . “ ” . „ ‚ . ‟ ‛}], [qw{. † ‡ • . § ¶ # . © ® ™ . ° ′ ″ . − × ÷ . ± ² √}], diff --git a/writing.plp b/writing.plp index e57ceec..30080ec 100644 --- a/writing.plp +++ b/writing.plp @@ -26,6 +26,10 @@ and common chars.

<: use Shiar_Sheet::FormatChar; my $glyphs = Shiar_Sheet::FormatChar->new; +unless (exists $get{v}) { + $glyphs->{unicode}--; + $glyphs->{digraph}--; +} print $glyphs->table([qw{ .>Chinese 壹 貳 參 肆 伍 陸 柒 捌 玖 零 @@ -55,17 +59,7 @@ print $glyphs->table([qw{ .>Osmanya 𐒡 𐒢 𐒣 𐒤 𐒥 𐒦 𐒧 𐒨 𐒩 𐒠 }]); -sub print_glyph_tables { - while (@_) { - printf '

%s

'."\n\n", shift; - while (ref $_[0] and $_ = shift) { - print $glyphs->table($_); - } - print '
'; - } -} - -print_glyph_tables( +$glyphs->print( Western => [qw{ .>Latin A > B C G D > E F Y VU W Z H - I J K L M N > X O P > - Q R > S T .>Old_Italic 𐌀 > 𐌁 > 𐌂 𐌃 > 𐌄 𐌅𐌚 > > 𐌖 𐌆 𐌇 𐌈 𐌉 𐌝 𐌊 𐌋 𐌌 𐌍 > 𐌎 𐌏 𐌐 > 𐌑 𐌒 𐌓 > 𐌔 𐌕 -- 2.30.0