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