\d+) )? \z }x) {
+ if (defined $row{endpoint}) {
+ # extend earlier range
+ my $skip = int(($row{endpoint} || $row{offset}) / $row{cols});
+ for ($skip + 1 .. ($+{offset} / $row{cols}) - 1) {
+ $row{skip}->{ $_ * $row{cols} - $row{offset} }++;
+ }
}
else {
- $row{table} = decode($row{set}, pack 'C*', $row{offset} .. $endpoint);
+ $row{offset} = $+{offset};
}
+ $row{endpoint} = $+{endpoint} || 0;
}
else {
- print "Encoding $input unknown
\n";
+ Alert("Unknown option $param
for charset $input");
}
- \%row;
- }
- else {
- ();
}
-} map { defined $ALIAS{$_} ? @{ $ALIAS{$_} } : $_ }
- $ENV{PATH_INFO} =~ /\w/ ? split(m{[/+\s]}, $ENV{PATH_INFO}) : 'default';
-my $NOCHAR = chr 0xFFFD;
-for my $cp437 (grep {$request[$_]->{set} eq 'cp437'} 0 .. $#request) {
- substr($request[$cp437]->{table}, 237, 1) = pack 'U*', 0x3D5; # phi sign
- substr($request[$cp437]->{table}, 0, 32) = pack 'U*', map {hex} qw(
- 2007 263A 263B 2665 2666 2663 2660 2022 25D8 25CB 25D9 2642 2640 266A 266B 263C
- 25BA 25C4 2195 203C 00B6 00A7 25AC 21A8 2191 2193 2192 2190 221F 2194 25B2 25BC
- );
-}
+ if ($input =~ m{ \A u ([0-9a-f]+) (?:-([0-9a-f]+))? \z }ix) {
+ my $start = hex($1) << ($2 ? 4 : 8);
+ my $end = $2 ? (hex($2) << 4) + $row{cols} - 1 : $start + 255;
+ $row{table} = join '', map { chr } $start .. $end;
+ utf8::upgrade($row{table}); # prevent latin1 output
+ $row{endpoint} = $end - $start;
+ $row{set} = sprintf 'Unicode block U+%02Xxx', $start >> 8;
+ $row{offset} = $start % 256;
+ }
+ elsif (lc $input eq 'uu') {
+ $row{set} = 'Unicode planes';
+ $row{cell} = do 'charset-ucplanes.inc.pl'
+ or Alert('Table data could not be read', $@ || $!);
+ $row{endpoint} = 1023 * $row{cell}->{colsize};
+ }
+ elsif (lc $input eq 'u') {
+ $row{cell} = do 'charset-unicode.inc.pl'
+ or Alert('Table data could not be read', $@ || $!);
-sub quote {
- local $_ = shift;
- s/"/"/g;
- s/</g;
- s/>/>/g;
- return $_;
-}
+ $row{endpoint} ||= 8191;
+ $row{endpoint} *= $row{cell}->{colsize};
+ $row{startpoint} = $row{cell}->{colsize} * $row{offset};
+ $row{offset} = 0;
+ $row{set} = 'Unicode ' . (
+ $row{startpoint} < 0x10000 && $row{endpoint} < 0x10000 ? 'BMP' :
+ $row{startpoint} >= 0x10000 && $row{endpoint} < 0x20000 ? 'SMP' :
+ 'allocations'
+ );
+ }
+ elsif ($input =~ m/^utf-*8$/i) {
+ $row{set} = 'UTF-8';
+ $row{cell} = do 'charset-utf8.inc.pl'
+ or Alert('Table data could not be read', $@ || $!);
+ $row{endpoint} = 255;
+ }
+ elsif ($row{set} = Encode::resolve_alias($input)) {
+ $row{endpoint} ||= 255;
+ if ($row{set} eq 'MacHebrew' or $row{set} eq 'MacThai') {
+ # array of possibly multiple characters per code point
+ $row{table} = [
+ map { Encode::decode($row{set}, pack 'C*', $_) } $row{offset} .. $row{endpoint}
+ ];
+ }
+ else {
+ # ~16x faster than decoding in loop;
+ # substr strings is twice as fast as splitting to an array
+ $row{table} = Encode::decode($row{set}, pack 'C*', $row{offset} .. $row{endpoint});
+ }
+ $row{endpoint} -= $row{offset};
-sub printcell_unicode {
- my ($value) = @_;
- if ($value > 0x27F) {
- print "\n".'?';
- }
- elsif ($value == 0) {
- print ' | control';
- }
- elsif ($value == 2) {
- print ' | latin';
- }
- elsif ($value == 8) {
- print ' | control';
- }
- elsif ($value == 10) {
- print ' | latin supplement';
- }
- elsif ($value == 0x10) {
- print ' | latin ext-A';
- }
- elsif ($value == 0x18) {
- print ' | latin ext-B';
- }
- elsif ($value == 0x20) {
- print ' | latin ext-B';
- }
- elsif ($value == 0x25) {
- print ' | IPA';
- }
- elsif ($value == 0x2B) {
- print ' | spacing modifier';
- }
- elsif ($value == 0x30) {
- print ' | diacritics';
- }
- elsif ($value == 0x38) {
- print ' | greek';
- }
- elsif ($value == 0x40) {
- print ' | cyrillic';
- }
- elsif ($value == 0x50) {
- print ' | cyrillic+';
- }
- elsif ($value == 0x53) {
- print ' | armenian';
- }
- elsif ($value == 0x58) {
- print ' | hebrew';
- }
- elsif ($value == 0x60) {
- print ' | arabic';
- }
- elsif ($value == 0x70) {
- print ' | syriac';
- }
- elsif ($value == 0x75) {
- print ' | arabic+';
- }
- elsif ($value == 0x78) {
- print ' | thaana';
- }
- elsif ($value == 0x7C) {
- print ' | nko';
- }
- elsif ($value == 0x80) {
- print ' | samaritan';
- }
- elsif ($value == 0x84) {
- print ' | manda';
- }
- elsif ($value == 0x86) {
- print ' | reserved';
- }
- elsif ($value == 0x90) {
- print ' | devanagari';
- }
- elsif ($value == 0x98) {
- print ' | bengali';
- }
- elsif ($value == 0xA0) {
- print ' | gurmukhi';
- }
- elsif ($value == 0xA8) {
- print ' | gujarati';
- }
- elsif ($value == 0xB0) {
- print ' | oriya';
- }
- elsif ($value == 0xB8) {
- print ' | tamil';
- }
- elsif ($value == 0xC0) {
- print ' | telugu';
- }
- elsif ($value == 0xC8) {
- print ' | kannada';
- }
- elsif ($value == 0xD0) {
- print ' | malayalam';
- }
- elsif ($value == 0xD8) {
- print ' | sinhala';
- }
- elsif ($value == 0xE0) {
- print ' | thai';
- }
- elsif ($value == 0xE8) {
- print ' | lao';
- }
- elsif ($value == 0xF0) {
- print ' | tibetan';
- }
- elsif ($value == 0x100) {
- print ' | myanmar';
- }
- elsif ($value == 0x10A) {
- print ' | georgian';
- }
- elsif ($value == 0x110) {
- print ' | hangeul jamo';
- }
- elsif ($value == 0x120) {
- print ' | ethiopic';
- }
- elsif ($value == 0x130) {
- print ' | ethiopic';
- }
- elsif ($value == 0x138) {
- print ' | eth+';
- }
- elsif ($value == 0x13A) {
- print ' | cherokee';
- }
- elsif ($value == 0x140) {
- print ' | unified canadian aboriginal syllabics';
- }
- elsif ($value == 0x160) {
- print ' | unified canadian syllabics';
- }
- elsif ($value == 0x168) {
- print ' | ogham';
- }
- elsif ($value == 0x16A) {
- print ' | runic';
- }
- elsif ($value == 0x170) {
- print ' | tagalog';
- }
- elsif ($value == 0x172) {
- print ' | hanun';
- }
- elsif ($value == 0x174) {
- print ' | buhid';
- }
- elsif ($value == 0x176) {
- print ' | tagb';
- }
- elsif ($value == 0x178) {
- print ' | khmer';
- }
- elsif ($value == 0x180) {
- print ' | mongolian';
- }
- elsif ($value == 0x18B) {
- print ' | canadian+';
- }
- elsif ($value == 0x190) {
- print ' | limbu';
- }
- elsif ($value == 0x195) {
- print ' | tai le';
- }
- elsif ($value == 0x198) {
- print ' | new tai lue';
- }
- elsif ($value == 0x19E) {
- print ' | km';
- }
- elsif ($value == 0x1A0) {
- print ' | lontara';
- }
- elsif ($value == 0x1A2) {
- print ' | tai tham';
- }
- elsif ($value == 0x1AB) {
- print ' | reserved';
- }
- elsif ($value == 0x1B0) {
- print ' | balinese';
- }
- elsif ($value == 0x1B8) {
- print ' | sundanese';
- }
- elsif ($value == 0x1BC) {
- print ' | batak';
- }
- elsif ($value == 0x1C0) {
- print ' | lepcha';
- }
- elsif ($value == 0x1C5) {
- print ' | ol chiki';
- }
- elsif ($value == 0x1C8) {
- print ' | reserved';
- }
- elsif ($value == 0x1CD) {
- print ' | vedic';
- }
- elsif ($value == 0x1D0) {
- print ' | phonetic';
- }
- elsif ($value == 0x1D8) {
- print ' | phonetic+';
- }
- elsif ($value == 0x1DC) {
- print ' | combining';
- }
- elsif ($value == 0x1E0) {
- print ' | latin extended additional';
- }
- elsif ($value == 0x1F0) {
- print ' | greek+';
- }
- elsif ($value == 0x200) {
- print ' | general punctuation';
- }
- elsif ($value == 0x207) {
- print ' | su[bp]script';
- }
- elsif ($value == 0x20A) {
- print ' | currency';
- }
- elsif ($value == 0x20D) {
- print ' | overlay';
- }
- elsif ($value == 0x210) {
- print ' | letterlike';
- }
- elsif ($value == 0x215) {
- print ' | number';
- }
- elsif ($value == 0x219) {
- print ' | arrows';
- }
- elsif ($value == 0x220) {
- print ' | mathematical symbols';
- }
- elsif ($value == 0x230) {
- print ' | miscellaneous technical';
- }
- elsif ($value == 0x240) {
- print ' | control';
- }
- elsif ($value == 0x244) {
- print ' | OCR';
- }
- elsif ($value == 0x246) {
- print ' | enclosed alphanumerics';
- }
- elsif ($value == 0x250) {
- print ' | box drawing';
- }
- elsif ($value == 0x258) {
- print ' | blocks';
- }
- elsif ($value == 0x25A) {
- print ' | geometric shapes';
- }
- elsif ($value == 0x260) {
- print ' | miscellaneous symbols';
- }
- elsif ($value == 0x270) {
- print ' | dingbats';
- }
- elsif ($value == 0x27C) {
- print ' | maths-A';
- }
- elsif ($value == 0x27F) {
- print ' | arr';
- }
-}
+ if ($row{set} eq 'cp437') {
+ for my $phipos (237 - $row{offset}) {
+ next if $phipos < 0 or $phipos > $row{endpoint};
+ # replace phi glyph
+ substr($row{table}, $phipos, 1) = pack 'U*', 0x3D5;
+ }
+ if ($row{offset} == 0) {
+ # replace control characters by visible variants
+ substr($row{table}, 0, 32) = pack 'U*', map {hex} qw(
+ 2007 263A 263B 2665 2666 2663 2660 2022
+ 25D8 25CB 25D9 2642 2640 266A 266B 263C
+ 25BA 25C4 2195 203C 00B6 00A7 25AC 21A8
+ 2191 2193 2192 2190 221F 2194 25B2 25BC
+ );
+ }
+ }
-sub printcell_utf8 {
- my ($value) = @_;
- if ($value <= 0x7F) {
- print ' | Single byte ASCII'
- if $value == 0;
- }
- elsif ($value <= 0xBF) {
- print ' | Multi-byte continuation'
- if $value == 0x80;
- }
- elsif ($value <= 0xC1) {
- print ' | (Overl.)'
- if $value == 0xC0;
- }
- elsif ($value <= 0xDF) {
- print ' | 2-byte sequence start'
- if $value == 0xC2;
- print ' | '
- if $value == 0xD0;
- }
- elsif ($value <= 0xEF) {
- print ' | 3-byte sequence start'
- if $value == 0xE0;
- }
- elsif ($value <= 0xF4) {
- print ' | 4-byte sequence'
- if $value == 0xF0;
- }
- elsif ($value <= 0xF7) {
- print ' | (Overflow)'
- if $value == 0xF5;
- }
- elsif ($value <= 0xFB) {
- print ' | 5-byte'
- if $value == 0xF8;
- }
- elsif ($value <= 0xFD) {
- print ' | 6-byte'
- if $value == 0xFC;
- }
- elsif ($value <= 0xFF) {
- print ' | Invalid'
- if $value == 0xFE;
+ $visible->{ascii} = # assume common base
+ $visible->{ $row{set} } = 1;
}
else {
- print "\n".' | ?';
+ Alert("Encoding $input unknown");
+ return;
}
+ push @request, \%row;
}
+tabinput($_) for @tablist;
-print "\n";
+my $NOCHAR = chr 0xFFFD;
+
+sub range_cell {
+ my ($info, $offset) = @_;
+ my $table = $info->{cell} or return;
+ my $def = $table->{$offset} or return;
+ my ($len, $class, $name, $title) = @{$def};
+
+ my $cols = $info->{cols};
+ my $colsize = $table->{colsize} || 1;
+ my $attr = '';
+ $len /= $colsize;
+ $name //= $len <= 2 ? 'res' : 'reserved';
+
+ if (my $part = $offset/$colsize % $cols) {
+ # continued row
+ my $rest = $cols - $part; # remaining
+ $rest = $len if $len < $rest; #TODO: optimise
+ if ($len -= $rest) {
+ # continued on new row
+ my @next = ($len * $colsize, "$class joinu");
+ if ($len > $rest) {
+ # minority remains
+ push @next, $name, $title;
+ $title ||= $name;
+ $name = '';
+ }
+ else {
+ # minority on next row
+ push @next, '"', $title || $name;
+ }
+ $table->{$offset + $colsize*$rest} //= \@next;
+ $class .= ' joind';
+ }
+ $len = $rest;
+ }
+ elsif (my $rows = int($len / $cols)) {
+ # multiple full rows
+ my $rowsize = $colsize * $cols;
+ if ($len -= $rows * $cols) {
+ # partial row remains
+ $table->{$offset + $rowsize * $rows} //= [$len*$colsize, "$class joinu", '', $title];
+ $class .= ' joind';
+ }
+
+ unless ($info->{realsize}) {
+ # coalesce multiple rows
+ while ($rows > 3) {
+ $info->{skip}->{$offset += $rowsize}++;
+ $rows--;
+ }
+ if ($rows > 2) {
+ $info->{skip}->{$offset += $rowsize} = 0;
+ }
+ }
+
+ $attr .= sprintf ' rowspan=%d', $rows;
+ $len = $cols;
+ }
+
+ $attr .= sprintf ' colspan=%d', $len unless $len == 1;
+ $attr .= $1 if $class and $class =~ s/( \w+="[^"]*")//;
+ $attr .= sprintf ' class="%s"', $class if $class;
+ $attr .= sprintf ' title="%s"', EscapeHTML($title) if $title;
+ return "$name\n";
+}
-my @nibble = (0..9, 'A'..'F');
for my $row (@request) {
- print '';
- printf '%s', $row->{set};
- print '';
+ my $cols = $row->{cols};
+ my $colsize = $row->{cell} && $row->{cell}->{colsize} || 1;
+ my $coldigits = ceil(log($colsize * $cols) / log(16)); # uniform length of hexadecimal header
+ my $rowdiv = 16 ** $coldigits; # row divide for column digits
+ $rowdiv = 1 if $rowdiv != $cols * $colsize; # divide only if all columns are matched
+ my $offset = $row->{startpoint} || 0;
+
+ printf '', !$row->{cell} && ' charmap';
+ my $title = $row->{set};
+ $title .= " "
+ for grep { $_ ne 'iso-8859-1' } $row->{parent} // ();
+ printf '%s', $title;
+ print '' x ($cols + 1);
for my $section (qw{thead}) {
- print "<$section>â±";
- print ' | ', $_ for @nibble;
+ print "<$section> |
---|
", $rowdiv == 1 ? '+' : 'â±';
+ printf ' | %0*X', $coldigits, $_ * $colsize for 0 .. $cols - 1;
print "\n";
}
print ' | ';
- for my $msb (0 .. (length($row->{table}) || 256) - 1 >> 4) {
- printf '%X', $msb + ($row->{offset} >> 4);
- for my $lsb (0 .. $#nibble) {
- if ($row->{set} eq 'UTF-8') {
- printcell_utf8(($msb<<4) + $lsb);
- next;
+ while ($offset < $row->{endpoint}) {
+ if ($row->{skip}->{$offset}) {
+ $offset += $cols * $colsize;
+ next;
+ }
+
+ print ' |
---|
';
+ if (defined $row->{skip}->{$offset}) {
+ print 'â®';
+ }
+ else {
+ if (my $rowmod = $offset % $rowdiv) {
+ # offset in column units
+ printf '+%X', $rowmod;
}
- elsif ($row->{set} eq 'Unicode BMP') {
- printcell_unicode(($msb<<4) + $lsb);
- next;
+ else {
+ # divided row offset
+ printf '%X', ($offset + $row->{offset}) / $rowdiv;
}
+ }
+ say '';
- my $glyph = substr $row->{table}, ($msb<<4) + $lsb, 1;
- if ($glyph eq $NOCHAR) {
- print ' | ';
+ for (1 .. $cols) {
+ if ($row->{cell}) {
+ print range_cell($row, $offset);
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);
+ my $cp = $offset + $row->{offset};
+ my $glyph = ref $row->{table} eq 'ARRAY' ? $row->{table}->[$offset] :
+ substr $row->{table}, $offset, 1;
+ my ($cell, $name, $class) = $glyph eq $NOCHAR ? () :
+ $glyphs->glyph_html($glyph);
- $glyph = "$glyph" if $prop eq 'Zs';
+ if (exists $get{compare}) {
+ state $visible = {};
+ $class = (
+ $cp == ord $glyph ? 'l4' :
+ $row->{parent} && $glyph eq
+ Encode::decode($row->{parent}, pack 'C', $cp) ? 'l3' :
+ !$class ? undef :
+ $visible->{$glyph} ? 'l2' :
+ 'l1'
+ );
+ $visible->{$glyph}++;
+ }
- printf "\n".' | %s',
- join(' ', @class), quote($desc), $glyph;
+ say sprintf $class ? ' | %s' : ' | ',
+ $name, $class, $cell;
+ }
+ continue {
+ $offset += $colsize;
}
- print "\n";
}
- print " |
---|
\n";
+ say ' ';
}
-print "\n";
-
:>
-
+
+ <: if (exists $get{compare}) { :>
+ unicode
+ | inherited
+ | existing
+ | original
+ | unassigned
+<: } else { :>
+ | control
+ | whitespace
+ | diacritic
+ | punctuation
+ | symbol
+ | numeric
+ | greek
+ | aramaic
+ | syllabic
+ african
+ | japanese
+ | cjk
+ | chinese
+ |
+ | alphabetic
+ |
+
+
+ unicode 7.0
+ | proposed
+ | deprecated
+ | unassigned
+ | invalid
+<: } :> |
+
-
| |