Skip to content

Commit 28e598f

Browse files
author
gitlost
committed
Improve comments in Normalizer.php, tabs -> 4 spaces, UNFC_REGEX_IS_INVALID_UTF8_XXX invert & rename.
1 parent 5fbc25f commit 28e598f

File tree

7 files changed

+128
-123
lines changed

7 files changed

+128
-123
lines changed

Symfony/Normalizer.php

Lines changed: 100 additions & 96 deletions
Large diffs are not rendered by default.

includes/class-unfc-normalize.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ function __construct() {
215215
static function activation_check() {
216216
if ( ! self::compatible_version() ) {
217217
deactivate_plugins( self::$plugin_basename );
218-
/* translators: %s: url to admin plugins page. */
219218
wp_die( sprintf(
219+
/* translators: %s: url to admin plugins page. */
220220
__( 'The plugin "UNFC Normalize" is not compatible with your system and can\'t be activated. <a href="%s">Return to Plugins page.</a>', 'unfc-normalize' ),
221221
esc_url( self_admin_url( 'plugins.php' ) )
222222
) );

languages/unfc-normalize-fr_FR.po

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ msgid ""
44
msgstr ""
55
"Project-Id-Version: UNFC Nörmalize 1.0.2\n"
66
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/unfc-normalize\n"
7-
"POT-Creation-Date: 2016-08-24 18:28+0100\n"
8-
"PO-Revision-Date: 2016-08-24 18:28+0100\n"
7+
"POT-Creation-Date: 2016-09-01 20:01+0100\n"
8+
"PO-Revision-Date: 2016-09-01 20:02+0100\n"
99
"Last-Translator: gitlost <[email protected]>\n"
1010
"Language-Team: \n"
1111
"Language: fr_FR\n"
@@ -508,7 +508,7 @@ msgstr[1] "%s identifiants n&rsquo;ont pas normalisé, échoué à normaliser."
508508

509509
#. translators: %s: file name
510510
#: tools/gen_combining_class.php:36 tools/gen_unfc_ins.php:132
511-
#: tools/gen_unfc_regex_alts.php:135
511+
#: tools/gen_unfc_regex_alts.php:137
512512
msgid "Could not read derived combining class file \"%s\""
513513
msgstr ""
514514
"Impossible de lire le fichier dérivé de classe combinante &laquo;&nbsp;"
@@ -522,14 +522,14 @@ msgstr ""
522522
"Impossible de lire le fichier de données unicode &laquo;&nbsp;%s&nbsp;&raquo;"
523523

524524
#. translators: %s: file name
525-
#: tools/gen_unfc_ins.php:33 tools/gen_unfc_regex_alts.php:31
525+
#: tools/gen_unfc_ins.php:33 tools/gen_unfc_regex_alts.php:33
526526
msgid "Could not read UCD derived normalization properties file \"%s\""
527527
msgstr ""
528528
"Impossible de lire le fichier UCD dérivé de propriétés de normalisation "
529529
"&laquo;&nbsp;%s&nbsp;&raquo;"
530530

531531
#. translators: %s: file name
532-
#: tools/gen_unfc_ins.php:117 tools/gen_unfc_regex_alts.php:120
532+
#: tools/gen_unfc_ins.php:117 tools/gen_unfc_regex_alts.php:122
533533
msgid ""
534534
"Missing NO or MAYBE codepoints in UCD derived normalization properties file "
535535
"\"%s\""

languages/unfc-normalize.pot

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ msgstr[0] ""
471471
msgstr[1] ""
472472

473473
#: tools/gen_combining_class.php:36 tools/gen_unfc_ins.php:132
474-
#: tools/gen_unfc_regex_alts.php:135
474+
#: tools/gen_unfc_regex_alts.php:137
475475
#. translators: %s: file name
476476
msgid "Could not read derived combining class file \"%s\""
477477
msgstr ""
@@ -482,12 +482,12 @@ msgstr ""
482482
msgid "Could not read unicode data file \"%s\""
483483
msgstr ""
484484

485-
#: tools/gen_unfc_ins.php:33 tools/gen_unfc_regex_alts.php:31
485+
#: tools/gen_unfc_ins.php:33 tools/gen_unfc_regex_alts.php:33
486486
#. translators: %s: file name
487487
msgid "Could not read UCD derived normalization properties file \"%s\""
488488
msgstr ""
489489

490-
#: tools/gen_unfc_ins.php:117 tools/gen_unfc_regex_alts.php:120
490+
#: tools/gen_unfc_ins.php:117 tools/gen_unfc_regex_alts.php:122
491491
#. translators: %s: file name
492492
msgid ""
493493
"Missing NO or MAYBE codepoints in UCD derived normalization properties file "

perf/perf_is_valid_utf8.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function unfc_null( $str ) {
4848
error_log( "bad result valids [ $i ]" );
4949
return;
5050
}
51-
if ( ( 1 === preg_match( UNFC_REGEX_IS_VALID_UTF8, $str ) ) !== ( 1 !== preg_match( UNFC_REGEX_IS_INVALID_UTF8_SKIP, $str ) ) ) {
51+
if ( ( 1 === preg_match( UNFC_REGEX_IS_VALID_UTF8, $str ) ) !== ( 0 === preg_match( UNFC_REGEX_IS_INVALID_UTF8, $str ) ) ) {
5252
error_log( "bad match valids invalid2 [ $i ]" );
5353
error_log( "str=" . bin2hex( $str ) );
5454
return;
@@ -74,7 +74,7 @@ function unfc_null( $str ) {
7474
error_log( "bad result invalids [ $i ]" );
7575
return;
7676
}
77-
if ( ( 1 === preg_match( UNFC_REGEX_IS_VALID_UTF8, $str ) ) !== ( 1 !== preg_match( UNFC_REGEX_IS_INVALID_UTF8_SKIP, $str ) ) ) {
77+
if ( ( 1 === preg_match( UNFC_REGEX_IS_VALID_UTF8, $str ) ) !== ( 0 === preg_match( UNFC_REGEX_IS_INVALID_UTF8, $str ) ) ) {
7878
error_log( "bad match invalids invalid2 [ $i ]" );
7979
error_log( "str=" . bin2hex( $str ) );
8080
return;
@@ -128,12 +128,12 @@ function unfc_null( $str ) {
128128
error_log( "str=" . bin2hex( $str ) );
129129
return;
130130
}
131-
if ( ( 1 === preg_match( UNFC_REGEX_IS_VALID_UTF8, $str ) ) !== ( 1 !== preg_match( UNFC_REGEX_IS_INVALID_UTF8, $str ) ) ) {
131+
if ( ( 1 === preg_match( UNFC_REGEX_IS_VALID_UTF8, $str ) ) !== ( 0 === preg_match( UNFC_REGEX_IS_INVALID_UTF8_NOVERB, $str ) ) ) {
132132
error_log( "bad match invalid $idx [ $i ]" );
133133
error_log( "str=" . bin2hex( $str ) );
134134
return;
135135
}
136-
if ( ( 1 === preg_match( UNFC_REGEX_IS_VALID_UTF8, $str ) ) !== ( 1 !== preg_match( UNFC_REGEX_IS_INVALID_UTF8_SKIP, $str ) ) ) {
136+
if ( ( 1 === preg_match( UNFC_REGEX_IS_VALID_UTF8, $str ) ) !== ( 0 === preg_match( UNFC_REGEX_IS_INVALID_UTF8, $str ) ) ) {
137137
error_log( "bad match invalid2 $idx [ $i ]" );
138138
error_log( "str=" . bin2hex( $str ) );
139139
return;
@@ -174,11 +174,11 @@ function unfc_null( $str ) {
174174
$tots_h[ $idx ] += microtime( true );
175175

176176
$tots_i[ $idx ] += -microtime( true );
177-
1 !== preg_match( UNFC_REGEX_IS_INVALID_UTF8, $str );
177+
0 === preg_match( UNFC_REGEX_IS_INVALID_UTF8_NOVERB, $str );
178178
$tots_i[ $idx ] += microtime( true );
179179

180180
$tots_s[ $idx ] += -microtime( true );
181-
1 !== preg_match( UNFC_REGEX_IS_INVALID_UTF8_SKIP, $str );
181+
0 === preg_match( UNFC_REGEX_IS_INVALID_UTF8, $str );
182182
$tots_s[ $idx ] += microtime( true );
183183

184184
$tots_v[ $idx ] += -microtime( true );

tests/normalizerTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ static function wpSetUpBeforeClass() {
6666
// Enable if using intl built with icu less than 56.1
6767
self::$new_8_0_0_regex = '/' . implode( '|', array_map( __CLASS__.'::chr', self::$new_8_0_0 ) ) . '/';
6868
}
69-
// Always set for the mo as icu for Unicode 9.0.0 not yet released as of 15 Jul 2016.
69+
// Always set for the mo as icu for Unicode 9.0.0 not yet released as of September 2016.
7070
self::$new_9_0_0_regex = '/' . implode( '|', array_map( __CLASS__.'::chr', self::$new_9_0_0 ) ) . '/';
7171

72-
self::$pcre_version = substr( PCRE_VERSION, 0, strspn( PCRE_VERSION, '01234567890.-' ) );
72+
self::$pcre_version = substr( PCRE_VERSION, 0, strspn( PCRE_VERSION, '0123456789.' ) );
7373

7474
// Normalizer::isNormalized() returns an integer on HHVM and a boolean on PHP
7575
list( self::$true, self::$false ) = defined( 'HHVM_VERSION' ) ? array( 1, 0 ) : array( true, false );
@@ -341,7 +341,6 @@ function test_conformance_9_0_0() {
341341
$last9_c1s = array();
342342
$last_x = 0;
343343
$in_part1 = false;
344-
global $line_num;
345344
foreach ( $t as $line_num => $line ) {
346345
$line_num++;
347346
if ( '@Part' === substr( $line, 0, 5 ) ) {
@@ -486,9 +485,9 @@ function test_is_valid_utf8_true( $str ) {
486485
if ( version_compare( PHP_VERSION, '5.3.4', '>=' ) ) { // RFC 3629 compliant.
487486
$this->assertTrue( '' === $str || '' !== htmlspecialchars( $str, ENT_NOQUOTES, 'UTF-8' ) );
488487
}
489-
$this->assertTrue( 1 !== preg_match( UNFC_REGEX_IS_INVALID_UTF8, $str ) );
488+
$this->assertTrue( 0 === preg_match( UNFC_REGEX_IS_INVALID_UTF8_NOVERBS, $str ) );
490489
if ( version_compare( self::$pcre_version, '7.3', '>=' ) ) { // Verbs available.
491-
$this->assertTrue( 1 !== preg_match( UNFC_REGEX_IS_INVALID_UTF8_SKIP, $str ) );
490+
$this->assertTrue( 0 === preg_match( UNFC_REGEX_IS_INVALID_UTF8, $str ) );
492491
}
493492
}
494493

@@ -526,9 +525,9 @@ function test_is_valid_utf8_false( $str ) {
526525
if ( version_compare( PHP_VERSION, '5.3.4', '>=' ) ) { // RFC 3629 compliant.
527526
$this->assertFalse( '' === $str || '' !== htmlspecialchars( $str, ENT_NOQUOTES, 'UTF-8' ) );
528527
}
529-
$this->assertFalse( 1 !== preg_match( UNFC_REGEX_IS_INVALID_UTF8, $str ) );
528+
$this->assertFalse( 0 === preg_match( UNFC_REGEX_IS_INVALID_UTF8_NOVERBS, $str ) );
530529
if ( version_compare( self::$pcre_version, '7.3', '>=' ) ) { // Verbs available.
531-
$this->assertFalse( 1 !== preg_match( UNFC_REGEX_IS_INVALID_UTF8_SKIP, $str ) );
530+
$this->assertFalse( 0 === preg_match( UNFC_REGEX_IS_INVALID_UTF8, $str ) );
532531
}
533532
}
534533

@@ -569,7 +568,7 @@ function test_is_valid_utf8_false_random() {
569568
if ( version_compare( PHP_VERSION, '5.3.4', '>=' ) ) { // RFC 3629 compliant.
570569
$this->assertFalse( '' === $str || '' !== htmlspecialchars( $str, ENT_NOQUOTES, 'UTF-8' ) );
571570
}
572-
$this->assertFalse( 1 !== preg_match( UNFC_REGEX_IS_INVALID_UTF8, $str ) );
571+
$this->assertFalse( 0 === preg_match( UNFC_REGEX_IS_INVALID_UTF8, $str ) );
573572
}
574573
}
575574

tools/gen_unfc_regex_alts.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
require $dirname . '/functions.php';
1616

17+
$prefix = $argc && ! empty( $argv[1] ) ? $argv[1] : 'UNFC_';
18+
1719
if ( ! function_exists( '__' ) ) {
1820
function __( $str, $td ) { return $str; }
1921
}
@@ -219,8 +221,8 @@ function __( $str, $td ) { return $str; }
219221
foreach ( $out_idxs as $idx ) {
220222
$IDX = strtoupper( $idx );
221223
$out[] = '';
222-
$out[] = "define( 'UNFC_REGEX_ALTS_{$IDX}', '" . $regex_alts[ $idx ] . "' );";
223-
$out[] = "define( 'UNFC_REGEX_{$IDX}', '/' . UNFC_REGEX_ALTS_{$IDX} . '/' );";
224+
$out[] = "define( '{$prefix}REGEX_ALTS_{$IDX}', '" . $regex_alts[ $idx ] . "' );";
225+
$out[] = "define( '{$prefix}REGEX_{$IDX}', '/' . {$prefix}REGEX_ALTS_{$IDX} . '/' );";
224226
}
225227

226228
if ( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || ! empty( $_SERVER['UNFC_DEBUG'] ) ) { // Set via command line "UNFC_DEBUG=1 php __FILE__".
@@ -234,8 +236,8 @@ function __( $str, $td ) { return $str; }
234236

235237
$IDX = strtoupper( $idx );
236238
$out[] = '';
237-
$out[] = "\t" . "define( 'UNFC_REGEX_ALTS_{$IDX}_U', '" . $regex_alts . "' );";
238-
$out[] = "\t" . "define( 'UNFC_REGEX_{$IDX}_U', '/[' . UNFC_REGEX_ALTS_{$IDX}_U . ']/u' );";
239+
$out[] = "\t" . "define( '{$prefix}REGEX_ALTS_{$IDX}_U', '" . $regex_alts . "' );";
240+
$out[] = "\t" . "define( '{$prefix}REGEX_{$IDX}_U', '/[' . {$prefix}REGEX_ALTS_{$IDX}_U . ']/u' );";
239241

240242
$out[] = '';
241243
$out[] = "\t" . "global \$unfc_{$idx};";

0 commit comments

Comments
 (0)