From 722ab535a67d3193356b851e071cef6fdfa6c40b Mon Sep 17 00:00:00 2001 From: David M Date: Sat, 7 Oct 2006 22:51:55 +0000 Subject: Case folding! :D git-svn-id: file:///svn/phpbb/trunk@6464 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/develop/generate_utf_casefold.php | 147 ++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 phpBB/develop/generate_utf_casefold.php (limited to 'phpBB/develop/generate_utf_casefold.php') diff --git a/phpBB/develop/generate_utf_casefold.php b/phpBB/develop/generate_utf_casefold.php new file mode 100644 index 0000000000..2537c831c1 --- /dev/null +++ b/phpBB/develop/generate_utf_casefold.php @@ -0,0 +1,147 @@ + 0xFFFF) + { + return chr(0xF0 | ($cp >> 18)) . chr(0x80 | (($cp >> 12) & 0x3F)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F)); + } + else if ($cp > 0x7FF) + { + return chr(0xE0 | ($cp >> 12)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F)); + } + else if ($cp > 0x7F) + { + return chr(0xC0 | ($cp >> 6)) . chr(0x80 | ($cp & 0x3F)); + } + else + { + return chr($cp); + } +} + +preg_match_all('/^([0-9A-F]+); ([CFS]); ([0-9A-F]+(?: [0-9A-F]+)*);/im', $unidata, $array, PREG_SET_ORDER); + +$uniarray = array(); + +foreach ($array as $value) +{ + $uniarray[$value[2]][utf8_chr(hexdec((string)$value[1]))] = implode(array_map('utf8_chr', array_map('hexdec', explode(' ', $value[3])))); +} + +foreach ($uniarray as $idx => $contents) +{ + echo "Writing to case_fold_$idx.$phpEx\n"; + $fp = fopen($phpbb_root_path . 'includes/utf/data/case_fold_' . $idx . '.' . $phpEx, 'wb'); + fwrite($fp, ' $v) + { + $lines[] = my_var_export($k) . '=>' . my_var_export($v); + } + + return 'array(' . implode(',', $lines) . ')'; + } + elseif (is_string($var)) + { + return "'" . str_replace(array('\\', "'"), array('\\\\', "\\'"), $var) . "'"; + } + else + { + return $var; + } +} + +/** +* Download a file to the develop/ dir +* +* @param string $url URL of the file to download +* @return void +*/ +function download($url) +{ + global $phpbb_root_path; + + if (file_exists($phpbb_root_path . 'develop/' . basename($url))) + { + return; + } + + echo 'Downloading from ', $url, ' '; + + if (!$fpr = fopen($url, 'rb')) + { + die("Can't download from $url\nPlease download it yourself and put it in the develop/ dir, kthxbai"); + } + + if (!$fpw = fopen($phpbb_root_path . 'develop/' . basename($url), 'wb')) + { + die("Can't open develop/" . basename($url) . " for output... please check your permissions or something"); + } + + $i = 0; + $chunk = 32768; + $done = ''; + + while (!feof($fpr)) + { + $i += fwrite($fpw, fread($fpr, $chunk)); + echo str_repeat("\x08", strlen($done)); + + $done = ($i >> 10) . ' KiB'; + echo $done; + } + fclose($fpr); + fclose($fpw); + + echo "\n"; +} + +?> \ No newline at end of file -- cgit v1.2.1