3 * This script generates Utf8Case.php from the Unicode Character Database
4 * and supplementary files.
6 * Copyright © 2004,2008 Brion Vibber <brion@pobox.com>
7 * http://www.mediawiki.org/
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
28 if( php_sapi_name() != 'cli' ) {
29 die( "Run me from the command line please.\n" );
32 require_once 'UtfNormalDefines.php';
33 require_once 'UtfNormalUtil.php';
35 $in = fopen("UnicodeData.txt", "rt" );
37 print "Can't open UnicodeData.txt for reading.\n";
38 print "If necessary, fetch this file from the internet:\n";
39 print "http://www.unicode.org/Public/UNIDATA/UnicodeData.txt\n";
42 $wikiUpperChars = array();
43 $wikiLowerChars = array();
45 print "Reading character definitions...\n";
46 while( false !== ($line = fgets( $in ) ) ) {
47 $columns = explode(';', $line);
48 $codepoint = $columns[0];
50 $simpleUpper = $columns[12];
51 $simpleLower = $columns[13];
53 $source = codepointToUtf8( hexdec( $codepoint ) );
55 $wikiUpperChars[$source] = codepointToUtf8( hexdec( $simpleUpper ) );
58 $wikiLowerChars[$source] = codepointToUtf8( hexdec( $simpleLower ) );
63 $out = fopen("Utf8Case.php", "wt");
65 $outUpperChars = escapeArray( $wikiUpperChars );
66 $outLowerChars = escapeArray( $wikiLowerChars );
67 $outdata = "<" . "?php
69 * Simple 1:1 upper/lowercase switching arrays for utf-8 text.
70 * Won't get context-sensitive things yet.
72 * Hack for bugs in ucfirst() and company
74 * These are pulled from memcached if possible, as this is faster than filling
75 * up a big array manually.
82 * Translation array to get upper case character
84 \$wikiUpperChars = $outUpperChars;
87 * Translation array to get lower case character
89 \$wikiLowerChars = $outLowerChars;\n";
90 fputs( $out, $outdata );
92 print "Wrote out Utf8Case.php\n";
94 print "Can't create file Utf8Case.php\n";
99 function escapeArray( $arr ) {
102 array_map( "escapeLine",
104 array_values( $arr ) ) ) .
108 function escapeLine( $key, $val ) {
109 $encKey = escapeSingleString( $key );
110 $encVal = escapeSingleString( $val );
111 return "\t'$encKey' => '$encVal'";