MediaWiki master
generateUpperCharTable.php
Go to the documentation of this file.
1<?php
27
28// @codeCoverageIgnoreStart
29require_once __DIR__ . '/../Maintenance.php';
30// @codeCoverageIgnoreEnd
31
33
34 public function __construct() {
35 parent::__construct();
36 $this->addDescription( 'Generates the lowercase => uppercase json table' );
37 $this->addOption( 'outfile', 'Output file', true, true, 'o' );
38 $this->addOption( 'titlecase', 'Use title case instead of upper case' );
39 }
40
41 public function execute() {
42 $outfile = $this->getOption( 'outfile', 'upperchar.json' );
43 $toUpperTable = [];
44 $titlecase = $this->getOption( 'titlecase' );
45 for ( $i = 0; $i <= 0x10ffff; $i++ ) {
46 // skip all surrogate codepoints or json_encode would fail.
47 if ( $i >= 0xd800 && $i <= 0xdfff ) {
48 continue;
49 }
50 $char = UtfNormal\Utils::codepointToUtf8( $i );
51 if ( $titlecase ) {
52 $upper = mb_convert_case( $char, MB_CASE_TITLE );
53 } else {
54 $upper = mb_strtoupper( $char );
55 }
56 $toUpperTable[$char] = $upper;
57 }
58 file_put_contents( $outfile, json_encode( $toUpperTable ) );
59 }
60}
61
62// @codeCoverageIgnoreStart
63$maintClass = GenerateUpperCharTable::class;
64require_once RUN_MAINTENANCE_IF_MAIN;
65// @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.