Another (and hopefully last) major streams commit.

This moves unicode conversion to the filter layer
(rather than at the lower streams layer)
unicode_filter.c has been moved from ext/unicode to main/streams
as it's an integral part of the streams unicode conversion process.

There are now three ways to set encoding on a stream:

(1) By context
$ctx = stream_context_create(NULL,array('encoding'=>'latin1'));
$fp = fopen('somefile', 'r+t', false, $ctx);

(2) By stream_encoding()
$fp = fopen('somefile', 'r+');
stream_encoding($fp, 'latin1');

(3) By filter
$fp = fopen('somefile', 'r+');
stream_filter_append($fp, 'unicode.from.latin1', STREAM_FILTER_READ);
stream_filter_append($fp, 'unicode.to.latin1', STREAM_FILTER_WRITE);

Note: Methods 1 and 2 are convenience wrappers around method 3.
This commit is contained in:
Sara Golemon 2006-03-29 01:20:43 +00:00
parent f028fcecb5
commit 30a2bd1d11
15 changed files with 275 additions and 238 deletions

View file

@ -206,12 +206,9 @@ struct _php_stream {
php_stream_context *context;
int flags; /* PHP_STREAM_FLAG_XXX */
/* unicode */
UConverter *input_encoding;
UConverter *output_encoding;
/* buffer */
off_t position; /* of underlying stream */
zend_uchar readbuf_type;
zstr readbuf; /* readbuf.s or readbuf.u */
size_t readbuflen; /* Length in units (char or UChar) */
off_t readpos; /* Position in units (char or UChar) */
@ -252,8 +249,6 @@ END_EXTERN_C()
#define php_stream_from_zval_no_verify(xstr, ppzval) (xstr) = (php_stream*)zend_fetch_resource((ppzval) TSRMLS_CC, -1, "stream", NULL, 2, php_file_le_stream(), php_file_le_pstream())
#define PS_ULEN(is_unicode, len) ((is_unicode) ? UBYTES(len) : (len))
#define php_stream_reads_unicode(stream) ((stream->input_encoding) ? 1 : 0)
#define php_stream_writes_unicode(stream) ((stream->output_encoding) ? 1 : 0)
BEGIN_EXTERN_C()
PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream **stream TSRMLS_DC);