unicode: one common function to display all glyph tables
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 11 Oct 2008 10:43:07 +0000 (10:43 +0000)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 6 Jan 2009 22:39:02 +0000 (22:39 +0000)
New glyph_table() arguments include table header, and have a common inline
format for row/column headers.  Now used for all (even non-IPA) tables.
Should make for much more maintainable code.

unicode.plp

index 15651eb12e3f080e9cf5aff58c89023096541216..8dfe1322ba87b1aeab5cf6bf457908b1c2af7e6a 100644 (file)
@@ -41,19 +41,37 @@ sub quote {
 }
 
 sub glyph_table {
 }
 
 sub glyph_table {
-       my ($digraphs, $rowheads, $colheads) = @_;
+       my ($digraphs) = @_;
 
        my @rows;
 
 
        my @rows;
 
+       my @colheads;
+       while ($digraphs->[0] !~ /^\./) {
+               my $cell = shift @$digraphs or last;
+               push @colheads, sprintf(
+                       '<%s%s>%s',
+                       $cell =~ s/^-// ? 'td' : 'th',
+                       $cell =~ s/:(.*)// ? qq{ title="$1"} : '',
+                       $cell eq '_' ? '&nbsp;' : $cell
+               );
+       }
+       push @rows, sprintf '<thead><tr>%s<tbody>', join '', @colheads if @colheads;
+
        my $colspan = 1;
        for my $cell (@$digraphs) {
                my $class;
        my $colspan = 1;
        for my $cell (@$digraphs) {
                my $class;
-               if ($cell eq '.') {
+               if ($cell =~ s/^\.//) {
+                       # dot indicates start of a new row
                        push @rows, '';
                        push @rows, '';
-                       $rows[-1] .= '<th>'.(shift @$rowheads || '&nbsp;') if $rowheads;
+                       if ($cell =~ s/^>//) {
+                               # header cell text follows
+                               $cell =~ s/_/ /g;  # underscores may be used instead of whitespace (for qw//ability)
+                               $rows[-1] .= '<th>'.($cell || '&nbsp;');
+                       }
                        next;
                }
                elsif ($cell eq '>') {
                        next;
                }
                elsif ($cell eq '>') {
+                       # merge this cell to the next column
                        $colspan++;
                        next;
                }
                        $colspan++;
                        next;
                }
@@ -61,6 +79,7 @@ sub glyph_table {
                my $code = join '', map { $di{ord $_} || '' } split //, $cell;
                my $name = $diinfo->{$code}->[1];
 
                my $code = join '', map { $di{ord $_} || '' } split //, $cell;
                my $name = $diinfo->{$code}->[1];
 
+               # determine display class
                if ($cell =~ s/^-//) {
 #                      $class = 'Empty';
                }
                if ($cell =~ s/^-//) {
 #                      $class = 'Empty';
                }
@@ -81,6 +100,7 @@ sub glyph_table {
                        $class = 'Di';
                }
 
                        $class = 'Di';
                }
 
+               # add cell html
                $rows[-1] .= sprintf('<td%s%s%s>%s%s',
                        defined $name  ? qq{ title="$name"}  : '',
                        defined $class ? qq{ class="$class"} : '',
                $rows[-1] .= sprintf('<td%s%s%s>%s%s',
                        defined $name  ? qq{ title="$name"}  : '',
                        defined $class ? qq{ class="$class"} : '',
@@ -95,196 +115,148 @@ sub glyph_table {
                $colspan = 1;
        }
 
                $colspan = 1;
        }
 
-       if ($colheads) {
-               unshift @rows, sprintf '<thead><tr><td>%s<tbody>', join '',
-                       map { sprintf '<th title="%2$s">%s', split(/:/, $_, 2), '', '' }
-                       @$colheads
-       }
-
        return sprintf qq{<table class="glyphs dilabel">\n%s</table>\n},
                join '', map {"<tr>$_\n"} @rows;
 }
 
        return sprintf qq{<table class="glyphs dilabel">\n%s</table>\n},
                join '', map {"<tr>$_\n"} @rows;
 }
 
-print "<div>\n", "<h2>Popular</h2>\n\n";
-print glyph_table(@$_) for (
-       [ [qw{. « » . ‹ › . ‘ ’ . “ ” . „ ‚}]],
-       [ [qw{. † ‡ • . § ¶ # . © ® ™ . − × ÷ . ± ² √}]],
-       [ [qw{. å ä ö ü ß . Å æ ø ű ſ}]],
-       [ [qw{. ¿ ç ñ é ê è}]],
-);
-print "</div>\n\n";
+sub print_glyph_tables {
+       while (@_) {
+               printf "<div><h2>%s</h2>\n\n", shift;
+               while (ref $_[0] and $_ = shift) {
+                       print glyph_table($_);
+               }
+               print '</div>';
+       }
+}
 
 
-print "<div>\n", "<h2>Arrows</h2>\n\n";
-print glyph_table(@$_) for (
-       [ [qw{. ↖ ↑ ↗ ↔ . ← - → ↕ . ↙ ↓ ↘ -}]],
-       [ [qw{. ⇖ ⇑ ⇗ ⇔ . ⇐ - ⇒ ⇕ . ⇙ ⇓ ⇘ -}]],
-       [ [qw{. ◤ ▲ ◥ . ◀ ◆ ▶ . ◣ ▼ ◢}]],
-       [ [qw{. ◸ △ ◹ . ◁ ◇ ▷ . ◺ ▽ ◿}]],
-);
-print "</div>\n\n";
+print_glyph_tables(
+       'Popular',
+       [qw{. « » . ‹ › . ‘ ’ . “ ” . „ ‚}],
+       [qw{. † ‡ • . § ¶ # . © ® ™ . − × ÷ . ± ² √}],
+       [qw{. å ä ö ü ß . Å æ ø ű ſ}],
+       [qw{. ¿ ç ñ é ê è}],
 
 
-print "<div>\n", "<h2>Line drawing</h2>\n\n";
-print glyph_table(@$_) for (
-       [ [qw{. ┌ ┬ ┐ . ├ ┼ ┤ . └ ┴ ┘}]],
-       [ [qw{. ┏ ┳ ┓ . ┣ ╋ ┫ . ┗ ┻ ┛}]],
-       [ [qw{. ┍ ┯ ┑ . ┝ ┿ ┥ . ┕ ┷ ┙}]],
-       [ [qw{. ┎ ┰ ┒ . ┠ ╂ ┨ . ┖ ┸ ┚}]],
-       [ [qw{
+       'Arrows',
+       [qw{. ↖ ↑ ↗ ↔ . ← - → ↕ . ↙ ↓ ↘ -}],
+       [qw{. ⇖ ⇑ ⇗ ⇔ . ⇐ - ⇒ ⇕ . ⇙ ⇓ ⇘ -}],
+       [qw{. ◤ ▲ ◥ . ◀ ◆ ▶ . ◣ ▼ ◢}],
+       [qw{. ◸ △ ◹ . ◁ ◇ ▷ . ◺ ▽ ◿}],
+
+       'Line drawing',
+       [qw{. ┌ ┬ ┐ . ├ ┼ ┤ . └ ┴ ┘}],
+       [qw{. ┏ ┳ ┓ . ┣ ╋ ┫ . ┗ ┻ ┛}],
+       [qw{. ┍ ┯ ┑ . ┝ ┿ ┥ . ┕ ┷ ┙}],
+       [qw{. ┎ ┰ ┒ . ┠ ╂ ┨ . ┖ ┸ ┚}],
+       [qw{
                . ╴ ─ ╌ ┄ ┈ ╶ ╾
                . ╸ ━ ╍ ┅ ┉ ╺ ╼
                . ╵ │ ╎ ┆ ┊ ╷ ╿
                . ╹ ┃ ╏ ┇ ┋ ╻ ╽
                . ╴ ─ ╌ ┄ ┈ ╶ ╾
                . ╸ ━ ╍ ┅ ┉ ╺ ╼
                . ╵ │ ╎ ┆ ┊ ╷ ╿
                . ╹ ┃ ╏ ┇ ┋ ╻ ╽
-       }]],
-       [ [qw{. ╱ ╳ ╲ }]],
-       [ [qw{. ╔ ╦ ╗ ═ . ╠ ╬ ╣ ║ . ╚ ╩ ╝ - }]],
-       [ [qw{. ╒ ╤ ╕ . ╞ ╪ ╡ . ╘ ╧ ╛ }]],
-       [ [qw{. ╓ ╥ ╖ . ╟ ╫ ╢ . ╙ ╨ ╜ }]],
-);
-print "</div>\n\n";
+       }],
+       [qw{. ╱ ╳ ╲ }],
+       [qw{. ╔ ╦ ╗ ═ . ╠ ╬ ╣ ║ . ╚ ╩ ╝ - }],
+       [qw{. ╒ ╤ ╕ . ╞ ╪ ╡ . ╘ ╧ ╛ }],
+       [qw{. ╓ ╥ ╖ . ╟ ╫ ╢ . ╙ ╨ ╜ }],
 
 
-print "<div>\n", "<h2>Blocks</h2>\n\n";
-print glyph_table(@$_) for (
-       [ [qw{. ▘ ▀ ▝ . ▌ █ ▐ . ▖ ▄ ▗ }]],
-       [ [qw{. ░ . ▒ . ▓ }]],
-       [ [qw{. ▛ ▚ ▟ . ▙ ▞ ▜ }]],
-       [ [qw{. ▁ ▂ ▃ ▄ ▅ ▆ ▇ ▔ . ▏ ▎ ▍ ▌ ▋ ▊ ▉ ▕ }]],
-       [ [qw{. □ ▣ ■ . ▤ ▦ ▥ . ▧ ▩ ▨}]],
-);
-print "</div>\n\n";
+       'Blocks',
+       [qw{. ▘ ▀ ▝ . ▌ █ ▐ . ▖ ▄ ▗ }],
+       [qw{. ░ . ▒ . ▓ }],
+       [qw{. ▛ ▚ ▟ . ▙ ▞ ▜ }],
+       [qw{. ▁ ▂ ▃ ▄ ▅ ▆ ▇ ▔ . ▏ ▎ ▍ ▌ ▋ ▊ ▉ ▕ }],
+       [qw{. □ ▣ ■ . ▤ ▦ ▥ . ▧ ▩ ▨}],
 
 
-print "<div>\n", "<h2>Signs</h2>\n\n";
-print glyph_table(@$_) for (
-       [ [qw{. ¤ ¢ ₥ € £ ₨ $ ¥ . ₫ ₭ ₦ ₱ ₧ ₮ ₩ ₪}]],
-       [ [qw{. ♠ ♡ ♢ ♣ . ♤ ♥ ♦ ♧}]],
-       [ [qw{. ☉ ☿ ♀ ♁ ♂ ♃ ♄ ♅ ♆ ♇}]],  # solar
-       [ [qw{. ♈ ♉ ♊ ♋ ♌ ♍ ♎ ♏ ♐ ♑ ♒ ♓}]],  # zodiac
-);
-print "</div>\n\n";
+       'Signs',
+       [qw{. ¤ ¢ ₥ € £ ₨ $ ¥ . ₫ ₭ ₦ ₱ ₧ ₮ ₩ ₪}],
+       [qw{. ♠ ♡ ♢ ♣ . ♤ ♥ ♦ ♧}],
+       [qw{. ☉ ☿ ♀ ♁ ♂ ♃ ♄ ♅ ♆ ♇}],  # solar
+       [qw{. ♈ ♉ ♊ ♋ ♌ ♍ ♎ ♏ ♐ ♑ ♒ ♓}],  # zodiac
 
 
-print "<div>\n", "<h2>IPA</h2>\n\n";
-print glyph_table(@$_) for (
-       [
-               [qw{
-                       . p  p̪  >  >  t  ʈ  c  k  q  =  ʡ  ʔ
-                       . b  b̪  >  >  d  ɖ  ɟ  ɡ  ɢ  =  -  =
-                       . m  ɱ  >  >  n  ɳ  ɲ  ŋ  ɴ  =  =  =
-                       . ʙ  -  >  >  r  -  -  =  ʀ  =  -я =
-                       . -  ⱱ  >  >  ɾ  ɽ  -  =  ɢ̆  =  -  =
-                       . ɸ  f  θ  s  ʃ  ʂ  ç  x  χ  ħ  ʜ  h
-                       . β  v  ð  z  ʒ  ʐ  ʝ  ɣ  ʁ  ʕ  ʢ  ɦ
-                       . =  =  >  >  ɬ  -  -  -  -  =  =  =
-                       . =  =  >  >  ɮ  -  -  -  -  =  =  =
-                       . -  ʋ  >  >  ɹ  ɻ  j  ɰ  -  -  -  =
-                       . =  =  >  >  l  ɭ  ʎ  ʟ  -  =  =  =
-                       . ʘ  -  ǀ  ǁ  ǃ  -‼ ǂ  -  -  =  =  =
-                       . ɓ  ɗ̪  >  >  ɗ  -ᶑ ʄ  ɠ  ʛ  =  =  =
-               }],
-               [
-                       'Plosive',
-                       'Voiced plosive',
-                       'Nasal',
-                       'Trill',
-                       'Tap/flap',
-                       'Fricative',
-                       'Voiced fricative',
-                       'Lateral fricative',
-                       'Voiced lateral fricative',
-                       'Approximant',
-                       'Lateral approximant',
-                       'Click',
-                       'Implosive',
-               ],
-               [
-                       qw'BiL:Bilabial LD:Labiodental D:Dental Alv:Alveolar PA:Postalveolar Rf:Retroflex Pal:Palatal Vel:Velar Uv:Uvular Ph:Pharyngeal EG:Epiglottal Gl:Glottal',
-               ],
-       ],
-       [
-               [qw{
-                       . i y  ɨ ʉ  ɯ u
-                       . - ɪ  ʏ -  ʊ -
-                       . e ø  ɘ ɵ  ɤ o
-                       . - -  ə -  - -
-                       . ɛ œ  ɜ ɞ  ʌ ɔ
-                       . æ -  ɐ -  - -
-                       . a ɶ  - -  ɑ ɒ
-               }],
-               [qw{Close Near-close Close-mid Mid Open-mid Near-open Open}],
-               [map {substr($_, 0, 1).':'.$_, substr($_, 0, 1)." r:$_ rounded"} qw{Front Central Back}]
-       ],
-);
-print "</div>\n\n";
+       'IPA',
+       [qw{
+               - BiL:Bilabial LD:Labiodental D:Dental Alv:Alveolar PA:Postalveolar
+                 Rf:Retroflex Pal:Palatal Vel:Velar Uv:Uvular Ph:Pharyngeal
+                 EG:Epiglottal Gl:Glottal
+               .>Plosive                   p  p̪  >  >  t  ʈ  c  k  q  =  ʡ  ʔ
+               .>Voiced_Plosive            b  b̪  >  >  d  ɖ  ɟ  ɡ  ɢ  =  -  =
+               .>Nasal                     m  ɱ  >  >  n  ɳ  ɲ  ŋ  ɴ  =  =  =
+               .>Trill                     ʙ  -  >  >  r  -  -  =  ʀ  =  -я =
+               .>Tap/flap                  -  ⱱ  >  >  ɾ  ɽ  -  =  ɢ̆  =  -  =
+               .>Fricative                 ɸ  f  θ  s  ʃ  ʂ  ç  x  χ  ħ  ʜ  h
+               .>Voiced_fricative          β  v  ð  z  ʒ  ʐ  ʝ  ɣ  ʁ  ʕ  ʢ  ɦ
+               .>Lateral_fricative         =  =  >  >  ɬ  -  -  -  -  =  =  =
+               .>Voiced_lateral_fricative  =  =  >  >  ɮ  -  -  -  -  =  =  =
+               .>Approximant               -  ʋ  >  >  ɹ  ɻ  j  ɰ  -  -  -  =
+               .>Lateral_approximant       =  =  >  >  l  ɭ  ʎ  ʟ  -  =  =  =
+               .>Click                     ʘ  -  ǀ  ǁ  ǃ  -‼ ǂ  -  -  =  =  =
+               .>Implosive                 ɓ  ɗ̪  >  >  ɗ  -ᶑ ʄ  ɠ  ʛ  =  =  =
+       }],
+       [(
+               '-',
+               map { substr($_, 0, 1).':'.$_, substr($_, 0, 1)." r:$_ rounded" }
+               qw{Front Central Back}
+       ), qw{
+               .>Close      i y  ɨ ʉ  ɯ u
+               .>Near-close - ɪ  ʏ -  ʊ -
+               .>Close-mid  e ø  ɘ ɵ  ɤ o
+               .>Mid        - -  ə -  - -
+               .>Open-mid   ɛ œ  ɜ ɞ  ʌ ɔ
+               .>Near-open  æ -  ɐ -  - -
+               .>Open       a ɶ  - -  ɑ ɒ
+       }],
 
 
-print "<div>\n", "<h2>Alphabetics</h2>\n\n";
-print glyph_table(
-       [ map { ('.', split //, $_->[1]) } @$_ ],
-       [ map {                 $_->[0]  } @$_ ],
-) for [
-       [Latin    => 'aīıęôɳŋṡšđðƷ'],
-       [Cyrillic => 'аійэёнњшщчьЯ'],
-       [Greek    => 'αίϊηϋπψσςθξΩ'],
-       [Hebrew   => 'אײיעונןסשטצץ'],
-];
-print "</div>\n\n";
+       'Alphabetics',
+       [qw{
+               .>Latin    a ī ı ę ô ɳ ŋ ṡ š đ ð Ʒ
+               .>Cyrillic а і й э ё н њ ш щ ч ь Я
+               .>Greek    α ί ϊ η ϋ π ψ σ ς θ ξ Ω
+               .>Hebrew   א ײ י ע ו נ ן ס ש ט צ ץ
+       }],
 
 
-print "<div>\n", "<h2>Japanese</h2>\n\n";
-print glyph_table(@$_) for (
-       [
-               [qw{
-                       . あ い う え お =
-                       . か き く け こ =
-                       . さ し す せ そ =
-                       . た ち つ て と =
-                       . な に ぬ ね の ん
-                       . は ひ ふ へ ほ =
-                       . ま み む め も =
-                       . や =  ゆ =  よ =
-                       . ら り る れ ろ =
-                       . わ ゐ =  ゑ を =
-               }],
-               ['', qw{K S T N H M Y R W}],
-               [qw{A I U E O}, ''],
-       ],
-       [
-               [qw{
-                       . が ぎ ぐ げ ご
-                       . ざ じ ず ぜ ぞ
-                       . だ ぢ づ で ど
-                       . ば び ぶ べ ぼ
-                       . ぱ ぴ ぷ ぺ ぽ
-               }],
-               [qw{G Z D B P}],
-               [qw{A I U E O}],
-       ],
-       [
-               [qw{
-                       . ア イ ウ エ オ ー
-                       . カ キ ク ケ コ =
-                       . サ シ ス セ ソ =
-                       . タ チ ツ テ ト =
-                       . ナ ニ ヌ ネ ノ ン
-                       . ハ ヒ フ ヘ ホ =
-                       . マ ミ ム メ モ =
-                       . ヤ -  ユ -  ヨ =
-                       . ラ リ ル レ ロ =
-                       . ワ ヰ -  ヱ ヲ =
-               }],
-               ['', qw{K S T N H M Y R W}],
-               [qw{A I U E O}, ''],
-       ],
-       [
-               [qw{
-                       . ガ ギ グ ゲ ゴ
-                       . ザ ジ ズ ゼ ゾ
-                       . ダ ヂ ヅ デ ド
-                       . バ ビ ブ ベ ボ
-                       . パ ピ プ ペ ポ
-                       . ヷ ヸ ヴ ヹ ヺ
-               }],
-               [qw{G Z D B P V}],
-               [qw{A I U E O}],
-       ],
+       'Japanese',
+       [qw{
+                 - A  I  U  E  O  _
+               .>  あ い う え お =
+               .>K か き く け こ =
+               .>S さ し す せ そ =
+               .>T た ち つ て と =
+               .>N な に ぬ ね の ん
+               .>H は ひ ふ へ ほ =
+               .>M ま み む め も =
+               .>Y や =  ゆ =  よ =
+               .>R ら り る れ ろ =
+               .>W わ ゐ =  ゑ を =
+       }],
+       [qw{
+                 - A  I  U  E  O
+               .>G が ぎ ぐ げ ご
+               .>Z ざ じ ず ぜ ぞ
+               .>D だ ぢ づ で ど
+               .>B ば び ぶ べ ぼ
+               .>P ぱ ぴ ぷ ぺ ぽ
+       }],
+       [qw{
+                 - A  I  U  E  O  _
+               .>  ア イ ウ エ オ ー
+               .>K カ キ ク ケ コ =
+               .>S サ シ ス セ ソ =
+               .>T タ チ ツ テ ト =
+               .>N ナ ニ ヌ ネ ノ ン
+               .>H ハ ヒ フ ヘ ホ =
+               .>M マ ミ ム メ モ =
+               .>Y ヤ -  ユ -  ヨ =
+               .>R ラ リ ル レ ロ =
+               .>W ワ ヰ -  ヱ ヲ =
+       }],
+       [qw{
+                 - A  I  U  E  O
+               .>G ガ ギ グ ゲ ゴ
+               .>Z ザ ジ ズ ゼ ゾ
+               .>D ダ ヂ ヅ デ ド
+               .>B バ ビ ブ ベ ボ
+               .>P パ ピ プ ペ ポ
+               .>V ヷ ヸ ヴ ヹ ヺ
+       }],
 );
 );
-print "</div>\n\n";
 
 :></div>
 
 
 :></div>