2# Copyright (C) 2004 Brion Vibber <brion@pobox.com>
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
15# You should have received a copy of the GNU General Public License along
16# with this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28#define( 'PRETTY_UTF8', true );
30if( defined(
'PRETTY_UTF8' ) ) {
31 function pretty( $string ) {
32 return preg_replace_callback(
35 return sprintf(
"%02X", ord($hit[1]));
44 function pretty( $string ) {
45 return trim( preg_replace_callback(
56 dl(
'php_utfnormal.so' );
59require_once
'UtfNormalUtil.php';
60require_once
'UtfNormal.php';
62if( php_sapi_name() !=
'cli' ) {
63 die(
"Run me from the command line please.\n" );
66$in = fopen(
"NormalizationTest.txt",
"rt");
68 print "Couldn't open NormalizationTest.txt -- can't run tests.\n";
69 print "If necessary, manually download this file. It can be obtained at\n";
70 print "http://www.unicode.org/Public/UNIDATA/NormalizationTest.txt";
81while(
false !== ( $line = fgets(
$in ) ) ) {
83 if(
$data ===
'' )
continue;
85 if( preg_match(
'/@Part([\d])/',
$data, $matches ) ) {
86 if( $matches[1] > 0 ) {
89 print "Part {$matches[1]}: $comment";
93 $columns = array_map(
"hexSequenceToUtf8", explode(
";",
$data ) );
102 # print "FAILED: $comment";
110$in = fopen(
"UnicodeData.txt",
"rt" );
112 print "Can't open UnicodeData.txt for reading.\n";
113 print "If necessary, fetch this file from the internet:\n";
114 print "http://www.unicode.org/Public/UNIDATA/UnicodeData.txt\n";
118while(
false !== ($line = fgets(
$in ) ) ) {
119 $cols = explode(
';', $line );
121 $desc = $cols[0] .
": " . $cols[1];
123 # Can't check NULL with the ICU plugin, as null bytes fail in C land.
124 # Skip other control characters, as we strip them for XML safety.
125 # Surrogates are illegal on their own or in UTF-8, ignore.
143 print "TEST SUCCEEDED!\n";
146 print "TEST FAILED!\n";
156 print "$success tests successful ($percSucc%)\n";
157 print "$failure tests failed ($percFail%)\n\n";
181 #$result = ($a === $b);
182 $result = (strcmp( $a, $b ) == 0);
188 print " $ok $form c$col '$aa' $eq '$bb'\n";
if(php_sapi_name() !='cli') $in
testNFC(&$u, $c, $comment, $verbose)
testNormals(&$u, $c, $comment, $reportFailure=false)
testCleanUp(&$u, $c, $comment, $verbose)
testNFKC(&$u, $c, $comment, $verbose)
testNFD(&$u, $c, $comment, $verbose)
testNFKD(&$u, $c, $comment, $verbose)
verbosify( $a, $b, $col, $form, $verbose)
testInvariant(&$u, $char, $desc, $reportFailure=false)
reportResults(&$total, &$success, &$failure)
utf8ToCodepoint( $char)
Determine the Unicode codepoint of a single-character UTF-8 sequence.
codepointToUtf8( $codepoint)
Return UTF-8 sequence for a given Unicode code point.
const UTF8_SURROGATE_FIRST
const UTF8_SURROGATE_LAST
Unicode normalization routines for working with UTF-8 strings.
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']