[PHP-CVS] cvs: php4 /ext/standard string.c
pollita Fri Jun 20 11:41:43 2003 EDT Modified files: /php4/ext/standard string.c Log: When skipping blank searchvals we should advance the corresponding replace hash as well Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.390 php4/ext/standard/string.c:1.391 --- php4/ext/standard/string.c:1.390Tue Jun 10 22:16:19 2003 +++ php4/ext/standard/string.c Fri Jun 20 11:41:43 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.390 2003/06/11 02:16:19 iliaa Exp $ */ +/* $Id: string.c,v 1.391 2003/06/20 15:41:43 pollita Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -3063,6 +3063,9 @@ convert_to_string(*search_entry); if (Z_STRLEN_PP(search_entry) == 0) { zend_hash_move_forward(Z_ARRVAL_P(search)); + if (Z_TYPE_P(replace) == IS_ARRAY) { + zend_hash_move_forward(Z_ARRVAL_P(replace)); + } continue; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
iliaa Tue Jun 10 22:16:19 2003 EDT Modified files: /php4/ext/standard string.c Log: fixed proto Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.389 php4/ext/standard/string.c:1.390 --- php4/ext/standard/string.c:1.389Tue Jun 10 16:03:38 2003 +++ php4/ext/standard/string.c Tue Jun 10 22:16:19 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.389 2003/06/10 20:03:38 imajes Exp $ */ +/* $Id: string.c,v 1.390 2003/06/11 02:16:19 iliaa Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -4477,7 +4477,7 @@ } /* }}} */ -/* {{{ proto void str_word_count(string str, [int format]) +/* {{{ proto mixed str_word_count(string str, [int format]) Counts the number of words inside a string. If format of 1 is specified, then the function will return an array containing all the words found inside the string. If format of 2 is specified, then the function -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c /ext/standard/tests/strings strripos.phpt strrpos.phpt
pollita Sat Apr 12 16:04:06 2003 EDT Added files: /php4/ext/standard/tests/stringsstrripos.phpt strrpos.phpt Modified files: /php4/ext/standard string.c Log: Add tests for strrpos/stripos, and minor fix to maintain BC for condition with empty needles/haystacks Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.371 php4/ext/standard/string.c:1.372 --- php4/ext/standard/string.c:1.371Sat Apr 12 03:36:22 2003 +++ php4/ext/standard/string.c Sat Apr 12 16:04:06 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.371 2003/04/12 07:36:22 pollita Exp $ */ +/* $Id: string.c,v 1.372 2003/04/12 20:04:06 pollita Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -1579,6 +1579,10 @@ RETURN_FALSE; } + if ((haystack_len == 0) || (needle_len == 0)) { + RETURN_FALSE; + } + if (offset = 0) { p = haystack + offset; e = haystack + haystack_len - needle_len; @@ -1612,6 +1616,10 @@ char *needle_dup, *haystack_dup; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ss|l, haystack, haystack_len, needle, needle_len, offset) == FAILURE) { + RETURN_FALSE; + } + + if ((haystack_len == 0) || (needle_len == 0)) { RETURN_FALSE; } Index: php4/ext/standard/tests/strings/strripos.phpt +++ php4/ext/standard/tests/strings/strripos.phpt --TEST-- strripos() function --POST-- --GET-- --FILE-- ?php var_dump(strripos(test test string, test)); var_dump(strripos(test string sTring, string)); var_dump(strripos(test strip string strand, str)); var_dump(strripos(I am what I am and that's all what I am, am, -3)); var_dump(strripos(test string, g)); var_dump(strripos(te.chr(0).st, chr(0))); var_dump(strripos(tEst, test)); var_dump(strripos(teSt, test)); var_dump(@strripos(foo, f, 1)); var_dump(@strripos(, )); var_dump(@strripos(a, )); var_dump(@strripos(, a)); var_dump(@strripos(a, \\a)); ? --EXPECT-- int(5) int(12) int(18) int(12) int(10) int(2) int(0) int(0) bool(false) bool(false) bool(false) bool(false) int(1) Index: php4/ext/standard/tests/strings/strrpos.phpt +++ php4/ext/standard/tests/strings/strrpos.phpt --TEST-- strrpos() function --POST-- --GET-- --FILE-- ?php var_dump(strrpos(test test string, test)); var_dump(strrpos(test string sTring, string)); var_dump(strrpos(test strip string strand, str)); var_dump(strrpos(I am what I am and that's all what I am, am, -3)); var_dump(strrpos(test string, g)); var_dump(strrpos(te.chr(0).st, chr(0))); var_dump(strrpos(tEst, test)); var_dump(strrpos(teSt, test)); var_dump(@strrpos(foo, f, 1)); var_dump(@strrpos(, )); var_dump(@strrpos(a, )); var_dump(@strrpos(, a)); var_dump(@strrpos(a, \\a)); ? --EXPECT-- int(5) int(5) int(18) int(12) int(10) int(2) bool(false) bool(false) bool(false) bool(false) bool(false) bool(false) int(1) -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
rasmus Wed Apr 2 16:33:03 2003 EDT Modified files: /php4/ext/standard string.c Log: MFB: Fix the setlocale() segfault Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.368 php4/ext/standard/string.c:1.369 --- php4/ext/standard/string.c:1.368Tue Apr 1 19:25:45 2003 +++ php4/ext/standard/string.c Wed Apr 2 16:33:02 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.368 2003/04/02 00:25:45 iliaa Exp $ */ +/* $Id: string.c,v 1.369 2003/04/02 21:33:02 rasmus Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -3377,6 +3377,7 @@ } while (1) { if (Z_TYPE_PP(args[1]) == IS_ARRAY) { + if(!zend_hash_num_elements(Z_ARRVAL_PP(args[1]))) break; zend_hash_get_current_data(Z_ARRVAL_PP(args[1]),(void **)plocale); } else { plocale = args[i]; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
derick Thu Apr 3 01:21:59 2003 EDT Modified files: /php4/ext/standard string.c Log: - CS Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.369 php4/ext/standard/string.c:1.370 --- php4/ext/standard/string.c:1.369Wed Apr 2 16:33:02 2003 +++ php4/ext/standard/string.c Thu Apr 3 01:21:59 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.369 2003/04/02 21:33:02 rasmus Exp $ */ +/* $Id: string.c,v 1.370 2003/04/03 06:21:59 derick Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -3377,7 +3377,9 @@ } while (1) { if (Z_TYPE_PP(args[1]) == IS_ARRAY) { - if(!zend_hash_num_elements(Z_ARRVAL_PP(args[1]))) break; + if (!zend_hash_num_elements(Z_ARRVAL_PP(args[1]))) { + break; + } zend_hash_get_current_data(Z_ARRVAL_PP(args[1]),(void **)plocale); } else { plocale = args[i]; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
momoTue Apr 1 07:46:02 2003 EDT Modified files: /php4/ext/standard string.c Log: revert last commit for now Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.366 php4/ext/standard/string.c:1.367 --- php4/ext/standard/string.c:1.366Mon Mar 31 13:56:41 2003 +++ php4/ext/standard/string.c Tue Apr 1 07:46:01 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.366 2003/03/31 18:56:41 momo Exp $ */ +/* $Id: string.c,v 1.367 2003/04/01 12:46:01 momo Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -2331,14 +2331,9 @@ l--; } *s++ = *t++; - } else if (*t == '\\' l 0) { - if(t[1] == '0') { - *s++='\0'; - t++; - } else { - *s++=*(++t); - } - t++; + } else if (*t == '\\' t[1] == '0' l 0) { + *s++='\0'; + t+=2; if (len != NULL) { (*len)--; } @@ -2632,10 +2627,6 @@ case '\'': *target++ = '\''; *target++ = '\''; - break; - case '\\': - *target++ = '\\'; - *target++ = '\\'; break; default: *target++ = *source; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
iliaa Tue Apr 1 19:25:46 2003 EDT Modified files: /php4/ext/standard string.c Log: Fixed possible integer overflow in str_repeat(). Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.367 php4/ext/standard/string.c:1.368 --- php4/ext/standard/string.c:1.367Tue Apr 1 07:46:01 2003 +++ php4/ext/standard/string.c Tue Apr 1 19:25:45 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.367 2003/04/01 12:46:01 momo Exp $ */ +/* $Id: string.c,v 1.368 2003/04/02 00:25:45 iliaa Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -3787,6 +3787,10 @@ /* Initialize the result string */ result_len = Z_STRLEN_PP(input_str) * Z_LVAL_PP(mult); + if (result_len 1 || result_len 2147483647) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, You may not create strings longer then 2147483647 bytes); + RETURN_FALSE; + } result = (char *)emalloc(result_len + 1); /* Heavy optimization for situations where input string is 1 byte long */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/standard string.c
Please, don't use that @ sign in commit messages...or at least TRY to write something that really means something after it. (Read the NEWS file sometime to see how these should look like..) --Jani On Mon, 31 Mar 2003, Moshe Doron wrote: momo Mon Mar 31 13:56:41 2003 EDT Modified files: /php4/ext/standard string.c Log: fix for 22904 @ now addslashes() do it also on cybase magic mode(moshe). Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.365 php4/ext/standard/string.c:1.366 --- php4/ext/standard/string.c:1.365 Mon Mar 31 07:08:31 2003 +++ php4/ext/standard/string.c Mon Mar 31 13:56:41 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.365 2003/03/31 12:08:31 momo Exp $ */ +/* $Id: string.c,v 1.366 2003/03/31 18:56:41 momo Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -2331,13 +2331,18 @@ l--; } *s++ = *t++; - } else if (*t == '\\' l 0 t[1] == '0') { + } else if (*t == '\\' l 0) { + if(t[1] == '0') { *s++='\0'; - t += 2; - if (len != NULL) { - (*len)--; - } - l--; + t++; + } else { + *s++=*(++t); + } + t++; + if (len != NULL) { + (*len)--; + } + l--; } else { *s++ = *t++; } @@ -2627,6 +2632,10 @@ case '\'': *target++ = '\''; *target++ = '\''; + break; + case '\\': + *target++ = '\\'; + *target++ = '\\'; break; default: *target++ = *source; -- - For Sale! - -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
momoMon Mar 31 13:56:41 2003 EDT Modified files: /php4/ext/standard string.c Log: fix for 22904 @ now addslashes() do it also on cybase magic mode(moshe). Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.365 php4/ext/standard/string.c:1.366 --- php4/ext/standard/string.c:1.365Mon Mar 31 07:08:31 2003 +++ php4/ext/standard/string.c Mon Mar 31 13:56:41 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.365 2003/03/31 12:08:31 momo Exp $ */ +/* $Id: string.c,v 1.366 2003/03/31 18:56:41 momo Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -2331,13 +2331,18 @@ l--; } *s++ = *t++; - } else if (*t == '\\' l 0 t[1] == '0') { + } else if (*t == '\\' l 0) { + if(t[1] == '0') { *s++='\0'; - t += 2; - if (len != NULL) { - (*len)--; - } - l--; + t++; + } else { + *s++=*(++t); + } + t++; + if (len != NULL) { + (*len)--; + } + l--; } else { *s++ = *t++; } @@ -2627,6 +2632,10 @@ case '\'': *target++ = '\''; *target++ = '\''; + break; + case '\\': + *target++ = '\\'; + *target++ = '\\'; break; default: *target++ = *source; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/standard string.c
On Mon, 31 Mar 2003, Moshe Doron wrote: momo Mon Mar 31 13:56:41 2003 EDT Modified files: /php4/ext/standardstring.c Log: fix for 22904 @ now addslashes() do it also on cybase magic mode(moshe). Please add tests for this too! Derick -- my other box is your windows PC - Derick Rethans http://derickrethans.nl/ PHP Magazine - PHP Magazine for Professionals http://php-mag.net/ - -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
derick Sat Mar 8 19:05:49 2003 EDT Modified files: /php4/ext/standard string.c Log: - Fix proto Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.362 php4/ext/standard/string.c:1.363 --- php4/ext/standard/string.c:1.362Thu Mar 6 18:07:27 2003 +++ php4/ext/standard/string.c Sat Mar 8 19:05:48 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.362 2003/03/06 23:07:27 ddhill Exp $ */ +/* $Id: string.c,v 1.363 2003/03/09 00:05:48 derick Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -623,7 +623,7 @@ } /* }}} */ -/* {{{ proto string wordwrap(string str [, int width [, string break [, int cut]]]) +/* {{{ proto string wordwrap(string str [, int width [, string break [, boolean cut]]]) Wraps buffer to selected number of characters using string break char */ PHP_FUNCTION(wordwrap) { -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
moriyoshi Mon Feb 24 17:19:37 2003 EDT Modified files: /php4/ext/standard string.c Log: Fixed possible buffer overflow of php_strip_tags Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.360 php4/ext/standard/string.c:1.361 --- php4/ext/standard/string.c:1.360Mon Feb 24 17:01:12 2003 +++ php4/ext/standard/string.c Mon Feb 24 17:19:36 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.360 2003/02/24 22:01:12 moriyoshi Exp $ */ +/* $Id: string.c,v 1.361 2003/02/24 22:19:36 moriyoshi Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -3746,7 +3746,9 @@ c = *(++p); i++; } - *rp = '\0'; + if (rp rbuf + len) { + *rp = '\0'; + } efree(buf); if (allow) efree(tbuf); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
moriyoshi Tue Feb 18 13:11:35 2003 EDT Modified files: /php4/ext/standard string.c Log: Fixed bug #21708 (ucfirst() trouble again) # this bug is related to bug #21689 Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.358 php4/ext/standard/string.c:1.359 --- php4/ext/standard/string.c:1.358Fri Feb 14 13:59:50 2003 +++ php4/ext/standard/string.c Tue Feb 18 13:11:34 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.358 2003/02/14 18:59:50 moriyoshi Exp $ */ +/* $Id: string.c,v 1.359 2003/02/18 18:11:34 moriyoshi Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -2019,7 +2019,7 @@ *r = toupper((unsigned char) *r); for (r_end = r + Z_STRLEN_P(return_value) - 1; r r_end; ) { - if (isspace((int) *r++)) { + if (isspace((int) *(unsigned char *)r++)) { *r = toupper((unsigned char) *r); } } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c /ext/standard/tests/strings bug22224.phpt
moriyoshi Fri Feb 14 13:42:36 2003 EDT Added files: /php4/ext/standard/tests/stringsbug4.phpt Modified files: /php4/ext/standard string.c Log: Fixed bug #4 (implode changes object references in array) Added test case for the bug Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.356 php4/ext/standard/string.c:1.357 --- php4/ext/standard/string.c:1.356Tue Feb 11 17:47:25 2003 +++ php4/ext/standard/string.c Fri Feb 14 13:42:36 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.356 2003/02/11 22:47:25 iliaa Exp $ */ +/* $Id: string.c,v 1.357 2003/02/14 18:42:36 moriyoshi Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -835,7 +835,8 @@ zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), pos); while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **) tmp, pos) == SUCCESS) { - convert_to_string_ex(tmp); + SEPARATE_ZVAL(tmp); + convert_to_string(*tmp); smart_str_appendl(implstr, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); if (++i != numelems) { Index: php4/ext/standard/tests/strings/bug4.phpt +++ php4/ext/standard/tests/strings/bug4.phpt --TEST-- Bug #4 (implode changes object references in array) --INI-- error_reporting=0 --FILE-- ?php class foo { } $a = new foo(); $arr = array(0=$a, 1=$a); var_dump(implode(,,$arr)); var_dump($arr) ? --EXPECT-- string(13) Object,Object array(2) { [0]= object(foo)(0) { } [1]= object(foo)(0) { } } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
moriyoshi Fri Feb 14 13:59:51 2003 EDT Modified files: /php4/ext/standard string.c Log: Fixed a str_replace() bug similar to bug #4 Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.357 php4/ext/standard/string.c:1.358 --- php4/ext/standard/string.c:1.357Fri Feb 14 13:42:36 2003 +++ php4/ext/standard/string.c Fri Feb 14 13:59:50 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.357 2003/02/14 18:42:36 moriyoshi Exp $ */ +/* $Id: string.c,v 1.358 2003/02/14 18:59:50 moriyoshi Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -2865,7 +2865,8 @@ /* For each entry in the search array, get the entry */ while (zend_hash_get_current_data(Z_ARRVAL_P(search), (void **) search_entry) == SUCCESS) { /* Make sure we're dealing with strings. */ - convert_to_string_ex(search_entry); + SEPARATE_ZVAL(search_entry); + convert_to_string(*search_entry); if (Z_STRLEN_PP(search_entry) == 0) { zend_hash_move_forward(Z_ARRVAL_P(search)); continue; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
sniper Sat Feb 8 10:26:17 2003 EDT Modified files: /php4/ext/standard string.c Log: style ws fixes Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.354 php4/ext/standard/string.c:1.355 --- php4/ext/standard/string.c:1.354Fri Feb 7 16:36:18 2003 +++ php4/ext/standard/string.c Sat Feb 8 10:26:17 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.354 2003/02/07 21:36:18 iliaa Exp $ */ +/* $Id: string.c,v 1.355 2003/02/08 15:26:17 sniper Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -828,14 +828,13 @@ numelems = zend_hash_num_elements(Z_ARRVAL_P(arr)); - if(numelems == 0) { + if (numelems == 0) { RETURN_EMPTY_STRING(); } zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), pos); - while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), -(void **) tmp, -pos) == SUCCESS) { + + while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **) tmp, pos) == +SUCCESS) { convert_to_string_ex(tmp); smart_str_appendl(implstr, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); @@ -924,44 +923,47 @@ char *pe; int skipped = 0; - if (ZEND_NUM_ARGS() 1 || ZEND_NUM_ARGS() 2 || - zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) + if (ZEND_NUM_ARGS() 1 || ZEND_NUM_ARGS() 2 || +zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { WRONG_PARAM_COUNT; - - switch (ZEND_NUM_ARGS()) { - case 1: - tok = args[0]; - break; - default: - case 2: - str = args[0]; - tok = args[1]; - convert_to_string_ex(str); - - zval_add_ref(str); - if (BG(strtok_zval)) - zval_ptr_dtor(BG(strtok_zval)); - BG(strtok_zval) = *str; + } - BG(strtok_last) = BG(strtok_string) = Z_STRVAL_PP(str); - BG(strtok_len) = Z_STRLEN_PP(str); - break; + switch (ZEND_NUM_ARGS()) { + case 1: + tok = args[0]; + break; + + default: + case 2: + str = args[0]; + tok = args[1]; + convert_to_string_ex(str); + + zval_add_ref(str); + if (BG(strtok_zval)) { + zval_ptr_dtor(BG(strtok_zval)); + } + BG(strtok_zval) = *str; + BG(strtok_last) = BG(strtok_string) = Z_STRVAL_PP(str); + BG(strtok_len) = Z_STRLEN_PP(str); + break; } p = BG(strtok_last); /* Where we start to search */ pe = BG(strtok_string) + BG(strtok_len); - if (!p || p = pe) + if (!p || p = pe) { RETURN_FALSE; + } convert_to_string_ex(tok); token = Z_STRVAL_PP(tok); token_end = token + Z_STRLEN_PP(tok); - while (token token_end) + while (token token_end) { STRTOK_TABLE(token++) = 1; - + } + /* Skip leading delimiters */ while (STRTOK_TABLE(p)) { if (++p = pe) { @@ -974,10 +976,12 @@ } /* We know at this place that *p is no delimiter, so skip it */ - while (++p pe) - if (STRTOK_TABLE(p)) + while (++p pe) { + if (STRTOK_TABLE(p)) { goto return_token; - + } + } + if (p - BG(strtok_last)) { return_token: RETVAL_STRINGL(BG(strtok_last) + skipped, (p - BG(strtok_last)) - skipped, 1); @@ -987,13 +991,13 @@ BG(strtok_last) = NULL; } - /* Restore table -- usually faster then memset'ing the table - on every invocation */ + /* Restore table -- usually faster then memset'ing the table on every +invocation */ restore: token = Z_STRVAL_PP(tok); - while (token token_end) + while (token token_end) { STRTOK_TABLE(token++) = 0; + } } /* }}} */ @@ -1083,14 +1087,15 @@ } } - /* strip trailing slashes */ while (*c == '/' #ifdef PHP_WIN32 || (*c == '\\' !IsDBCSLeadByte(*(c-1))) #endif - ) + ) { c--; + } + if (c s+len-1) { buf = *(c + 1); /* Save overwritten char */ *(c + 1) = '\0'; /*
[PHP-CVS] cvs: php4 /ext/standard string.c
pollita Thu Jan 30 15:09:20 2003 EDT Modified files: /php4/ext/standard string.c Log: Unify str_replace and str_ireplace using INTERNAL_FUNCTION_PARAM_PASSTHRU -- reduce codebase/maintenance complexity Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.352 php4/ext/standard/string.c:1.353 --- php4/ext/standard/string.c:1.352Thu Jan 30 00:00:41 2003 +++ php4/ext/standard/string.c Thu Jan 30 15:09:19 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.352 2003/01/30 05:00:41 pollita Exp $ */ +/* $Id: string.c,v 1.353 2003/01/30 20:09:19 pollita Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -2887,9 +2887,9 @@ } /* }}} */ -/* {{{ proto mixed str_replace(mixed search, mixed replace, mixed subject) - Replaces all occurrences of search in haystack with replace */ -PHP_FUNCTION(str_replace) +/* {{{ php_str_replace_common + */ +static void php_str_replace_common(INTERNAL_FUNCTION_PARAMETERS, int case_sensitivity) { zval **subject, **search, **replace, **subject_entry; zval *result; @@ -2923,7 +2923,7 @@ and add the result to the return_value array. */ while (zend_hash_get_current_data(Z_ARRVAL_PP(subject), (void **)subject_entry) == SUCCESS) { MAKE_STD_ZVAL(result); - php_str_replace_in_subject(*search, *replace, subject_entry, result, 1); + php_str_replace_in_subject(*search, *replace, subject_entry, +result, case_sensitivity); /* Add to return array */ switch (zend_hash_get_current_key_ex(Z_ARRVAL_PP(subject), string_key, string_key_len, num_key, 0, NULL)) { @@ -2939,65 +2939,24 @@ zend_hash_move_forward(Z_ARRVAL_PP(subject)); } } else {/* if subject is not an array */ - php_str_replace_in_subject(*search, *replace, subject, return_value, 1); + php_str_replace_in_subject(*search, *replace, subject, return_value, +case_sensitivity); } } /* }}} */ +/* {{{ proto mixed str_replace(mixed search, mixed replace, mixed subject) + Replaces all occurrences of search in haystack with replace */ +PHP_FUNCTION(str_replace) +{ + php_str_replace_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); +} +/* }}} */ + /* {{{ proto mixed str_ireplace(mixed search, mixed replace, mixed subject) Replaces all occurrences of search in haystack with replace / case-insensitive */ PHP_FUNCTION(str_ireplace) { - zval **subject, **search, **replace, **subject_entry; - zval *result; - char *string_key; - uint string_key_len; - ulong num_key; - - if (ZEND_NUM_ARGS() != 3 || - zend_get_parameters_ex(3, search, replace, subject) == FAILURE) { - WRONG_PARAM_COUNT; - } - - SEPARATE_ZVAL(search); - SEPARATE_ZVAL(replace); - SEPARATE_ZVAL(subject); - - /* Make sure we're dealing with strings and do the replacement. */ - if (Z_TYPE_PP(search) != IS_ARRAY) { - convert_to_string_ex(search); - convert_to_string_ex(replace); - } else if (Z_TYPE_PP(replace) != IS_ARRAY) { - convert_to_string_ex(replace); - } - - /* if subject is an array */ - if (Z_TYPE_PP(subject) == IS_ARRAY) { - array_init(return_value); - zend_hash_internal_pointer_reset(Z_ARRVAL_PP(subject)); - - /* For each subject entry, convert it to string, then perform replacement - and add the result to the return_value array. */ - while (zend_hash_get_current_data(Z_ARRVAL_PP(subject), (void **)subject_entry) == SUCCESS) { - MAKE_STD_ZVAL(result); - php_str_replace_in_subject(*search, *replace, subject_entry, result, 0); - /* Add to return array */ - switch (zend_hash_get_current_key_ex(Z_ARRVAL_PP(subject), string_key, - string_key_len, num_key, 0, NULL)) { - case HASH_KEY_IS_STRING: - add_assoc_zval_ex(return_value, string_key, string_key_len, result); - break; - - case HASH_KEY_IS_LONG: - add_index_zval(return_value, num_key, result); - break; - } - - zend_hash_move_forward(Z_ARRVAL_PP(subject)); - } - } else {/* if subject is not an
Re: [PHP-CVS] cvs: php4 /ext/standard string.c
MFH?? --Jani On Fri, 24 Jan 2003, Andrey Hristov wrote: andrey Fri Jan 24 08:18:09 2003 EDT Modified files: /php4/ext/standard string.c Log: Resolving problem on OSF1 and probably other 64 bit platforms. Thanks for the feedback of Magnus (novell kiruna se). Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.350 php4/ext/standard/string.c:1.351 --- php4/ext/standard/string.c:1.350 Fri Jan 24 07:19:59 2003 +++ php4/ext/standard/string.c Fri Jan 24 08:18:08 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.350 2003/01/24 12:19:59 andrey Exp $ */ +/* $Id: string.c,v 1.351 2003/01/24 13:18:08 andrey Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -199,7 +199,7 @@ static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) { char *s11, *s22; - long len1, len2, start, len; + int len1, len2, start, len; start = 0; len = 0; -- - For Sale! - -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
andrey Fri Jan 24 07:20:00 2003 EDT Modified files: /php4/ext/standard string.c Log: Adding cast. Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.349 php4/ext/standard/string.c:1.350 --- php4/ext/standard/string.c:1.349Tue Jan 21 09:53:17 2003 +++ php4/ext/standard/string.c Fri Jan 24 07:19:59 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.349 2003/01/21 14:53:17 iliaa Exp $ */ +/* $Id: string.c,v 1.350 2003/01/24 12:19:59 andrey Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -4190,7 +4190,7 @@ *return_value = **arg; zval_copy_ctor(return_value); if (Z_STRLEN_P(return_value) 1) { - php_string_shuffle(Z_STRVAL_P(return_value), Z_STRLEN_P(return_value) TSRMLS_CC); + php_string_shuffle(Z_STRVAL_P(return_value), (long) +Z_STRLEN_P(return_value) TSRMLS_CC); } } /* }}} */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
andrey Fri Jan 24 08:18:09 2003 EDT Modified files: /php4/ext/standard string.c Log: Resolving problem on OSF1 and probably other 64 bit platforms. Thanks for the feedback of Magnus (novell kiruna se). Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.350 php4/ext/standard/string.c:1.351 --- php4/ext/standard/string.c:1.350Fri Jan 24 07:19:59 2003 +++ php4/ext/standard/string.c Fri Jan 24 08:18:08 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.350 2003/01/24 12:19:59 andrey Exp $ */ +/* $Id: string.c,v 1.351 2003/01/24 13:18:08 andrey Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -199,7 +199,7 @@ static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) { char *s11, *s22; - long len1, len2, start, len; + int len1, len2, start, len; start = 0; len = 0; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c /ext/standard/tests/strings bug21744.phpt
moriyoshi Sun Jan 19 06:32:55 2003 EDT Added files: /php4/ext/standard/tests/stringsbug21744.phpt Modified files: /php4/ext/standard string.c Log: Fixed bug #21744(21741) Added test case for the bug Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.347 php4/ext/standard/string.c:1.348 --- php4/ext/standard/string.c:1.347Sat Jan 18 15:01:46 2003 +++ php4/ext/standard/string.c Sun Jan 19 06:32:54 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.347 2003/01/18 20:01:46 iliaa Exp $ */ +/* $Id: string.c,v 1.348 2003/01/19 11:32:54 moriyoshi Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -3630,8 +3630,16 @@ state = 3; lc = c; } else { - *(rp++) = c; - } + if (state == 0) { + *(rp++) = c; + } else if (allow state == 1) { + *(tp++) = c; + if ( (tp-tbuf) = PHP_TAG_BUF_SIZE ) { + /* prevent buffer overflows */ + tp = tbuf; + } + } + } break; case '?': Index: php4/ext/standard/tests/strings/bug21744.phpt +++ php4/ext/standard/tests/strings/bug21744.phpt --TEST-- Bug #21744 (strip_tags misses exclamation marks in alt text) --FILE-- ?php $test = HERE a href=test?test\\!!!testtest/a !-- test -- HERE; print strip_tags($test, ''); print strip_tags($test, 'a'); ? --EXPECT-- test a href=test?test\!!!testtest/a -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
iliaa Sat Jan 11 12:52:39 2003 EDT Modified files: /php4/ext/standard string.c Log: Added stripos() strripos() functions. Added 3rd parameter (offset) to strrpos(). Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.343 php4/ext/standard/string.c:1.344 --- php4/ext/standard/string.c:1.343Mon Jan 6 17:13:03 2003 +++ php4/ext/standard/string.c Sat Jan 11 12:52:38 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.343 2003/01/06 22:13:03 iliaa Exp $ */ +/* $Id: string.c,v 1.344 2003/01/11 17:52:38 iliaa Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -1481,24 +1481,142 @@ } /* }}} */ -/* {{{ proto int strrpos(string haystack, string needle) +/* {{{ proto int stripos(string haystack, string needle [, int offset]) + Finds position of first occurrence of a string within another, case insensitive */ +PHP_FUNCTION(stripos) +{ + char *found = NULL; + char *haystack; + int haystack_len; + long offset = 0; + char *needle_dup = NULL, *haystack_dup; + char needle_char[2]; + zval *needle; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, sz|l, haystack, +haystack_len, needle, offset) == FAILURE) { + return; + } + if (offset 0 || offset haystack_len) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, Offset not contained in +string.); + RETURN_FALSE; + } + + haystack_dup = estrndup(haystack, haystack_len); + php_strtolower(haystack_dup, haystack_len); + + if (Z_TYPE_P(needle) == IS_STRING) { + needle_dup = estrndup(Z_STRVAL_P(needle), Z_STRLEN_P(needle)); + php_strtolower(needle_dup, Z_STRLEN_P(needle)); + found = php_memnstr(haystack_dup + offset, needle_dup, +Z_STRLEN_P(needle), haystack_dup + haystack_len); + } else { + switch (Z_TYPE_P(needle)) { + case IS_LONG: + case IS_BOOL: + needle_char[0] = tolower((char) Z_LVAL_P(needle)); + break; + case IS_DOUBLE: + needle_char[0] = tolower((char) Z_DVAL_P(needle)); + break; + default: + php_error_docref(NULL TSRMLS_CC, E_WARNING, needle is +not a string or an integer.); + efree(haystack_dup); + RETURN_FALSE; + break; + + } + needle_char[1] = '\0'; + found = php_memnstr(haystack_dup + offset, needle_char, +sizeof(needle_char) - 1, haystack_dup + haystack_len); + } + + efree(haystack_dup); + if (needle_dup) { + efree(needle_dup); + } + + if (found) { + RETURN_LONG(found - haystack_dup); + } else { + RETURN_FALSE; + } +} +/* }}} */ + +/* {{{ proto int strrpos(string haystack, string needle [, int offset]) Finds position of last occurrence of a character in a string within another */ PHP_FUNCTION(strrpos) { - zval **haystack, **needle; + zval **haystack, **needle, **offset; char *found = NULL; + int argc = ZEND_NUM_ARGS(); + int off = 0; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, haystack, needle) == FAILURE) { + if (argc 2 || argc 3 || zend_get_parameters_ex(argc, haystack, needle, +offset) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string_ex(haystack); + if (argc == 3) { + convert_to_long_ex(offset); + if (Z_LVAL_PP(offset) 0 || Z_LVAL_PP(offset) +Z_STRLEN_PP(haystack)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, Offset not +contained in string.); + RETURN_FALSE; + } + off = Z_LVAL_PP(offset); + } + + if (Z_TYPE_PP(needle) == IS_STRING) { + found = strrchr(Z_STRVAL_PP(haystack) + off, *Z_STRVAL_PP(needle)); + } else { + convert_to_long_ex(needle); + found = strrchr(Z_STRVAL_PP(haystack) + off, (char) Z_LVAL_PP(needle)); + } + + if (found) { + RETURN_LONG(Z_STRLEN_PP(haystack) - strlen(found)); + } else { + RETURN_FALSE; + } +} +/* }}} */ + +/* {{{ proto int strripos(string haystack, string needle [, int offset]) + Finds position of last occurrence of a character in a string within another, case +insensitive */ +PHP_FUNCTION(strripos) +{ + zval **haystack, **needle, **offset; + char *found = NULL; + int argc = ZEND_NUM_ARGS(); + int off = 0; + char
[PHP-CVS] cvs: php4 /ext/standard string.c
iliaa Sat Jan 4 23:29:14 2003 EDT Modified files: /php4/ext/standard string.c Log: Fixed a memory leak in setlocale() localeconv(). Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.341 php4/ext/standard/string.c:1.342 --- php4/ext/standard/string.c:1.341Wed Jan 1 06:04:44 2003 +++ php4/ext/standard/string.c Sat Jan 4 23:29:14 2003 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.341 2003/01/01 11:04:44 wez Exp $ */ +/* $Id: string.c,v 1.342 2003/01/05 04:29:14 iliaa Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -3199,6 +3199,7 @@ cat = LC_TIME; else { php_error_docref(NULL TSRMLS_CC, E_WARNING, Invalid locale category name %s, must be one of LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, or LC_TIME., category); + efree(args); RETURN_FALSE; } } @@ -3742,13 +3743,13 @@ zval *grouping, *mon_grouping; int len, i; - MAKE_STD_ZVAL(grouping); - MAKE_STD_ZVAL(mon_grouping); - /* We don't need no stinkin' parameters... */ if (ZEND_NUM_ARGS() 0) { WRONG_PARAM_COUNT; } + + MAKE_STD_ZVAL(grouping); + MAKE_STD_ZVAL(mon_grouping); array_init(return_value); array_init(grouping); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
rasmus Tue Dec 31 10:18:53 2002 EDT Modified files: /php4/ext/standard string.c Log: Fix for bug #21311 Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.338 php4/ext/standard/string.c:1.339 --- php4/ext/standard/string.c:1.338Thu Dec 26 15:52:42 2002 +++ php4/ext/standard/string.c Tue Dec 31 10:18:52 2002 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.338 2002/12/26 20:52:42 sterling Exp $ */ +/* $Id: string.c,v 1.339 2002/12/31 15:18:52 rasmus Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -3509,11 +3509,12 @@ /* JavaScript Other HTML scripting languages */ if (state == 1 *(p-1) == '') { state = 3; + lc = c; } else { *(rp++) = c; } break; - + case '?': if (state == 1 *(p-1)=='') { @@ -3522,13 +3523,28 @@ break; } + case 'E': + case 'e': + /* !DOCTYPE exception */ + if (state==3 p buf+6 + tolower(*(p-1)) == 'p' + tolower(*(p-2)) == 'y' + tolower(*(p-3)) == 't' + tolower(*(p-4)) == 'c' + tolower(*(p-5)) == 'o' + tolower(*(p-6)) == 'd') { + state = 1; + break; + } + /* fall-through */ + case 'l': /* swm: If we encounter '?xml' then we shouldn't be in * state == 2 (PHP). Switch back to HTML. */ - if (state == 2 *(p-1) == 'm' *(p-2) == 'x') { + if (state == 2 p buf+2 *(p-1) == 'm' *(p-2) +== 'x') { state = 1; break; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c /ext/standard/tests/strings bug20927.phpt
iliaa Thu Dec 12 08:38:19 2002 EDT Modified files: /php4/ext/standard string.c /php4/ext/standard/tests/stringsbug20927.phpt Log: Fixed bug #20927 and updated the test case for the bug. Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.335 php4/ext/standard/string.c:1.336 --- php4/ext/standard/string.c:1.335Thu Dec 5 17:28:02 2002 +++ php4/ext/standard/string.c Thu Dec 12 08:38:18 2002 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.335 2002/12/05 22:28:02 iliaa Exp $ */ +/* $Id: string.c,v 1.336 2002/12/12 13:38:18 iliaa Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -628,7 +628,7 @@ { const char *text, *breakchar = \n; char *newtext; - int textlen, breakcharlen = 1, newtextlen; + int textlen, breakcharlen = 1, newtextlen, alloced, chk; long current = 0, laststart = 0, lastspace = 0; long linelength = 75; zend_bool docut = 0; @@ -670,18 +670,24 @@ } else { /* Multiple character line break or forced cut */ if (linelength 0) { - /* Add extra 10% to accomodate strings with unpredicatable number of breaks */ - newtextlen = textlen + (int)((textlen/linelength + 1) * breakcharlen * 1.1) + 1; + chk = (int)(textlen/linelength + 1); + alloced = textlen + chk * breakcharlen + 1; } else { - newtextlen = textlen * (breakcharlen + 1) + 1; + chk = textlen; + alloced = textlen * (breakcharlen + 1) + 1; } - newtext = emalloc(newtextlen); - + newtext = emalloc(alloced); + /* now keep track of the actual new text length */ newtextlen = 0; laststart = lastspace = 0; for (current = 0; current textlen; current++) { + if (chk = 0) { + alloced += (int) (((textlen - current + 1)/linelength ++ 1) * breakcharlen) + 1; + newtext = erealloc(newtext, alloced); + chk = (int) ((textlen - current)/linelength) + 1; + } /* when we hit an existing break, copy to new buffer, and * fix up laststart and lastspace */ if (text[current] == breakchar[0] @@ -691,6 +697,7 @@ newtextlen += current-laststart+breakcharlen; current += breakcharlen - 1; laststart = lastspace = current + 1; + chk--; } /* if it is a space, check if it is at the line boundary, * copy and insert a break, or just keep track of it */ @@ -701,6 +708,7 @@ memcpy(newtext+newtextlen, breakchar, breakcharlen); newtextlen += breakcharlen; laststart = current + 1; + chk--; } lastspace = current; } @@ -714,6 +722,7 @@ memcpy(newtext+newtextlen, breakchar, breakcharlen); newtextlen += breakcharlen; laststart = lastspace = current; + chk--; } /* if the current word puts us over the linelength, copy * back up until the last space, insert a break, and move @@ -725,6 +734,7 @@ memcpy(newtext+newtextlen, breakchar, breakcharlen); newtextlen += breakcharlen; laststart = lastspace = lastspace + 1; + chk--; } } Index: php4/ext/standard/tests/strings/bug20927.phpt diff -u php4/ext/standard/tests/strings/bug20927.phpt:1.1 php4/ext/standard/tests/strings/bug20927.phpt:1.2 --- php4/ext/standard/tests/strings/bug20927.phpt:1.1 Wed Dec 11 15:22:42 2002 +++ php4/ext/standard/tests/strings/bug20927.phpt Thu Dec 12 08:38:19 2002 @@ -3,17 +3,16 @@ --SKIPIF-- --FILE-- ?php -$x = ADV:CLAIM YOUR FORTUNE NOW !!MAKE; -$x .= xxHUNDREDS OF THOUSANDS; -$b = CANITBREAKFOO\n; -$x = wordwrap($x, 20, $b, 1); -$x = wordwrap($x, 20, $b, 1); -print $x\n; +$string= str_repeat(1234567890 X , 10); +$break = str_repeat(a-very-long-break-string-to-clobber-the-heap, 8); +$linelength= 10; + +echo Length of
Re: [PHP-CVS] cvs: php4 /ext/standard string.c
I do not get those so i do not fix them. At 05:17 09.11.2002, Maxim Maletsky wrote: Actually, i was just about to mention one thing - in math.c on line 779 (I think) it warn of an unasigned comparison compilation. I was about to work out a patch and submit it as I got no karma for that part. Why don't you take over it once you're there :) -- Maxim Maletsky [EMAIL PROTECTED] On Thu, 24 Oct 2002 19:11:50 - Marcus Börger [EMAIL PROTECTED] wrote: helly Thu Oct 24 15:11:50 2002 EDT Modified files: /php4/ext/standardstring.c Log: fix compiler warning Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.327 php4/ext/standard/string.c:1.328 --- php4/ext/standard/string.c:1.327 Tue Oct 22 14:27:56 2002 +++ php4/ext/standard/string.cThu Oct 24 15:11:49 2002 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.327 2002/10/22 18:27:56 helly Exp $ */ +/* $Id: string.c,v 1.328 2002/10/24 19:11:49 helly Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -915,6 +915,7 @@ case 1: tok = args[0]; break; + default: case 2: str = args[0]; tok = args[1]; @@ -1198,7 +1199,7 @@ PHP_FUNCTION(pathinfo) { zval *tmp; - char *path, *ret; + char *path, *ret = NULL; int path_len; int opt = PHP_PATHINFO_ALL; @@ -3182,6 +3183,7 @@ if (Z_TYPE_PP(args[1]) == IS_ARRAY) { zend_hash_internal_pointer_reset(Z_ARRVAL_PP(args[1])); + i=0; /* not needed in this case: only kill a compiler warning */ } else { i=1; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/standard string.c
I get it if compile with VC++. line 779 unsigned mismatch --- Maxim Maletsky [EMAIL PROTECTED] On Sat, 09 Nov 2002 11:05:15 +0100 [EMAIL PROTECTED] (Marcus Börger) wrote: I do not get those so i do not fix them. At 05:17 09.11.2002, Maxim Maletsky wrote: Actually, i was just about to mention one thing - in math.c on line 779 (I think) it warn of an unasigned comparison compilation. I was about to work out a patch and submit it as I got no karma for that part. Why don't you take over it once you're there :) -- Maxim Maletsky [EMAIL PROTECTED] On Thu, 24 Oct 2002 19:11:50 - Marcus Börger [EMAIL PROTECTED] wrote: helly Thu Oct 24 15:11:50 2002 EDT Modified files: /php4/ext/standardstring.c Log: fix compiler warning Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.327 php4/ext/standard/string.c:1.328 --- php4/ext/standard/string.c:1.327 Tue Oct 22 14:27:56 2002 +++ php4/ext/standard/string.cThu Oct 24 15:11:49 2002 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.327 2002/10/22 18:27:56 helly Exp $ */ +/* $Id: string.c,v 1.328 2002/10/24 19:11:49 helly Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -915,6 +915,7 @@ case 1: tok = args[0]; break; + default: case 2: str = args[0]; tok = args[1]; @@ -1198,7 +1199,7 @@ PHP_FUNCTION(pathinfo) { zval *tmp; - char *path, *ret; + char *path, *ret = NULL; int path_len; int opt = PHP_PATHINFO_ALL; @@ -3182,6 +3183,7 @@ if (Z_TYPE_PP(args[1]) == IS_ARRAY) { zend_hash_internal_pointer_reset(Z_ARRVAL_PP(args[1])); + i=0; /* not needed in this case: only kill a compiler warning */ } else { i=1; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/standard string.c
Actually, i was just about to mention one thing - in math.c on line 779 (I think) it warn of an unasigned comparison compilation. I was about to work out a patch and submit it as I got no karma for that part. Why don't you take over it once you're there :) -- Maxim Maletsky [EMAIL PROTECTED] On Thu, 24 Oct 2002 19:11:50 - Marcus Börger [EMAIL PROTECTED] wrote: helly Thu Oct 24 15:11:50 2002 EDT Modified files: /php4/ext/standardstring.c Log: fix compiler warning Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.327 php4/ext/standard/string.c:1.328 --- php4/ext/standard/string.c:1.327 Tue Oct 22 14:27:56 2002 +++ php4/ext/standard/string.cThu Oct 24 15:11:49 2002 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: string.c,v 1.327 2002/10/22 18:27:56 helly Exp $ */ +/* $Id: string.c,v 1.328 2002/10/24 19:11:49 helly Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -915,6 +915,7 @@ case 1: tok = args[0]; break; + default: case 2: str = args[0]; tok = args[1]; @@ -1198,7 +1199,7 @@ PHP_FUNCTION(pathinfo) { zval *tmp; - char *path, *ret; + char *path, *ret = NULL; int path_len; int opt = PHP_PATHINFO_ALL; @@ -3182,6 +3183,7 @@ if (Z_TYPE_PP(args[1]) == IS_ARRAY) { zend_hash_internal_pointer_reset(Z_ARRVAL_PP(args[1])); + i=0; /* not needed in this case: only kill a compiler warning */ } else { i=1; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
moriyoshi Tue Nov 5 08:52:11 2002 EDT Modified files: /php4/ext/standard string.c Log: style fix Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.332 php4/ext/standard/string.c:1.333 --- php4/ext/standard/string.c:1.332Sat Nov 2 13:54:31 2002 +++ php4/ext/standard/string.c Tue Nov 5 08:52:11 2002 -18,7 +18,7 +--+ */ -/* $Id: string.c,v 1.332 2002/11/02 18:54:31 iliaa Exp $ */ +/* $Id: string.c,v 1.333 2002/11/05 13:52:11 moriyoshi Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ -889,9 +889,16 } php_implode(delim, arr, return_value); - if (arg1 != NULL arg1_separated) zval_ptr_dtor(arg1); - if (arg2 != NULL arg2_separated) zval_ptr_dtor(arg2); - if (delim_needs_dtor) FREE_ZVAL(delim); + + if (arg1 != NULL arg1_separated) { + zval_ptr_dtor(arg1); + } + if (arg2 != NULL arg2_separated) { + zval_ptr_dtor(arg2); + } + if (delim_needs_dtor) { + FREE_ZVAL(delim); + } } /* }}} */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/standard string.c
I know but in the fopen wrappers I normalize paths to the default slash. I think all of PHP should behave in the same way. Andi At 09:11 AM 11/1/2002 -0500, Ilia A. wrote: Windows can interpret / as well as \, makes no difference to it. In fact when we resolve paths on Windows, we already use / and not \. Ilia On November 1, 2002 03:01 am, Andi Gutmans wrote: I'm not sure this is the right thing to do. UNIX and Windows are diffferent and that's what DEFAULT_SLASH is for. Andi At 12:53 AM 11/1/2002 +, Ilia Alshanetsky wrote: iliaa Thu Oct 31 19:53:28 2002 EDT Modified files: /php4/ext/standard string.c Log: Fixed bug #18710. dirname() now returns consistent output when dealing with \ directory separators on Windows. Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.330 php4/ext/standard/string.c:1.331 --- php4/ext/standard/string.c:1.330Wed Oct 30 06:42:51 2002 +++ php4/ext/standard/string.c Thu Oct 31 19:53:27 2002 -18,7 +18,7 +--+ */ -/* $Id: string.c,v 1.330 2002/10/30 11:42:51 moriyoshi Exp $ */ +/* $Id: string.c,v 1.331 2002/11/01 00:53:27 iliaa Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ -1148,7 +1148,7 } if (end path) { /* The path only contained slashes */ - path[0] = DEFAULT_SLASH; + path[0] = '/'; path[1] = '\0'; return; } -1169,7 +1169,7 end--; } if (end path) { - path[0] = DEFAULT_SLASH; + path[0] = '/'; path[1] = '\0'; return; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
iliaa Sat Nov 2 13:54:31 2002 EDT Modified files: /php4/ext/standard string.c Log: Revert previous dirname() patch. Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.331 php4/ext/standard/string.c:1.332 --- php4/ext/standard/string.c:1.331Thu Oct 31 19:53:27 2002 +++ php4/ext/standard/string.c Sat Nov 2 13:54:31 2002 -18,7 +18,7 +--+ */ -/* $Id: string.c,v 1.331 2002/11/01 00:53:27 iliaa Exp $ */ +/* $Id: string.c,v 1.332 2002/11/02 18:54:31 iliaa Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ -1148,7 +1148,7 } if (end path) { /* The path only contained slashes */ - path[0] = '/'; + path[0] = DEFAULT_SLASH; path[1] = '\0'; return; } -1169,7 +1169,7 end--; } if (end path) { - path[0] = '/'; + path[0] = DEFAULT_SLASH; path[1] = '\0'; return; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/standard string.c
Fair enough, I'll revert the patch. We are still left with a problem of pathes on windows not using / consistently however. Ilia On November 2, 2002 01:11 pm, Andi Gutmans wrote: I know but in the fopen wrappers I normalize paths to the default slash. I think all of PHP should behave in the same way. Andi At 09:11 AM 11/1/2002 -0500, Ilia A. wrote: Windows can interpret / as well as \, makes no difference to it. In fact when we resolve paths on Windows, we already use / and not \. Ilia On November 1, 2002 03:01 am, Andi Gutmans wrote: I'm not sure this is the right thing to do. UNIX and Windows are diffferent and that's what DEFAULT_SLASH is for. Andi At 12:53 AM 11/1/2002 +, Ilia Alshanetsky wrote: iliaa Thu Oct 31 19:53:28 2002 EDT Modified files: /php4/ext/standard string.c Log: Fixed bug #18710. dirname() now returns consistent output when dealing with \ directory separators on Windows. Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.330 php4/ext/standard/string.c:1.331 --- php4/ext/standard/string.c:1.330 Wed Oct 30 06:42:51 2002 +++ php4/ext/standard/string.c Thu Oct 31 19:53:27 2002 -18,7 +18,7 + --+ */ -/* $Id: string.c,v 1.330 2002/10/30 11:42:51 moriyoshi Exp $ */ +/* $Id: string.c,v 1.331 2002/11/01 00:53:27 iliaa Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ -1148,7 +1148,7 } if (end path) { /* The path only contained slashes */ - path[0] = DEFAULT_SLASH; + path[0] = '/'; path[1] = '\0'; return; } -1169,7 +1169,7 end--; } if (end path) { - path[0] = DEFAULT_SLASH; + path[0] = '/'; path[1] = '\0'; return; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/standard string.c
I'm not sure this is the right thing to do. UNIX and Windows are diffferent and that's what DEFAULT_SLASH is for. Andi At 12:53 AM 11/1/2002 +, Ilia Alshanetsky wrote: iliaa Thu Oct 31 19:53:28 2002 EDT Modified files: /php4/ext/standard string.c Log: Fixed bug #18710. dirname() now returns consistent output when dealing with \ directory separators on Windows. Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.330 php4/ext/standard/string.c:1.331 --- php4/ext/standard/string.c:1.330Wed Oct 30 06:42:51 2002 +++ php4/ext/standard/string.c Thu Oct 31 19:53:27 2002 -18,7 +18,7 +--+ */ -/* $Id: string.c,v 1.330 2002/10/30 11:42:51 moriyoshi Exp $ */ +/* $Id: string.c,v 1.331 2002/11/01 00:53:27 iliaa Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ -1148,7 +1148,7 } if (end path) { /* The path only contained slashes */ - path[0] = DEFAULT_SLASH; + path[0] = '/'; path[1] = '\0'; return; } -1169,7 +1169,7 end--; } if (end path) { - path[0] = DEFAULT_SLASH; + path[0] = '/'; path[1] = '\0'; return; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/standard string.c
Windows can interpret / as well as \, makes no difference to it. In fact when we resolve paths on Windows, we already use / and not \. Ilia On November 1, 2002 03:01 am, Andi Gutmans wrote: I'm not sure this is the right thing to do. UNIX and Windows are diffferent and that's what DEFAULT_SLASH is for. Andi At 12:53 AM 11/1/2002 +, Ilia Alshanetsky wrote: iliaa Thu Oct 31 19:53:28 2002 EDT Modified files: /php4/ext/standard string.c Log: Fixed bug #18710. dirname() now returns consistent output when dealing with \ directory separators on Windows. Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.330 php4/ext/standard/string.c:1.331 --- php4/ext/standard/string.c:1.330Wed Oct 30 06:42:51 2002 +++ php4/ext/standard/string.c Thu Oct 31 19:53:27 2002 -18,7 +18,7 +--+ */ -/* $Id: string.c,v 1.330 2002/10/30 11:42:51 moriyoshi Exp $ */ +/* $Id: string.c,v 1.331 2002/11/01 00:53:27 iliaa Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ -1148,7 +1148,7 } if (end path) { /* The path only contained slashes */ - path[0] = DEFAULT_SLASH; + path[0] = '/'; path[1] = '\0'; return; } -1169,7 +1169,7 end--; } if (end path) { - path[0] = DEFAULT_SLASH; + path[0] = '/'; path[1] = '\0'; return; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
moriyoshi Wed Oct 30 06:42:51 2002 EDT Modified files: /php4/ext/standard string.c Log: Fixed bug #20169 Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.329 php4/ext/standard/string.c:1.330 --- php4/ext/standard/string.c:1.329Fri Oct 25 16:09:53 2002 +++ php4/ext/standard/string.c Wed Oct 30 06:42:51 2002 -18,7 +18,7 +--+ */ -/* $Id: string.c,v 1.329 2002/10/25 20:09:53 iliaa Exp $ */ +/* $Id: string.c,v 1.330 2002/10/30 11:42:51 moriyoshi Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ -848,6 +848,7 { zval **arg1 = NULL, **arg2 = NULL, *delim, *arr; int argc = ZEND_NUM_ARGS(); + int arg1_separated = 0, arg2_separated = 0, delim_needs_dtor = 0; if (argc 1 || argc 2 || zend_get_parameters_ex(argc, arg1, arg2) == FAILURE) { -865,15 +866,19 ZVAL_STRINGL(delim, _IMPL_EMPTY, sizeof(_IMPL_EMPTY) - 1, 0); SEPARATE_ZVAL(arg1); + arg1_separated = 1; + delim_needs_dtor = 1; arr = *arg1; } else { if (Z_TYPE_PP(arg1) == IS_ARRAY) { SEPARATE_ZVAL(arg1); + arg1_separated = 1; arr = *arg1; convert_to_string_ex(arg2); delim = *arg2; } else if (Z_TYPE_PP(arg2) == IS_ARRAY) { SEPARATE_ZVAL(arg2); + arg2_separated = 1; arr = *arg2; convert_to_string_ex(arg1); delim = *arg1; -884,12 +889,9 } php_implode(delim, arr, return_value); - zval_ptr_dtor(arg1); - if (arg2) { - zval_ptr_dtor(arg2); - } else { - FREE_ZVAL(delim); - } + if (arg1 != NULL arg1_separated) zval_ptr_dtor(arg1); + if (arg2 != NULL arg2_separated) zval_ptr_dtor(arg2); + if (delim_needs_dtor) FREE_ZVAL(delim); } /* }}} */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
andrey Thu Oct 10 14:41:25 2002 EDT Modified files: /php4/ext/standard string.c Log: ws fixes Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.320 php4/ext/standard/string.c:1.321 --- php4/ext/standard/string.c:1.320Thu Oct 10 12:29:35 2002 +++ php4/ext/standard/string.c Thu Oct 10 14:41:24 2002 -18,7 +18,7 +--+ */ -/* $Id: string.c,v 1.320 2002/10/10 16:29:35 iliaa Exp $ */ +/* $Id: string.c,v 1.321 2002/10/10 18:41:24 andrey Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ -654,30 +654,25 for (current = 0; current textlen; current++) { if (text[current] == breakchar[0]) { laststart = lastspace = current; - } - else if (text[current] == ' ') { + } else if (text[current] == ' ') { if (current - laststart = linelength) { newtext[current] = breakchar[0]; laststart = current; } lastspace = current; - } - else if (current - laststart = linelength -laststart != lastspace) { + } else if (current - laststart = linelength laststart != +lastspace) { newtext[lastspace] = breakchar[0]; laststart = lastspace; } } RETURN_STRINGL(newtext, textlen, 0); - } - else { + } else { /* Multiple character line break or forced cut */ if (linelength 0) { /* Add extra 10% to accomodate strings with unpredicatable number of breaks */ newtextlen = textlen + (int)((textlen/linelength + 1) * breakcharlen * 1.1) + 1; - } - else { + } else { newtextlen = textlen * (breakcharlen + 1) + 1; } newtext = emalloc(newtextlen); -950,8 +945,7 STRTOK_TABLE(token++) = 1; /* Skip leading delimiters */ - while (STRTOK_TABLE(p)) - { + while (STRTOK_TABLE(p)) { if (++p = pe) { /* no other chars left */ BG(strtok_last) = NULL; -1478,8 +1472,7 if (Z_TYPE_PP(needle) == IS_STRING) { found = strrchr(Z_STRVAL_PP(haystack), *Z_STRVAL_PP(needle)); - } - else { + } else { convert_to_long_ex(needle); found = strrchr(Z_STRVAL_PP(haystack), (char) Z_LVAL_PP(needle)); } -1508,8 +1501,7 if (Z_TYPE_PP(needle) == IS_STRING) { found = strrchr(Z_STRVAL_PP(haystack), *Z_STRVAL_PP(needle)); - } - else { + } else { convert_to_long_ex(needle); found = strrchr(Z_STRVAL_PP(haystack), (char) Z_LVAL_PP(needle)); } -1690,8 +1682,7 if (argc 3) { convert_to_long_ex(len); l = Z_LVAL_PP(len); - } - else { + } else { l = Z_STRLEN_PP(str); } -1705,8 +1696,9 if (f 0) { f = 0; } - } else if (f Z_STRLEN_PP(str)) + } else if (f Z_STRLEN_PP(str)) { f = Z_STRLEN_PP(str); + } /* if length position is negative, set it to the length -2066,8 +2058,7 *max = 0; for (p = (char *) txt1; p end1; p++) { for (q = (char *) txt2; q end2; q++) { - for (l = 0; (p + l end1) (q + l end2) (p[l] == q[l]); -l++); + for (l = 0; (p + l end1) (q + l end2) (p[l] == +q[l]); l++); if (l *max) { *max = l; *pos1 = p - txt1; -2193,9 +2184,9 l--; } } else { - if (s != t) + if (s != t) { *s++ = *t++; - else { + } else { s++; t++; } -2790,8 +2781,9 if (Z_TYPE_PP(search) != IS_ARRAY) { convert_to_string_ex(search); convert_to_string_ex(replace); - } else if (Z_TYPE_PP(replace) != IS_ARRAY) + } else if (Z_TYPE_PP(replace) != IS_ARRAY) { convert_to_string_ex(replace); + } /* if
Re: [PHP-CVS] cvs: php4 /ext/standard string.c
I thought of that. If that is the desired behaviour I will do it. So if I receive another +1 I will do it :) Orto add additional parameter(with default to work on the original string) to switch the behavior. Andrey - Original Message - From: Sander Roobol [EMAIL PROTECTED] To: Andrey Hristov [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, October 08, 2002 7:20 PM Subject: Re: [PHP-CVS] cvs: php4 /ext/standard string.c On Tue, Oct 08, 2002 at 09:52:59AM -, Andrey Hristov wrote: andrey Tue Oct 8 05:52:59 2002 EDT Modified files: /php4/ext/standard string.c Log: Now str_shuffle() has the randomization characteristics of shuffle(). str_shuffle() won't return anymore the randomized string and thus will be consistent with shuffle(). Since this function is new to 4.3.0 no BC problems. Although it's not consistant with shuffle(), I'd rather see str_shuffle() returning the new string instead of modifying it in place. Sander -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
andrey Wed Oct 9 06:33:22 2002 EDT Modified files: /php4/ext/standard string.c Log: Returning to the old behavior of str_shuffle() a bit. Now the passed string is left unmodified and the shuffled string is returned. Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.316 php4/ext/standard/string.c:1.317 --- php4/ext/standard/string.c:1.316Tue Oct 8 05:52:59 2002 +++ php4/ext/standard/string.c Wed Oct 9 06:33:22 2002 -18,7 +18,7 +--+ */ -/* $Id: string.c,v 1.316 2002/10/08 09:52:59 andrey Exp $ */ +/* $Id: string.c,v 1.317 2002/10/09 10:33:22 andrey Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ -4025,15 +4025,18 Shuffles string. One permutation of all possible is created */ PHP_FUNCTION(str_shuffle) { - char *str; - int str_len; + zval **arg; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s, str, str_len) == FAILURE) { - RETURN_FALSE; + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, arg)) { + WRONG_PARAM_COUNT; } - php_string_shuffle(str, str_len TSRMLS_CC); - return; + convert_to_string_ex(arg); + *return_value = **arg; + zval_copy_ctor(return_value); + if (Z_STRLEN_P(return_value) 1) { + php_string_shuffle(Z_STRVAL_P(return_value), Z_STRLEN_P(return_value) +TSRMLS_CC); + } } /* }}} */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
andrey Tue Oct 8 05:52:59 2002 EDT Modified files: /php4/ext/standard string.c Log: Now str_shuffle() has the randomization characteristics of shuffle(). str_shuffle() won't return anymore the randomized string and thus will be consistent with shuffle(). Since this function is new to 4.3.0 no BC problems. #Thanks to Adam Trachtenberg for providing good example to check the #permuations distribution. Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.315 php4/ext/standard/string.c:1.316 --- php4/ext/standard/string.c:1.315Sun Oct 6 14:39:03 2002 +++ php4/ext/standard/string.c Tue Oct 8 05:52:59 2002 -18,7 +18,7 +--+ */ -/* $Id: string.c,v 1.315 2002/10/06 18:39:03 sander Exp $ */ +/* $Id: string.c,v 1.316 2002/10/08 09:52:59 andrey Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ -3995,35 +3995,45 /* }}} */ -static int php_string_shuffle(const void *a, const void *b TSRMLS_DC) +static void php_string_shuffle(char *str, long len TSRMLS_DC) { - long rnd; - rnd = php_rand(TSRMLS_C); - if (rnd % 3) - return 1; - else if (rnd % 5) - return 0; - else - return -1; + long n_elems, rnd_idx, n_left; + char temp; + /* The implementation is stolen from array_data_shuffle */ + /* Thus the characteristics of the randomization are the same */ + n_elems = len; + + if (n_elems = 1) { + return; + } + + n_left = n_elems; + + while (--n_left) { + rnd_idx = php_rand(TSRMLS_C); + RAND_RANGE(rnd_idx, 0, n_left, PHP_RAND_MAX); + if (rnd_idx != n_left) { + temp = str[n_left]; + str[n_left] = str[rnd_idx]; + str[rnd_idx] = temp; + } + } } -/* {{{ proto string str_shuffle(string str) + +/* {{{ proto void str_shuffle(string str) Shuffles string. One permutation of all possible is created */ PHP_FUNCTION(str_shuffle) { - /* Note : by using current php_string_shuffle for string */ - /* with 6 chars (6! permutations) about 2/3 of them are */ - /* computed for 6! calls for the function. So it isn't so */ - /* unique. The ratio is the same for other lengths. */ char *str; - int i, str_len; + int str_len; - i = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s, str, str_len) == FAILURE) { RETURN_FALSE; } - zend_qsort((void *)str, str_len, sizeof(char), php_string_shuffle TSRMLS_CC); - RETURN_STRINGL(str, str_len, 1); + php_string_shuffle(str, str_len TSRMLS_CC); + + return; } /* }}} */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/standard string.c
On Tue, Oct 08, 2002 at 09:52:59AM -, Andrey Hristov wrote: andreyTue Oct 8 05:52:59 2002 EDT Modified files: /php4/ext/standardstring.c Log: Now str_shuffle() has the randomization characteristics of shuffle(). str_shuffle() won't return anymore the randomized string and thus will be consistent with shuffle(). Since this function is new to 4.3.0 no BC problems. Although it's not consistant with shuffle(), I'd rather see str_shuffle() returning the new string instead of modifying it in place. Sander -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-CVS] cvs: php4 /ext/standard string.c
On Tue, 8 Oct 2002, Sander Roobol wrote: On Tue, Oct 08, 2002 at 09:52:59AM -, Andrey Hristov wrote: andrey Tue Oct 8 05:52:59 2002 EDT Modified files: /php4/ext/standard string.c Log: Now str_shuffle() has the randomization characteristics of shuffle(). str_shuffle() won't return anymore the randomized string and thus will be consistent with shuffle(). Since this function is new to 4.3.0 no BC problems. Although it's not consistant with shuffle(), I'd rather see str_shuffle() returning the new string instead of modifying it in place. I agree with that. Derick -- --- Derick Rethans http://derickrethans.nl/ JDI Media Solutions --[ if you hold a unix shell to your ear, do you hear the c? ]- -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
sander Sun Oct 6 07:28:12 2002 EDT Modified files: /php4/ext/standard string.c Log: Fixed segfault and memory leak in the new implementation of implode() Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.313 php4/ext/standard/string.c:1.314 --- php4/ext/standard/string.c:1.313Fri Oct 4 16:44:19 2002 +++ php4/ext/standard/string.c Sun Oct 6 07:28:11 2002 -18,7 +18,7 +--+ */ -/* $Id: string.c,v 1.313 2002/10/04 20:44:19 sterling Exp $ */ +/* $Id: string.c,v 1.314 2002/10/06 11:28:11 sander Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ -825,6 +825,10 numelems = zend_hash_num_elements(Z_ARRVAL_P(arr)); + if(numelems == 0) { + RETURN_EMPTY_STRING(); + } + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), pos); while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **) tmp, -888,6 +892,8 zval_ptr_dtor(arg1); if (arg2) { zval_ptr_dtor(arg2); + } else { + FREE_ZVAL(delim); } } /* }}} */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
sterlingFri Oct 4 16:44:19 2002 EDT Modified files: /php4/ext/standard string.c Log: have implode use the smart_str_*() functions, this should speed things up quite a bit... Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.312 php4/ext/standard/string.c:1.313 --- php4/ext/standard/string.c:1.312Fri Oct 4 13:10:51 2002 +++ php4/ext/standard/string.c Fri Oct 4 16:44:19 2002 -18,7 +18,7 +--+ */ -/* $Id: string.c,v 1.312 2002/10/04 17:10:51 sander Exp $ */ +/* $Id: string.c,v 1.313 2002/10/04 20:44:19 sterling Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ -818,42 +818,28 */ PHPAPI void php_implode(zval *delim, zval *arr, zval *return_value) { - zval **tmp; - char *tmp_str; - int len = 0, count = 0, target = 0; - HashPosition pos; + zval **tmp; + HashPosition pos; + smart_str implstr = {0}; + intnumelems, i = 0; + + numelems = zend_hash_num_elements(Z_ARRVAL_P(arr)); - /* convert everything to strings, and calculate length */ zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), pos); - while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **) tmp, pos) == SUCCESS) { + while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), +(void +**) tmp, +pos) +== SUCCESS) { convert_to_string_ex(tmp); - len += Z_STRLEN_PP(tmp); - if (count 0) { - len += Z_STRLEN_P(delim); - } - - count++; - zend_hash_move_forward_ex(Z_ARRVAL_P(arr), pos); - } - /* do it */ - tmp_str = (char *) emalloc(len + 1); - tmp_str[0] = 0; - - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), pos); - while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **) tmp, pos) == SUCCESS) { - count--; - memcpy(tmp_str + target, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); - target += Z_STRLEN_PP(tmp); - if (count 0) { - memcpy(tmp_str + target, Z_STRVAL_P(delim), Z_STRLEN_P(delim)); - target += Z_STRLEN_P(delim); + smart_str_appendl(implstr, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); + if (++i != numelems) { + smart_str_appendl(implstr, Z_STRVAL_P(delim), +Z_STRLEN_P(delim)); } zend_hash_move_forward_ex(Z_ARRVAL_P(arr), pos); } - tmp_str[len] = 0; - - RETURN_STRINGL(tmp_str, len, 0); + smart_str_0(implstr); + + RETURN_STRINGL(implstr.c, implstr.len, 0); } /* }}} */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
yohgaki Thu Oct 3 00:56:55 2002 EDT Modified files: /php4/ext/standard string.c Log: Forgot 1 byte for \0 Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.305 php4/ext/standard/string.c:1.306 --- php4/ext/standard/string.c:1.305Thu Oct 3 00:54:01 2002 +++ php4/ext/standard/string.c Thu Oct 3 00:56:54 2002 -18,7 +18,7 +--+ */ -/* $Id: string.c,v 1.305 2002/10/03 04:54:01 yohgaki Exp $ */ +/* $Id: string.c,v 1.306 2002/10/03 04:56:54 yohgaki Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ -2468,7 +2468,7 if (should_free) { STR_FREE(str); } - new_str = (char *) erealloc(new_str, *new_length); + new_str = (char *) erealloc(new_str, *new_length+1); return new_str; } /* }}} */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
sebastian Thu Sep 26 15:18:36 2002 EDT Modified files: /php4/ext/standard string.c Log: Fix warning. Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.299 php4/ext/standard/string.c:1.300 --- php4/ext/standard/string.c:1.299Wed Sep 25 15:06:29 2002 +++ php4/ext/standard/string.c Thu Sep 26 15:18:35 2002 -18,13 +18,14 +--+ */ -/* $Id: string.c,v 1.299 2002/09/25 19:06:29 andrey Exp $ */ +/* $Id: string.c,v 1.300 2002/09/26 19:18:35 sebastian Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ #include stdio.h #include php.h #include reg.h +#include php_rand.h #include php_string.h #include php_variables.h #ifdef HAVE_LOCALE_H -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
andrey Wed Sep 25 15:06:30 2002 EDT Modified files: /php4/ext/standard string.c Log: Added common handler for strspn() and strcspn(). Almost of the code is identical. Modified to accept up to 4 params. Last 2 optional start len. They are analogic to start len of substr(). So the behavior when start len are used is like strspn(substr($s,$start,$len),$good_chars) and strcspn(substr($s,$start,$len), $bad_chars) Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.298 php4/ext/standard/string.c:1.299 --- php4/ext/standard/string.c:1.298Wed Sep 25 14:06:05 2002 +++ php4/ext/standard/string.c Wed Sep 25 15:06:29 2002 -18,7 +18,7 +--+ */ -/* $Id: string.c,v 1.298 2002/09/25 18:06:05 andrey Exp $ */ +/* $Id: string.c,v 1.299 2002/09/25 19:06:29 andrey Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ -54,6 +54,9 #define PHP_PATHINFO_EXTENSION 4 #define PHP_PATHINFO_ALL (PHP_PATHINFO_DIRNAME | PHP_PATHINFO_BASENAME | PHP_PATHINFO_EXTENSION) +#define STR_STRSPN 0 +#define STR_STRCSPN1 + /* {{{ register_string_constants */ void register_string_constants(INIT_FUNC_ARGS) -195,39 +198,71 } /* }}} */ -/* {{{ proto int strspn(string str, string mask) - Finds length of initial segment consisting entirely of characters found in mask */ -PHP_FUNCTION(strspn) +static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) { - zval **s1, **s2; + char *s11, *s22; + long len1, len2, start, len; - if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, s1, s2) == FAILURE) { - WRONG_PARAM_COUNT; + start = 0; + len = 0; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ss|ll, s11, len1, + s22, len2, start, len) == FAILURE) { + return; + } + + if (ZEND_NUM_ARGS() 4) { + len = len1; + } + + /* look at substr() function for more information */ + + if (start 0) { + start += len1; + if (start 0) { + start = 0; + } + } else if (start len1) { + RETURN_FALSE; + } + + if (len 0) { + len += (len1 - start); + if (len 0) { + len = 0; + } + } + + if ((start + len) len1) { + len = len1 - start; } - convert_to_string_ex(s1); - convert_to_string_ex(s2); - RETURN_LONG(php_strspn(Z_STRVAL_PP(s1), Z_STRVAL_PP(s2), - Z_STRVAL_PP(s1) + Z_STRLEN_PP(s1), - Z_STRVAL_PP(s2) + Z_STRLEN_PP(s2))); + if (behavior == STR_STRSPN) { + RETURN_LONG(php_strspn(s11 + start /*str1_start*/, + s22 /*str2_start*/, + s11 + start + len /*str1_end*/, + s22 + len2 /*str2_end*/)); + } else if (behavior == STR_STRCSPN) { + RETURN_LONG(php_strcspn(s11 + start /*str1_start*/, + s22 /*str2_start*/, + s11 + start + len /*str1_end*/, + s22 + len2 /*str2_end*/)); + } + +} + +/* {{{ proto int strspn(string str, string mask [, start [, len]]) + Finds length of initial segment consisting entirely of characters found in mask. +If start or/and length is provided works like +strspn(substr($s,$start,$len),$good_chars) */ +PHP_FUNCTION(strspn) +{ + php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, STR_STRSPN); } /* }}} */ -/* {{{ proto int strcspn(string str, string mask) - Finds length of initial segment consisting entirely of characters not found in mask */ +/* {{{ proto int strcspn(string str, string mask [, start [, len]]) + Finds length of initial segment consisting entirely of characters not found in +mask. If start or/and length is provide works like +strcspn(substr($s,$start,$len),$bad_chars) */ PHP_FUNCTION(strcspn) { - zval **s1, **s2; - - if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, s1, s2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(s1); - convert_to_string_ex(s2); - - RETURN_LONG(php_strcspn(Z_STRVAL_PP(s1), Z_STRVAL_PP(s2), - Z_STRVAL_PP(s1) + Z_STRLEN_PP(s1), - Z_STRVAL_PP(s2) + Z_STRLEN_PP(s2))); + php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, STR_STRCSPN); } /* }}} */ -- PHP CVS Mailing List (http://www.php.net/) To
[PHP-CVS] cvs: php4 /ext/standard string.c
sebastian Mon Sep 23 10:20:03 2002 EDT Modified files: /php4/ext/standard string.c Log: Fix warning. Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.296 php4/ext/standard/string.c:1.297 --- php4/ext/standard/string.c:1.296Sat Sep 21 13:34:06 2002 +++ php4/ext/standard/string.c Mon Sep 23 10:20:02 2002 -18,7 +18,7 +--+ */ -/* $Id: string.c,v 1.296 2002/09/21 17:34:06 iliaa Exp $ */ +/* $Id: string.c,v 1.297 2002/09/23 14:20:02 sebastian Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ -3113,7 +3113,6 { pval ***args = (pval ***) emalloc(sizeof(pval **)*ZEND_NUM_ARGS()); zval **pcategory, **plocale; - zval *locale; int i, cat, n_args=ZEND_NUM_ARGS(); char *loc, *retval; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php4 /ext/standard string.c
iliaa Fri Sep 20 07:48:48 2002 EDT Modified files: /php4/ext/standard string.c Log: Fixed bugs #12989 and #12120 Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.294 php4/ext/standard/string.c:1.295 --- php4/ext/standard/string.c:1.294Wed Sep 18 03:55:30 2002 +++ php4/ext/standard/string.c Fri Sep 20 07:48:47 2002 -18,7 +18,7 +--+ */ -/* $Id: string.c,v 1.294 2002/09/18 07:55:30 hholzgra Exp $ */ +/* $Id: string.c,v 1.295 2002/09/20 11:48:47 iliaa Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ -3324,7 +3324,7 PHPAPI void php_strip_tags(char *rbuf, int len, int *stateptr, char *allow, int allow_len) { char *tbuf, *buf, *p, *tp, *rp, c, lc; - int br, i=0; + int br, i=0, depth=0; int state = 0; if (stateptr) -3353,6 +3353,8 if(allow) { *(tp++) = ''; } + } else if (state) { + depth++; } break; -3383,6 +3385,11 break; case '': + if (depth) { + depth--; + break; + } + if (state == 1) { lc = ''; state = 0; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php