MediaWiki  master
generateUpperCharTable.php
Go to the documentation of this file.
1 <?php
26 require_once __DIR__ . '/../Maintenance.php';
27 
29 
30  public function __construct() {
31  parent::__construct();
32  $this->addDescription( 'Generates the lowercase => uppercase json table' );
33  $this->addOption( 'outfile', 'Output file', true, true, 'o' );
34  }
35 
36  public function execute() {
37  $outfile = $this->getOption( 'outfile', 'upperchar.json' );
38  $toUpperTable = [];
39  for ( $i = 0; $i <= 0x10ffff; $i++ ) {
40  // skip all surrogate codepoints or json_encode would fail.
41  if ( $i >= 0xd800 && $i <= 0xdfff ) {
42  continue;
43  }
44  $char = UtfNormal\Utils::codepointToUtf8( $i );
45  $upper = mb_strtoupper( $char );
46  $toUpperTable[$char] = $upper;
47  }
48  file_put_contents( $outfile, json_encode( $toUpperTable ) );
49  }
50 }
51 
52 $maintClass = GenerateUpperCharTable::class;
53 require_once RUN_MAINTENANCE_IF_MAIN;
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
getOption( $name, $default=null)
Get an option, or return the default.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:82
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.