X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/7ffd70c8bf485c8c0777899c792d68ef9ed58436..017f784142bc2a77d8e283dc61ff6306e556387d:/charset.inc.pl diff --git a/charset.inc.pl b/charset.inc.pl new file mode 100644 index 0000000..020cb2d --- /dev/null +++ b/charset.inc.pl @@ -0,0 +1,59 @@ +use 5.014; +use warnings; +use utf8; + ++{ + %{ Data('./charset-encoding') }, + + '' => {setup => sub { + my $row = shift; + $row->{offset} = delete $row->{startpoint}; + $row->{set} = 'Unicode characters'; + my $block = $row->{offset} >> 8; + $row->{endpoint} ||= ($block + 1 << 8) - 1; + $block == ($row->{endpoint} >> 8) or undef $block; + + $row->{table} = join '', map { chr =~ s/\A\p{Unassigned}\z/�/r } + $row->{offset} .. $row->{endpoint}; + utf8::upgrade($row->{table}); # prevent latin1 output + + $row->{endpoint} -= $row->{offset}; + + if (defined $block) { + $row->{set} = sprintf 'Unicode block U+%02Xxx', $block; + $row->{offset} %= 0x100; + } + + return $row; + }}, + u => {setup => sub { + my $row = shift; + state $celldata = eval { Data('charset-unicode') } + or Alert('Table data could not be read', ref $@ && $@->[1]); + $row->{cell} = $celldata; + + $row->{endpoint} ||= 0x1FFF; + $row->{set} = 'Unicode ' . ( + $row->{startpoint} < 0x1000 && $row->{endpoint} < 0x1000 ? 'BMP' : + $row->{startpoint} >= 0x1000 && $row->{endpoint} < 0x2000 ? 'SMP' : + 'allocations' + ); + return $row; + }}, + uu => {setup => sub { + my $row = shift; + $row->{cell} = eval { Data('charset-ucplanes') } + or Alert('Table data could not be read', ref $@ && $@->[1]); + $row->{endpoint} ||= 0x3FF; + $row->{set} = 'Unicode planes'; + return $row; + }}, + utf8 => {setup => sub { + my $row = shift; + $row->{set} = 'UTF-8'; + $row->{cell} = eval { Data('charset-utf8') } + or Alert('Table data could not be read', ref $@ && $@->[1]); + return $row; + }}, + 'utf-8' => 'utf8', +};