pollita Tue Sep 19 20:36:49 2006 UTC
Modified files:
/ZendEngine2 zend.c zend_globals.h
/php-src/ext/standard streamsfuncs.c
/php-src/main/streams streams.c
Log:
Add INI controlled default stream encoding (unicode.stream_encoding).
Add convenience function stream_defualt_encoding() for setting it.
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend.c?r1=1.370&r2=1.371&diff_format=u
Index: ZendEngine2/zend.c
diff -u ZendEngine2/zend.c:1.370 ZendEngine2/zend.c:1.371
--- ZendEngine2/zend.c:1.370 Mon Sep 11 14:28:19 2006
+++ ZendEngine2/zend.c Tue Sep 19 20:36:48 2006
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend.c,v 1.370 2006/09/11 14:28:19 tony2001 Exp $ */
+/* $Id: zend.c,v 1.371 2006/09/19 20:36:48 pollita Exp $ */
#include "zend.h"
#include "zend_extensions.h"
@@ -181,6 +181,7 @@
STD_ZEND_INI_ENTRY("unicode.script_encoding", NULL, ZEND_INI_ALL,
OnUpdateEncoding, script_encoding_conv, zend_unicode_globals, unicode_globals)
STD_ZEND_INI_ENTRY("unicode.http_input_encoding", NULL, ZEND_INI_ALL,
OnUpdateEncoding, http_input_encoding_conv, zend_unicode_globals,
unicode_globals)
STD_ZEND_INI_ENTRY("unicode.filesystem_encoding", NULL, ZEND_INI_ALL,
OnUpdateEncoding, filesystem_encoding_conv, zend_unicode_globals,
unicode_globals)
+ STD_ZEND_INI_ENTRY("unicode.stream_encoding", "utf8", ZEND_INI_ALL,
OnUpdateStringUnempty, stream_encoding, zend_unicode_globals, unicode_globals)
ZEND_INI_END()
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_globals.h?r1=1.162&r2=1.163&diff_format=u
Index: ZendEngine2/zend_globals.h
diff -u ZendEngine2/zend_globals.h:1.162 ZendEngine2/zend_globals.h:1.163
--- ZendEngine2/zend_globals.h:1.162 Mon Sep 11 14:28:19 2006
+++ ZendEngine2/zend_globals.h Tue Sep 19 20:36:48 2006
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_globals.h,v 1.162 2006/09/11 14:28:19 tony2001 Exp $ */
+/* $Id: zend_globals.h,v 1.163 2006/09/19 20:36:48 pollita Exp $ */
#ifndef ZEND_GLOBALS_H
#define ZEND_GLOBALS_H
@@ -276,6 +276,10 @@
UConverter *utf8_conv; /* all-purpose UTF-8
converter */
UConverter *ascii_conv; /* all-purpose ASCII
converter */
+ char *stream_encoding; /* default stream encoding
(contents, not FS entries)
+ Uses name of encoding rather
than a real converter
+ because each stream needs its
own instance */
+
uint16_t from_error_mode;
UChar from_subst_char[3];
uint16_t to_error_mode;
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/streamsfuncs.c?r1=1.85&r2=1.86&diff_format=u
Index: php-src/ext/standard/streamsfuncs.c
diff -u php-src/ext/standard/streamsfuncs.c:1.85
php-src/ext/standard/streamsfuncs.c:1.86
--- php-src/ext/standard/streamsfuncs.c:1.85 Tue Sep 19 10:38:31 2006
+++ php-src/ext/standard/streamsfuncs.c Tue Sep 19 20:36:48 2006
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: streamsfuncs.c,v 1.85 2006/09/19 10:38:31 dmitry Exp $ */
+/* $Id: streamsfuncs.c,v 1.86 2006/09/19 20:36:48 pollita Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -1458,6 +1458,24 @@
}
/* }}} */
+
+/* {{{ proto bool stream_default_encoding(string encoding) U
+Convenience wrapper for ini_set('unicode.stream_encoding', $encoding) */
+PHP_FUNCTION(stream_default_encoding)
+{
+ char *encoding;
+ int encoding_len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &encoding,
&encoding_len) == FAILURE) {
+ return;
+ }
+
+ RETURN_BOOL(SUCCESS == zend_alter_ini_entry("unicode.stream_encoding",
sizeof("unicode.stream_encoding"),
+ encoding, encoding_len,
PHP_INI_ALL, PHP_INI_STAGE_RUNTIME));
+}
+/* }}} */
+
+
/* {{{ proto void stream_encoding(resource stream[, string encoding])
Set character set for stream encoding
UTODO: Return current encoding charset
http://cvs.php.net/viewvc.cgi/php-src/main/streams/streams.c?r1=1.134&r2=1.135&diff_format=u
Index: php-src/main/streams/streams.c
diff -u php-src/main/streams/streams.c:1.134
php-src/main/streams/streams.c:1.135
--- php-src/main/streams/streams.c:1.134 Tue Sep 19 10:38:31 2006
+++ php-src/main/streams/streams.c Tue Sep 19 20:36:48 2006
@@ -19,7 +19,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: streams.c,v 1.134 2006/09/19 10:38:31 dmitry Exp $ */
+/* $Id: streams.c,v 1.135 2006/09/19 20:36:48 pollita Exp $ */
#define _GNU_SOURCE
#include "php.h"
@@ -2306,7 +2306,7 @@
/* Only apply implicit unicode.to. filter if the wrapper didn't
do it for us */
if ((php_stream_filter_product(&stream->writefilters,
IS_UNICODE) == IS_UNICODE) &&
(strchr(implicit_mode, 'w') || strchr(implicit_mode,
'a') || strchr(implicit_mode, '+'))) {
- char *encoding = (context && context->output_encoding)
? context->output_encoding : "utf8";
+ char *encoding = (context && context->output_encoding)
? context->output_encoding : UG(stream_encoding);
/* UTODO: (Maybe?) Allow overriding the default error
handlers on a per-stream basis via context params */
php_stream_encoding_apply(stream, 1, encoding,
UG(from_error_mode), UG(from_subst_char));
@@ -2314,7 +2314,7 @@
/* Only apply implicit unicode.from. filter if the wrapper
didn't do it for us */
if ((stream->readbuf_type == IS_STRING) &&
(strchr(implicit_mode, 'r') || strchr(implicit_mode, '+'))) {
- char *encoding = (context && context->input_encoding) ?
context->input_encoding : "utf8";
+ char *encoding = (context && context->input_encoding) ?
context->input_encoding : UG(stream_encoding);
/* UTODO: (Maybe?) Allow overriding the default error
handlers on a per-stream basis via context params */
php_stream_encoding_apply(stream, 0, encoding,
UG(to_error_mode), NULL);
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php