From 85055ac97fa57ca339924cef719115d85bdf6c2e Mon Sep 17 00:00:00 2001 From: David M Date: Thu, 3 Jan 2008 17:00:40 +0000 Subject: oh boy... - Migrate code base to PHP 5.1+ git-svn-id: file:///svn/phpbb/trunk@8295 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/develop/utf_normalizer_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/develop/utf_normalizer_test.php') diff --git a/phpBB/develop/utf_normalizer_test.php b/phpBB/develop/utf_normalizer_test.php index 7705cd6851..2ce74fe833 100644 --- a/phpBB/develop/utf_normalizer_test.php +++ b/phpBB/develop/utf_normalizer_test.php @@ -198,7 +198,7 @@ while (!feof($fp)) foreach (array('nfc', 'nfkc', 'nfd', 'nfkd') as $form) { $utf_result = $utf_expected; - utf_normalizer::$form($utf_result); + call_user_func(array('utf_normalizer', $form), $utf_result); $hex_result = utf_to_hexseq($utf_result); // echo "$form($utf_expected) == $utf_result\n"; -- cgit v1.2.1 From 2cfc6b7e0b567dca9bf361ad3a694ba071821c44 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 5 May 2008 00:14:46 +0000 Subject: fixing access to const members in the normalizer and the normalizer test git-svn-id: file:///svn/phpbb/trunk@8550 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/develop/utf_normalizer_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/develop/utf_normalizer_test.php') diff --git a/phpBB/develop/utf_normalizer_test.php b/phpBB/develop/utf_normalizer_test.php index 2ce74fe833..9c4ad7f5f3 100644 --- a/phpBB/develop/utf_normalizer_test.php +++ b/phpBB/develop/utf_normalizer_test.php @@ -20,7 +20,7 @@ if (php_sapi_name() != 'cli') // Remove or comment the next line (die(".... ) to enable this script. // Do NOT FORGET to either remove this script or disable it after you have used it. // -die("Please read the first lines of this script for instructions on how to enable it"); +//die("Please read the first lines of this script for instructions on how to enable it"); set_time_limit(0); error_reporting(E_ALL); @@ -184,14 +184,14 @@ while (!feof($fp)) $utf_expected = hex_to_utf($hex_expected); - if ($utf_expected >= UTF8_SURROGATE_FIRST - && $utf_expected <= UTF8_SURROGATE_LAST) + if ($utf_expected >= utf_normalizer::UTF8_SURROGATE_FIRST + && $utf_expected <= utf_normalizer::UTF8_SURROGATE_LAST) { /** * Surrogates are illegal on their own, we expect the normalizer * to return a replacement char */ - $utf_expected = UTF8_REPLACEMENT; + $utf_expected = utf_normalizer::UTF8_REPLACEMENT; $hex_expected = utf_to_hexseq($utf_expected); } -- cgit v1.2.1 From 9aac603888071d730f8f33bfdf51cfd0ff176c42 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 5 May 2008 00:17:12 +0000 Subject: :o don't allow access to that file for people who cannot add a comment git-svn-id: file:///svn/phpbb/trunk@8551 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/develop/utf_normalizer_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/develop/utf_normalizer_test.php') diff --git a/phpBB/develop/utf_normalizer_test.php b/phpBB/develop/utf_normalizer_test.php index 9c4ad7f5f3..cf381e58fa 100644 --- a/phpBB/develop/utf_normalizer_test.php +++ b/phpBB/develop/utf_normalizer_test.php @@ -20,7 +20,7 @@ if (php_sapi_name() != 'cli') // Remove or comment the next line (die(".... ) to enable this script. // Do NOT FORGET to either remove this script or disable it after you have used it. // -//die("Please read the first lines of this script for instructions on how to enable it"); +die("Please read the first lines of this script for instructions on how to enable it"); set_time_limit(0); error_reporting(E_ALL); -- cgit v1.2.1 From 2f4a618900e2c3b6ea14c68cbeb5897cd2ac1a04 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Thu, 29 May 2008 12:25:56 +0000 Subject: ok... i hope i haven't messed too much with the code and everything is still working. Changes: - Ascraeus now uses constants for the phpbb root path and the php extension. This ensures more security for external applications and modifications (no more overwriting of root path and extension possible through insecure mods and register globals enabled) as well as no more globalizing needed. - A second change implemented here is an additional short-hand-notation for append_sid(). It is allowed to omit the root path and extension now (for example calling append_sid('memberlist')) - in this case the root path and extension get added automatically. The hook is called after these are added. git-svn-id: file:///svn/phpbb/trunk@8572 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/develop/utf_normalizer_test.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'phpBB/develop/utf_normalizer_test.php') diff --git a/phpBB/develop/utf_normalizer_test.php b/phpBB/develop/utf_normalizer_test.php index cf381e58fa..8a7c31a1b0 100644 --- a/phpBB/develop/utf_normalizer_test.php +++ b/phpBB/develop/utf_normalizer_test.php @@ -26,8 +26,8 @@ set_time_limit(0); error_reporting(E_ALL); define('IN_PHPBB', true); -$phpbb_root_path = '../'; -$phpEx = substr(strrchr(__FILE__, '.'), 1); +define('PHPBB_ROOT_PATH', './../'); +define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1)); /** @@ -77,13 +77,13 @@ $test_suite = array( ) ); -require_once($phpbb_root_path . 'includes/utf/utf_normalizer.' . $phpEx); +require_once(PHPBB_ROOT_PATH . 'includes/utf/utf_normalizer.' . PHP_EXT); $i = $n = 0; $failed = false; $tested_chars = array(); -$fp = fopen($phpbb_root_path . 'develop/NormalizationTest.txt', 'rb'); +$fp = fopen(PHPBB_ROOT_PATH . 'develop/NormalizationTest.txt', 'rb'); while (!feof($fp)) { $line = fgets($fp); @@ -158,7 +158,7 @@ fclose($fp); */ echo "\n\nTesting for invariants...\n\n"; -$fp = fopen($phpbb_root_path . 'develop/UnicodeData.txt', 'rt'); +$fp = fopen(PHPBB_ROOT_PATH . 'develop/UnicodeData.txt', 'rt'); $n = 0; while (!feof($fp)) @@ -227,9 +227,7 @@ die("\n\nALL TESTS PASSED SUCCESSFULLY\n"); */ function download($url) { - global $phpbb_root_path; - - if (file_exists($phpbb_root_path . 'develop/' . basename($url))) + if (file_exists(PHPBB_ROOT_PATH . 'develop/' . basename($url))) { return; } @@ -241,7 +239,7 @@ function download($url) die("Can't download from $url\nPlease download it yourself and put it in the develop/ dir, kthxbai"); } - if (!$fpw = fopen($phpbb_root_path . 'develop/' . basename($url), 'wb')) + if (!$fpw = fopen(PHPBB_ROOT_PATH . 'develop/' . basename($url), 'wb')) { die("Can't open develop/" . basename($url) . " for output... please check your permissions or something"); } -- cgit v1.2.1 From bf8ac19eaa8d74f9dfd6d597190f5664e7339382 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 4 Oct 2009 18:13:59 +0000 Subject: Move trunk/phpBB to old_trunk/phpBB git-svn-id: file:///svn/phpbb/trunk@10210 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/develop/utf_normalizer_test.php | 389 ---------------------------------- 1 file changed, 389 deletions(-) delete mode 100644 phpBB/develop/utf_normalizer_test.php (limited to 'phpBB/develop/utf_normalizer_test.php') diff --git a/phpBB/develop/utf_normalizer_test.php b/phpBB/develop/utf_normalizer_test.php deleted file mode 100644 index 8a7c31a1b0..0000000000 --- a/phpBB/develop/utf_normalizer_test.php +++ /dev/null @@ -1,389 +0,0 @@ - array( - 'c2' => array('c1', 'c2', 'c3'), - 'c4' => array('c4', 'c5') - ), - - /** - * NFD - * c3 == NFD(c1) == NFD(c2) == NFD(c3) - * c5 == NFD(c4) == NFD(c5) - */ - 'NFD' => array( - 'c3' => array('c1', 'c2', 'c3'), - 'c5' => array('c4', 'c5') - ), - - /** - * NFKC - * c4 == NFKC(c1) == NFKC(c2) == NFKC(c3) == NFKC(c4) == NFKC(c5) - */ - 'NFKC' => array( - 'c4' => array('c1', 'c2', 'c3', 'c4', 'c5') - ), - - /** - * NFKD - * c5 == NFKD(c1) == NFKD(c2) == NFKD(c3) == NFKD(c4) == NFKD(c5) - */ - 'NFKD' => array( - 'c5' => array('c1', 'c2', 'c3', 'c4', 'c5') - ) -); - -require_once(PHPBB_ROOT_PATH . 'includes/utf/utf_normalizer.' . PHP_EXT); - -$i = $n = 0; -$failed = false; -$tested_chars = array(); - -$fp = fopen(PHPBB_ROOT_PATH . 'develop/NormalizationTest.txt', 'rb'); -while (!feof($fp)) -{ - $line = fgets($fp); - ++$n; - - if ($line[0] == '@') - { - if ($i) - { - echo "done\n"; - } - - $i = 0; - echo "\n", substr($line, 1), "\n\n"; - continue; - } - - if (!strpos(' 0123456789ABCDEF', $line[0])) - { - continue; - } - - if (++$i % 100 == 0) - { - echo $i, ' '; - } - - list($c1, $c2, $c3, $c4, $c5) = explode(';', $line); - - if (!strpos($c1, ' ')) - { - /** - * We are currently testing a single character, we add it to the list of - * characters we have processed so that we can exclude it when testing - * for invariants - */ - $tested_chars[$c1] = 1; - } - - foreach ($test_suite as $form => $serie) - { - foreach ($serie as $expected => $tests) - { - $hex_expected = ${$expected}; - $utf_expected = hexseq_to_utf($hex_expected); - - foreach ($tests as $test) - { - $utf_result = $utf_expected; - call_user_func(array('utf_normalizer', $form), $utf_result); - - if (strcmp($utf_expected, $utf_result)) - { - $failed = true; - $hex_result = utf_to_hexseq($utf_result); - - echo "\nFAILED $expected == $form($test) ($hex_expected != $hex_result)"; - } - } - } - - if ($failed) - { - die("\n\nFailed at line $n\n"); - } - } -} -fclose($fp); - -/** -* Test for invariants -*/ -echo "\n\nTesting for invariants...\n\n"; - -$fp = fopen(PHPBB_ROOT_PATH . 'develop/UnicodeData.txt', 'rt'); - -$n = 0; -while (!feof($fp)) -{ - if (++$n % 100 == 0) - { - echo $n, ' '; - } - - $line = fgets($fp, 1024); - - if (!$pos = strpos($line, ';')) - { - continue; - } - - $hex_tested = $hex_expected = substr($line, 0, $pos); - - if (isset($tested_chars[$hex_tested])) - { - continue; - } - - $utf_expected = hex_to_utf($hex_expected); - - if ($utf_expected >= utf_normalizer::UTF8_SURROGATE_FIRST - && $utf_expected <= utf_normalizer::UTF8_SURROGATE_LAST) - { - /** - * Surrogates are illegal on their own, we expect the normalizer - * to return a replacement char - */ - $utf_expected = utf_normalizer::UTF8_REPLACEMENT; - $hex_expected = utf_to_hexseq($utf_expected); - } - - foreach (array('nfc', 'nfkc', 'nfd', 'nfkd') as $form) - { - $utf_result = $utf_expected; - call_user_func(array('utf_normalizer', $form), $utf_result); - $hex_result = utf_to_hexseq($utf_result); -// echo "$form($utf_expected) == $utf_result\n"; - - if (strcmp($utf_expected, $utf_result)) - { - $failed = 1; - - echo "\nFAILED $hex_expected == $form($hex_tested) ($hex_expected != $hex_result)"; - } - } - - if ($failed) - { - die("\n\nFailed at line $n\n"); - } -} -fclose($fp); - -die("\n\nALL TESTS PASSED SUCCESSFULLY\n"); - -/** -* Download a file to the develop/ dir -* -* @param string $url URL of the file to download -* @return void -*/ -function download($url) -{ - if (file_exists(PHPBB_ROOT_PATH . 'develop/' . basename($url))) - { - return; - } - - echo 'Downloading from ', $url, ' '; - - if (!$fpr = fopen($url, 'rb')) - { - die("Can't download from $url\nPlease download it yourself and put it in the develop/ dir, kthxbai"); - } - - if (!$fpw = fopen(PHPBB_ROOT_PATH . 'develop/' . basename($url), 'wb')) - { - die("Can't open develop/" . basename($url) . " for output... please check your permissions or something"); - } - - $i = 0; - $chunk = 32768; - $done = ''; - - while (!feof($fpr)) - { - $i += fwrite($fpw, fread($fpr, $chunk)); - echo str_repeat("\x08", strlen($done)); - - $done = ($i >> 10) . ' KiB'; - echo $done; - } - fclose($fpr); - fclose($fpw); - - echo "\n"; -} - -/** -* Convert a UTF string to a sequence of codepoints in hexadecimal -* -* @param string $utf UTF string -* @return integer Unicode codepoints in hex -*/ -function utf_to_hexseq($str) -{ - $pos = 0; - $len = strlen($str); - $ret = array(); - - while ($pos < $len) - { - $c = $str[$pos]; - switch ($c & "\xF0") - { - case "\xC0": - case "\xD0": - $utf_char = substr($str, $pos, 2); - $pos += 2; - break; - - case "\xE0": - $utf_char = substr($str, $pos, 3); - $pos += 3; - break; - - case "\xF0": - $utf_char = substr($str, $pos, 4); - $pos += 4; - break; - - default: - $utf_char = $c; - ++$pos; - } - - $hex = dechex(utf_to_cp($utf_char)); - - if (!isset($hex[3])) - { - $hex = substr('000' . $hex, -4); - } - - $ret[] = $hex; - } - - return strtr(implode(' ', $ret), 'abcdef', 'ABCDEF'); -} - -/** -* Convert a UTF-8 char to its codepoint -* -* @param string $utf_char UTF-8 char -* @return integer Unicode codepoint -*/ -function utf_to_cp($utf_char) -{ - switch (strlen($utf_char)) - { - case 1: - return ord($utf_char); - - case 2: - return ((ord($utf_char[0]) & 0x1F) << 6) | (ord($utf_char[1]) & 0x3F); - - case 3: - return ((ord($utf_char[0]) & 0x0F) << 12) | ((ord($utf_char[1]) & 0x3F) << 6) | (ord($utf_char[2]) & 0x3F); - - case 4: - return ((ord($utf_char[0]) & 0x07) << 18) | ((ord($utf_char[1]) & 0x3F) << 12) | ((ord($utf_char[2]) & 0x3F) << 6) | (ord($utf_char[3]) & 0x3F); - - default: - die('UTF-8 chars can only be 1-4 bytes long'); - } -} - -/** -* Return a UTF string formed from a sequence of codepoints in hexadecimal -* -* @param string $seq Sequence of codepoints, separated with a space -* @return string UTF-8 string -*/ -function hexseq_to_utf($seq) -{ - return implode('', array_map('hex_to_utf', explode(' ', $seq))); -} - -/** -* Convert a codepoint in hexadecimal to a UTF-8 char -* -* @param string $hex Codepoint, in hexadecimal -* @return string UTF-8 char -*/ -function hex_to_utf($hex) -{ - return cp_to_utf(hexdec($hex)); -} - -/** -* Convert a codepoint to a UTF-8 char -* -* @param integer $cp Unicode codepoint -* @return string UTF-8 string -*/ -function cp_to_utf($cp) -{ - if ($cp > 0xFFFF) - { - return chr(0xF0 | ($cp >> 18)) . chr(0x80 | (($cp >> 12) & 0x3F)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F)); - } - else if ($cp > 0x7FF) - { - return chr(0xE0 | ($cp >> 12)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F)); - } - else if ($cp > 0x7F) - { - return chr(0xC0 | ($cp >> 6)) . chr(0x80 | ($cp & 0x3F)); - } - else - { - return chr($cp); - } -} \ No newline at end of file -- cgit v1.2.1 From 2e17e448deed073f8614bb555a8ef20c57291c2a Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 4 Oct 2009 18:14:59 +0000 Subject: Copy 3.0.x branch to trunk git-svn-id: file:///svn/phpbb/trunk@10211 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/develop/utf_normalizer_test.php | 391 ++++++++++++++++++++++++++++++++++ 1 file changed, 391 insertions(+) create mode 100644 phpBB/develop/utf_normalizer_test.php (limited to 'phpBB/develop/utf_normalizer_test.php') diff --git a/phpBB/develop/utf_normalizer_test.php b/phpBB/develop/utf_normalizer_test.php new file mode 100644 index 0000000000..7705cd6851 --- /dev/null +++ b/phpBB/develop/utf_normalizer_test.php @@ -0,0 +1,391 @@ + array( + 'c2' => array('c1', 'c2', 'c3'), + 'c4' => array('c4', 'c5') + ), + + /** + * NFD + * c3 == NFD(c1) == NFD(c2) == NFD(c3) + * c5 == NFD(c4) == NFD(c5) + */ + 'NFD' => array( + 'c3' => array('c1', 'c2', 'c3'), + 'c5' => array('c4', 'c5') + ), + + /** + * NFKC + * c4 == NFKC(c1) == NFKC(c2) == NFKC(c3) == NFKC(c4) == NFKC(c5) + */ + 'NFKC' => array( + 'c4' => array('c1', 'c2', 'c3', 'c4', 'c5') + ), + + /** + * NFKD + * c5 == NFKD(c1) == NFKD(c2) == NFKD(c3) == NFKD(c4) == NFKD(c5) + */ + 'NFKD' => array( + 'c5' => array('c1', 'c2', 'c3', 'c4', 'c5') + ) +); + +require_once($phpbb_root_path . 'includes/utf/utf_normalizer.' . $phpEx); + +$i = $n = 0; +$failed = false; +$tested_chars = array(); + +$fp = fopen($phpbb_root_path . 'develop/NormalizationTest.txt', 'rb'); +while (!feof($fp)) +{ + $line = fgets($fp); + ++$n; + + if ($line[0] == '@') + { + if ($i) + { + echo "done\n"; + } + + $i = 0; + echo "\n", substr($line, 1), "\n\n"; + continue; + } + + if (!strpos(' 0123456789ABCDEF', $line[0])) + { + continue; + } + + if (++$i % 100 == 0) + { + echo $i, ' '; + } + + list($c1, $c2, $c3, $c4, $c5) = explode(';', $line); + + if (!strpos($c1, ' ')) + { + /** + * We are currently testing a single character, we add it to the list of + * characters we have processed so that we can exclude it when testing + * for invariants + */ + $tested_chars[$c1] = 1; + } + + foreach ($test_suite as $form => $serie) + { + foreach ($serie as $expected => $tests) + { + $hex_expected = ${$expected}; + $utf_expected = hexseq_to_utf($hex_expected); + + foreach ($tests as $test) + { + $utf_result = $utf_expected; + call_user_func(array('utf_normalizer', $form), $utf_result); + + if (strcmp($utf_expected, $utf_result)) + { + $failed = true; + $hex_result = utf_to_hexseq($utf_result); + + echo "\nFAILED $expected == $form($test) ($hex_expected != $hex_result)"; + } + } + } + + if ($failed) + { + die("\n\nFailed at line $n\n"); + } + } +} +fclose($fp); + +/** +* Test for invariants +*/ +echo "\n\nTesting for invariants...\n\n"; + +$fp = fopen($phpbb_root_path . 'develop/UnicodeData.txt', 'rt'); + +$n = 0; +while (!feof($fp)) +{ + if (++$n % 100 == 0) + { + echo $n, ' '; + } + + $line = fgets($fp, 1024); + + if (!$pos = strpos($line, ';')) + { + continue; + } + + $hex_tested = $hex_expected = substr($line, 0, $pos); + + if (isset($tested_chars[$hex_tested])) + { + continue; + } + + $utf_expected = hex_to_utf($hex_expected); + + if ($utf_expected >= UTF8_SURROGATE_FIRST + && $utf_expected <= UTF8_SURROGATE_LAST) + { + /** + * Surrogates are illegal on their own, we expect the normalizer + * to return a replacement char + */ + $utf_expected = UTF8_REPLACEMENT; + $hex_expected = utf_to_hexseq($utf_expected); + } + + foreach (array('nfc', 'nfkc', 'nfd', 'nfkd') as $form) + { + $utf_result = $utf_expected; + utf_normalizer::$form($utf_result); + $hex_result = utf_to_hexseq($utf_result); +// echo "$form($utf_expected) == $utf_result\n"; + + if (strcmp($utf_expected, $utf_result)) + { + $failed = 1; + + echo "\nFAILED $hex_expected == $form($hex_tested) ($hex_expected != $hex_result)"; + } + } + + if ($failed) + { + die("\n\nFailed at line $n\n"); + } +} +fclose($fp); + +die("\n\nALL TESTS PASSED SUCCESSFULLY\n"); + +/** +* Download a file to the develop/ dir +* +* @param string $url URL of the file to download +* @return void +*/ +function download($url) +{ + global $phpbb_root_path; + + if (file_exists($phpbb_root_path . 'develop/' . basename($url))) + { + return; + } + + echo 'Downloading from ', $url, ' '; + + if (!$fpr = fopen($url, 'rb')) + { + die("Can't download from $url\nPlease download it yourself and put it in the develop/ dir, kthxbai"); + } + + if (!$fpw = fopen($phpbb_root_path . 'develop/' . basename($url), 'wb')) + { + die("Can't open develop/" . basename($url) . " for output... please check your permissions or something"); + } + + $i = 0; + $chunk = 32768; + $done = ''; + + while (!feof($fpr)) + { + $i += fwrite($fpw, fread($fpr, $chunk)); + echo str_repeat("\x08", strlen($done)); + + $done = ($i >> 10) . ' KiB'; + echo $done; + } + fclose($fpr); + fclose($fpw); + + echo "\n"; +} + +/** +* Convert a UTF string to a sequence of codepoints in hexadecimal +* +* @param string $utf UTF string +* @return integer Unicode codepoints in hex +*/ +function utf_to_hexseq($str) +{ + $pos = 0; + $len = strlen($str); + $ret = array(); + + while ($pos < $len) + { + $c = $str[$pos]; + switch ($c & "\xF0") + { + case "\xC0": + case "\xD0": + $utf_char = substr($str, $pos, 2); + $pos += 2; + break; + + case "\xE0": + $utf_char = substr($str, $pos, 3); + $pos += 3; + break; + + case "\xF0": + $utf_char = substr($str, $pos, 4); + $pos += 4; + break; + + default: + $utf_char = $c; + ++$pos; + } + + $hex = dechex(utf_to_cp($utf_char)); + + if (!isset($hex[3])) + { + $hex = substr('000' . $hex, -4); + } + + $ret[] = $hex; + } + + return strtr(implode(' ', $ret), 'abcdef', 'ABCDEF'); +} + +/** +* Convert a UTF-8 char to its codepoint +* +* @param string $utf_char UTF-8 char +* @return integer Unicode codepoint +*/ +function utf_to_cp($utf_char) +{ + switch (strlen($utf_char)) + { + case 1: + return ord($utf_char); + + case 2: + return ((ord($utf_char[0]) & 0x1F) << 6) | (ord($utf_char[1]) & 0x3F); + + case 3: + return ((ord($utf_char[0]) & 0x0F) << 12) | ((ord($utf_char[1]) & 0x3F) << 6) | (ord($utf_char[2]) & 0x3F); + + case 4: + return ((ord($utf_char[0]) & 0x07) << 18) | ((ord($utf_char[1]) & 0x3F) << 12) | ((ord($utf_char[2]) & 0x3F) << 6) | (ord($utf_char[3]) & 0x3F); + + default: + die('UTF-8 chars can only be 1-4 bytes long'); + } +} + +/** +* Return a UTF string formed from a sequence of codepoints in hexadecimal +* +* @param string $seq Sequence of codepoints, separated with a space +* @return string UTF-8 string +*/ +function hexseq_to_utf($seq) +{ + return implode('', array_map('hex_to_utf', explode(' ', $seq))); +} + +/** +* Convert a codepoint in hexadecimal to a UTF-8 char +* +* @param string $hex Codepoint, in hexadecimal +* @return string UTF-8 char +*/ +function hex_to_utf($hex) +{ + return cp_to_utf(hexdec($hex)); +} + +/** +* Convert a codepoint to a UTF-8 char +* +* @param integer $cp Unicode codepoint +* @return string UTF-8 string +*/ +function cp_to_utf($cp) +{ + if ($cp > 0xFFFF) + { + return chr(0xF0 | ($cp >> 18)) . chr(0x80 | (($cp >> 12) & 0x3F)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F)); + } + else if ($cp > 0x7FF) + { + return chr(0xE0 | ($cp >> 12)) . chr(0x80 | (($cp >> 6) & 0x3F)) . chr(0x80 | ($cp & 0x3F)); + } + else if ($cp > 0x7F) + { + return chr(0xC0 | ($cp >> 6)) . chr(0x80 | ($cp & 0x3F)); + } + else + { + return chr($cp); + } +} \ No newline at end of file -- cgit v1.2.1 From af5b9a96409d788733fcb1ff367e0c7fb0583702 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Tue, 9 Nov 2010 08:59:25 +0100 Subject: [ticket/9556] Drop php closing tags, add trailing newline Closing tags converted using Oleg's script. remove-php-end-tags.py -a . Trailing newlines added using the following where $ext is file extension. find . -type f -name "*.$ext" -print | xargs printf "e %s\nw\n" | ed -s; Extensions: php, css, html, js, xml. PHPBB3-9556 --- phpBB/develop/utf_normalizer_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/develop/utf_normalizer_test.php') diff --git a/phpBB/develop/utf_normalizer_test.php b/phpBB/develop/utf_normalizer_test.php index 7705cd6851..463a274f66 100644 --- a/phpBB/develop/utf_normalizer_test.php +++ b/phpBB/develop/utf_normalizer_test.php @@ -388,4 +388,4 @@ function cp_to_utf($cp) { return chr($cp); } -} \ No newline at end of file +} -- cgit v1.2.1 From a759704b39fc1c1353f865a633759b1369589b67 Mon Sep 17 00:00:00 2001 From: Yuriy Rusko Date: Tue, 27 May 2014 20:18:06 +0200 Subject: [ticket/12594] Remove @package tags and update file headers PHPBB3-12594 --- phpBB/develop/utf_normalizer_test.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'phpBB/develop/utf_normalizer_test.php') diff --git a/phpBB/develop/utf_normalizer_test.php b/phpBB/develop/utf_normalizer_test.php index af8556507f..27ff786db7 100644 --- a/phpBB/develop/utf_normalizer_test.php +++ b/phpBB/develop/utf_normalizer_test.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ -- cgit v1.2.1