From: Dmitry Stogov Date: Tue, 16 Aug 2005 09:11:00 +0000 (+0000) Subject: Unicode support X-Git-Tag: PRE_NEW_OCI8_EXTENSION~226 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=238a40418baf1feed633157d3e602191d91879bf;p=php Unicode support --- diff --git a/ext/standard/image.c b/ext/standard/image.c index acc0b42ea1..3cc4a0e8b6 100644 --- a/ext/standard/image.c +++ b/ext/standard/image.c @@ -1120,13 +1120,20 @@ PHP_FUNCTION(image_type_to_mime_type) { zval **p_image_type; int arg_c = ZEND_NUM_ARGS(); + char *temp; if ((arg_c!=1) || zend_get_parameters_ex(arg_c, &p_image_type) == FAILURE) { RETVAL_FALSE; WRONG_PARAM_COUNT; } convert_to_long_ex(p_image_type); - ZVAL_STRING(return_value, (char*)php_image_type_to_mime_type(Z_LVAL_PP(p_image_type)), 1); + temp = (char*)php_image_type_to_mime_type(Z_LVAL_PP(p_image_type)); + if (UG(unicode)) { + UChar *u_temp = zend_ascii_to_unicode(temp, strlen(temp)+1 ZEND_FILE_LINE_CC); + ZVAL_UNICODE(return_value, u_temp, 0); + } else { + ZVAL_STRING(return_value, temp, 1); + } } /* }}} */ @@ -1136,6 +1143,7 @@ PHP_FUNCTION(image_type_to_extension) { long image_type; zend_bool inc_dot=1; + char *temp = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|b", &image_type, &inc_dot) == FAILURE) { RETURN_FALSE; @@ -1143,30 +1151,38 @@ PHP_FUNCTION(image_type_to_extension) switch (image_type) { case IMAGE_FILETYPE_GIF: - RETURN_STRING(".gif" + !inc_dot, 1); + temp = ".gif"; case IMAGE_FILETYPE_JPEG: - RETURN_STRING(".jpeg" + !inc_dot, 1); + temp = ".jpeg"; case IMAGE_FILETYPE_PNG: - RETURN_STRING(".png" + !inc_dot, 1); + temp = ".png"; case IMAGE_FILETYPE_SWF: case IMAGE_FILETYPE_SWC: - RETURN_STRING(".swf" + !inc_dot, 1); + temp = ".swf"; case IMAGE_FILETYPE_PSD: - RETURN_STRING(".psd" + !inc_dot, 1); + temp = ".psd"; case IMAGE_FILETYPE_BMP: case IMAGE_FILETYPE_WBMP: - RETURN_STRING(".bmp" + !inc_dot, 1); + temp = ".bmp"; case IMAGE_FILETYPE_TIFF_II: case IMAGE_FILETYPE_TIFF_MM: - RETURN_STRING(".tiff" + !inc_dot, 1); + temp = ".tiff"; case IMAGE_FILETYPE_IFF: - RETURN_STRING(".iff" + !inc_dot, 1); + temp = ".iff"; case IMAGE_FILETYPE_JPC: - RETURN_STRING(".jpc" + !inc_dot, 1); + temp = ".jpc"; case IMAGE_FILETYPE_JP2: - RETURN_STRING(".jp2" + !inc_dot, 1); + temp = ".jp2"; case IMAGE_FILETYPE_XBM: - RETURN_STRING(".xbm" + !inc_dot, 1); + temp = ".xbm"; + } + if (temp) { + if (UG(unicode)) { + UChar *u_temp = zend_ascii_to_unicode(temp + !inc_dot, strlen(temp)+inc_dot ZEND_FILE_LINE_CC); + RETURN_UNICODE(u_temp, 0); + } else { + RETURN_STRING(temp + !inc_dot, 1); + } } RETURN_FALSE; @@ -1357,7 +1373,13 @@ PHP_FUNCTION(getimagesize) add_index_long(return_value, 1, result->height); add_index_long(return_value, 2, itype); spprintf(&temp, 0, "width=\"%d\" height=\"%d\"", result->width, result->height); - add_index_string(return_value, 3, temp, 0); + if (UG(unicode)) { + UChar *u_temp = zend_ascii_to_unicode(temp, strlen(temp)+1 ZEND_FILE_LINE_CC); + add_index_unicode(return_value, 3, u_temp, 0); + efree(temp); + } else { + add_index_string(return_value, 3, temp, 0); + } if (result->bits != 0) { add_assoc_long(return_value, "bits", result->bits); @@ -1365,7 +1387,13 @@ PHP_FUNCTION(getimagesize) if (result->channels != 0) { add_assoc_long(return_value, "channels", result->channels); } - add_assoc_string(return_value, "mime", (char*)php_image_type_to_mime_type(itype), 1); + temp = (char*)php_image_type_to_mime_type(itype); + if (UG(unicode)) { + UChar *u_temp = zend_ascii_to_unicode(temp, strlen(temp)+1 ZEND_FILE_LINE_CC); + add_assoc_unicode(return_value, "mime", u_temp, 0); + } else { + add_assoc_string(return_value, "mime", temp, 1); + } efree(result); } else { RETURN_FALSE; diff --git a/ext/standard/tests/image/bug13213.phpt b/ext/standard/tests/image/bug13213.phpt index c97b7016b4..a191905847 100644 --- a/ext/standard/tests/image/bug13213.phpt +++ b/ext/standard/tests/image/bug13213.phpt @@ -21,3 +21,20 @@ array(7) { ["mime"]=> string(10) "image/jpeg" } +--UEXPECT-- +array(7) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + unicode(20) "width="1" height="1"" + [u"bits"]=> + int(8) + [u"channels"]=> + int(3) + [u"mime"]=> + unicode(10) "image/jpeg" +} diff --git a/ext/standard/tests/image/getimagesize.phpt b/ext/standard/tests/image/getimagesize.phpt index 46003cffac..368da04cea 100644 --- a/ext/standard/tests/image/getimagesize.phpt +++ b/ext/standard/tests/image/getimagesize.phpt @@ -194,3 +194,175 @@ array(11) { string(10) "image/tiff" } } +--UEXPECT-- +array(11) { + [u"test1pix.bmp"]=> + array(6) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(6) + [3]=> + unicode(20) "width="1" height="1"" + [u"bits"]=> + int(24) + [u"mime"]=> + unicode(9) "image/bmp" + } + [u"test1pix.jp2"]=> + array(7) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(10) + [3]=> + unicode(20) "width="1" height="1"" + [u"bits"]=> + int(8) + [u"channels"]=> + int(3) + [u"mime"]=> + unicode(9) "image/jp2" + } + [u"test1pix.jpc"]=> + array(7) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(9) + [3]=> + unicode(20) "width="1" height="1"" + [u"bits"]=> + int(8) + [u"channels"]=> + int(3) + [u"mime"]=> + unicode(24) "application/octet-stream" + } + [u"test1pix.jpg"]=> + array(7) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + unicode(20) "width="1" height="1"" + [u"bits"]=> + int(8) + [u"channels"]=> + int(3) + [u"mime"]=> + unicode(10) "image/jpeg" + } + [u"test2pix.gif"]=> + array(7) { + [0]=> + int(2) + [1]=> + int(1) + [2]=> + int(1) + [3]=> + unicode(20) "width="2" height="1"" + [u"bits"]=> + int(1) + [u"channels"]=> + int(3) + [u"mime"]=> + unicode(9) "image/gif" + } + [u"test4pix.gif"]=> + array(7) { + [0]=> + int(4) + [1]=> + int(1) + [2]=> + int(1) + [3]=> + unicode(20) "width="4" height="1"" + [u"bits"]=> + int(2) + [u"channels"]=> + int(3) + [u"mime"]=> + unicode(9) "image/gif" + } + [u"test4pix.iff"]=> + array(6) { + [0]=> + int(4) + [1]=> + int(1) + [2]=> + int(14) + [3]=> + unicode(20) "width="4" height="1"" + [u"bits"]=> + int(4) + [u"mime"]=> + unicode(9) "image/iff" + } + [u"test4pix.png"]=> + array(6) { + [0]=> + int(4) + [1]=> + int(1) + [2]=> + int(3) + [3]=> + unicode(20) "width="4" height="1"" + [u"bits"]=> + int(4) + [u"mime"]=> + unicode(9) "image/png" + } + [u"test4pix.psd"]=> + array(5) { + [0]=> + int(4) + [1]=> + int(1) + [2]=> + int(5) + [3]=> + unicode(20) "width="4" height="1"" + [u"mime"]=> + unicode(9) "image/psd" + } + [u"test4pix.swf"]=> + array(5) { + [0]=> + int(550) + [1]=> + int(400) + [2]=> + int(4) + [3]=> + unicode(24) "width="550" height="400"" + [u"mime"]=> + unicode(29) "application/x-shockwave-flash" + } + [u"test4pix.tif"]=> + array(5) { + [0]=> + int(4) + [1]=> + int(1) + [2]=> + int(7) + [3]=> + unicode(20) "width="4" height="1"" + [u"mime"]=> + unicode(10) "image/tiff" + } +} diff --git a/ext/standard/tests/image/getimagesize_246x247.phpt b/ext/standard/tests/image/getimagesize_246x247.phpt index e5a0aea779..6f1c44124d 100644 --- a/ext/standard/tests/image/getimagesize_246x247.phpt +++ b/ext/standard/tests/image/getimagesize_246x247.phpt @@ -40,3 +40,21 @@ array(1) { string(9) "image/png" } } +--UEXPECT-- +array(1) { + [u"246x247.png"]=> + array(6) { + [0]=> + int(246) + [1]=> + int(247) + [2]=> + int(3) + [3]=> + unicode(24) "width="246" height="247"" + [u"bits"]=> + int(4) + [u"mime"]=> + unicode(9) "image/png" + } +} diff --git a/ext/standard/tests/image/getimagesize_384x385.phpt b/ext/standard/tests/image/getimagesize_384x385.phpt index 0051df71e0..a75c8e051a 100644 --- a/ext/standard/tests/image/getimagesize_384x385.phpt +++ b/ext/standard/tests/image/getimagesize_384x385.phpt @@ -40,3 +40,21 @@ array(1) { string(9) "image/png" } } +--UEXPECT-- +array(1) { + [u"384x385.png"]=> + array(6) { + [0]=> + int(384) + [1]=> + int(385) + [2]=> + int(3) + [3]=> + unicode(24) "width="384" height="385"" + [u"bits"]=> + int(1) + [u"mime"]=> + unicode(9) "image/png" + } +} diff --git a/ext/standard/tests/image/getimagesize_swc.phpt b/ext/standard/tests/image/getimagesize_swc.phpt index f8c74498a4..516164d7a9 100644 --- a/ext/standard/tests/image/getimagesize_swc.phpt +++ b/ext/standard/tests/image/getimagesize_swc.phpt @@ -23,3 +23,16 @@ array(5) { ["mime"]=> string(29) "application/x-shockwave-flash" } +--UEXPECT-- +array(5) { + [0]=> + int(550) + [1]=> + int(400) + [2]=> + int(13) + [3]=> + unicode(24) "width="550" height="400"" + [u"mime"]=> + unicode(29) "application/x-shockwave-flash" +} diff --git a/ext/standard/tests/image/image_type_to_mime_type.phpt b/ext/standard/tests/image/image_type_to_mime_type.phpt index 94aabba0b9..d241aaf4ed 100644 --- a/ext/standard/tests/image/image_type_to_mime_type.phpt +++ b/ext/standard/tests/image/image_type_to_mime_type.phpt @@ -48,4 +48,29 @@ array(11) { string(29) "application/x-shockwave-flash" ["test4pix.tif"]=> string(10) "image/tiff" +} +--UEXPECT-- +array(11) { + [u"test1pix.bmp"]=> + unicode(9) "image/bmp" + [u"test1pix.jp2"]=> + unicode(9) "image/jp2" + [u"test1pix.jpc"]=> + unicode(24) "application/octet-stream" + [u"test1pix.jpg"]=> + unicode(10) "image/jpeg" + [u"test2pix.gif"]=> + unicode(9) "image/gif" + [u"test4pix.gif"]=> + unicode(9) "image/gif" + [u"test4pix.iff"]=> + unicode(9) "image/iff" + [u"test4pix.png"]=> + unicode(9) "image/png" + [u"test4pix.psd"]=> + unicode(9) "image/psd" + [u"test4pix.swf"]=> + unicode(29) "application/x-shockwave-flash" + [u"test4pix.tif"]=> + unicode(10) "image/tiff" } \ No newline at end of file