| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
require_once __DIR__ . '/../Maintenance.php'; |
| 28 |
|
| 29 |
|
| 30 |
class GenerateUpperCharTable extends Maintenance { |
| 31 |
|
| 32 |
public function __construct() { |
| 33 |
parent::__construct(); |
| 34 |
$this->addDescription( 'Generates the lowercase => uppercase json table' ); |
| 35 |
$this->addOption( 'outfile', 'Output file', true, true, 'o' ); |
| 36 |
$this->addOption( 'titlecase', 'Use title case instead of upper case' ); |
| 37 |
} |
| 38 |
|
| 39 |
public function execute() { |
| 40 |
$outfile = $this->getOption( 'outfile', 'upperchar.json' ); |
| 41 |
$toUpperTable = []; |
| 42 |
$titlecase = $this->getOption( 'titlecase' ); |
| 43 |
for ( $i = 0; $i <= 0x10ffff; $i++ ) { |
| 44 |
|
| 45 |
if ( $i >= 0xd800 && $i <= 0xdfff ) { |
| 46 |
continue; |
| 47 |
} |
| 48 |
$char = UtfNormal\Utils::codepointToUtf8( $i ); |
| 49 |
if ( $titlecase ) { |
| 50 |
$upper = mb_convert_case( $char, MB_CASE_TITLE ); |
| 51 |
} else { |
| 52 |
$upper = mb_strtoupper( $char ); |
| 53 |
} |
| 54 |
$toUpperTable[$char] = $upper; |
| 55 |
} |
| 56 |
file_put_contents( $outfile, json_encode( $toUpperTable ) ); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
$maintClass = GenerateUpperCharTable::class; |
| 62 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 63 |
|