From: Mischa POSLAWSKY Date: Sat, 22 Apr 2017 10:15:20 +0000 (+0200) Subject: charset: move encoding-specific setup code to include X-Git-Tag: v1.10~95 X-Git-Url: http://git.shiar.nl/sheet.git/commitdiff_plain/2f6bd0f228e04949e561c9e5d7713a0baef77cd5?hp=3e2e19818a6102eff505984ca2430ae3ac901d08 charset: move encoding-specific setup code to include --- diff --git a/charset-encoding.inc.pl b/charset-encoding.inc.pl index fc6b4b1..0f1d2d6 100644 --- a/charset-encoding.inc.pl +++ b/charset-encoding.inc.pl @@ -52,10 +52,10 @@ use warnings; 'adobezdingbat'=> {inherit => ['MacDingbats' => '80-9F']}, # should be identical but maps to private use 'symbol' => {inherit => ['' => '20-7F+A0']}, 'adobesymbol' => {inherit => ['symbol' => '20-7F+A0', '' => '20-7F+A0']}, # minor differences, irrelevant except for different '€' - 'wingdings' => {inherit => ['' => '20']}, - 'wingdings2' => {inherit => ['' => '20']}, - 'wingdings3' => {inherit => ['' => '20']}, - 'webdings' => {inherit => ['' => '20']}, + 'wingdings' => {inherit => ['' => '20'], setup => sub {require Encode::Wingdings}}, + 'wingdings2' => {inherit => ['' => '20'], setup => sub {require Encode::Wingdings2}}, + 'wingdings3' => {inherit => ['' => '20'], setup => sub {require Encode::Wingdings3}}, + 'webdings' => {inherit => ['' => '20'], setup => sub {require Encode::Webdings}}, 'iso-8859-2' => {inherit => ['iso-8859-1' => 'A0']}, 'iso-8859-3' => {inherit => ['iso-8859-1' => 'A0']}, #TODO: also apply to iso-8859-9 @@ -122,4 +122,55 @@ use warnings; 'cp1047' => {inherit => ['cp37' => '10-2F+50-5F+A0-BF']}, 'cp1026' => {inherit => ['cp37' => '40']}, 'cp875' => {inherit => ['cp37' => '30']}, + + '' => {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 } $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; + $row->{cell} = do 'charset-unicode.inc.pl' + or Alert('Table data could not be read', $@ || $!); + + $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} = do 'charset-ucplanes.inc.pl' + or Alert('Table data could not be read', $@ || $!); + $row->{endpoint} ||= 0x3FF; + $row->{set} = 'Unicode planes'; + return $row; + }}, + 'utf-8' => 'utf8', + utf8 => {setup => sub { + my $row = shift; + $row->{set} = 'UTF-8'; + $row->{cell} = do 'charset-utf8.inc.pl' + or Alert('Table data could not be read', $@ || $!); + $row->{endpoint} = 0xFF; + return $row; + }}, }; diff --git a/charset.plp b/charset.plp index 4f60765..ed495fe 100644 --- a/charset.plp +++ b/charset.plp @@ -143,50 +143,12 @@ sub tabinput { } } - if ($input =~ m{ \A (?:wing|web)dings \d* \z }ix) { - eval "require Encode::\u$input"; + if ($charset->{setup}) { + eval { $charset->{setup}->(\%row) } + or Alert("Incomplete setup of $input", $@); } - if ($input eq '') { - $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 } $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; - } - } - elsif (lc $input eq 'uu') { - $row{cell} = do 'charset-ucplanes.inc.pl' - or Alert('Table data could not be read', $@ || $!); - $row{endpoint} ||= 0x3FF; - $row{set} = 'Unicode planes'; - } - elsif (lc $input eq 'u') { - $row{cell} = do 'charset-unicode.inc.pl' - or Alert('Table data could not be read', $@ || $!); - - $row{endpoint} ||= 0x1FFF; - $row{set} = 'Unicode ' . ( - $row{startpoint} < 0x1000 && $row{endpoint} < 0x1000 ? 'BMP' : - $row{startpoint} >= 0x1000 && $row{endpoint} < 0x2000 ? '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} = 0xFF; - } + if ($row{set}) {} elsif ($row{set} = Encode::resolve_alias($input)) { $row{offset} = delete $row{startpoint}; $row{endpoint} ||= 0xFF;