12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- use strict;
- use v5.10;
- use Unicode::UCD qw(charprop);
- AddModuleDescription('ban-mixed-scripts.pl', 'Ban Mixed Scripts Extension');
- *OldBanMixedScriptsBannedContent = \&BannedContent;
- *BannedContent = \&NewBanMixedScriptsBannedContent;
- sub NewBanMixedScriptsBannedContent {
- my $rule = OldBanMixedScriptsBannedContent(@_);
- $rule ||= BanMixedScript(@_);
- return $rule;
- }
- sub BanMixedScript {
- my $str = shift;
- my @words = $str =~ m/\w+/g;
- my %seen;
- my %prop;
- for my $word (@words) {
- next if $seen{$word};
- $seen{$word} = 1;
- my $script;
- for my $char (split(//, $word)) {
- my $s = $prop{$char};
- if (not $s) {
- $s = charprop(ord($char), "Script_Extensions");
- if ($s eq 'Hiragana') {
- $s = 'Han';
- }
- $prop{$char} = $s;
- }
- next if $s eq "Common";
- if (not $script) {
- $script = $s;
- } elsif ($script ne $s) {
- return "Mixed scripts in $word ($script and $s, if not more)";
- }
- }
- }
- }
|