pollita Mon Feb 23 15:35:00 2004 EDT Modified files: /php-src/ext/standard string.c Log: Make today's changes work w/ str_ireplace() as well. http://cvs.php.net/diff.php/php-src/ext/standard/string.c?r1=1.410&r2=1.411&ty=u Index: php-src/ext/standard/string.c diff -u php-src/ext/standard/string.c:1.410 php-src/ext/standard/string.c:1.411 --- php-src/ext/standard/string.c:1.410 Mon Feb 23 15:13:14 2004 +++ php-src/ext/standard/string.c Mon Feb 23 15:34:59 2004 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: string.c,v 1.410 2004/02/23 20:13:14 pollita Exp $ */ +/* $Id: string.c,v 1.411 2004/02/23 20:34:59 pollita Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -2966,7 +2966,7 @@ char *new_str; if (needle_len < length) { - char *end, *haystack_dup, *needle_dup; + char *end, *haystack_dup = NULL, *needle_dup = NULL; char *e, *s, *p, *r; if (needle_len == str_len) { @@ -3002,14 +3002,33 @@ new_str = emalloc(length + 1); } else { int count = 0; - char *o = haystack, *endp = haystack + length; + char *o, *n, *endp; - while ((o = php_memnstr(o, needle, needle_len, endp))) { + if (case_sensitivity) { + o = haystack; + n = needle; + } else { + haystack_dup = estrndup(haystack, length); + needle_dup = estrndup(needle, needle_len); + php_strtolower(haystack_dup, length); + php_strtolower(needle_dup, needle_len); + o = haystack_dup; + n = needle_dup; + } + endp = o + length; + + while ((o = php_memnstr(o, n, needle_len, endp))) { o += needle_len; count++; } if (count == 0) { /* Needle doesn't occur, shortcircuit the actual replacement. */ + if (haystack_dup) { + efree(haystack_dup); + } + if (needle_dup) { + efree(needle_dup); + } new_str = estrndup(haystack, length); if (_new_length) { *_new_length = length; @@ -3039,11 +3058,6 @@ e += end - p; } } else { - haystack_dup = estrndup(haystack, length); - needle_dup = estrndup(needle, needle_len); - php_strtolower(haystack_dup, length); - php_strtolower(needle_dup, needle_len); - end = haystack_dup + length; for (p = haystack_dup; (r = php_memnstr(p, needle_dup, needle_len, end)); p = r + needle_len) { @@ -3060,7 +3074,12 @@ memcpy(e, haystack + (p - haystack_dup), end - p); e += end - p; } + } + + if (haystack_dup) { efree(haystack_dup); + } + if (needle_dup) { efree(needle_dup); }
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php