X-Git-Url: https://git.cyclocoop.org/%242?a=blobdiff_plain;f=includes%2Fnormal%2FUtfNormalTest.php;h=6d0dce258c5ea9f1c94b8f7cce903f37d6da9760;hb=c771fc9c96aacb44b86ade5ecca68334c5d8213f;hp=6aea3a40d5c7d46958734bdb65ebc19d09c233a5;hpb=5cf94de93f8ddc65c565002189f52eeca8fa9e56;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/normal/UtfNormalTest.php b/includes/normal/UtfNormalTest.php index 6aea3a40d5..6d0dce258c 100644 --- a/includes/normal/UtfNormalTest.php +++ b/includes/normal/UtfNormalTest.php @@ -1,26 +1,26 @@ # http://www.mediawiki.org/ -# +# # 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 +# 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., -# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # http://www.gnu.org/copyleft/gpl.html /** * Implements the conformance test at: * http://www.unicode.org/Public/UNIDATA/NormalizationTest.txt - * @package UtfNormal + * @addtogroup UtfNormal */ /** */ @@ -32,7 +32,7 @@ if( defined( 'PRETTY_UTF8' ) ) { return preg_replace( '/([\x00-\xff])/e', 'sprintf("%02X", ord("$1"))', $string ); - } + } } else { /** * @ignore @@ -41,7 +41,7 @@ if( defined( 'PRETTY_UTF8' ) ) { return trim( preg_replace( '/(.)/use', 'sprintf("%04X ", utf8ToCodepoint("$1"))', $string ) ); - } + } } if( isset( $_SERVER['argv'] ) && in_array( '--icu', $_SERVER['argv'] ) ) { @@ -73,6 +73,7 @@ $testedChars = array(); while( false !== ( $line = fgets( $in ) ) ) { list( $data, $comment ) = explode( '#', $line ); if( $data === '' ) continue; + $matches = array(); if( preg_match( '/@Part([\d])/', $data, $matches ) ) { if( $matches[1] > 0 ) { $ok = reportResults( $total, $success, $failure ) && $ok; @@ -80,10 +81,10 @@ while( false !== ( $line = fgets( $in ) ) ) { print "Part {$matches[1]}: $comment"; continue; } - + $columns = array_map( "hexSequenceToUtf8", explode( ";", $data ) ); array_unshift( $columns, '' ); - + $testedChars[$columns[1]] = true; $total++; if( testNormals( $normalizer, $columns, $comment ) ) { @@ -110,8 +111,9 @@ while( false !== ($line = fgets( $in ) ) ) { $cols = explode( ';', $line ); $char = codepointToUtf8( hexdec( $cols[0] ) ); $desc = $cols[0] . ": " . $cols[1]; - if( $char === "\x00" || $char >= UTF8_SURROGATE_FIRST && $char <= UTF8_SURROGATE_LAST ) { + if( $char < "\x20" || $char >= UTF8_SURROGATE_FIRST && $char <= UTF8_SURROGATE_LAST ) { # Can't check NULL with the ICU plugin, as null bytes fail in C land. + # Skip other control characters, as we strip them for XML safety. # Surrogates are illegal on their own or in UTF-8, ignore. continue; } @@ -140,8 +142,8 @@ if( $ok ) { ## ------ function reportResults( &$total, &$success, &$failure ) { - $percSucc = IntVal( $success * 100 / $total ); - $percFail = IntVal( $failure * 100 / $total ); + $percSucc = intval( $success * 100 / $total ); + $percFail = intval( $failure * 100 / $total ); print "\n"; print "$success tests successful ($percSucc%)\n"; print "$failure tests failed ($percFail%)\n\n"; @@ -158,7 +160,7 @@ function testNormals( &$u, $c, $comment, $reportFailure = false ) { $result = testNFKC( $u, $c, $comment, $reportFailure ) && $result; $result = testNFKD( $u, $c, $comment, $reportFailure ) && $result; $result = testCleanUp( $u, $c, $comment, $reportFailure ) && $result; - + global $verbose; if( $verbose && !$result && !$reportFailure ) { print $comment; @@ -235,7 +237,6 @@ function testInvariant( &$u, $char, $desc, $reportFailure = false ) { $result = verbosify( $char, $u->toNFD( $char ), 1, 'NFD', $reportFailure ) && $result; $result = verbosify( $char, $u->toNFKC( $char ), 1, 'NFKC', $reportFailure ) && $result; $result = verbosify( $char, $u->toNFKD( $char ), 1, 'NFKD', $reportFailure ) && $result; - $c = $char; $result = verbosify( $char, $u->cleanUp( $char ), 1, 'cleanUp', $reportFailure ) && $result; global $verbose; if( $verbose && !$result && !$reportFailure ) {