mirror of
https://github.com/php/php-src.git
synced 2025-08-18 23:18:56 +02:00
@- Fix behaviour of strtok. Bug 13866 (jmoore)
# I have brought the behaviour of strtok into line with how the # libc strtok's behave. currently given # <string1><token><string2><token><token>string> # three recursive calls to strtok returns <string1>. <string2>, <token><string3> # it now returns <string1>, <string2>, <string3>. (there was some # debate in #php.bugs if it should return <string1>, <string2>, false, <string3> # but php's strtok now behaves the same way as the libc version.
This commit is contained in:
parent
288871505b
commit
c8896a38ae
1 changed files with 5 additions and 1 deletions
|
@ -923,6 +923,7 @@ PHP_FUNCTION(strtok)
|
||||||
char *token_end;
|
char *token_end;
|
||||||
char *p;
|
char *p;
|
||||||
char *pe;
|
char *pe;
|
||||||
|
int skipped = 0;
|
||||||
|
|
||||||
if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 ||
|
if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 ||
|
||||||
zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE)
|
zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE)
|
||||||
|
@ -963,12 +964,15 @@ PHP_FUNCTION(strtok)
|
||||||
|
|
||||||
/* Skip leading delimiters */
|
/* Skip leading delimiters */
|
||||||
while (STRTOK_TABLE(p))
|
while (STRTOK_TABLE(p))
|
||||||
|
{
|
||||||
if (++p >= pe) {
|
if (++p >= pe) {
|
||||||
/* no other chars left */
|
/* no other chars left */
|
||||||
BG(strtok_last) = NULL;
|
BG(strtok_last) = NULL;
|
||||||
RETVAL_FALSE;
|
RETVAL_FALSE;
|
||||||
goto restore;
|
goto restore;
|
||||||
}
|
}
|
||||||
|
skipped++;
|
||||||
|
}
|
||||||
|
|
||||||
/* We know at this place that *p is no delimiter, so skip it */
|
/* We know at this place that *p is no delimiter, so skip it */
|
||||||
while (++p < pe)
|
while (++p < pe)
|
||||||
|
@ -977,7 +981,7 @@ PHP_FUNCTION(strtok)
|
||||||
|
|
||||||
if (p - BG(strtok_last)) {
|
if (p - BG(strtok_last)) {
|
||||||
return_token:
|
return_token:
|
||||||
RETVAL_STRINGL(BG(strtok_last), p - BG(strtok_last), 1);
|
RETVAL_STRINGL(BG(strtok_last) + skipped, (p - BG(strtok_last)) - skipped, 1);
|
||||||
BG(strtok_last) = p + 1;
|
BG(strtok_last) = p + 1;
|
||||||
} else {
|
} else {
|
||||||
RETVAL_FALSE;
|
RETVAL_FALSE;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue