Skip to content

Commit

Permalink
Fix looking up characters by name on Perl 5.32
Browse files Browse the repository at this point in the history
The format changed in
Perl/perl5@b555069

Also switch to using `state $corpus = do …` instead of `my $corpus =
require …` so it doesn't error if called multiple times, but is still
only loaded once.
  • Loading branch information
ilmari committed Jul 2, 2020
1 parent 08858d7 commit 7a064a0
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions lib/App/Uni.pm
Original file line number Diff line number Diff line change
Expand Up @@ -224,28 +224,34 @@ sub chars_by_name {
}
}
my $corpus = require 'unicore/Name.pl';
die "somebody beat us here" if $corpus eq '1';
state $corpus = do 'unicore/Name.pl';
unless (defined $corpus) {
die "couldn't parse unicore/Name.pl: $@" if $@;
die "couldn't read unicore/Name.pl: $!" if $!;
die "unicore/Name.pl returned undef";
}
my @lines = split /\cJ/, $corpus;
# https://github.com/perl/perl5/commit/b555069b72f93a232deba173dc7bf7892cfa5868
my ($entry_sep, $field_sep) = "$]" >= 5.031010 ? ("\n\n", "\n") : ("\n", "\t");
my @entries = split $entry_sep, $corpus;
my @chars;
my %seen;
LINE: for my $line (@lines) {
my $i = index($line, "\t");
next if rindex($line, " ", $i) >= 0; # no sequences
ENTRY: for my $entry (@entries) {
my $i = index($entry, $field_sep);
next if rindex($entry, " ", $i) >= 0; # no sequences

my $name = substr($line, $i+1);
my $ord = hex substr($line, 0, $i);
my $name = substr($entry, $i+1);
my $ord = hex substr($entry, 0, $i);

for (@terms) {
next LINE unless $name =~ $_->{pattern}
or defined $_->{ord} && $_->{ord} == $ord;
next ENTRY unless $name =~ $_->{pattern}
or defined $_->{ord} && $_->{ord} == $ord;
}

my $c = chr hex substr $line, 0, $i;
my $c = chr hex substr $entry, 0, $i;
next if $seen{$c}++;
push @chars, chr hex substr $line, 0, $i;
push @chars, chr hex substr $entry, 0, $i;
}

return \@chars;
Expand Down

0 comments on commit 7a064a0

Please sign in to comment.