charset: split unicode includes from static encodings
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 23 May 2022 22:54:06 +0000 (00:54 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Thu, 2 Jun 2022 21:57:11 +0000 (23:57 +0200)
Code only in container charset.inc.pl include, with plp dependency for
common Data() to get most tables more quickly.

charset-encoding.inc.pl
charset.inc.pl [new file with mode: 0644]
charset.plp
common.inc.plp

index ab0eeda85f7665e7569f38deefb58cc38a7ded4d..8e748ed3f5e25cfe89e14c10098b075af0914f35 100644 (file)
@@ -333,56 +333,4 @@ use utf8;
                                ),
                ],
        },
-
-       ''             => {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 = do 'charset-unicode.inc.pl'
-                       or Alert('Table data could not be read', $@ || $!);
-               $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} = do 'charset-ucplanes.inc.pl'
-                       or Alert('Table data could not be read', $@ || $!);
-               $row->{endpoint} ||= 0x3FF;
-               $row->{set} = 'Unicode planes';
-               return $row;
-       }},
-       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', $@ || $!);
-               return $row;
-       }},
-       'utf-8'        => 'utf8',
 };
diff --git a/charset.inc.pl b/charset.inc.pl
new file mode 100644 (file)
index 0000000..020cb2d
--- /dev/null
@@ -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',
+};
index d1e8d4dade12ec1ac9f83f6616338ea1538ebb3d..33f02c7428db0d7cb08381e913e0068f8ca5a4d8 100644 (file)
@@ -16,7 +16,7 @@ Html({
        '],
        (stylesheet => [qw'light']) x !$mode,
        data => [qw(
-               charset-encoding.inc.pl
+               charset.inc.pl charset-encoding.inc.pl
                charset-unicode.inc.pl charset-ucplanes.inc.pl charset-utf8.inc.pl
        )],
 });
@@ -79,7 +79,7 @@ use Shiar_Sheet::FormatChar;
 my $glyphs = Shiar_Sheet::FormatChar->new;
 my @request;
 
-my $charsets = Data('charset-encoding');
+my $charsets = Data('charset');
 
 sub tabinput {
        # generate character table(s)
index afec9d11f2172bb2130301eaf7468422a86020a2..a1eb3e5e2a54ce24a0f7c9b110a6cdb5d5751b02 100644 (file)
@@ -103,7 +103,7 @@ sub Data {
        my ($filename) = @_;
        my @data = eval {
                open my $cache, '<:raw', "data/$filename.json"
-                       or return do "$filename.inc.pl"; # silent fallback to original code
+                       or return do "./$filename.inc.pl"; # silent fallback to original code
                require JSON;
                local $/; # slurp
                return JSON::decode_json(readline $cache);