CVS update: php3/functions

From: Date: Mon, 19 Apr 1999 07:45:38 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-5129@lists.php.net to get a copy of this message
Date: Monday April 19, 1999 @ 3:45 Author: thies Update of /repository/php3/functions In directory asf:/u/temp/cvs-serv10310/functions Modified Files: php3_string.h string.c Log Message: made strtr() binary safe & faster (no more calls to strlen())! we should REALLY check every single strlen() in the sources and check if they are REALLY needed!! Index: php3/functions/php3_string.h diff -c php3/functions/php3_string.h:1.40 php3/functions/php3_string.h:1.41 *** php3/functions/php3_string.h:1.40 Tue Apr 13 10:28:46 1999 --- php3/functions/php3_string.h Mon Apr 19 03:45:38 1999 *************** *** 29,35 **** */ ! /* $Id: php3_string.h,v 1.40 1999/04/13 14:28:46 fmk Exp $ */ #ifndef _PHPSTRING_H #define _PHPSTRING_H --- 29,35 ---- */ ! /* $Id: php3_string.h,v 1.41 1999/04/19 07:45:38 thies Exp $ */ #ifndef _PHPSTRING_H #define _PHPSTRING_H *************** *** 95,101 **** #if 0 extern PHPAPI char *_StrTr(char *string, char *str_from, char *str_to); #endif ! extern PHPAPI char *_php3_strtr(char *string, char *str_from, char *str_to); extern PHPAPI char *_php3_addslashes(char *string, int length, int *new_length, int freeit); extern PHPAPI void _php3_stripslashes(char *string, int *len); extern PHPAPI void _php3_dirname(char *str, int len); --- 95,101 ---- #if 0 extern PHPAPI char *_StrTr(char *string, char *str_from, char *str_to); #endif ! extern PHPAPI char *_php3_strtr(char *string, int len, char *str_from, char *str_to, int trlen); extern PHPAPI char *_php3_addslashes(char *string, int length, int *new_length, int freeit); extern PHPAPI void _php3_stripslashes(char *string, int *len); extern PHPAPI void _php3_dirname(char *str, int len); Index: php3/functions/string.c diff -c php3/functions/string.c:1.184 php3/functions/string.c:1.185 *** php3/functions/string.c:1.184 Sat Apr 17 20:09:50 1999 --- php3/functions/string.c Mon Apr 19 03:45:38 1999 *************** *** 30,36 **** */ ! /* $Id: string.c,v 1.184 1999/04/18 00:09:50 sas Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif --- 30,36 ---- */ ! /* $Id: string.c,v 1.185 1999/04/19 07:45:38 thies Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif *************** *** 229,235 **** void php3_ltrim(INTERNAL_FUNCTION_PARAMETERS) { pval *str; - register int i; TLS_VARS; if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &str) == FAILURE) { --- 229,234 ---- *************** *** 1019,1043 **** } /* }}} */ ! PHPAPI char *_php3_strtr(char *string, char *str_from, char *str_to) { ! int i, len1, len2; unsigned char xlat[256]; ! len1 = strlen(str_from); ! len2 = strlen(str_to); - if (len1 > len2) { - str_from[len2] = '\0'; - len1 = len2; - } for (i = 0; i < 256; xlat[i] = i, i++); ! for (i = 0; i < len1; i++) { xlat[(unsigned char) str_from[i]] = str_to[i]; } ! for (i = 0; i < (int)strlen(string); i++) { string[i] = xlat[(unsigned char) string[i]]; } --- 1018,1038 ---- } /* }}} */ ! PHPAPI char *_php3_strtr(char *string, int len, char *str_from, char *str_to, int trlen) { ! int i; unsigned char xlat[256]; ! if ((trlen < 1) || (len < 1)) ! return string; for (i = 0; i < 256; xlat[i] = i, i++); ! for (i = 0; i < trlen; i++) { xlat[(unsigned char) str_from[i]] = str_to[i]; } ! for (i = 0; i < len; i++) { string[i] = xlat[(unsigned char) string[i]]; } *************** *** 1059,1065 **** convert_to_string(from); convert_to_string(to); ! RETVAL_STRING(_php3_strtr(str->value.str.val, from->value.str.val, to->value.str.val),1); } /* }}} */ --- 1054,1065 ---- convert_to_string(from); convert_to_string(to); ! RETVAL_STRING(_php3_strtr(str->value.str.val, ! str->value.str.len, ! from->value.str.val, ! to->value.str.val, ! MIN(from->value.str.len,to->value.str.len)), ! 1); } /* }}} */ -- 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 (#5129) next »