countries: store abbreviations in include
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 1 Feb 2015 07:11:28 +0000 (08:11 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Sun, 1 Feb 2015 17:34:50 +0000 (18:34 +0100)
Static, so no reason to redo it every time.

countries.plp
tools/mkcountries-geonames

index 972e312ae15c32a66874fbbb4eb84a667f967c06..cd2040ded94690db700698b1e2c899ea13e369a2 100644 (file)
@@ -41,19 +41,6 @@ my $cc = do 'countries.inc.pl';
                        }
                        else {
                                $_ = $short || $name;
                        }
                        else {
                                $_ = $short || $name;
-                               s/,.*//;
-                               s/(?<=.)\(.*\)\s*//;
-                               s/ republic\b//gi;
-                               s/ islands?\b//gi;
-                               s/\bthe //g;
-                               s/ and / & /g and s/(?<=.)[a-z ]+//g;
-                               s/\bsaint /st /gi;
-                               s/South(?:ern)? /S-/g;
-                               s/North(?:ern)? /N-/g;
-                               s/New /n./g;
-                               s/(\S)(\S+)-/$1-/g;  # strip most chars preceding dash
-                               s/(\S{4}[b-df-hj-np-tv-xz])((?<!Austr)(?!land)\w{2,})/$1./g;  # abbreviate (at consonant)
-                               $_ = EscapeHTML($_);
                        }
                        $name =~ s/([^,]*), (.*)/$2 $1/;
                        printf "\n".'<td class="%s" title="%s">%s',
                        }
                        $name =~ s/([^,]*), (.*)/$2 $1/;
                        printf "\n".'<td class="%s" title="%s">%s',
index 0eaf88006fff31cac9cebf5805419d317a288af9..d9b938a03ce070c4a10df882ba21107f948eddf6 100755 (executable)
@@ -11,6 +11,23 @@ while (<>) {
        $cc{ lc $iso } = [ $name, $class ];
 }
 
        $cc{ lc $iso } = [ $name, $class ];
 }
 
+for (values %cc) {
+       for ($_->[2] //= $_->[0]) {
+               s/,.*//;
+               s/(?<=.)\(.*\)\s*//;
+               s/ republic\b//gi;
+               s/ islands?\b//gi;
+               s/\bthe //g;
+               s/ and / & /g and s/(?<=.)[a-z ]+//g;
+               s/\bsaint /st /gi;
+               s/South(?:ern)? /S-/g;
+               s/North(?:ern)? /N-/g;
+               s/New /n./g;
+               s/(\S)(\S+)-/$1-/g;  # strip most chars preceding dash
+               s/(\S{4}[b-df-hj-np-tv-xz])((?<!Austr)(?!land)\w{2,})/$1./g;  # abbreviate (at consonant)
+       }
+}
+
 say "# automatically generated by $0";
 use Data::Dump 'dd';
 $Data::Dump::INDENT = '';
 say "# automatically generated by $0";
 use Data::Dump 'dd';
 $Data::Dump::INDENT = '';