CVS update: php3/functions
| From: | sas | Date: | Sun, 07 Mar 1999 21:31:24 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-4521@lists.php.net to get a copy of this message | ||
Date: Sunday March 7, 1999 @ 16:31
Author: sas
Update of /repository/php3/functions
In directory asf:/u/temp/cvs-serv29346/functions
Modified Files:
string.c
Log Message:
ok, in ack to the problems with the previous version, this is much simpler. play with it as much as
you can and stress it, please
Index: php3/functions/string.c
diff -c php3/functions/string.c:1.178 php3/functions/string.c:1.179
*** php3/functions/string.c:1.178 Fri Feb 12 10:41:17 1999
--- php3/functions/string.c Sun Mar 7 16:31:24 1999
***************
*** 30,36 ****
*/
! /* $Id: string.c,v 1.178 1999/02/12 15:41:17 fmk Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
--- 30,36 ----
*/
! /* $Id: string.c,v 1.179 1999/03/07 21:31:24 sas Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
***************
*** 1324,1329 ****
--- 1324,1330 ----
*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
***************
*** 1398,1403 ****
--- 1399,1452 ----
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 Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net