mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-07 12:36:25 +00:00
Correct tokenize for empty strings.
This commit is contained in:
parent
dc52f0bc0e
commit
3ecce19732
2 changed files with 8 additions and 4 deletions
|
@ -303,6 +303,10 @@ class StringTest extends CakeTestCase {
|
||||||
$result = String::tokenize('tagA "single tag" tagB', ' ', '"', '"');
|
$result = String::tokenize('tagA "single tag" tagB', ' ', '"', '"');
|
||||||
$expected = array('tagA', '"single tag"', 'tagB');
|
$expected = array('tagA', '"single tag"', 'tagB');
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
|
$result = String::tokenize('');
|
||||||
|
$expected = array();
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReplaceWithQuestionMarkInString() {
|
public function testReplaceWithQuestionMarkInString() {
|
||||||
|
|
|
@ -99,17 +99,17 @@ class String {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tokenizes a string using $separator, ignoring any instance of $separator that appears between
|
* Tokenizes a string using $separator, ignoring any instance of $separator that appears between
|
||||||
* $leftBound and $rightBound
|
* $leftBound and $rightBound.
|
||||||
*
|
*
|
||||||
* @param string $data The data to tokenize
|
* @param string $data The data to tokenize.
|
||||||
* @param string $separator The token to split the data on.
|
* @param string $separator The token to split the data on.
|
||||||
* @param string $leftBound The left boundary to ignore separators in.
|
* @param string $leftBound The left boundary to ignore separators in.
|
||||||
* @param string $rightBound The right boundary to ignore separators in.
|
* @param string $rightBound The right boundary to ignore separators in.
|
||||||
* @return array Array of tokens in $data.
|
* @return array Array of tokens in $data.
|
||||||
*/
|
*/
|
||||||
public static function tokenize($data, $separator = ',', $leftBound = '(', $rightBound = ')') {
|
public static function tokenize($data, $separator = ',', $leftBound = '(', $rightBound = ')') {
|
||||||
if (empty($data) || is_array($data)) {
|
if (empty($data)) {
|
||||||
return $data;
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$depth = 0;
|
$depth = 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue