Commit: 352a1956b60059f9792cac840d57b184c7305667 Author: Lars Strojny <lstro...@php.net> Sun, 2 Sep 2012 14:52:05 +0200 Parents: 32a97dfae6ad7cec85cf88feb45c3547e7a47176 Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=352a1956b60059f9792cac840d57b184c7305667 Log: Allow null as a default value for length in mb_substr() and mb_strcut() Changed paths: M ext/mbstring/mbstring.c A ext/mbstring/tests/mb_str_functions_opt-parameter.phpt Diff: diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 47f5fa4..0861fa6 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -2715,9 +2715,10 @@ PHP_FUNCTION(mb_substr) char *str, *encoding; long from, len; int mblen, str_len, encoding_len; + zval **z_len = NULL; mbfl_string string, result, *ret; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|ls", &str, &str_len, &from, &len, &encoding, &encoding_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|Zs", &str, &str_len, &from, &z_len, &encoding, &encoding_len) == FAILURE) { return; } @@ -2736,8 +2737,11 @@ PHP_FUNCTION(mb_substr) string.val = (unsigned char *)str; string.len = str_len; - if (argc < 3) { + if (argc < 3 || Z_TYPE_PP(z_len) == IS_NULL) { len = str_len; + } else { + convert_to_long_ex(z_len); + len = Z_LVAL_PP(z_len); } /* measures length */ @@ -2788,13 +2792,14 @@ PHP_FUNCTION(mb_strcut) char *encoding; long from, len; int encoding_len; + zval **z_len = NULL; mbfl_string string, result, *ret; mbfl_string_init(&string); string.no_language = MBSTRG(language); string.no_encoding = MBSTRG(current_internal_encoding)->no_encoding; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|ls", (char **)&string.val, (int **)&string.len, &from, &len, &encoding, &encoding_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|Zs", (char **)&string.val, (int **)&string.len, &from, &z_len, &encoding, &encoding_len) == FAILURE) { return; } @@ -2806,8 +2811,11 @@ PHP_FUNCTION(mb_strcut) } } - if (argc < 3) { + if (argc < 3 || Z_TYPE_PP(z_len) == IS_NULL) { len = string.len; + } else { + convert_to_long_ex(z_len); + len = Z_LVAL_PP(z_len); } /* if "from" position is negative, count start position from the end diff --git a/ext/mbstring/tests/mb_str_functions_opt-parameter.phpt b/ext/mbstring/tests/mb_str_functions_opt-parameter.phpt new file mode 100644 index 0000000..5fb642f --- /dev/null +++ b/ext/mbstring/tests/mb_str_functions_opt-parameter.phpt @@ -0,0 +1,30 @@ +--TEST-- +Optional long parameter might be null +--FILE-- +<?php +echo mb_strpos('abb', 'b', null, 'UTF-8') . "\n"; +echo mb_strrpos('abb', 'b', null, 'UTF-8') . "\n"; +echo mb_stripos('abb', 'B', null, 'UTF-8') . "\n"; +echo mb_strripos('abb', 'B', null, 'UTF-8') . "\n"; +echo mb_strstr('foobarbaz', 'ba', null, 'UTF-8') . "\n"; +echo mb_strrchr('foobarbaz', 'ba', null, 'UTF-8') . "\n"; +echo mb_stristr('foobarbaz', 'BA', null, 'UTF-8') . "\n"; +echo mb_strrichr('foobarbaz', 'BA', null, 'UTF-8') . "\n"; +echo mb_substr('foobarbaz', 6, null, 'UTF-8') . "\n"; +echo mb_strcut('foobarbaz', 6, null, 'UTF-8') . "\n"; +echo mb_strimwidth('foobar', 0, 3, null, 'UTF-8') . "\n"; +?> +==DONE== +--EXPECT-- +1 +2 +1 +2 +barbaz +baz +barbaz +baz +baz +baz +foo +==DONE== -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php