Hook into new unicode conversion error handling API

This commit is contained in:
Sara Golemon 2006-03-24 20:21:48 +00:00
parent 880dd406f2
commit 0260dfc9b1
2 changed files with 14 additions and 4 deletions

View file

@ -706,9 +706,14 @@ PHPAPI int _php_stream_bucket_convert(php_stream_bucket *bucket, unsigned char t
} else { } else {
UErrorCode status = U_ZERO_ERROR; UErrorCode status = U_ZERO_ERROR;
char *dest; char *dest;
int destlen; int destlen, num_conv;
zend_convert_from_unicode(conv, &dest, &destlen, bucket->buf.u, bucket->buflen, &status); num_conv = zend_convert_from_unicode(conv, &dest, &destlen, bucket->buf.u, bucket->buflen, &status);
if (U_FAILURE(status)) {
int32_t offset = u_countChar32(bucket->buf.u, num_conv)-1;
zend_raise_conversion_error_ex("Could not convert Unicode string to binary string", conv, offset, (UG(from_u_error_mode) & ZEND_CONV_ERROR_EXCEPTION) TSRMLS_CC);
}
if (bucket->own_buf) { if (bucket->own_buf) {
pefree(bucket->buf.u, bucket->is_persistent); pefree(bucket->buf.u, bucket->is_persistent);

View file

@ -1256,10 +1256,15 @@ static size_t _php_stream_write_buffer(php_stream *stream, int buf_type, zstr bu
if (stream->output_encoding && buf_type == IS_UNICODE) { if (stream->output_encoding && buf_type == IS_UNICODE) {
char *dest; char *dest;
int destlen; int destlen, num_conv;
UErrorCode status = U_ZERO_ERROR; UErrorCode status = U_ZERO_ERROR;
zend_convert_from_unicode(stream->output_encoding, &dest, &destlen, buf.u, buflen, &status); num_conv = zend_convert_from_unicode(stream->output_encoding, &dest, &destlen, buf.u, buflen, &status);
if (U_FAILURE(status)) {
int32_t offset = u_countChar32(buf.u, num_conv)-1;
zend_raise_conversion_error_ex("Could not convert Unicode string to binary string", stream->output_encoding, offset, (UG(from_u_error_mode) & ZEND_CONV_ERROR_EXCEPTION) TSRMLS_CC);
}
freeme = buf.s = dest; freeme = buf.s = dest;
buflen = destlen; buflen = destlen;
} else { } else {