CVS update: php3/functions

From: Date: Sun, 20 Dec 1998 15:44:59 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-2910@lists.php.net to get a copy of this message
Date: Sunday December 20, 1998 @ 10:44 Author: rasmus Update of /repository/php3/functions In directory asf:/home/rasmus/php3/functions Modified Files: basic_functions.c php3_string.h string.c Log Message: Get rid of chr_replace() and let str_replace() be the single unified interface to this functionality. Make _php3_char_to_str() binary-safe. Index: php3/functions/basic_functions.c diff -c php3/functions/basic_functions.c:1.240 php3/functions/basic_functions.c:1.241 *** php3/functions/basic_functions.c:1.240 Sun Dec 20 02:32:28 1998 --- php3/functions/basic_functions.c Sun Dec 20 10:44:58 1998 *************** *** 175,181 **** {"hebrev", php3_hebrev, NULL}, {"hebrevc", php3_hebrev_with_conversion,NULL}, {"nl2br", php3_newline_to_br, NULL}, - {"chr_replace", php3_chr_replace, NULL}, {"basename", php3_basename, NULL}, {"dirname", php3_dirname, NULL}, {"stripslashes", php3_stripslashes, NULL}, --- 175,180 ---- Index: php3/functions/php3_string.h diff -c php3/functions/php3_string.h:1.26 php3/functions/php3_string.h:1.27 *** php3/functions/php3_string.h:1.26 Sun Dec 20 02:32:28 1998 --- php3/functions/php3_string.h Sun Dec 20 10:44:58 1998 *************** *** 29,35 **** */ ! /* $Id: php3_string.h,v 1.26 1998/12/20 07:32:28 sas Exp $ */ #ifndef _PHPSTRING_H #define _PHPSTRING_H --- 29,35 ---- */ ! /* $Id: php3_string.h,v 1.27 1998/12/20 15:44:58 rasmus Exp $ */ #ifndef _PHPSTRING_H #define _PHPSTRING_H *************** *** 75,81 **** extern void php3_chr(INTERNAL_FUNCTION_PARAMETERS); extern void php3_ord(INTERNAL_FUNCTION_PARAMETERS); extern void php3_newline_to_br(INTERNAL_FUNCTION_PARAMETERS); - extern void php3_chr_replace(INTERNAL_FUNCTION_PARAMETERS); extern void php3_setlocale(INTERNAL_FUNCTION_PARAMETERS); extern void php3_stristr(INTERNAL_FUNCTION_PARAMETERS); extern void php3_chunk_split(INTERNAL_FUNCTION_PARAMETERS); --- 75,80 ---- Index: php3/functions/string.c diff -c php3/functions/string.c:1.154 php3/functions/string.c:1.155 *** php3/functions/string.c:1.154 Sun Dec 20 10:14:30 1998 --- php3/functions/string.c Sun Dec 20 10:44:59 1998 *************** *** 30,36 **** */ ! /* $Id: string.c,v 1.154 1998/12/20 15:14:30 rasmus Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif --- 30,36 ---- */ ! /* $Id: string.c,v 1.155 1998/12/20 15:44:59 rasmus Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif *************** *** 1197,1205 **** static void _php3_char_to_str(char *str,uint len,char from,char *to,int to_len,pval *result) { int char_count=0; ! char *source,*target,*tmp,*source_end=str+len; ! for (source=str; *source; source++) { if (*source==from) { char_count++; } --- 1197,1205 ---- static void _php3_char_to_str(char *str,uint len,char from,char *to,int to_len,pval *result) { int char_count=0; ! char *source,*target,*tmp,*source_end=str+len, *tmp_end=NULL; ! for (source=str; source<source_end; source++) { if (*source==from) { char_count++; } *************** *** 1218,1224 **** for (source=str; source<source_end; source++) { if (*source==from) { ! for (tmp=to; *tmp; tmp++) { *target = *tmp; target++; } --- 1218,1224 ---- for (source=str; source<source_end; source++) { if (*source==from) { ! for (tmp=to,tmp_end=tmp+to_len; tmp<tmp_end; tmp++) { *target = *tmp; target++; } *************** *** 1288,1294 **** } /* {{{ proto string str_replace(string needle, string str, string haystack) ! Replaces all occurences of needle in haystack with str */ void php3_str_replace(INTERNAL_FUNCTION_PARAMETERS) { pval *haystack, *needle, *str; --- 1288,1294 ---- } /* {{{ proto string str_replace(string needle, string str, string haystack) ! Replace all occurrences of needle in haystack with str */ void php3_str_replace(INTERNAL_FUNCTION_PARAMETERS) { pval *haystack, *needle, *str; *************** *** 1303,1311 **** convert_to_string(needle); convert_to_string(str); ! if(needle->value.str.len == 1 && isalnum((int)*(needle->value.str.val))) { ! /* argh, chr_replace isn't binary safe */ ! return php3_chr_replace(INTERNAL_FUNCTION_PARAM_PASSTHRU); } new = _php3_str_to_str(haystack->value.str.val, haystack->value.str.len, --- 1303,1311 ---- convert_to_string(needle); convert_to_string(str); ! if(needle->value.str.len == 1) { ! _php3_char_to_str(haystack->value.str.val,haystack->value.str.len,needle->value.str.val[0],str->value.str.val, str->value.str.len ,return_value); ! return; } new = _php3_str_to_str(haystack->value.str.val, haystack->value.str.len, *************** *** 1313,1320 **** str->value.str.val, str->value.str.len, &return_value->value.str.len); return_value->value.str.val = emalloc(return_value->value.str.len + 1); ! memcpy(return_value->value.str.val, new, ! return_value->value.str.len + 1); free(new); return_value->type = IS_STRING; } --- 1313,1319 ---- str->value.str.val, str->value.str.len, &return_value->value.str.len); return_value->value.str.val = emalloc(return_value->value.str.len + 1); ! memcpy(return_value->value.str.val, new, return_value->value.str.len + 1); free(new); return_value->type = IS_STRING; } *************** *** 1516,1539 **** convert_to_string(str); _php3_char_to_str(str->value.str.val,str->value.str.len,'\n',"<br>\n",5,return_value); - } - /* }}} */ - - /* {{{ proto string chr_replace(string char, string repl, string str) - Find all occurrences of char in str and replace with repl */ - void php3_chr_replace(INTERNAL_FUNCTION_PARAMETERS) - { - pval *chr, *replace, *str; - - if (ARG_COUNT(ht)!=3 || getParameters(ht, 3, &chr, &replace, &str)==FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string(chr); - convert_to_string(replace); - convert_to_string(str); - - _php3_char_to_str(str->value.str.val,str->value.str.len,chr->value.str.val[0],replace->value.str.val, replace->value.str.len ,return_value); } /* }}} */ --- 1515,1520 ---- -- 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

« previous php.dev (#2910) next »