diff --git a/libraries/StringMB.class.php b/libraries/StringMB.class.php deleted file mode 100644 index 402907cbea..0000000000 --- a/libraries/StringMB.class.php +++ /dev/null @@ -1,321 +0,0 @@ -strlen($string); - if ($stringLength <= $start) { - return false; - } - if ($stringLength + $length < $start) { - return false; - } - - return mb_substr($string, $start, $length, 'utf-8'); - } - - /** - * Returns number of substring from string. - * - * @param string $string string to check - * @param int $needle string to count - * - * @return int number of substring from the string - */ - public function substrCount($string, $needle) - { - return mb_substr_count($string, $needle, 'utf-8'); - } - - /** - * Returns position of $needle in $haystack or false if not found - * - * @param string $haystack the string being checked - * @param string $needle the string to find in haystack - * @param int $offset the search offset - * - * @return int|false position of $needle in $haystack or false - */ - public function strpos($haystack, $needle, $offset = 0) - { - if (null === $haystack) { - return false; - } - if (false === $needle) { - return false; - } - if (!is_string($needle) && is_numeric($needle)) { - $needle = (int)$needle; - $needle = $this->chr($needle); - } - return mb_strpos($haystack, $needle, $offset); - } - - /** - * Returns position of $needle in $haystack - case insensitive - or false if - * not found - * - * @param string $haystack the string being checked - * @param string $needle the string to find in haystack - * @param int $offset the search offset - * - * @return int|false position of $needle in $haystack or false - */ - public function stripos($haystack, $needle, $offset = 0) - { - if (null === $haystack) { - return false; - } - if (false === $needle) { - return false; - } - if (!is_string($needle) && is_numeric($needle)) { - $needle = (int)$needle; - $needle = $this->chr($needle); - } - return mb_stripos($haystack, $needle, $offset); - } - - /** - * Returns position of last $needle in $haystack or false if not found - * - * @param string $haystack the string being checked - * @param string $needle the string to find in haystack - * @param int $offset the search offset - * - * @return int|false position of last $needle in $haystack or false - */ - public function strrpos($haystack, $needle, $offset = 0) - { - if (null === $haystack) { - return false; - } - if (false === $needle) { - return false; - } - if (!is_string($needle) && is_numeric($needle)) { - $needle = (int)$needle; - $needle = $this->chr($needle); - } - return mb_strrpos($haystack, $needle, $offset); - } - - /** - * Returns position of last $needle in $haystack - case insensitive - or false - * if not found - * - * @param string $haystack the string being checked - * @param string $needle the string to find in haystack - * @param int $offset the search offset - * - * @return int|false position of last $needle in $haystack or false - */ - public function strripos($haystack, $needle, $offset = 0) - { - if (null === $haystack) { - return false; - } - if (false === $needle) { - return false; - } - if (!is_string($needle) && is_numeric($needle)) { - $needle = (int)$needle; - $needle = $this->chr($needle); - } - return mb_strripos($haystack, $needle, $offset); - } - - /** - * Returns part of $haystack string starting from and including the first - * occurrence of $needle to the end of $haystack or false if not found - * - * @param string $haystack the string being checked - * @param string $needle the string to find in haystack - * @param bool $before_needle the part before the needle - * - * @return string|false part of $haystack or false - */ - public function strstr($haystack, $needle, $before_needle = false) - { - if (!is_string($needle) && is_numeric($needle)) { - $needle = (int)$needle; - $needle = $this->chr($needle); - } - if (!is_string($haystack) || !is_string($needle) || null === $needle) { - return false; - } - return mb_strstr($haystack, $needle, $before_needle); - } - - /** - * Returns part of $haystack string starting from and including the first - * occurrence of $needle to the end of $haystack - case insensitive - or false - * if not found - * - * @param string $haystack the string being checked - * @param string $needle the string to find in haystack - * @param bool $before_needle the part before the needle - * - * @return string|false part of $haystack or false - */ - public function stristr($haystack, $needle, $before_needle = false) - { - if (!is_string($needle) && is_numeric($needle)) { - $needle = (int)$needle; - $needle = $this->chr($needle); - } - if (!is_string($haystack) || !is_string($needle) || null === $needle) { - return false; - } - return mb_stristr($haystack, $needle, $before_needle); - } - - /** - * Returns the portion of haystack which starts at the last occurrence or false - * if not found - * - * @param string $haystack the string being checked - * @param string $needle the string to find in haystack - * - * @return string|false portion of haystack which starts at the last occurrence or - * false - */ - public function strrchr($haystack, $needle) - { - if (!is_string($needle) && is_numeric($needle)) { - $needle = (int)$needle; - $needle = $this->chr($needle); - } - if (!is_string($haystack) || !is_string($needle) || null === $needle) { - return false; - } - return mb_strrchr($haystack, $needle); - } - - /** - * Make a string lowercase - * - * @param string $string the string being lowercased - * - * @return string the lower case string - */ - public function strtolower($string) - { - return mb_strtolower($string); - } - - /** - * Make a string uppercase - * - * @param string $string the string being uppercased - * - * @return string the upper case string - */ - public function strtoupper($string) - { - return mb_strtoupper($string); - } - - /** - * Get the ordinal value of a multibyte string - * (Adapted from http://www.php.net/manual/en/function.ord.php#72463) - * - * @param string $string the string for which ord is required - * - * @return string the ord value - */ - public function ord($string) - { - if (false === $string || null === $string || '' === $string) { - return 0; - } - - $str = mb_convert_encoding($string, "UCS-4BE", "UTF-8"); - $substr = mb_substr($str, 0, 1, "UCS-4BE"); - $val = unpack("N", $substr); - return $val[1]; - } - - /** - * Get the multibyte character of an ASCII - * (from http://fr2.php.net/manual/en/function.chr.php#69082) - * - * @param int $ascii the ASCII code for which character is required - * - * @return string the multibyte character - */ - public function chr($ascii) - { - return mb_convert_encoding( - pack("N", $ascii), - mb_internal_encoding(), - 'UCS-4BE' - ); - } - - /** - * Perform a regular expression match - * - * Take care: might not work with lookbehind expressions. - * - * @param string $pattern Pattern to search for - * @param string $subject Input string - * @param int $offset Start from search - * - * @return int|false 1 if matched, 0 if doesn't, false on failure - */ - public function pregStrpos($pattern, $subject, $offset = 0) - { - $matches = array(); - $bFind = preg_match( - $pattern, $this->substr($subject, $offset), $matches, PREG_OFFSET_CAPTURE - ); - if (1 !== $bFind) { - return false; - } - - return $matches[1][1] + $offset; - } -} -?> diff --git a/libraries/StringNative.class.php b/libraries/StringNative.class.php deleted file mode 100644 index ce07e0a8a1..0000000000 --- a/libraries/StringNative.class.php +++ /dev/null @@ -1,246 +0,0 @@ -= $this->strlen($haystack) - ) { - return false; - } - return stripos($haystack, $needle, $offset); - } - - /** - * Returns position of last $needle in $haystack or false if not found - * - * @param string $haystack the string being checked - * @param string $needle the string to find in haystack - * @param int $offset the search offset - * - * @return int|false position of last $needle in $haystack or false - */ - public function strrpos($haystack, $needle, $offset = 0) - { - return strrpos($haystack, $needle, $offset); - } - - /** - * Returns position of last $needle in $haystack - case insensitive - or false - * if not found - * - * @param string $haystack the string being checked - * @param string $needle the string to find in haystack - * @param int $offset the search offset - * - * @return int|false position of last $needle in $haystack or false - */ - public function strripos($haystack, $needle, $offset = 0) - { - if (('' === $haystack || false === $haystack) - && $offset >= $this->strlen($haystack) - ) { - return false; - } - return strripos($haystack, $needle, $offset); - } - - /** - * Returns part of $haystack string starting from and including the first - * occurrence of $needle to the end of $haystack or false if not found - * - * @param string $haystack the string being checked - * @param string $needle the string to find in haystack - * @param bool $before_needle the part before the needle - * - * @return string|false part of $haystack or false - */ - public function strstr($haystack, $needle, $before_needle = false) - { - return strstr($haystack, $needle, $before_needle); - } - - /** - * Returns part of $haystack string starting from and including the first - * occurrence of $needle to the end of $haystack - case insensitive - or false - * if not found - * - * @param string $haystack the string being checked - * @param string $needle the string to find in haystack - * @param bool $before_needle the part before the needle - * - * @return string|false part of $haystack or false - */ - public function stristr($haystack, $needle, $before_needle = false) - { - return stristr($haystack, $needle, $before_needle); - } - - /** - * Returns the portion of haystack which starts at the last occurrence or false - * if not found - * - * @param string $haystack the string being checked - * @param string $needle the string to find in haystack - * - * @return string|false portion of haystack which starts at the last occurrence - * or false - */ - public function strrchr($haystack, $needle) - { - return strrchr($haystack, $needle); - } - - /** - * Make a string lowercase - * - * @param string $string the string being lowercased - * - * @return string the lower case string - */ - public function strtolower($string) - { - return strtolower($string); - } - - /** - * Make a string uppercase - * - * @param string $string the string being uppercased - * - * @return string the upper case string - */ - public function strtoupper($string) - { - return strtoupper($string); - } - - /** - * Perform a regular expression match - * - * @param string $pattern Pattern to search for - * @param string $subject Input string - * @param int $offset Start from search - * - * @return int|false 1 if matched, 0 if doesn't, false on failure - */ - public function pregStrpos($pattern, $subject, $offset = 0) - { - $matches = array(); - $bFind = preg_match( - $pattern, $subject, $matches, PREG_OFFSET_CAPTURE, $offset - ); - if (1 !== $bFind) { - return false; - } - - return $matches[1][1]; - } - - /** - * Get the ordinal value of a string - * - * @param string $string the string for which ord is required - * - * @return int the ord value - */ - public function ord($string) - { - return ord($string); - } - - /** - * Get the character of an ASCII - * - * @param int $ascii the ASCII code for which character is required - * - * @return string the character - */ - public function chr($ascii) - { - return chr($ascii); - } -}; -?> diff --git a/test/libraries/PMA_String_Compare_test.php b/test/libraries/PMA_String_Compare_test.php deleted file mode 100644 index 582cb9da3d..0000000000 --- a/test/libraries/PMA_String_Compare_test.php +++ /dev/null @@ -1,1259 +0,0 @@ -markTestSkipped('Multibyte String Functions are not available.'); - } - $this->_native = new PMA_StringNative(); - $this->_mb = new PMA_StringMB(); - } - - /** - * Tests for strlen - * - * @param mixed $value Value to test - * - * @return void - * @test - * @dataProvider providerStrlen - */ - public function testStrlen($value) - { - $native = $this->_native->strlen($value); - $multibytes = $this->_mb->strlen($value); - $this->assertTrue( - $native === $multibytes, - 'native length: ' . var_export($native, true) - . ' - mb length: ' . var_export($multibytes, true) - ); - } - - /** - * Data provider for testStrlen - * - * @return array Test data - */ - public function providerStrlen() - { - return array( - array('test'), - array('3'), - array(''), - array(""), - array(false), - array(true), - array(null), - array(3), - array(10), - ); - } - - /** - * Tests for substr - * - * @param mixed $value Value to test - * @param int $start Position to start cutting - * @param int $length Number of characters to cut - * - * @return void - * @test - * @dataProvider providerSubstr - */ - public function testSubstr($value, $start, $length = 2147483647) - { - $native = $this->_native->substr($value, $start, $length); - $multibytes = $this->_mb->substr($value, $start, $length); - $this->assertTrue( - $native === $multibytes, - 'native substr: ' . var_export($native, true) - . ' - mb substr: ' . var_export($multibytes, true) - ); - } - - /** - * Data provider for testSubstr - * - * @return array Test data - */ - public function providerSubstr() - { - return array( - array('abcdefabcdef', 0), - array('abcdefabcdef', 0, 3), - array('abcdefabcdef', 0, 10), - array('abcdefabcdef', 0, -2), - array('abcdefabcdef', 2), - array('abcdefabcdef', 2, 3), - array('abcdefabcdef', 2, 10), - array('abcdefabcdef', 2, -1), - array('abcdefabcdef', 2, -4), - array('abcdefabcdef', 2, -5), - array('abcdefabcdef', 6), - array('abcdefabcdef', 6, 2), - array('abcdefabcdef', 6, 10), - array('abcdefabcdef', 6, -4), - array('abcdefabcdef', -3), - array('abcdefabcdef', -3, 1), - array('abcdefabcdef', -3, 10), - array('abcdefabcdef', -3, -1), - array('abcdefabcdef', -3, -3), - array('abcdefabcdef', -3, -5), - array(false, 0), - array(false, 0, 2), - array(false, 10), - array(false, 10, 2), - array(true, 0), - array(true, 0, 1), - array(true, 0, 10), - array(true, 0, -1), - array(true, 0, -10), - array(true, 10), - array(true, 10, 1), - array(true, 10, 10), - array(true, 10, -3), - array(3, 0), - array(3, 0, 1), - array(3, 0, 2), - array(3, 0, -1), - array(3, 10), - array(3, 10, 1), - array(3, 10, 10), - array(3, 10, -1), - array('3', 0), - array('3', 0, 1), - array('3', 0, 2), - array('3', 0, -1), - array('3', 10), - array('3', 10, 1), - array('3', 10, 10), - array('3', 10, -1), - array('', 0), - array('', 0, 1), - array('', 0, 10), - array('', 0, -1), - array('', 10), - array('', 10, 1), - array('', 10, 10), - array('', 10, -1), - array(null, 10), - array(null, 10, 1), - array(null, 10, 10), - array(null, 10, -1), - ); - } - - /** - * Tests for substr_count - * - * @param string $haystack String to look into - * @param int $needle String to look for - * - * @return void - * @test - * @dataProvider providerSubstrCount - */ - public function testSubstrCount($haystack, $needle) - { - $native = $this->_native->substrCount($haystack, $needle); - $multibytes = $this->_mb->substrCount($haystack, $needle); - $this->assertTrue( - $native === $multibytes, - 'native substrCount: ' . var_export($native, true) - . ' - mb substrCount: ' . var_export($multibytes, true) - ); - } - - /** - * Data provider for testSubstrCount - * - * @return array Test data - */ - public function providerSubstrCount() - { - return array( - array('abcdefabcdef', 'a'), - array('abcdefabcdef', 'ab'), - array('abcdefabcdef', 'ba'), - array('abcdefabcdef', 'A'), - array('abcdefabcdef', 'e'), - array('abcdefabcdef', 'z'), - array(false, 'a'), - array(false, 0), - array(true, 0), - array(true, 0, 1), - array(true, 1), - array(true, 1, 1), - array(3, 0), - array(3, 3), - array(3, '3'), - array('3', '3'), - array(null, 0), - array('', 0), - ); - } - - /** - * Tests for substr_count - * - * @param string $haystack String to look into - * @param int $needle String to look for - * - * @return void - * @test - * @dataProvider providerSubstrCountException - */ - public function testSubstrCountException($haystack, $needle) - { - $native = null; - $multibytes = null; - $nativeException = false; - $multibytesException = false; - try { - $native = $this->_native->substrCount($haystack, $needle); - } catch (PHPUnit_Framework_Error $e) { - $nativeException = true; - } - try { - $multibytes = $this->_mb->substrCount($haystack, $needle); - } catch (PHPUnit_Framework_Error $e) { - $multibytesException = true; - } - - $this->assertTrue( - true === $nativeException && true === $multibytesException, - 'native substrCount: ' . var_export($native, true) - . ' - mb substrCount: ' . var_export($multibytes, true) - ); - } - - /** - * Data provider for testSubstrCountException - * - * @return array Test data - */ - public function providerSubstrCountException() - { - return array( - array('abcdefabcdef', false), - array(false, false), - array(null, false), - array('', false), - ); - } - - /** - * Tests for strpos - * - * @param string $haystack String to search in - * @param mixed $needle Characters to search - * @param int $offset Start position - * - * @return void - * @test - * @dataProvider providerStrpos - */ - public function testStrpos($haystack, $needle, $offset = 0) - { - $native = $this->_native->strpos($haystack, $needle, $offset); - $multibytes = $this->_mb->strpos($haystack, $needle, $offset); - $this->assertTrue( - $native === $multibytes, - 'native strpos: ' . var_export($native, true) - . ' - mb strpos: ' . var_export($multibytes, true) - ); - } - - /** - * Data provider for testStrpos - * - * @return array Test data - */ - public function providerStrpos() - { - return array( - array('abcdefabcdef', 'a'), - array('abcdefabcdef', 'a', 2), - array('abcdefabcdef', 'a', 10), - array('abcdefabcdef', 'A'), - array('abcdefabcdef', 'A', 2), - array('abcdefabcdef', 'A', 10), - array('abcdefabcdef', 'e'), - array('abcdefabcdef', 'e', 2), - array('abcdefabcdef', 'e', 10), - array('abcdefabcdef', 'z'), - array('abcdefabcdef', 'z', 2), - array('abcdefabcdef', ord('a')), - array('abcdefabcdef', ord('a'), 2), - array('abcdefabcdef', ord('A')), - array('abcdefabcdef', ord('A'), 2), - array('abcdefabcdef', ord('e')), - array('abcdefabcdef', ord('e'), 2), - array('abcdefabcdef', ord('z')), - array('abcdefabcdef', ord('z'), 2), - array('abcdefabcdef', false), - array(false, 'a'), - array(false, 0), - array(false, false), - array(true, 0), - array(true, 0, 1), - array(true, 1), - array(true, 1, 1), - array(3, 0), - array(3, 3), - array(3, '3'), - array('3', '3'), - array(null, 0), - array(null, false), - array('', 0), - array('', false), - ); - } - - /** - * Tests for strpos - * - * @param string $haystack String to search in - * @param mixed $needle Characters to search - * @param int $offset Start position - * - * @return void - * @test - * @dataProvider providerStrposException - */ - public function testStrposException($haystack, $needle, $offset = 0) - { - $native = null; - $multibytes = null; - $nativeException = false; - $multibytesException = false; - try { - $native = $this->_native->strpos($haystack, $needle, $offset); - } catch (PHPUnit_Framework_Error $e) { - $nativeException = true; - } - try { - $multibytes = $this->_mb->strpos($haystack, $needle, $offset); - } catch (PHPUnit_Framework_Error $e) { - $multibytesException = true; - } - - $this->assertTrue( - true === $nativeException && true === $multibytesException, - 'native strpos: ' . var_export($native, true) - . ' - mb strpos: ' . var_export($multibytes, true) - ); - } - - /** - * Data provider for testStrposException - * - * @return array Test data - */ - public function providerStrposException() - { - return array( - array('abcdefabcdef', 'a', 20), - array('abcdefabcdef', 'e', 20), - array('abcdefabcdef', 'z', 20), - array('abcdefabcdef', ord('a'), 20), - array('abcdefabcdef', ord('e'), 20), - array('abcdefabcdef', ord('z'), 20), - array(false, 0, 1), - array(3, 0, 2), - array(3, 3, 2), - array(3, '3', 2), - array('3', '3', 2), - array('', 0, 2), - ); - } - - /** - * Tests for stripos - * - * @param string $haystack String to search in - * @param mixed $needle Characters to search - * @param int $offset Start position - * - * @return void - * @test - * @dataProvider providerStripos - */ - public function testStripos($haystack, $needle, $offset = 0) - { - $native = $this->_native->stripos($haystack, $needle, $offset); - $multibytes = $this->_mb->stripos($haystack, $needle, $offset); - $this->assertTrue( - $native === $multibytes, - 'native stripos: ' . var_export($native, true) - . ' - mb stripos: ' . var_export($multibytes, true) - ); - } - - /** - * Data provider for testStripos - * - * @return array Test data - */ - public function providerStripos() - { - return array( - array('abcdefabcdef', 'a'), - array('abcdefabcdef', 'a', 2), - array('abcdefabcdef', 'a', 10), - array('abcdefabcdef', 'A'), - array('abcdefabcdef', 'A', 2), - array('abcdefabcdef', 'A', 10), - array('abcdefabcdef', 'e'), - array('abcdefabcdef', 'e', 2), - array('abcdefabcdef', 'e', 10), - array('abcdefabcdef', 'e'), - array('abcdefabcdef', 'z'), - array('abcdefabcdef', 'z', 2), - array('abcdefabcdef', ord('a')), - array('abcdefabcdef', ord('a'), 2), - array('abcdefabcdef', ord('A')), - array('abcdefabcdef', ord('A'), 2), - array('abcdefabcdef', ord('e')), - array('abcdefabcdef', ord('e'), 2), - array('abcdefabcdef', ord('z')), - array('abcdefabcdef', ord('z'), 2), - array('abcdefabcdef', false), - array(false, 'a'), - array(false, 0), - array(false, 0, 1), - array(false, false), - array(true, 0), - array(true, 0, 1), - array(true, 1), - array(true, 1, 1), - array(3, 0), - array(3, 3), - array(3, '3'), - array('3', '3'), - array(null, 0), - array(null, false), - array('', 0), - array('', 0, 2), - array('', false), - ); - } - - /** - * Tests for stripos - * - * @param string $haystack String to search in - * @param mixed $needle Characters to search - * @param int $offset Start position - * - * @return void - * @test - * @dataProvider providerStriposException - */ - public function testStriposException($haystack, $needle, $offset = 0) - { - $native = null; - $multibytes = null; - $nativeException = false; - $multibytesException = false; - try { - $native = $this->_native->stripos($haystack, $needle, $offset); - } catch (PHPUnit_Framework_Error $e) { - $nativeException = true; - } - try { - $multibytes = $this->_mb->stripos($haystack, $needle, $offset); - } catch (PHPUnit_Framework_Error $e) { - $multibytesException = true; - } - - $this->assertTrue( - true === $nativeException && true === $multibytesException, - 'native stripos: ' . var_export($native, true) - . ' - mb stripos: ' . var_export($multibytes, true) - ); - } - - /** - * Data provider for testStriposException - * - * @return array Test data - */ - public function providerStriposException() - { - return array( - array('abcdefabcdef', 'a', 20), - array('abcdefabcdef', 'e', 20), - array('abcdefabcdef', 'z', 20), - array('abcdefabcdef', ord('a'), 20), - array('abcdefabcdef', ord('e'), 20), - array('abcdefabcdef', ord('z'), 20), - array(3, 0, 2), - array(3, 3, 2), - array(3, '3', 2), - array('3', '3', 2), - ); - } - - /** - * Tests for strrpos - * - * @param string $haystack String to search in - * @param mixed $needle Characters to search - * @param int $offset Start position - * - * @return void - * @test - * @dataProvider providerStrrpos - */ - public function testStrrpos($haystack, $needle, $offset = 0) - { - $native = $this->_native->strrpos($haystack, $needle, $offset); - $multibytes = $this->_mb->strrpos($haystack, $needle, $offset); - $this->assertTrue( - $native === $multibytes, - 'native strrpos: ' . var_export($native, true) - . ' - mb strrpos: ' . var_export($multibytes, true) - ); - } - - /** - * Data provider for testStrrpos - * - * @return array Test data - */ - public function providerStrrpos() - { - return array( - array('abcdefabcdef', 'a'), - array('abcdefabcdef', 'a', 2), - array('abcdefabcdef', 'a', 10), - array('abcdefabcdef', 'a', -10), - array('abcdefabcdef', 'A'), - array('abcdefabcdef', 'A', 2), - array('abcdefabcdef', 'A', 10), - array('abcdefabcdef', 'A', -10), - array('abcdefabcdef', 'e'), - array('abcdefabcdef', 'e', 2), - array('abcdefabcdef', 'e', 10), - array('abcdefabcdef', 'e', -2), - array('abcdefabcdef', 'e'), - array('abcdefabcdef', 'z'), - array('abcdefabcdef', 'z', 2), - array('abcdefabcdef', 'z', -2), - array('abcdefabcdef', ord('a')), - array('abcdefabcdef', ord('a'), 2), - array('abcdefabcdef', ord('a'), -2), - array('abcdefabcdef', ord('A')), - array('abcdefabcdef', ord('A'), 2), - array('abcdefabcdef', ord('A'), -2), - array('abcdefabcdef', ord('e')), - array('abcdefabcdef', ord('e'), 2), - array('abcdefabcdef', ord('e'), -2), - array('abcdefabcdef', ord('z')), - array('abcdefabcdef', ord('z'), 2), - array('abcdefabcdef', ord('z'), -2), - array('abcdefabcdef', false), - array(false, 'a'), - array(false, 0), - array(false, 0, 1), - array(false, false), - array(true, 0), - array(true, 0, 1), - array(true, 1), - array(true, 1, 1), - array(3, 0), - array(3, 3), - array(3, '3'), - array('3', '3'), - array(null, 0), - array(null, false), - array('', 0), - array('', 0, 2), - array('', false), - ); - } - - /** - * Tests for strrpos - * - * @param string $haystack String to search in - * @param mixed $needle Characters to search - * @param int $offset Start position - * - * @return void - * @test - * @dataProvider providerStrrposException - */ - public function testStrrposException($haystack, $needle, $offset = 0) - { - $native = null; - $multibytes = null; - $nativeException = false; - $multibytesException = false; - try { - $native = $this->_native->strrpos($haystack, $needle, $offset); - } catch (PHPUnit_Framework_Error $e) { - $nativeException = true; - } - try { - $multibytes = $this->_mb->strrpos($haystack, $needle, $offset); - } catch (PHPUnit_Framework_Error $e) { - $multibytesException = true; - } - - $this->assertTrue( - true === $nativeException && true === $multibytesException, - 'native strrpos: ' . var_export($native, true) - . ' - mb strrpos: ' . var_export($multibytes, true) - ); - } - - /** - * Data provider for testStrrposException - * - * @return array Test data - */ - public function providerStrrposException() - { - return array( - array('abcdefabcdef', 'a', 20), - array('abcdefabcdef', 'a', -20), - array('abcdefabcdef', 'e', 20), - array('abcdefabcdef', 'e', -20), - array('abcdefabcdef', 'z', 20), - array('abcdefabcdef', 'z', -20), - array('abcdefabcdef', ord('a'), 20), - array('abcdefabcdef', ord('e'), 20), - array('abcdefabcdef', ord('z'), 20), - array(3, 0, 2), - array(3, 3, 2), - array(3, '3', 2), - array('3', '3', 2), - ); - } - - /** - * Tests for strripos - * - * @param string $haystack String to search in - * @param mixed $needle Characters to search - * @param int $offset Start position - * - * @return void - * @test - * @dataProvider providerStrripos - */ - public function testStrripos($haystack, $needle, $offset = 0) - { - $native = $this->_native->strripos($haystack, $needle, $offset); - $multibytes = $this->_mb->strripos($haystack, $needle, $offset); - $this->assertTrue( - $native === $multibytes, - 'native strripos: ' . var_export($native, true) - . ' - mb strripos: ' . var_export($multibytes, true) - ); - } - - /** - * Data provider for testStrripos - * - * @return array Test data - */ - public function providerStrripos() - { - return array( - array('abcdefabcdef', 'a'), - array('abcdefabcdef', 'a', 2), - array('abcdefabcdef', 'a', 10), - array('abcdefabcdef', 'a', -10), - array('abcdefabcdef', 'A'), - array('abcdefabcdef', 'A', 2), - array('abcdefabcdef', 'A', 10), - array('abcdefabcdef', 'A', -10), - array('abcdefabcdef', 'e'), - array('abcdefabcdef', 'e', 2), - array('abcdefabcdef', 'e', 10), - array('abcdefabcdef', 'e', -2), - array('abcdefabcdef', 'e'), - array('abcdefabcdef', 'z'), - array('abcdefabcdef', 'z', 2), - array('abcdefabcdef', 'z', -2), - array('abcdefabcdef', ord('a')), - array('abcdefabcdef', ord('a'), 2), - array('abcdefabcdef', ord('a'), -2), - array('abcdefabcdef', ord('A')), - array('abcdefabcdef', ord('A'), 2), - array('abcdefabcdef', ord('A'), -2), - array('abcdefabcdef', ord('e')), - array('abcdefabcdef', ord('e'), 2), - array('abcdefabcdef', ord('e'), -2), - array('abcdefabcdef', ord('z')), - array('abcdefabcdef', ord('z'), 2), - array('abcdefabcdef', ord('z'), -2), - array('abcdefabcdef', false), - array(false, 'a'), - array(false, 0), - array(false, 0, 1), - array(false, false), - array(true, 0), - array(true, 0, 1), - array(true, 1), - array(true, 1, 1), - array(3, 0), - array(3, 3), - array(3, '3'), - array('3', '3'), - array(null, 0), - array(null, false), - array('', 0), - array('', 0, 2), - array('', false), - ); - } - - /** - * Tests for strripos - * - * @param string $haystack String to search in - * @param mixed $needle Characters to search - * @param int $offset Start position - * - * @return void - * @test - * @dataProvider providerStrriposException - */ - public function testStrriposException($haystack, $needle, $offset = 0) - { - $native = null; - $multibytes = null; - $nativeException = false; - $multibytesException = false; - try { - $native = $this->_native->strripos($haystack, $needle, $offset); - } catch (PHPUnit_Framework_Error $e) { - $nativeException = true; - } - try { - $multibytes = $this->_mb->strripos($haystack, $needle, $offset); - } catch (PHPUnit_Framework_Error $e) { - $multibytesException = true; - } - - $this->assertTrue( - true === $nativeException && true === $multibytesException, - 'native strripos: ' . var_export($native, true) - . ' - mb strripos: ' . var_export($multibytes, true) - ); - } - - /** - * Data provider for testStrriposException - * - * @return array Test data - */ - public function providerStrriposException() - { - return array( - array('abcdefabcdef', 'a', 20), - array('abcdefabcdef', 'a', -20), - array('abcdefabcdef', 'e', 20), - array('abcdefabcdef', 'e', -20), - array('abcdefabcdef', 'z', 20), - array('abcdefabcdef', 'z', -20), - array('abcdefabcdef', ord('a'), 20), - array('abcdefabcdef', ord('e'), 20), - array('abcdefabcdef', ord('z'), 20), - array(3, 0, 2), - array(3, 3, 2), - array(3, '3', 2), - array('3', '3', 2), - ); - } - - /** - * Tests for strstr - * - * @param string $haystack String to search in - * @param mixed $needle Characters to search - * @param bool $before_needle Start position - * - * @return void - * @test - * @dataProvider providerStrstr - */ - public function testStrstr($haystack, $needle, $before_needle = false) - { - $native = $this->_native->strstr($haystack, $needle, $before_needle); - $multibytes = $this->_mb->strstr($haystack, $needle, $before_needle); - $this->assertTrue( - $native === $multibytes, - 'native strstr: ' . var_export($native, true) - . ' - mb strstr: ' . var_export($multibytes, true) - ); - } - - /** - * Data provider for testStrstr - * - * @return array Test data - */ - public function providerStrstr() - { - return array( - array('abcdefabcdef', 'a'), - array('abcdefabcdef', 'a', true), - array('abcdefabcdef', 'A'), - array('abcdefabcdef', 'A', true), - array('abcdefabcdef', 97), - array('abcdefabcdef', 97, true), - array('abcdefabcdef', 65), - array('abcdefabcdef', 65, true), - array('abcdefabcdef', 'e'), - array('abcdefabcdef', 'e', true), - array('abcdefabcdef', 'z'), - array('abcdefabcdef', 'z', true), - array('abcdefabcdef', null), - array('abcdefabcdef', null, true), - array('abcdefabcdef', false), - array('abcdefabcdef', false, true), - array(false, 'a'), - array(false, false), - array(true, 0), - array(true, 1), - array(true, true), - array(true, true, true), - array(3, 0), - array(3, 3), - array(3, 3, true), - array(123456789, 0), - array(123456789, 3), - array(123456789, 3, true), - array('3', '3'), - array('3', '3', true), - array('123456789', 3), - array('123456789', 3, true), - array('123456789', 49), //ASCII 49 = 1 - array('123456789', 49, true), - array(null, 0), - array(null, null), - array('', 0), - array('', false), - array('', null), - ); - } - - /** - * Tests for strstr - * - * @param string $haystack String to search in - * @param mixed $needle Characters to search - * @param bool $before_needle Start position - * - * @return void - * @test - * @dataProvider providerStrstrException - */ - public function testStrstrException($haystack, $needle, $before_needle = false) - { - $native = null; - $multibytes = null; - $nativeException = false; - $multibytesException = false; - try { - $native = $this->_native->strstr($haystack, $needle, $before_needle); - } catch (PHPUnit_Framework_Error $e) { - $nativeException = true; - } - try { - $multibytes = $this->_mb->strstr($haystack, $needle, $before_needle); - } catch (PHPUnit_Framework_Error $e) { - $multibytesException = true; - } - - $this->assertTrue( - true === $nativeException && true === $multibytesException, - 'native strstr: ' . var_export($native, true) - . ' - mb strstr: ' . var_export($multibytes, true) - ); - } - - /** - * Data provider for testStrstrException - * - * @return array Test data - */ - public function providerStrstrException() - { - return array( - array('abcdefabcdef', ''), - array('abcdefabcdef', '', true), - ); - } - - /** - * Tests for stristr - * - * @param string $haystack String to search in - * @param mixed $needle Characters to search - * @param bool $before_needle Start position - * - * @return void - * @test - * @dataProvider providerStristr - */ - public function testStristr($haystack, $needle, $before_needle = false) - { - $this->markTestSkipped('Skip until hhvm implements third parameter.'); - $native = $this->_native->stristr($haystack, $needle, $before_needle); - $multibytes = $this->_mb->stristr($haystack, $needle, $before_needle); - $this->assertTrue( - $native === $multibytes, - 'native stristr: ' . var_export($native, true) - . ' - mb stristr: ' . var_export($multibytes, true) - ); - } - - /** - * Data provider for testStristr - * - * @return array Test data - */ - public function providerStristr() - { - return array( - array('abcdefabcdef', 'a'), - array('abcdefabcdef', 'a', true), - array('abcdefabcdef', 'A'), - array('abcdefabcdef', 'A', true), - array('abcdefabcdef', 97), - array('abcdefabcdef', 97, true), - array('abcdefabcdef', 65), - array('abcdefabcdef', 65, true), - array('abcdefabcdef', 'e'), - array('abcdefabcdef', 'e', true), - array('abcdefabcdef', 'z'), - array('abcdefabcdef', 'z', true), - array('abcdefabcdef', null), - array('abcdefabcdef', null, true), - array('abcdefabcdef', false), - array('abcdefabcdef', false, true), - array(false, 'a'), - array(false, false), - array(true, 0), - array(true, 1), - array(true, true), - array(true, true, true), - array(3, 0), - array(3, 3), - array(3, 3, true), - array(123456789, 0), - array(123456789, 3), - array(123456789, 3, true), - array('3', '3'), - array('3', '3', true), - array('123456789', 3), - array('123456789', 3, true), - array('123456789', 49), //ASCII 49 = 1 - array('123456789', 49, true), - array(null, 0), - array(null, null), - array('', 0), - array('', false), - array('', null), - ); - } - - /** - * Tests for stristr - * - * @param string $haystack String to search in - * @param mixed $needle Characters to search - * @param bool $before_needle Start position - * - * @return void - * @test - * @dataProvider providerStristrException - */ - public function testStristrException($haystack, $needle, $before_needle = false) - { - $this->markTestSkipped('Skip until hhvm implements third parameter.'); - $native = null; - $multibytes = null; - $nativeException = false; - $multibytesException = false; - try { - $native = $this->_native->stristr($haystack, $needle, $before_needle); - } catch (PHPUnit_Framework_Error $e) { - $nativeException = true; - } - try { - $multibytes = $this->_mb->stristr($haystack, $needle, $before_needle); - } catch (PHPUnit_Framework_Error $e) { - $multibytesException = true; - } - - $this->assertTrue( - true === $nativeException && true === $multibytesException, - 'native stristr: ' . var_export($native, true) - . ' - mb stristr: ' . var_export($multibytes, true) - ); - } - - /** - * Data provider for testStristrException - * - * @return array Test data - */ - public function providerStristrException() - { - return array( - array('abcdefabcdef', ''), - array('abcdefabcdef', '', true), - ); - } - - /** - * Tests for strrchr - * - * @param string $haystack String to search in - * @param mixed $needle Characters to search - * - * @return void - * @test - * @dataProvider providerStrstr - */ - public function testStrrchr($haystack, $needle) - { - $native = $this->_native->strrchr($haystack, $needle); - $multibytes = $this->_mb->strrchr($haystack, $needle); - $this->assertTrue( - $native === $multibytes, - 'native strrchr: ' . var_export($native, true) - . ' - mb strrchr: ' . var_export($multibytes, true) - ); - } - - /** - * Data provider for testStrrchr - * - * @return array Test data - */ - public function providerStrrchr() - { - return array( - array('abcdefabcdef', 'a'), - array('abcdefabcdef', 'A'), - array('abcdefabcdef', 97), - array('abcdefabcdef', 65), - array('abcdefabcdef', 'e'), - array('abcdefabcdef', 'z'), - array('abcdefabcdef', ''), - array('abcdefabcdef', null), - array('abcdefabcdef', false), - array(false, 'a'), - array(false, false), - array(true, 0), - array(true, 1), - array(true, true), - array(3, 0), - array(3, 3), - array(123456789, 0), - array(123456789, 3), - array('3', '3'), - array('123456789', 3), - array('123456789', 49), //ASCII 49 = 1 - array(null, 0), - array(null, null), - array('', 0), - array('', false), - array('', null), - ); - } - - /** - * Tests for strtolower - * - * @param string $str Input string - * - * @return void - * @test - * @dataProvider providerCase - */ - public function testStrtolower($str) - { - $native = $this->_native->strtolower($str); - $multibytes = $this->_mb->strtolower($str); - $this->assertTrue( - $native === $multibytes, - 'native strtolower: ' . var_export($native, true) - . ' - mb strtolower: ' . var_export($multibytes, true) - ); - } - - /** - * Tests for strtoupper - * - * @param string $str Input string - * - * @return void - * @test - * @dataProvider providerCase - */ - public function testStrtoupper($str) - { - $native = $this->_native->strtoupper($str); - $multibytes = $this->_mb->strtoupper($str); - $this->assertTrue( - $native === $multibytes, - 'native strtoupper: ' . var_export($native, true) - . ' - mb strtoupper: ' . var_export($multibytes, true) - ); - } - - /** - * Data provider for testStrtolower and testStrtoupper - * - * @return array Test data - */ - public function providerCase() - { - return array( - array('abcdefabcdef'), - array('abcdefABCDEF'), - //array('abcdefABCDEFàéÀÉ'), //Error with those characters. - array('abcdefABCDEF@+12345'), - array(false), - array(true), - array(3), - array(123456789), - array('3'), - array('4k'), - array('4kb'), - array('4K'), - array('4KB'), - array('123456789'), - array(null), - array(''), - ); - } - - /** - * Tests for ord - * - * @param string $chr Input char - * - * @return void - * @test - * @dataProvider providerOrd - */ - public function testOrd($chr) - { - $native = $this->_native->ord($chr); - $multibytes = $this->_mb->ord($chr); - $this->assertTrue( - $native === $multibytes, - 'native ord: ' . var_export($native, true) - . ' - mb ord: ' . var_export($multibytes, true) - ); - } - - /** - * Data provider for testOrd - * - * @return array Test data - */ - public function providerOrd() - { - return array( - array('a'), - array('A'), - array('az'), - array('AZ'), - array('3a'), - array(3), - array(3.1), - array(true), - array(false), - array(null), - array(''), - ); - } - - /** - * Tests for chr - * - * @param string $ascii Ascii code - * - * @return void - * @test - * @dataProvider providerChr - */ - public function testChr($ascii) - { - $native = $this->_native->chr($ascii); - $multibytes = $this->_mb->chr($ascii); - $this->assertTrue( - $native === $multibytes, - 'native chr: ' . var_export($native, true) - . ' - mb chr: ' . var_export($multibytes, true) - ); - } - - /** - * Data provider for testChr - * - * @return array Test data - */ - public function providerChr() - { - return array( - array('a'), - array('A'), - array('az'), - array('AZ'), - array('a3'), - array(3), - array(3.1), - array(false), - array(true), - array(null), - array(''), - ); - } -}