1
0
mirror of https://github.com/php/php-src.git synced 2026-04-26 17:38:14 +02:00

Unicode support in var_export().

This commit is contained in:
Andrei Zmievski
2006-12-04 18:55:40 +00:00
parent aaf7159f2a
commit 411f6ca0fb
2 changed files with 46 additions and 3 deletions
+1 -1
View File
@@ -4799,7 +4799,7 @@ PHPAPI UChar *php_u_addslashes_ex(UChar *str, int length, int *new_length, int s
*(buf+buf_len) = (UChar)0x30; buf_len++; /* 0 */
break;
case '\'':
case '\"':
case '\"':
case '\\':
*(buf+buf_len) = (UChar)0x5C; buf_len++; /* \ */
/* break is missing *intentionally* */
+45 -2
View File
@@ -521,6 +521,47 @@ static int php_object_element_export(zval **zv, int num_args, va_list args, zend
return 0;
}
static void php_unicode_export(UChar *ustr, int ustr_len TSRMLS_DC)
{
UChar32 cp;
int i = 0;
char buf[10];
int buf_len;
/*
* We export all codepoints > 128 in escaped form to avoid encoding issues
* in case the result is used in a script.
*/
while (i < ustr_len) {
U16_NEXT(ustr, i, ustr_len, cp);
switch (cp) {
case 0x0: /* '\0' */
PHPWRITE("\\0", 2);
break;
case 0x27: /* '\'' */
PHPWRITE("\\'", 2);
break;
case 0x5c: /* '\\' */
PHPWRITE("\\\\", 2);
break;
default:
if ((uint32_t)cp < 128) {
buf[0] = (char) (short) cp;
buf_len = 1;
} else if (U_IS_BMP(cp)) {
buf_len = snprintf(buf, sizeof(buf), "\\u%04X", cp);
} else {
buf_len = snprintf(buf, sizeof(buf), "\\u%06X", cp);
}
PHPWRITE(buf, buf_len);
break;
}
}
}
PHPAPI void php_var_export(zval **struc, int level TSRMLS_DC)
{
HashTable *myht;
@@ -550,7 +591,9 @@ PHPAPI void php_var_export(zval **struc, int level TSRMLS_DC)
efree (tmp_str);
break;
case IS_UNICODE:
php_var_dump_unicode(Z_USTRVAL_PP(struc), Z_USTRLEN_PP(struc), 0, "'", 1 TSRMLS_CC);
PUTS ("'");
php_unicode_export(Z_USTRVAL_PP(struc), Z_USTRLEN_PP(struc) TSRMLS_CC);
PUTS ("'");
break;
case IS_ARRAY:
myht = Z_ARRVAL_PP(struc);
@@ -589,7 +632,7 @@ PHPAPI void php_var_export(zval **struc, int level TSRMLS_DC)
/* }}} */
/* {{{ proto mixed var_export(mixed var [, bool return])
/* {{{ proto mixed var_export(mixed var [, bool return]) U
Outputs or returns a string representation of a variable */
PHP_FUNCTION(var_export)
{