#!/usr/bin/php
<?php
+/**
+ * Other tests for the unicode normalization module.
+ *
+ * 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
+ *
+ * @file
+ * @ingroup UtfNormal
+ */
if( php_sapi_name() != 'cli' ) {
die( "Run me from the command line please.\n" );
// From http://unicode.org/Public/UNIDATA/NormalizationTest.txt
$file = "NormalizationTest.txt";
-$sep = ';';
-$comment = "#";
+
+// Anything after this character is a comment
+define ( 'COMMENT', '#' );
+
+// Semicolons are used to separate the columns
+define ( 'SEPARATOR', ';' );
+
$f = fopen($file, "r");
/**
require_once("./UtfNormal.php");
function normalize_form_c($c) { return UtfNormal::toNFC($c); }
-function normalize_form_c_php($c) { return UtfNormal::toNFC($c, "php"); }
function normalize_form_d($c) { return UtfNormal::toNFD($c); }
-function normalize_form_d_php($c) { return UtfNormal::toNFD($c, "php"); }
function normalize_form_kc($c) { return UtfNormal::toNFKC($c); }
-function normalize_form_kc_php($c) { return UtfNormal::toNFKC($c, "php"); }
function normalize_form_kd($c) { return UtfNormal::toNFKD($c); }
+
+/**
+ * This set of functions is only useful if youve added a param to the
+ * following functions to force pure PHP usage. I decided not to
+ * commit that code since might produce a slowdown in the UTF
+ * normalization code just for the sake of these tests. -- hexmode
+ * @return string
+ */
+function normalize_form_c_php($c) { return UtfNormal::toNFC($c, "php"); }
+function normalize_form_d_php($c) { return UtfNormal::toNFD($c, "php"); }
+function normalize_form_kc_php($c) { return UtfNormal::toNFKC($c, "php"); }
function normalize_form_kd_php($c) { return UtfNormal::toNFKD($c, "php"); }
assert_options(ASSERT_ACTIVE, 1);
assert_options(ASSERT_CALLBACK, 'my_assert');
function my_assert( $file, $line, $code ) {
- global $col, $count, $lineNo;
+ global $col, $lineNo;
echo "Assertion that '$code' failed on line $lineNo ($col[5])\n";
}
function unichr($c) {
if ($c <= 0x7F) {
return chr($c);
- } else if ($c <= 0x7FF) {
+ } elseif ($c <= 0x7FF) {
return chr(0xC0 | $c >> 6) . chr(0x80 | $c & 0x3F);
- } else if ($c <= 0xFFFF) {
+ } elseif ($c <= 0xFFFF) {
return chr(0xE0 | $c >> 12) . chr(0x80 | $c >> 6 & 0x3F)
. chr(0x80 | $c & 0x3F);
- } else if ($c <= 0x10FFFF) {
+ } elseif ($c <= 0x10FFFF) {
return chr(0xF0 | $c >> 18) . chr(0x80 | $c >> 12 & 0x3F)
. chr(0x80 | $c >> 6 & 0x3F)
. chr(0x80 | $c & 0x3F);
}
function getRow( $f ) {
- global $comment, $sep;
-
$row = fgets( $f );
if( $row === false ) return false;
$row = rtrim($row);
- $pos = strpos( $row, $comment );
+ $pos = strpos( $row, COMMENT );
$pos2 = strpos( $row, ")" );
if( $pos === 0 ) return array($row);
$c = "";
}
$ret = array();
- foreach(explode( $sep, $row ) as $ent) {
- if(trim($ent) !== "") {
+ foreach( explode( SEPARATOR, $row ) as $ent ) {
+ if( trim( $ent ) !== "" ) {
$ret[] = unistr($ent);
}
}
$ret[] = $c;
return $ret;
-}
\ No newline at end of file
+}