pollita Fri Mar 24 21:32:39 2006 UTC
Modified files:
/php-src/ext/standard file.c
Log:
Update fgetss() for unicode
http://cvs.php.net/viewcvs.cgi/php-src/ext/standard/file.c?r1=1.428&r2=1.429&diff_format=u
Index: php-src/ext/standard/file.c
diff -u php-src/ext/standard/file.c:1.428 php-src/ext/standard/file.c:1.429
--- php-src/ext/standard/file.c:1.428 Fri Mar 17 22:52:55 2006
+++ php-src/ext/standard/file.c Fri Mar 24 21:32:39 2006
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: file.c,v 1.428 2006/03/17 22:52:55 andrei Exp $ */
+/* $Id: file.c,v 1.429 2006/03/24 21:32:39 pollita Exp $ */
/* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
@@ -1048,70 +1048,55 @@
/* {{{ proto string fgetss(resource fp [, int length, string allowable_tags])
Get a line from file pointer and strip HTML tags */
-/* UTODO: Accept unicode contents */
PHPAPI PHP_FUNCTION(fgetss)
{
- zval **fd, **bytes = NULL, **allow=NULL;
- size_t len = 0;
- size_t actual_len, retval_len;
- char *buf = NULL, *retval;
- php_stream *stream;
- char *allowed_tags=NULL;
- int allowed_tags_len=0;
-
- switch(ZEND_NUM_ARGS()) {
- case 1:
- if (zend_get_parameters_ex(1, &fd) == FAILURE) {
- RETURN_FALSE;
- }
- break;
-
- case 2:
- if (zend_get_parameters_ex(2, &fd, &bytes) == FAILURE) {
- RETURN_FALSE;
- }
- break;
-
- case 3:
- if (zend_get_parameters_ex(3, &fd, &bytes, &allow) ==
FAILURE) {
- RETURN_FALSE;
- }
- convert_to_string_ex(allow);
- allowed_tags = Z_STRVAL_PP(allow);
- allowed_tags_len = Z_STRLEN_PP(allow);
- break;
+ zval *zstream;
+ php_stream *stream;
+ long length = 0;
+ zval **allow = NULL;
+ size_t retlen = 0;
- default:
- WRONG_PARAM_COUNT;
- /* NOTREACHED */
- break;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|lZ", &zstream,
&length, &allow) == FAILURE) {
+ return;
}
- PHP_STREAM_TO_ZVAL(stream, fd);
+ php_stream_from_zval(stream, &zstream);
+
+ if (php_stream_reads_unicode(stream)) {
+ UChar *buf = php_stream_get_line_ex(stream, IS_UNICODE,
NULL_ZSTR, 0, length, &retlen);
+ UChar *allowed = NULL;
+ int allowed_len = 0;
- if (bytes != NULL) {
- convert_to_long_ex(bytes);
- if (Z_LVAL_PP(bytes) <= 0) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length
parameter must be greater than 0");
+ if (!buf) {
RETURN_FALSE;
}
- len = (size_t) Z_LVAL_PP(bytes);
- buf = safe_emalloc(sizeof(char), (len + 1), 0);
- /*needed because recv doesnt set null char at end*/
- memset(buf, 0, len + 1);
- }
+ if (allow) {
+ convert_to_unicode_ex(allow);
+ allowed = Z_USTRVAL_PP(allow);
+ allowed_len = Z_USTRLEN_PP(allow);
+ }
+ retlen = php_u_strip_tags(buf, retlen, &stream->fgetss_state,
allowed, allowed_len TSRMLS_CC);
- if ((retval = php_stream_get_line(stream, buf, len, &actual_len)) ==
NULL) {
- if (buf != NULL) {
- efree(buf);
+ RETURN_UNICODEL(buf, retlen, 0);
+ } else {
+ char *buf = php_stream_get_line_ex(stream, IS_STRING,
NULL_ZSTR, 0, length, &retlen);
+ char *allowed = NULL;
+ int allowed_len = 0;
+
+ if (!buf) {
+ RETURN_FALSE;
}
- RETURN_FALSE;
- }
- retval_len = php_strip_tags(retval, actual_len, &stream->fgetss_state,
allowed_tags, allowed_tags_len);
+ if (allow) {
+ convert_to_string_ex(allow);
+ allowed = Z_STRVAL_PP(allow);
+ allowed_len = Z_STRLEN_PP(allow);
+ }
+ retlen = php_strip_tags(buf, retlen, &stream->fgetss_state,
allowed, allowed_len);
- RETURN_STRINGL(retval, retval_len, 0);
+ RETURN_STRINGL(buf, retlen, 0);
+ }
}
/* }}} */
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php