2011-01-17 14:02:22 +00:00
|
|
|
<?php
|
2012-02-08 16:55:54 +00:00
|
|
|
/**
|
2012-06-14 12:25:13 +00:00
|
|
|
* Maintenance script to generate first letter data files for Collation.php.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2012-02-08 16:55:54 +00:00
|
|
|
* @file
|
2012-09-07 20:03:56 +00:00
|
|
|
* @ingroup MaintenanceLanguage
|
2012-02-08 16:55:54 +00:00
|
|
|
*/
|
2011-01-17 14:02:22 +00:00
|
|
|
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/../Maintenance.php';
|
2011-01-17 14:02:22 +00:00
|
|
|
|
2019-04-11 15:31:11 +00:00
|
|
|
use Wikimedia\StaticArrayWriter;
|
|
|
|
|
|
2011-01-17 14:02:22 +00:00
|
|
|
/**
|
|
|
|
|
* Generate first letter data files for Collation.php
|
2012-09-07 20:03:56 +00:00
|
|
|
*
|
|
|
|
|
* @ingroup MaintenanceLanguage
|
2011-01-17 14:02:22 +00:00
|
|
|
*/
|
|
|
|
|
class GenerateCollationData extends Maintenance {
|
|
|
|
|
/** The directory with source data files in it */
|
2012-09-14 18:57:14 +00:00
|
|
|
public $dataDir;
|
2011-01-17 14:02:22 +00:00
|
|
|
|
|
|
|
|
/** The primary weights, indexed by codepoint */
|
2012-09-14 18:57:14 +00:00
|
|
|
public $weights;
|
2011-01-17 14:02:22 +00:00
|
|
|
|
2011-10-18 17:30:36 +00:00
|
|
|
/**
|
2011-01-17 14:02:22 +00:00
|
|
|
* A hashtable keyed by codepoint, where presence indicates that a character
|
|
|
|
|
* has a decomposition mapping. This makes it non-preferred for group header
|
|
|
|
|
* selection.
|
|
|
|
|
*/
|
2012-09-14 18:57:14 +00:00
|
|
|
public $mappedChars;
|
2011-01-17 14:02:22 +00:00
|
|
|
|
2012-09-14 18:57:14 +00:00
|
|
|
public $debugOutFile;
|
2011-01-17 14:02:22 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Important tertiary weights from UTS #10 section 7.2
|
|
|
|
|
*/
|
|
|
|
|
const NORMAL_UPPERCASE = 0x08;
|
2014-09-16 18:51:07 +00:00
|
|
|
const NORMAL_HIRAGANA = 0x0E;
|
2011-01-17 14:02:22 +00:00
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
|
|
|
|
$this->addOption( 'data-dir', 'A directory on the local filesystem ' .
|
2011-10-18 17:30:36 +00:00
|
|
|
'containing allkeys.txt and ucd.all.grouped.xml from unicode.org',
|
2011-01-17 14:02:22 +00:00
|
|
|
false, true );
|
|
|
|
|
$this->addOption( 'debug-output', 'Filename for sending debug output to',
|
|
|
|
|
false, true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
|
$this->dataDir = $this->getOption( 'data-dir', '.' );
|
2013-01-18 21:36:32 +00:00
|
|
|
|
|
|
|
|
$allkeysPresent = file_exists( "{$this->dataDir}/allkeys.txt" );
|
|
|
|
|
$ucdallPresent = file_exists( "{$this->dataDir}/ucd.all.grouped.xml" );
|
|
|
|
|
|
|
|
|
|
// As of January 2013, these links work for all versions of Unicode
|
|
|
|
|
// between 5.1 and 6.2, inclusive.
|
2017-12-02 20:38:29 +00:00
|
|
|
$allkeysURL = "https://www.unicode.org/Public/UCA/<Unicode version>/allkeys.txt";
|
|
|
|
|
$ucdallURL = "https://www.unicode.org/Public/<Unicode version>/ucdxml/ucd.all.grouped.zip";
|
2013-01-18 21:36:32 +00:00
|
|
|
|
|
|
|
|
if ( !$allkeysPresent || !$ucdallPresent ) {
|
2018-05-25 00:01:02 +00:00
|
|
|
$icuVersion = INTL_ICU_VERSION;
|
2013-02-09 15:20:06 +00:00
|
|
|
$unicodeVersion = IcuCollation::getUnicodeVersionForICU();
|
2013-01-18 21:36:32 +00:00
|
|
|
|
|
|
|
|
$error = "";
|
|
|
|
|
|
|
|
|
|
if ( !$allkeysPresent ) {
|
|
|
|
|
$error .= "Unable to find allkeys.txt. "
|
|
|
|
|
. "Download it and specify its location with --data-dir=<DIR>. "
|
|
|
|
|
. "\n\n";
|
|
|
|
|
}
|
|
|
|
|
if ( !$ucdallPresent ) {
|
2013-02-10 22:53:39 +00:00
|
|
|
$error .= "Unable to find ucd.all.grouped.xml. "
|
2013-01-18 21:36:32 +00:00
|
|
|
. "Download it, unzip, and specify its location with --data-dir=<DIR>. "
|
|
|
|
|
. "\n\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$versionKnown = false;
|
2018-05-25 00:01:02 +00:00
|
|
|
if ( version_compare( $icuVersion, "4.0", "<" ) ) {
|
2013-01-18 21:36:32 +00:00
|
|
|
// Extra old version
|
|
|
|
|
$error .= "You are using outdated version of ICU ($icuVersion), intended for "
|
|
|
|
|
. ( $unicodeVersion ? "Unicode $unicodeVersion" : "an unknown version of Unicode" )
|
|
|
|
|
. "; this file might not be avalaible for it, and it's not supported by MediaWiki. "
|
2013-04-13 11:36:24 +00:00
|
|
|
. " You are on your own; consider upgrading PHP's intl extension or try "
|
2013-01-18 21:36:32 +00:00
|
|
|
. "one of the files available at:";
|
|
|
|
|
} elseif ( version_compare( $icuVersion, "51.0", ">=" ) ) {
|
|
|
|
|
// Extra recent version
|
|
|
|
|
$error .= "You are using ICU $icuVersion, released after this script was last updated. "
|
|
|
|
|
. "Check what is the Unicode version it is using at http://site.icu-project.org/download . "
|
|
|
|
|
. "It can't be guaranteed everything will work, but appropriate file(s) should "
|
|
|
|
|
. "be available at:";
|
|
|
|
|
} else {
|
|
|
|
|
// ICU 4.0 to 50.x
|
|
|
|
|
$versionKnown = true;
|
|
|
|
|
$error .= "You are using ICU $icuVersion, intended for "
|
|
|
|
|
. ( $unicodeVersion ? "Unicode $unicodeVersion" : "an unknown version of Unicode" )
|
|
|
|
|
. ". Appropriate file(s) should be available at:";
|
|
|
|
|
}
|
|
|
|
|
$error .= "\n";
|
|
|
|
|
|
|
|
|
|
if ( $versionKnown && $unicodeVersion ) {
|
|
|
|
|
$allkeysURL = str_replace( "<Unicode version>", "$unicodeVersion.0", $allkeysURL );
|
|
|
|
|
$ucdallURL = str_replace( "<Unicode version>", "$unicodeVersion.0", $ucdallURL );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( !$allkeysPresent ) {
|
|
|
|
|
$error .= "* $allkeysURL\n";
|
|
|
|
|
}
|
|
|
|
|
if ( !$ucdallPresent ) {
|
|
|
|
|
$error .= "* $ucdallURL\n";
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( $error );
|
2011-01-17 14:02:22 +00:00
|
|
|
}
|
2013-01-18 21:36:32 +00:00
|
|
|
|
2011-01-17 14:02:22 +00:00
|
|
|
$debugOutFileName = $this->getOption( 'debug-output' );
|
|
|
|
|
if ( $debugOutFileName ) {
|
|
|
|
|
$this->debugOutFile = fopen( $debugOutFileName, 'w' );
|
|
|
|
|
if ( !$this->debugOutFile ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "Unable to open debug output file for writing" );
|
2011-01-17 14:02:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this->loadUcd();
|
|
|
|
|
$this->generateFirstChars();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadUcd() {
|
|
|
|
|
$uxr = new UcdXmlReader( "{$this->dataDir}/ucd.all.grouped.xml" );
|
2016-02-17 09:09:32 +00:00
|
|
|
$uxr->readChars( [ $this, 'charCallback' ] );
|
2011-01-17 14:02:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function charCallback( $data ) {
|
2011-09-12 02:10:11 +00:00
|
|
|
// Skip non-printable characters,
|
|
|
|
|
// but do not skip a normal space (U+0020) since
|
|
|
|
|
// people like to use that as a fake no header symbol.
|
2011-01-17 14:02:22 +00:00
|
|
|
$category = substr( $data['gc'], 0, 1 );
|
2011-10-18 17:30:36 +00:00
|
|
|
if ( strpos( 'LNPS', $category ) === false
|
2013-11-11 14:37:52 +00:00
|
|
|
&& $data['cp'] !== '0020'
|
|
|
|
|
) {
|
2011-01-17 14:02:22 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$cp = hexdec( $data['cp'] );
|
|
|
|
|
|
|
|
|
|
// Skip the CJK ideograph blocks, as an optimisation measure.
|
|
|
|
|
// UCA doesn't sort them properly anyway, without tailoring.
|
|
|
|
|
if ( IcuCollation::isCjk( $cp ) ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-18 17:30:36 +00:00
|
|
|
// Skip the composed Hangul syllables, we will use the bare Jamo
|
2011-01-17 14:02:22 +00:00
|
|
|
// as first letters
|
|
|
|
|
if ( $data['block'] == 'Hangul Syllables' ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Calculate implicit weight per UTS #10 v6.0.0, sec 7.1.3
|
|
|
|
|
if ( $data['UIdeo'] === 'Y' ) {
|
|
|
|
|
if ( $data['block'] == 'CJK Unified Ideographs'
|
2013-11-11 14:37:52 +00:00
|
|
|
|| $data['block'] == 'CJK Compatibility Ideographs'
|
|
|
|
|
) {
|
2011-01-17 14:02:22 +00:00
|
|
|
$base = 0xFB40;
|
|
|
|
|
} else {
|
|
|
|
|
$base = 0xFB80;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$base = 0xFBC0;
|
|
|
|
|
}
|
|
|
|
|
$a = $base + ( $cp >> 15 );
|
|
|
|
|
$b = ( $cp & 0x7fff ) | 0x8000;
|
|
|
|
|
|
|
|
|
|
$this->weights[$cp] = sprintf( ".%04X.%04X", $a, $b );
|
|
|
|
|
|
|
|
|
|
if ( $data['dm'] !== '#' ) {
|
|
|
|
|
$this->mappedChars[$cp] = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $cp % 4096 == 0 ) {
|
|
|
|
|
print "{$data['cp']}\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function generateFirstChars() {
|
|
|
|
|
$file = fopen( "{$this->dataDir}/allkeys.txt", 'r' );
|
|
|
|
|
if ( !$file ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "Unable to open allkeys.txt" );
|
2011-01-17 14:02:22 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$goodTertiaryChars = [];
|
2011-01-17 14:02:22 +00:00
|
|
|
|
|
|
|
|
// For each character with an entry in allkeys.txt, overwrite the implicit
|
|
|
|
|
// entry in $this->weights that came from the UCD.
|
|
|
|
|
// Also gather a list of tertiary weights, for use in selecting the group header
|
2018-06-30 09:43:00 +00:00
|
|
|
while ( ( $line = fgets( $file ) ) !== false ) {
|
2011-01-17 14:02:22 +00:00
|
|
|
// We're only interested in single-character weights, pick them out with a regex
|
|
|
|
|
$line = trim( $line );
|
|
|
|
|
if ( !preg_match( '/^([0-9A-F]+)\s*;\s*([^#]*)/', $line, $m ) ) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$cp = hexdec( $m[1] );
|
|
|
|
|
$allWeights = trim( $m[2] );
|
|
|
|
|
$primary = '';
|
|
|
|
|
$tertiary = '';
|
|
|
|
|
|
|
|
|
|
if ( !isset( $this->weights[$cp] ) ) {
|
|
|
|
|
// Non-printable, ignore
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
foreach ( StringUtils::explode( '[', $allWeights ) as $weightStr ) {
|
|
|
|
|
preg_match_all( '/[*.]([0-9A-F]+)/', $weightStr, $m );
|
|
|
|
|
if ( !empty( $m[1] ) ) {
|
|
|
|
|
if ( $m[1][0] !== '0000' ) {
|
|
|
|
|
$primary .= '.' . $m[1][0];
|
|
|
|
|
}
|
|
|
|
|
if ( $m[1][2] !== '0000' ) {
|
|
|
|
|
$tertiary .= '.' . $m[1][2];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this->weights[$cp] = $primary;
|
|
|
|
|
if ( $tertiary === '.0008'
|
2013-11-11 14:37:52 +00:00
|
|
|
|| $tertiary === '.000E'
|
|
|
|
|
) {
|
2011-01-17 14:02:22 +00:00
|
|
|
$goodTertiaryChars[$cp] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fclose( $file );
|
|
|
|
|
|
|
|
|
|
// Identify groups of characters with the same primary weight
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->groups = [];
|
2011-01-17 14:02:22 +00:00
|
|
|
asort( $this->weights, SORT_STRING );
|
|
|
|
|
$prevWeight = reset( $this->weights );
|
2016-02-17 09:09:32 +00:00
|
|
|
$group = [];
|
2011-01-17 14:02:22 +00:00
|
|
|
foreach ( $this->weights as $cp => $weight ) {
|
|
|
|
|
if ( $weight !== $prevWeight ) {
|
|
|
|
|
$this->groups[$prevWeight] = $group;
|
|
|
|
|
$prevWeight = $weight;
|
2018-10-27 12:30:02 +00:00
|
|
|
$group = $this->groups[$weight] ?? [];
|
2011-01-17 14:02:22 +00:00
|
|
|
}
|
|
|
|
|
$group[] = $cp;
|
|
|
|
|
}
|
|
|
|
|
if ( $group ) {
|
|
|
|
|
$this->groups[$prevWeight] = $group;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If one character has a given primary weight sequence, and a second
|
2011-10-18 17:30:36 +00:00
|
|
|
// character has a longer primary weight sequence with an initial
|
|
|
|
|
// portion equal to the first character, then remove the second
|
2011-01-17 14:02:22 +00:00
|
|
|
// character. This avoids having characters like U+A732 (double A)
|
2018-10-05 16:37:53 +00:00
|
|
|
// polluting the basic Latin sort area.
|
2011-03-30 19:00:11 +00:00
|
|
|
|
2011-01-17 14:02:22 +00:00
|
|
|
foreach ( $this->groups as $weight => $group ) {
|
|
|
|
|
if ( preg_match( '/(\.[0-9A-F]*)\./', $weight, $m ) ) {
|
|
|
|
|
if ( isset( $this->groups[$m[1]] ) ) {
|
|
|
|
|
unset( $this->groups[$weight] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ksort( $this->groups, SORT_STRING );
|
|
|
|
|
|
|
|
|
|
// Identify the header character in each group
|
2016-02-17 09:09:32 +00:00
|
|
|
$headerChars = [];
|
2011-01-17 14:02:22 +00:00
|
|
|
$prevChar = "\000";
|
|
|
|
|
$tertiaryCollator = new Collator( 'root' );
|
|
|
|
|
$primaryCollator = new Collator( 'root' );
|
|
|
|
|
$primaryCollator->setStrength( Collator::PRIMARY );
|
|
|
|
|
$numOutOfOrder = 0;
|
|
|
|
|
foreach ( $this->groups as $weight => $group ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$uncomposedChars = [];
|
|
|
|
|
$goodChars = [];
|
2011-01-17 14:02:22 +00:00
|
|
|
foreach ( $group as $cp ) {
|
|
|
|
|
if ( isset( $goodTertiaryChars[$cp] ) ) {
|
|
|
|
|
$goodChars[] = $cp;
|
|
|
|
|
}
|
|
|
|
|
if ( !isset( $this->mappedChars[$cp] ) ) {
|
|
|
|
|
$uncomposedChars[] = $cp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$x = array_intersect( $goodChars, $uncomposedChars );
|
|
|
|
|
if ( !$x ) {
|
|
|
|
|
$x = $uncomposedChars;
|
|
|
|
|
if ( !$x ) {
|
|
|
|
|
$x = $group;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Use ICU to pick the lowest sorting character in the selection
|
|
|
|
|
$tertiaryCollator->sort( $x );
|
|
|
|
|
$cp = $x[0];
|
|
|
|
|
|
2015-03-07 09:27:42 +00:00
|
|
|
$char = UtfNormal\Utils::codepointToUtf8( $cp );
|
2011-01-17 14:02:22 +00:00
|
|
|
$headerChars[] = $char;
|
|
|
|
|
if ( $primaryCollator->compare( $char, $prevChar ) <= 0 ) {
|
2013-11-11 14:37:52 +00:00
|
|
|
$numOutOfOrder++;
|
2011-01-17 14:02:22 +00:00
|
|
|
}
|
|
|
|
|
$prevChar = $char;
|
|
|
|
|
|
|
|
|
|
if ( $this->debugOutFile ) {
|
|
|
|
|
fwrite( $this->debugOutFile, sprintf( "%05X %s %s (%s)\n", $cp, $weight, $char,
|
2015-03-07 09:27:42 +00:00
|
|
|
implode( ' ', array_map( 'UtfNormal\Utils::codepointToUtf8', $group ) ) ) );
|
2011-01-17 14:02:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print "Out of order: $numOutOfOrder / " . count( $headerChars ) . "\n";
|
|
|
|
|
|
2018-07-20 03:23:50 +00:00
|
|
|
global $IP;
|
2018-08-18 05:31:36 +00:00
|
|
|
$writer = new StaticArrayWriter();
|
2018-07-20 03:23:50 +00:00
|
|
|
file_put_contents(
|
|
|
|
|
"$IP/includes/collation/data/first-letters-root.php",
|
2018-08-18 05:31:36 +00:00
|
|
|
$writer->create( $headerChars, 'File created by generateCollationData.php' )
|
2018-07-20 03:23:50 +00:00
|
|
|
);
|
|
|
|
|
echo "first-letters-root: file written.\n";
|
2011-01-17 14:02:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class UcdXmlReader {
|
2012-09-14 18:57:14 +00:00
|
|
|
public $fileName;
|
|
|
|
|
public $callback;
|
|
|
|
|
public $groupAttrs;
|
|
|
|
|
public $xml;
|
2016-02-17 09:09:32 +00:00
|
|
|
public $blocks = [];
|
2012-09-14 18:57:14 +00:00
|
|
|
public $currentBlock;
|
2011-01-17 14:02:22 +00:00
|
|
|
|
|
|
|
|
function __construct( $fileName ) {
|
|
|
|
|
$this->fileName = $fileName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function readChars( $callback ) {
|
|
|
|
|
$this->getBlocks();
|
|
|
|
|
$this->currentBlock = reset( $this->blocks );
|
|
|
|
|
$xml = $this->open();
|
|
|
|
|
$this->callback = $callback;
|
|
|
|
|
|
2014-07-19 21:12:10 +00:00
|
|
|
while ( $xml->name !== 'repertoire' && $xml->next() );
|
2011-01-17 14:02:22 +00:00
|
|
|
|
|
|
|
|
while ( $xml->read() ) {
|
|
|
|
|
if ( $xml->nodeType == XMLReader::ELEMENT ) {
|
|
|
|
|
if ( $xml->name === 'group' ) {
|
|
|
|
|
$this->groupAttrs = $this->readAttributes();
|
|
|
|
|
} elseif ( $xml->name === 'char' ) {
|
|
|
|
|
$this->handleChar();
|
|
|
|
|
}
|
|
|
|
|
} elseif ( $xml->nodeType === XMLReader::END_ELEMENT ) {
|
|
|
|
|
if ( $xml->name === 'group' ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->groupAttrs = [];
|
2011-01-17 14:02:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$xml->close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function open() {
|
|
|
|
|
$this->xml = new XMLReader;
|
|
|
|
|
$this->xml->open( $this->fileName );
|
|
|
|
|
if ( !$this->xml ) {
|
2013-04-13 11:36:24 +00:00
|
|
|
throw new MWException( __METHOD__ . ": unable to open {$this->fileName}" );
|
2011-01-17 14:02:22 +00:00
|
|
|
}
|
2014-07-19 21:12:10 +00:00
|
|
|
while ( $this->xml->name !== 'ucd' && $this->xml->read() );
|
2011-01-17 14:02:22 +00:00
|
|
|
$this->xml->read();
|
2013-11-11 14:37:52 +00:00
|
|
|
|
2011-01-17 14:02:22 +00:00
|
|
|
return $this->xml;
|
2011-10-18 17:30:36 +00:00
|
|
|
}
|
2011-01-17 14:02:22 +00:00
|
|
|
|
|
|
|
|
/**
|
2011-10-18 17:30:36 +00:00
|
|
|
* Read the attributes of the current element node and return them
|
2011-01-17 14:02:22 +00:00
|
|
|
* as an array
|
2011-10-18 17:30:36 +00:00
|
|
|
* @return array
|
2011-01-17 14:02:22 +00:00
|
|
|
*/
|
|
|
|
|
protected function readAttributes() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$attrs = [];
|
2011-01-17 14:02:22 +00:00
|
|
|
while ( $this->xml->moveToNextAttribute() ) {
|
|
|
|
|
$attrs[$this->xml->name] = $this->xml->value;
|
|
|
|
|
}
|
2013-11-11 14:37:52 +00:00
|
|
|
|
2011-01-17 14:02:22 +00:00
|
|
|
return $attrs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function handleChar() {
|
|
|
|
|
$attrs = $this->readAttributes() + $this->groupAttrs;
|
|
|
|
|
if ( isset( $attrs['cp'] ) ) {
|
|
|
|
|
$first = $last = hexdec( $attrs['cp'] );
|
|
|
|
|
} else {
|
|
|
|
|
$first = hexdec( $attrs['first-cp'] );
|
|
|
|
|
$last = hexdec( $attrs['last-cp'] );
|
|
|
|
|
unset( $attrs['first-cp'] );
|
|
|
|
|
unset( $attrs['last-cp'] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for ( $cp = $first; $cp <= $last; $cp++ ) {
|
|
|
|
|
$hexCp = sprintf( "%04X", $cp );
|
2016-02-17 09:09:32 +00:00
|
|
|
foreach ( [ 'na', 'na1' ] as $nameProp ) {
|
2011-01-17 14:02:22 +00:00
|
|
|
if ( isset( $attrs[$nameProp] ) ) {
|
|
|
|
|
$attrs[$nameProp] = str_replace( '#', $hexCp, $attrs[$nameProp] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while ( $this->currentBlock ) {
|
|
|
|
|
if ( $cp < $this->currentBlock[0] ) {
|
|
|
|
|
break;
|
|
|
|
|
} elseif ( $cp <= $this->currentBlock[1] ) {
|
|
|
|
|
$attrs['block'] = key( $this->blocks );
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
$this->currentBlock = next( $this->blocks );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$attrs['cp'] = $hexCp;
|
|
|
|
|
call_user_func( $this->callback, $attrs );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getBlocks() {
|
|
|
|
|
if ( $this->blocks ) {
|
|
|
|
|
return $this->blocks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$xml = $this->open();
|
2014-07-19 21:12:10 +00:00
|
|
|
while ( $xml->name !== 'blocks' && $xml->read() );
|
2011-01-17 14:02:22 +00:00
|
|
|
|
|
|
|
|
while ( $xml->read() ) {
|
|
|
|
|
if ( $xml->nodeType == XMLReader::ELEMENT ) {
|
|
|
|
|
if ( $xml->name === 'block' ) {
|
|
|
|
|
$attrs = $this->readAttributes();
|
|
|
|
|
$first = hexdec( $attrs['first-cp'] );
|
|
|
|
|
$last = hexdec( $attrs['last-cp'] );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->blocks[$attrs['name']] = [ $first, $last ];
|
2011-01-17 14:02:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$xml->close();
|
2013-11-11 14:37:52 +00:00
|
|
|
|
2011-01-17 14:02:22 +00:00
|
|
|
return $this->blocks;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = GenerateCollationData::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|