CVS update: php3/functions

From: Date: Mon, 04 Jan 1999 17:26:19 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-3249@lists.php.net to get a copy of this message
Date: Monday January 4, 1999 @ 12:26 Author: fmk Update of /repository/php3/functions In directory asf:/u/temp/cvs-serv6206 Modified Files: html.c html.h Log Message: making _php3_htmlentities callable from other api-functions Index: php3/functions/html.c diff -c php3/functions/html.c:1.26 php3/functions/html.c:1.27 *** php3/functions/html.c:1.26 Fri Jan 1 12:59:11 1999 --- php3/functions/html.c Mon Jan 4 12:26:16 1999 *************** *** 28,34 **** +----------------------------------------------------------------------+ */ ! /* $Id: html.c,v 1.26 1999/01/01 17:59:11 zeev Exp $ */ #ifdef THREAD_SAFE #include "tls.h" --- 28,34 ---- +----------------------------------------------------------------------+ */ ! /* $Id: html.c,v 1.27 1999/01/04 17:26:16 fmk Exp $ */ #ifdef THREAD_SAFE #include "tls.h" *************** *** 60,65 **** --- 60,127 ---- "uuml","yacute","thorn","yuml" }; + PHPAPI char * _php3_htmlentities(char *s, int all) + { + int i, len, maxlen; + unsigned char *old; + char *new; + + old = (unsigned char *)s; + i = strlen(s); + + maxlen = 2 * i; + if (maxlen < 128) + maxlen = 128; + new = emalloc (maxlen); + len = 0; + + while (i--) { + if (len + 9 > maxlen) + new = erealloc (new, maxlen += 128); + if (38 == *old) { + memcpy (new + len, "&amp;", 5); + len += 5; + } else if (34 == *old) { + memcpy (new + len, "&quot;", 6); + len += 6; + } else if (60 == *old) { + memcpy (new + len, "&lt;", 4); + len += 4; + } else if (62 == *old) { + memcpy (new + len, "&gt;", 4); + len += 4; + } else if (all && 160 <= *old) { + new [len++] = '&'; + strcpy (new + len, EntTable [*old - 160]); + len += strlen (EntTable [*old - 160]); + new [len++] = ';'; + } else { + new [len++] = *old; + } + old++; + } + new [len] = '\0'; + return new; + } + + static void _htmlentities(INTERNAL_FUNCTION_PARAMETERS, int all) + { + pval *arg; + char *new; + TLS_VARS; + + if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_string(arg); + + new = _php3_htmlentities(arg->value.str.val, all); + + RETVAL_STRINGL(new,strlen(new),1); + efree(new); + } + /* static void _php3_htmlentities(INTERNAL_FUNCTION_PARAMETERS, int all) { pval *arg; *************** *** 112,123 **** RETVAL_STRINGL(new,len,1); efree(new); } /* {{{ proto string htmlspecialchars(string string) Convert special characters to HTML entities */ void php3_htmlspecialchars(INTERNAL_FUNCTION_PARAMETERS) { ! _php3_htmlentities(INTERNAL_FUNCTION_PARAM_PASSTHRU,0); } /* }}} */ --- 174,187 ---- RETVAL_STRINGL(new,len,1); efree(new); } + */ /* {{{ proto string htmlspecialchars(string string) Convert special characters to HTML entities */ void php3_htmlspecialchars(INTERNAL_FUNCTION_PARAMETERS) { ! // _php3_htmlentities(INTERNAL_FUNCTION_PARAM_PASSTHRU,0); ! _htmlentities(INTERNAL_FUNCTION_PARAM_PASSTHRU,0); } /* }}} */ *************** *** 125,131 **** Convert all applicable characters to HTML entities */ void php3_htmlentities(INTERNAL_FUNCTION_PARAMETERS) { ! _php3_htmlentities(INTERNAL_FUNCTION_PARAM_PASSTHRU,1); } /* }}} */ --- 189,196 ---- Convert all applicable characters to HTML entities */ void php3_htmlentities(INTERNAL_FUNCTION_PARAMETERS) { ! // _php3_htmlentities(INTERNAL_FUNCTION_PARAM_PASSTHRU,1); ! _htmlentities(INTERNAL_FUNCTION_PARAM_PASSTHRU,1); } /* }}} */ Index: php3/functions/html.h diff -c php3/functions/html.h:1.7 php3/functions/html.h:1.8 *** php3/functions/html.h:1.7 Fri Jan 1 12:59:11 1999 --- php3/functions/html.h Mon Jan 4 12:26:16 1999 *************** *** 27,38 **** +----------------------------------------------------------------------+ */ ! /* $Id: html.h,v 1.7 1999/01/01 17:59:11 zeev Exp $ */ #ifndef _HTML_H #define _HTML_H extern void php3_htmlspecialchars(INTERNAL_FUNCTION_PARAMETERS); extern void php3_htmlentities(INTERNAL_FUNCTION_PARAMETERS); #endif /* _HTML_H */ --- 27,39 ---- +----------------------------------------------------------------------+ */ ! /* $Id: html.h,v 1.8 1999/01/04 17:26:16 fmk Exp $ */ #ifndef _HTML_H #define _HTML_H extern void php3_htmlspecialchars(INTERNAL_FUNCTION_PARAMETERS); extern void php3_htmlentities(INTERNAL_FUNCTION_PARAMETERS); + PHPAPI char * _php3_htmlentities(char *s, int all); #endif /* _HTML_H */ -- 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 (#3249) next »