[PHP4BETA] CVS update: php4/ext/standard
| From: | sas | Date: | Wed, 21 Apr 1999 16:31:26 +0000 |
| Subject: | [PHP4BETA] CVS update: php4/ext/standard | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-226@lists.php.net to get a copy of this message | ||
Date: Wednesday April 21, 1999 @ 12:31
Author: sas
Update of /repository/php4/ext/standard
In directory php:/tmp/cvs-serv18433/ext/standard
Modified Files:
string.c
Log Message:
str_replace fix
Index: php4/ext/standard/string.c
diff -c php4/ext/standard/string.c:1.2 php4/ext/standard/string.c:1.3
*** php4/ext/standard/string.c:1.2 Sun Apr 18 11:58:27 1999
--- php4/ext/standard/string.c Wed Apr 21 12:31:25 1999
***************
*** 30,36 ****
*/
! /* $Id: string.c,v 1.2 1999/04/18 15:58:27 zeev Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
--- 30,36 ----
*/
! /* $Id: string.c,v 1.3 1999/04/21 16:31:25 sas Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
***************
*** 1234,1239 ****
--- 1234,1240 ----
*target = 0;
}
+ #if 0
/*
* this is a binary safe equivalent to strnstr
* note that we don't check for the end in str_to_str but here
***************
*** 1290,1295 ****
--- 1291,1344 ----
if(_new_length) *_new_length = q - new;
return new;
}
+ #endif
+
+ static char *_php3_memstr(char *s, char *c, size_t n, size_t m)
+ {
+ char *p;
+
+ for(p = s; (p - s) < n; p++)
+ if(memcmp(p, c, m) == 0)
+ return p;
+ return NULL;
+ }
+
+ #define ATTCHSTR(st, sz) \
+ nl += sz; \
+ n = realloc(n, nl + 1); \
+ memcpy(n + no, st, sz); \
+ no += sz
+
+
+ static char *_php3_str_to_str(char *a, int al, char *b, int bl, char *c, int cl,
+ int *newlen)
+ {
+ char *n = NULL, *p, *q;
+ int nl = 0;
+ int no = 0;
+
+ /* run through all occurences of b in a */
+ for(p = q = a; (p = _php3_memstr(p, b, al - (p - a), bl)); q = p) {
+ /* attach everything between the previous occ. and this one */
+ ATTCHSTR(q, p - q);
+ /* attach the replacement string c */
+ ATTCHSTR(c, cl);
+ /* jump over string b in a */
+ p += bl;
+ }
+
+ /* anything left over ? */
+ if((al - (q - a)) > 0) {
+ ATTCHSTR(q, al - (q - a));
+ }
+
+ if(newlen) *newlen = nl;
+ n[nl] = '\0';
+
+ return n;
+ }
+
+ #undef ATTCHSTR
/* {{{ proto string str_replace(string needle, string str, string haystack)
Replace all occurrences of needle in haystack with str */
--
PHP 4 Beta