Skip to content

Commit

Permalink
detect and warn when the user asks for short names for multiple
Browse files Browse the repository at this point in the history
charsets which have letters with the same name
  • Loading branch information
DrHyde authored and khwilliamson committed Feb 13, 2022
1 parent 1050ad2 commit dc406f9
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/_charnames.pm
Expand Up @@ -653,6 +653,8 @@ sub import
{
shift; ## ignore class name

populate_txt() unless $txt;

if (not @_) {
carp("'use charnames' needs explicit imports list");
}
Expand Down Expand Up @@ -711,8 +713,6 @@ sub import
## see if at least we can find one letter from each script.
##
if (warnings::enabled('utf8') && @scripts) {
populate_txt() unless $txt;

for my $script (@scripts) {
if (not $txt =~ m/^$script (?:CAPITAL |SMALL )?LETTER /m) {
warnings::warn('utf8', "No such script: '$script'");
Expand Down Expand Up @@ -740,6 +740,23 @@ sub import
}
}

my %letters_by_script = map {
$_ => [
($txt =~ m/$_(?: (?:small|capital))? letter (.*)/ig)
]
} @scripts;
SCRIPTS: foreach my $this_script (@scripts) {
my @other_scripts = grep { $_ ne $this_script } @scripts;
my @this_script_letters = @{$letters_by_script{$this_script}};
my @other_script_letters = map { @{$letters_by_script{$_}} } @other_scripts;
foreach my $this_letter (@this_script_letters) {
if(grep { $_ eq $this_letter } @other_script_letters) {
warn "charnames: some short character names may clash in [".join(', ', sort @scripts)."], for example $this_letter\n";
last SCRIPTS;
}
}
}

$^H{charnames_scripts} = join "|", @scripts; # Stringifiy them as a trie
} # import

Expand Down

0 comments on commit dc406f9

Please sign in to comment.