diff options
-rw-r--r-- | ext/standard/php_string.h | 1 | ||||
-rw-r--r-- | ext/standard/string.c | 29 |
2 files changed, 23 insertions, 7 deletions
diff --git a/ext/standard/php_string.h b/ext/standard/php_string.h index b2fad54791..be64af0d6c 100644 --- a/ext/standard/php_string.h +++ b/ext/standard/php_string.h @@ -130,6 +130,7 @@ PHPAPI char *php_str_to_str(char *haystack, int length, char *needle, int needle_len, char *str, int str_len, int *_new_length); PHPAPI char *php_trim(char *c, int len, char *what, int what_len, zval *return_value, int mode TSRMLS_DC); PHPAPI size_t php_strip_tags(char *rbuf, int len, int *state, char *allow, int allow_len); +PHPAPI int php_char_to_str_ex(char *str, uint len, char from, char *to, int to_len, pval *result, int case_sensitivity, int *replace_count); PHPAPI int php_char_to_str(char *str, uint len, char from, char *to, int to_len, pval *result); PHPAPI void php_implode(zval *delim, zval *arr, zval *return_value); PHPAPI void php_explode(zval *delim, zval *str, zval *return_value, int limit); diff --git a/ext/standard/string.c b/ext/standard/string.c index da254e5ccf..c8fc17afef 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -2854,9 +2854,9 @@ PHPAPI char *php_addslashes(char *str, int length, int *new_length, int should_f #define _isblank(c) (((((unsigned char) c) == ' ' || ((unsigned char) c) == '\t')) ? 1 : 0) #define _isnewline(c) (((((unsigned char) c) == '\n' || ((unsigned char) c) == '\r')) ? 1 : 0) -/* {{{ php_char_to_str +/* {{{ php_char_to_str_ex */ -PHPAPI int php_char_to_str(char *str, uint len, char from, char *to, int to_len, zval *result) +PHPAPI int php_char_to_str_ex(char *str, uint len, char from, char *to, int to_len, zval *result, int case_sensitivity, int *replace_count) { int char_count = 0; int replaced = 0; @@ -2878,8 +2878,11 @@ PHPAPI int php_char_to_str(char *str, uint len, char from, char *to, int to_len, Z_TYPE_P(result) = IS_STRING; for (source = str; source < source_end; source++) { - if (*source == from) { + if ((case_sensitivity && *source == from) || (!case_sensitivity && tolower(*source) == tolower(from))) { replaced = 1; + if (replace_count) { + *replace_count += 1; + } for (tmp = to, tmp_end = tmp+to_len; tmp < tmp_end; tmp++) { *target = *tmp; target++; @@ -2894,6 +2897,14 @@ PHPAPI int php_char_to_str(char *str, uint len, char from, char *to, int to_len, } /* }}} */ +/* {{{ php_char_to_str + */ +PHPAPI int php_char_to_str(char *str, uint len, char from, char *to, int to_len, zval *result) +{ + return php_char_to_str_ex(str, len, from, to, to_len, result, 1, NULL); +} +/* }}} */ + /* {{{ php_str_to_str_ex */ PHPAPI char *php_str_to_str_ex(char *haystack, int length, @@ -3089,12 +3100,14 @@ static void php_str_replace_in_subject(zval *search, zval *replace, zval **subje } if (Z_STRLEN_PP(search_entry) == 1) { - php_char_to_str(Z_STRVAL_P(result), + php_char_to_str_ex(Z_STRVAL_P(result), Z_STRLEN_P(result), Z_STRVAL_PP(search_entry)[0], replace_value, replace_len, - &temp_result); + &temp_result, + case_sensitivity, + replace_count); } else if (Z_STRLEN_PP(search_entry) > 1) { Z_STRVAL(temp_result) = php_str_to_str_ex(Z_STRVAL_P(result), Z_STRLEN_P(result), Z_STRVAL_PP(search_entry), Z_STRLEN_PP(search_entry), @@ -3113,12 +3126,14 @@ static void php_str_replace_in_subject(zval *search, zval *replace, zval **subje } } else { if (Z_STRLEN_P(search) == 1) { - php_char_to_str(Z_STRVAL_PP(subject), + php_char_to_str_ex(Z_STRVAL_PP(subject), Z_STRLEN_PP(subject), Z_STRVAL_P(search)[0], Z_STRVAL_P(replace), Z_STRLEN_P(replace), - result); + result, + case_sensitivity, + replace_count); } else if (Z_STRLEN_P(search) > 1) { Z_STRVAL_P(result) = php_str_to_str_ex(Z_STRVAL_PP(subject), Z_STRLEN_PP(subject), Z_STRVAL_P(search), Z_STRLEN_P(search), |