diff options
| author | Andrei Zmievski <andrei@php.net> | 2001-11-10 23:50:53 +0000 |
|---|---|---|
| committer | Andrei Zmievski <andrei@php.net> | 2001-11-10 23:50:53 +0000 |
| commit | 896e2e810d46192c94a0862d4faeb5b407a99f8d (patch) | |
| tree | 11be4fb28fbb42c55ba829b5b99a71dc1ce2c9ea /ext | |
| parent | 1a3f3309a5f3ab772ccb77153a9c581d165d96f1 (diff) | |
| download | php-git-896e2e810d46192c94a0862d4faeb5b407a99f8d.tar.gz | |
MFH
Diffstat (limited to 'ext')
| -rw-r--r-- | ext/pcre/php_pcre.c | 26 | ||||
| -rw-r--r-- | ext/standard/string.c | 20 |
2 files changed, 31 insertions, 15 deletions
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index e8e461951e..1cff51f28c 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -385,7 +385,8 @@ static void php_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) } /* Calculate the size of the offsets array, and allocate memory for it. */ - num_subpats = pcre_info(re, NULL, NULL) + 1; + pcre_fullinfo(re, extra, PCRE_INFO_CAPTURECOUNT, &num_subpats); + num_subpats++; size_offsets = num_subpats * 3; offsets = (int *)emalloc(size_offsets * sizeof(int)); @@ -434,29 +435,38 @@ static void php_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) if (global) { /* global pattern matching */ if (subpats_order_val == PREG_PATTERN_ORDER) { - /* For each subpattern, insert it into the appropriate array */ - for (i=0; i<count; i++) { + /* For each subpattern, insert it into the appropriate array. */ + for (i = 0; i < count; i++) { add_next_index_string(match_sets[i], (char *)stringlist[i], 1); } - } - else { + /* + * If the number of captured subpatterns on this run is + * less than the total possible number, pad the result + * arrays with empty strings. + */ + if (count < num_subpats) { + for (; i < num_subpats; i++) { + add_next_index_string(match_sets[i], empty_string, 1); + } + } + } else { /* Allocate the result set array */ ALLOC_ZVAL(result_set); array_init(result_set); INIT_PZVAL(result_set); /* Add all the subpatterns to it */ - for (i=0; i<count; i++) { + for (i = 0; i < count; i++) { add_next_index_string(result_set, (char *)stringlist[i], 1); } /* And add it to the output array */ zend_hash_next_index_insert(Z_ARRVAL_PP(subpats), &result_set, - sizeof(zval *), NULL); + sizeof(zval *), NULL); } } else { /* single pattern matching */ /* For each subpattern, insert it into the subpatterns array. */ - for (i=0; i<count; i++) { + for (i = 0; i < count; i++) { add_next_index_string((*subpats), (char *)stringlist[i], 1); } } diff --git a/ext/standard/string.c b/ext/standard/string.c index 9ef011d51e..74f48839ff 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -2628,6 +2628,7 @@ static void php_str_replace_in_subject(zval *search, zval *replace, zval **subje /* Duplicate subject string for repeated replacement */ *result = **subject; zval_copy_ctor(result); + INIT_PZVAL(result); zend_hash_internal_pointer_reset(Z_ARRVAL_P(search)); @@ -2676,14 +2677,18 @@ static void php_str_replace_in_subject(zval *search, zval *replace, zval **subje &temp_result); } else if (Z_STRLEN_PP(search_entry) > 1) { Z_STRVAL(temp_result) = str_to_str(Z_STRVAL_P(result), Z_STRLEN_P(result), - Z_STRVAL_PP(search_entry), Z_STRLEN_PP(search_entry), - replace_value, replace_len, &Z_STRLEN(temp_result)); + Z_STRVAL_PP(search_entry), Z_STRLEN_PP(search_entry), + replace_value, replace_len, &Z_STRLEN(temp_result)); } efree(Z_STRVAL_P(result)); Z_STRVAL_P(result) = Z_STRVAL(temp_result); Z_STRLEN_P(result) = Z_STRLEN(temp_result); + if (Z_STRLEN_P(result) == 0) { + return; + } + zend_hash_move_forward(Z_ARRVAL_P(search)); } } else { @@ -2696,11 +2701,12 @@ static void php_str_replace_in_subject(zval *search, zval *replace, zval **subje result); } else if (Z_STRLEN_P(search) > 1) { Z_STRVAL_P(result) = str_to_str(Z_STRVAL_PP(subject), Z_STRLEN_PP(subject), - Z_STRVAL_P(search), Z_STRLEN_P(search), - Z_STRVAL_P(replace), Z_STRLEN_P(replace), &Z_STRLEN_P(result)); + Z_STRVAL_P(search), Z_STRLEN_P(search), + Z_STRVAL_P(replace), Z_STRLEN_P(replace), &Z_STRLEN_P(result)); } else { *result = **subject; zval_copy_ctor(result); + INIT_PZVAL(result); } } } @@ -2718,9 +2724,9 @@ PHP_FUNCTION(str_replace) int boyer = 0; if(ZEND_NUM_ARGS() < 3 || - ZEND_NUM_ARGS() > 4 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &search, - &replace, &subject, &pboyer) == FAILURE) { + ZEND_NUM_ARGS() > 4 || + zend_get_parameters_ex(ZEND_NUM_ARGS(), &search, + &replace, &subject, &pboyer) == FAILURE) { WRONG_PARAM_COUNT; } |
