1
0
mirror of https://github.com/php/php-src.git synced 2026-03-26 17:22:15 +01:00

MFH: New parameter 'before_needle'

This commit is contained in:
Felipe Pena
2008-02-01 12:28:44 +00:00
parent 79da75ced0
commit 79cfa91a43
2 changed files with 22 additions and 10 deletions

View File

@@ -2536,15 +2536,17 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_pathinfo, 0, 0, 1)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO(arginfo_stristr, 0)
ZEND_BEGIN_ARG_INFO_EX(arginfo_stristr, 0, 0, 2)
ZEND_ARG_INFO(0, haystack)
ZEND_ARG_INFO(0, needle)
ZEND_ARG_INFO(0, part)
ZEND_END_ARG_INFO()
static
ZEND_BEGIN_ARG_INFO(arginfo_strstr, 0)
ZEND_BEGIN_ARG_INFO_EX(arginfo_strstr, 0, 0, 2)
ZEND_ARG_INFO(0, haystack)
ZEND_ARG_INFO(0, needle)
ZEND_ARG_INFO(0, part)
ZEND_END_ARG_INFO()
static

View File

@@ -1687,7 +1687,7 @@ PHPAPI size_t php_strcspn(char *s1, char *s2, char *s1_end, char *s2_end)
}
/* }}} */
/* {{{ proto string stristr(string haystack, string needle)
/* {{{ proto string stristr(string haystack, string needle[, bool part])
Finds first occurrence of a string within another, case insensitive */
PHP_FUNCTION(stristr)
{
@@ -1696,9 +1696,10 @@ PHP_FUNCTION(stristr)
int found_offset;
char *haystack_orig;
char needle_char[2];
zend_bool part = 0;
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &haystack, &needle) == FAILURE) {
WRONG_PARAM_COUNT;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ZZ|b", &haystack, &needle, &part) == FAILURE) {
return;
}
SEPARATE_ZVAL(haystack);
@@ -1732,7 +1733,11 @@ PHP_FUNCTION(stristr)
if (found) {
found_offset = found - Z_STRVAL_PP(haystack);
RETVAL_STRINGL(haystack_orig + found_offset, Z_STRLEN_PP(haystack) - found_offset, 1);
if (part) {
RETVAL_STRINGL(haystack_orig, found_offset, 1);
} else {
RETVAL_STRINGL(haystack_orig + found_offset, Z_STRLEN_PP(haystack) - found_offset, 1);
}
} else {
RETVAL_FALSE;
}
@@ -1741,7 +1746,7 @@ PHP_FUNCTION(stristr)
}
/* }}} */
/* {{{ proto string strstr(string haystack, string needle)
/* {{{ proto string strstr(string haystack, string needle[, bool part])
Finds first occurrence of a string within another */
PHP_FUNCTION(strstr)
{
@@ -1749,9 +1754,10 @@ PHP_FUNCTION(strstr)
char *found = NULL;
char needle_char[2];
long found_offset;
zend_bool part = 0;
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &haystack, &needle) == FAILURE) {
WRONG_PARAM_COUNT;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ZZ|b", &haystack, &needle, &part) == FAILURE) {
return;
}
convert_to_string_ex(haystack);
@@ -1779,7 +1785,11 @@ PHP_FUNCTION(strstr)
if (found) {
found_offset = found - Z_STRVAL_PP(haystack);
RETURN_STRINGL(found, Z_STRLEN_PP(haystack) - found_offset, 1);
if (part) {
RETURN_STRINGL(Z_STRVAL_PP(haystack), found_offset, 1);
} else {
RETURN_STRINGL(found, Z_STRLEN_PP(haystack) - found_offset, 1);
}
} else {
RETURN_FALSE;
}