]> granicus.if.org Git - php/commitdiff
MFH: New parameter 'before_needle'
authorFelipe Pena <felipe@php.net>
Fri, 1 Feb 2008 12:28:44 +0000 (12:28 +0000)
committerFelipe Pena <felipe@php.net>
Fri, 1 Feb 2008 12:28:44 +0000 (12:28 +0000)
ext/standard/basic_functions.c
ext/standard/string.c

index 46c073d7a4e5d2ec1e45587481026dcb3870c57f..13e822942c61aeac9eca3943b4c6b0625e57ea8f 100644 (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
index 41844a54e6e8f101a1d82e0d108de959d70830ab..5d5b963caf4897d091434b10f5796ec85702d14d 100644 (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;
        }