diff options
author | Andrei Zmievski <andrei@php.net> | 2001-05-04 16:43:53 +0000 |
---|---|---|
committer | Andrei Zmievski <andrei@php.net> | 2001-05-04 16:43:53 +0000 |
commit | 0eecec77735027264d79e9f55a6a802b9cc93d22 (patch) | |
tree | 9e68745e5b348bb286e134b742bff4c30675c85b /ext/pcre/php_pcre.c | |
parent | a085b708e12af1aa512831f3dbbd4842f9520bfb (diff) | |
download | php-git-0eecec77735027264d79e9f55a6a802b9cc93d22.tar.gz |
@- Fixed a bug in preg_split() that would incorrectly limit the number of
@ results when used along with PREG_SPLIT_NO_EMPTY flag. (Andrei)
- Fixed a bug in preg_split() that would incorrectly limit the number of
results when used along with PREG_SPLIT_NO_EMPTY flag. (Andrei)
- Also made limit = -1 when limit = 0, to emulate Perl.
Diffstat (limited to 'ext/pcre/php_pcre.c')
-rw-r--r-- | ext/pcre/php_pcre.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 89a55a866d..9289adc035 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -1085,6 +1085,8 @@ PHP_FUNCTION(preg_split) if (argc > 2) { convert_to_long_ex(limit); limit_val = Z_LVAL_PP(limit); + if (limit_val == 0) + limit_val = -1; if (argc > 3) { convert_to_long_ex(flags); @@ -1130,10 +1132,15 @@ PHP_FUNCTION(preg_split) if (count > 0) { match = Z_STRVAL_PP(subject) + offsets[0]; - if (!no_empty || &Z_STRVAL_PP(subject)[offsets[0]] != last_match) + if (!no_empty || &Z_STRVAL_PP(subject)[offsets[0]] != last_match) { /* Add the piece to the return value */ add_next_index_stringl(return_value, last_match, &Z_STRVAL_PP(subject)[offsets[0]]-last_match, 1); + + /* One less left to do */ + if (limit_val != -1) + limit_val--; + } last_match = &Z_STRVAL_PP(subject)[offsets[1]]; @@ -1147,10 +1154,6 @@ PHP_FUNCTION(preg_split) match_len, 1); } } - - /* One less left to do */ - if (limit_val != -1) - limit_val--; } else { /* Failed to match */ /* If we previously set PCRE_NOTEMPTY after a null match, this is not necessarily the end. We need to advance |