From 03583f7a9116b79807c82218255c04e297437c2d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Mon, 8 Jan 2018 23:18:00 +0100 Subject: [PATCH] Use PHP 7 "\u{NNNN}" Unicode codepoint escapes in string literals (part 2) This is a follow-up to Idc3dee3a7fb5ebfaef395754d8859b18f1f8769a containing some less trivial changes. Change-Id: Ia7af2c1d000307d43278cde4a246df413d4ef263 --- includes/installer/Installer.php | 27 ++----------------- .../preferences/DefaultPreferencesFactory.php | 4 +-- .../rdbms/database/DatabaseMysqlBaseTest.php | 12 +++------ 3 files changed, 8 insertions(+), 35 deletions(-) diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 00bd4d0605..f5fd3f20e2 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -1107,29 +1107,6 @@ abstract class Installer { return true; } - /** - * Convert a hex string representing a Unicode code point to that code point. - * @param string $c - * @return string|false - */ - protected function unicodeChar( $c ) { - $c = hexdec( $c ); - if ( $c <= 0x7F ) { - return chr( $c ); - } elseif ( $c <= 0x7FF ) { - return chr( 0xC0 | $c >> 6 ) . chr( 0x80 | $c & 0x3F ); - } elseif ( $c <= 0xFFFF ) { - return chr( 0xE0 | $c >> 12 ) . chr( 0x80 | $c >> 6 & 0x3F ) . - chr( 0x80 | $c & 0x3F ); - } elseif ( $c <= 0x10FFFF ) { - return chr( 0xF0 | $c >> 18 ) . chr( 0x80 | $c >> 12 & 0x3F ) . - chr( 0x80 | $c >> 6 & 0x3F ) . - chr( 0x80 | $c & 0x3F ); - } else { - return false; - } - } - /** * Check the libicu version */ @@ -1141,8 +1118,8 @@ abstract class Installer { * Note that we use the hex representation to create the code * points in order to avoid any Unicode-destroying during transit. */ - $not_normal_c = $this->unicodeChar( "FA6C" ); - $normal_c = $this->unicodeChar( "242EE" ); + $not_normal_c = "\u{FA6C}"; + $normal_c = "\u{242EE}"; $useNormalizer = 'php'; $needsUpdate = false; diff --git a/includes/preferences/DefaultPreferencesFactory.php b/includes/preferences/DefaultPreferencesFactory.php index 0a9e9c864b..2b497f677f 100644 --- a/includes/preferences/DefaultPreferencesFactory.php +++ b/includes/preferences/DefaultPreferencesFactory.php @@ -1409,8 +1409,8 @@ class DefaultPreferencesFactory implements PreferencesFactory { $pixels = $l10n->msg( 'unit-pixel' )->text(); foreach ( $this->config->get( 'ImageLimits' ) as $index => $limits ) { - // Note: A left-to-right marker (\u200e) is inserted, see T144386 - $display = "{$limits[0]}" . json_decode( '"\u200e"' ) . "×{$limits[1]}" . $pixels; + // Note: A left-to-right marker (U+200E) is inserted, see T144386 + $display = "{$limits[0]}\u{200E}×{$limits[1]}$pixels"; $ret[$display] = $index; } diff --git a/tests/phpunit/includes/libs/rdbms/database/DatabaseMysqlBaseTest.php b/tests/phpunit/includes/libs/rdbms/database/DatabaseMysqlBaseTest.php index 93192d01fb..a86a1c9c49 100644 --- a/tests/phpunit/includes/libs/rdbms/database/DatabaseMysqlBaseTest.php +++ b/tests/phpunit/includes/libs/rdbms/database/DatabaseMysqlBaseTest.php @@ -79,12 +79,12 @@ class DatabaseMysqlBaseTest extends PHPUnit\Framework\TestCase { // unicode chars [ - self::createUnicodeString( '`\u0001a\uFFFFb`' ), - self::createUnicodeString( '\u0001a\uFFFFb' ) + "`\u{0001}a\u{FFFF}b`", + "\u{0001}a\u{FFFF}b" ], [ - self::createUnicodeString( '`\u0001\uFFFF`' ), - self::createUnicodeString( '\u0001\u0000\uFFFF\u0000' ) + "`\u{0001}\u{FFFF}`", + "\u{0001}\u{0000}\u{FFFF}\u{0000}" ], [ '`☃`', '☃' ], [ '`メインページ`', 'メインページ' ], @@ -97,10 +97,6 @@ class DatabaseMysqlBaseTest extends PHPUnit\Framework\TestCase { ]; } - private static function createUnicodeString( $str ) { - return json_decode( '"' . $str . '"' ); - } - private function getMockForViews() { $db = $this->getMockBuilder( DatabaseMysqli::class ) ->disableOriginalConstructor() -- 2.20.1