Fix the scripts to generate ucfirst overriddes
authorGiuseppe Lavagetto <glavagetto@wikimedia.org>
Thu, 18 Apr 2019 10:09:33 +0000 (12:09 +0200)
committerGiuseppe Lavagetto <glavagetto@wikimedia.org>
Thu, 18 Apr 2019 16:28:17 +0000 (18:28 +0200)
* Fix a couple mistakes in generateUcfirstOverrides.php
* Skip surrogate codepoints as they can't be converted to json.

Change-Id: I5eddd90f7b348806d502dfbac08c367701d17f25

maintenance/language/generateUcfirstOverrides.php
maintenance/language/generateUpperCharTable.php

index c1e93f4..458231c 100644 (file)
@@ -54,7 +54,7 @@ class GenerateUcfirstOverrides extends Maintenance {
                foreach ( $from as $lc => $uc ) {
                        $ref = $to[$lc] ?? null;
                        if ( $ref !== null && $ref !== $uc ) {
-                               $overrides[$lc] = $uc;
+                               $overrides[$lc] = $ref;
                        }
                }
                $writer = new StaticArrayWriter();
@@ -70,8 +70,8 @@ class GenerateUcfirstOverrides extends Maintenance {
                        $msg = sprintf( "Could not load data from file '%s'\n", $filename );
                        $this->fatalError( $msg );
                }
-               $json = json_decode( $data );
-               if ( $result === null ) {
+               $json = json_decode( $data, true );
+               if ( $json === null ) {
                        $msg = sprintf( "Invalid json in the data file %s\n", $filename );
                        $this->fatalError( $msg, 2 );
                }
index b03d704..c8393bf 100644 (file)
@@ -37,6 +37,10 @@ class GenerateUpperCharTable extends Maintenance {
                $outfile = $this->getOption( 'outfile', 'upperchar.json' );
                $toUpperTable = [];
                for ( $i = 0; $i <= 0x10ffff; $i++ ) {
+                       // skip all surrogate codepoints or json_encode would fail.
+                       if ( $i >= 0xd800 && $i <= 0xdfff ) {
+                               continue;
+                       }
                        $char = UtfNormal\Utils::codepointToUtf8( $i );
                        $upper = mb_strtoupper( $char );
                        $toUpperTable[$char] = $upper;