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 972e312..cd2040d 100644 (file)
@@ -41,19 +41,6 @@ my $cc = do 'countries.inc.pl';
                        }
                        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',
index 0eaf880..d9b938a 100755 (executable)
@@ -11,6 +11,23 @@ while (<>) {
        $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 = '';