pollita Thu Jul 24 21:03:39 2003 EDT Modified files: /php-src/ext/standard php_string.h string.c Log: Fix Bug#24784 single character search keys not respecting case sensitivity/replace count parameters. Index: php-src/ext/standard/php_string.h diff -u php-src/ext/standard/php_string.h:1.78 php-src/ext/standard/php_string.h:1.79 --- php-src/ext/standard/php_string.h:1.78 Tue Jun 10 16:03:38 2003 +++ php-src/ext/standard/php_string.h Thu Jul 24 21:03:39 2003 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_string.h,v 1.78 2003/06/10 20:03:38 imajes Exp $ */ +/* $Id: php_string.h,v 1.79 2003/07/25 01:03:39 pollita Exp $ */ /* Synced with php 3.0 revision 1.43 1999-06-16 [ssb] */ @@ -130,6 +130,7 @@ 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); Index: php-src/ext/standard/string.c diff -u php-src/ext/standard/string.c:1.393 php-src/ext/standard/string.c:1.394 --- php-src/ext/standard/string.c:1.393 Sat Jul 12 05:33:31 2003 +++ php-src/ext/standard/string.c Thu Jul 24 21:03:39 2003 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: string.c,v 1.393 2003/07/12 09:33:31 moriyoshi Exp $ */ +/* $Id: string.c,v 1.394 2003/07/25 01:03:39 pollita Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -2854,9 +2854,9 @@ #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 @@ 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 @@ } /* }}} */ +/* {{{ 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 @@ } 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 @@ } } 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),
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php