Unicode support cleanup

This commit is contained in:
Dmitry Stogov 2005-08-23 09:33:46 +00:00
parent 24743055a3
commit f4b8f4e958
11 changed files with 67 additions and 137 deletions

View File

@ -604,6 +604,41 @@ END_EXTERN_C()
(z)->type = IS_STRING; \
}
#define ZVAL_U_STRING(conv, z, s, duplicate) \
if (UG(unicode)) { \
UErrorCode status = U_ZERO_ERROR; \
UChar *u_str; \
int32_t u_len; \
uint length = strlen(s); \
zend_convert_to_unicode(conv, &u_str, &u_len, s, length, &status); \
ZVAL_UNICODEL(z, u_str, u_len, 0); \
} else { \
char *__s=(s); \
(z)->value.str.len = strlen(__s); \
(z)->value.str.val = (duplicate?estrndup(__s, (z)->value.str.len):__s); \
(z)->type = IS_STRING; \
}
#define ZVAL_U_STRINGL(conv, z, s, l, duplicate) \
if (UG(unicode)) { \
UErrorCode status = U_ZERO_ERROR; \
UChar *u_str; \
int32_t u_len; \
zend_convert_to_unicode(conv, &u_str, &u_len, s, l, &status); \
ZVAL_UNICODEL(z, u_str, u_len, 0); \
} else { \
char *__s=(s); int __l=l; \
(z)->value.str.len = __l; \
(z)->value.str.val = (duplicate?estrndup(__s, __l):__s); \
(z)->type = IS_STRING; \
}
#define ZVAL_RT_STRING(z, s, duplicate) \
ZVAL_U_STRING(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), z, s, duplicate)
#define ZVAL_RT_STRINGL(z, s, l, duplicate) \
ZVAL_U_STRINGL(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), z, s, l, duplicate)
#define ZVAL_UNICODE(z, u, duplicate) { \
UChar *__u=(u); \
(z)->value.ustr.len = u_strlen(__u); \
@ -705,6 +740,10 @@ END_EXTERN_C()
#define RETVAL_STRINGL(s, l, duplicate) ZVAL_STRINGL(return_value, s, l, duplicate)
#define RETVAL_ASCII_STRING(s, duplicate) ZVAL_ASCII_STRING(return_value, s, duplicate)
#define RETVAL_ASCII_STRINGL(s, l, duplicate) ZVAL_ASCII_STRINGL(return_value, s, l, duplicate)
#define RETVAL_U_STRING(conv, s, duplicate) ZVAL_U_STRING(conv, return_value, s, duplicate)
#define RETVAL_U_STRINGL(conv, s, l, duplicate) ZVAL_U_STRINGL(conv, return_value, s, l, duplicate)
#define RETVAL_RT_STRING(s, duplicate) ZVAL_RT_STRING(return_value, s, duplicate)
#define RETVAL_RT_STRINGL(s, l, duplicate) ZVAL_RT_STRINGL(return_value, s, l, duplicate)
#define RETVAL_EMPTY_STRING() ZVAL_EMPTY_STRING(return_value)
#define RETVAL_UNICODE(u, duplicate) ZVAL_UNICODE(return_value, u, duplicate)
#define RETVAL_UNICODEL(u, l, duplicate) ZVAL_UNICODEL(return_value, u, l, duplicate)
@ -739,6 +778,10 @@ END_EXTERN_C()
#define RETURN_TEXTL(t, l, duplicate) { RETVAL_TEXTL(t, l, duplicate); return; }
#define RETURN_ASCII_STRING(t, duplicate) { RETVAL_ASCII_STRING(t, duplicate); return; }
#define RETURN_ASCII_STRINGL(t, l, duplicate) { RETVAL_ASCII_STRINGL(t, l, duplicate); return; }
#define RETURN_U_STRING(conv, t, duplicate) { RETVAL_U_STRING(conv, t, duplicate); return; }
#define RETURN_U_STRINGL(conv, t, l, duplicate) { RETVAL_U_STRINGL(conv, t, l, duplicate); return; }
#define RETURN_RT_STRING(t, duplicate) { RETVAL_RT_STRING(t, duplicate); return; }
#define RETURN_RT_STRINGL(t, l, duplicate) { RETVAL_RT_STRINGL(t, l, duplicate); return; }
#define SET_VAR_STRING(n, v) { \
{ \

View File

@ -428,19 +428,8 @@ static void pdo_stmt_construct(pdo_stmt_t *stmt, zval *object, zend_class_entry
zval z_key;
MAKE_STD_ZVAL(query_string);
if (UG(unicode)) {
UErrorCode status = U_ZERO_ERROR;
UChar *u_str;
int32_t u_len;
zend_convert_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &u_str, &u_len, stmt->query_string, stmt->query_stringlen, &status);
ZVAL_UNICODEL(query_string, u_str, u_len, 0);
u_str = zend_ascii_to_unicode("queryString", sizeof("queryString") ZEND_FILE_LINE_CC);
ZVAL_UNICODEL(&z_key, u_str, sizeof("queryString")-1, 0);
} else {
ZVAL_STRINGL(query_string, stmt->query_string, stmt->query_stringlen, 1);
ZVAL_STRINGL(&z_key, "queryString", sizeof("queryString")-1, 0);
}
ZVAL_RT_STRINGL(query_string, stmt->query_string, stmt->query_stringlen, 1);
ZVAL_ASCII_STRINGL(&z_key, "queryString", sizeof("queryString")-1, 0);
std_object_handlers.write_property(object, &z_key, query_string TSRMLS_CC);
zval_ptr_dtor(&query_string);
if (UG(unicode)) {

View File

@ -706,10 +706,7 @@ sxe_properties_get(zval *object TSRMLS_DC)
} else {
if (node->type == XML_TEXT_NODE) {
MAKE_STD_ZVAL(value);
ZVAL_STRING(value, xmlNodeListGetString(node->doc, node, 1), 1);
if (UG(unicode)) {
convert_to_unicode(value);
}
ZVAL_U_STRING(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), value, xmlNodeListGetString(node->doc, node, 1), 1);
zend_hash_next_index_insert(rv, &value, sizeof(zval *), NULL);
goto next_iter;
}

View File

@ -119,11 +119,7 @@ void spl_add_class_name(zval *list, zend_class_entry * pce, int allow, int ce_fl
if (zend_u_hash_find(Z_ARRVAL_P(list), ztype, pce->name, len+1, (void*)&tmp) == FAILURE) {
MAKE_STD_ZVAL(tmp);
if (UG(unicode)) {
ZVAL_UNICODEL(tmp, (UChar *)pce->name, pce->name_length, 1);
} else {
ZVAL_STRINGL(tmp, pce->name, pce->name_length, 1);
}
ZVAL_TEXTL(tmp, pce->name, pce->name_length, 1);
zend_u_hash_add(Z_ARRVAL_P(list), ztype, pce->name, len+1, &tmp, sizeof(zval *), NULL);
}
}

View File

@ -80,19 +80,10 @@ SPL_METHOD(SimpleXMLIterator, key) /* {{{ */
intern = (php_sxe_object *)zend_object_store_get_object(sxe->iter.data TSRMLS_CC);
if (intern != NULL && intern->node != NULL) {
curnode = (xmlNodePtr)((php_libxml_node_ptr *)intern->node)->node;
if (UG(unicode)) {
UErrorCode status = U_ZERO_ERROR;
UChar *u_str;
int32_t u_len;
zend_convert_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &u_str, &u_len, (char*)curnode->name, xmlStrlen(curnode->name), &status);
RETURN_UNICODEL(u_str, u_len, 0);
} else {
RETURN_STRINGL((char*)curnode->name, xmlStrlen(curnode->name), 1);
}
RETURN_U_STRINGL(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), (char*)curnode->name, xmlStrlen(curnode->name), 1);
}
RETURN_FALSE;
RETURN_FALSE;
}
/* }}} */

View File

@ -1917,11 +1917,7 @@ static void php_sqlite_fetch_column(struct php_sqlite_result *res, zval *which,
char *decoded = emalloc(l);
l = php_sqlite_decode_binary(rowdata[j]+1, decoded);
decoded[l] = '\0';
if (UG(unicode)) {
RETVAL_BINARYL(decoded, l, 0);
} else {
RETVAL_STRINGL(decoded, l, 0);
}
RETVAL_BINARYL(decoded, l, 0);
if (!res->buffered) {
efree((char*)rowdata[j]);
rowdata[j] = NULL;
@ -2444,13 +2440,7 @@ PHP_FUNCTION(sqlite_libversion)
if (ZEND_NUM_ARGS() != 0) {
WRONG_PARAM_COUNT;
}
if (UG(unicode)) {
char *temp = (char*)sqlite_libversion();
UChar *u_temp = zend_ascii_to_unicode(temp, strlen(temp)+1 ZEND_FILE_LINE_CC);
RETURN_UNICODE(u_temp, 0);
} else {
RETURN_STRING((char*)sqlite_libversion(), 1);
}
RETURN_ASCII_STRING((char*)sqlite_libversion(), 1);
}
/* }}} */
@ -2461,13 +2451,7 @@ PHP_FUNCTION(sqlite_libencoding)
if (ZEND_NUM_ARGS() != 0) {
WRONG_PARAM_COUNT;
}
if (UG(unicode)) {
char *temp = (char*)sqlite_libencoding();
UChar *u_temp = zend_ascii_to_unicode(temp, strlen(temp)+1 ZEND_FILE_LINE_CC);
RETURN_UNICODE(u_temp, 0);
} else {
RETURN_STRING((char*)sqlite_libencoding(), 1);
}
RETURN_ASCII_STRING((char*)sqlite_libencoding(), 1);
}
/* }}} */
@ -2664,16 +2648,7 @@ PHP_FUNCTION(sqlite_field_name)
RETURN_FALSE;
}
if (UG(unicode)) {
UErrorCode status = U_ZERO_ERROR;
UChar *u_str;
int32_t u_len;
zend_convert_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &u_str, &u_len, res->col_names[field], strlen(res->col_names[field]), &status);
RETURN_UNICODEL(u_str, u_len, 0);
} else {
RETURN_STRING(res->col_names[field], 1);
}
RETURN_U_STRING(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), res->col_names[field], 1);
}
/* }}} */
@ -2914,16 +2889,7 @@ PHP_FUNCTION(sqlite_error_string)
msg = sqlite_error_string(code);
if (msg) {
if (UG(unicode)) {
UErrorCode status = U_ZERO_ERROR;
UChar *u_str;
int32_t u_len;
zend_convert_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &u_str, &u_len, msg, strlen(msg), &status);
RETURN_UNICODEL(u_str, u_len, 0);
} else {
RETURN_STRING((char*)msg, 1);
}
RETURN_U_STRING(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), (char*)msg, 1);
} else {
RETURN_NULL();
}

View File

@ -1461,11 +1461,7 @@ PHP_FUNCTION(extract)
/* break omitted intentionally */
case EXTR_OVERWRITE:
if (UG(unicode)) {
ZVAL_UNICODEL(&final_name, var_name, var_name_len, 1);
} else {
ZVAL_STRINGL(&final_name, var_name, var_name_len, 1);
}
ZVAL_TEXTL(&final_name, var_name, var_name_len, 1);
break;
case EXTR_PREFIX_IF_EXISTS:
@ -1489,11 +1485,7 @@ PHP_FUNCTION(extract)
case EXTR_PREFIX_SAME:
if (!var_exists) {
if (UG(unicode)) {
ZVAL_UNICODEL(&final_name, var_name, var_name_len, 1);
} else {
ZVAL_STRINGL(&final_name, var_name, var_name_len, 1);
}
ZVAL_TEXTL(&final_name, var_name, var_name_len, 1);
}
/* break omitted intentionally */
@ -1534,22 +1526,14 @@ PHP_FUNCTION(extract)
memcpy(Z_STRVAL(final_name)+Z_STRLEN_PP(prefix)+1, var_name, var_name_len+1);
}
} else {
if (UG(unicode)) {
ZVAL_UNICODEL(&final_name, var_name, var_name_len, 1);
} else {
ZVAL_STRINGL(&final_name, var_name, var_name_len, 1);
}
ZVAL_TEXTL(&final_name, var_name, var_name_len, 1);
}
}
break;
default:
if (!var_exists) {
if (UG(unicode)) {
ZVAL_UNICODEL(&final_name, var_name, var_name_len, 1);
} else {
ZVAL_STRINGL(&final_name, var_name, var_name_len, 1);
}
ZVAL_TEXTL(&final_name, var_name, var_name_len, 1);
}
break;
}

View File

@ -1691,7 +1691,7 @@ PHP_FUNCTION(getopt)
MAKE_STD_ZVAL(val);
if (optarg != NULL) {
ZVAL_STRING(val, optarg, 1);
ZVAL_RT_STRING(val, optarg, 1);
} else {
ZVAL_FALSE(val);
}

View File

@ -1128,12 +1128,7 @@ PHP_FUNCTION(image_type_to_mime_type)
}
convert_to_long_ex(p_image_type);
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);
}
ZVAL_ASCII_STRING(return_value, temp, 1);
}
/* }}} */
@ -1177,12 +1172,7 @@ PHP_FUNCTION(image_type_to_extension)
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_ASCII_STRING(temp + !inc_dot, 1);
}
RETURN_FALSE;
@ -1373,12 +1363,9 @@ 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_ascii_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) {
@ -1388,12 +1375,7 @@ PHP_FUNCTION(getimagesize)
add_assoc_long(return_value, "channels", result->channels);
}
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);
}
add_assoc_ascii_string(return_value, "mime", temp, 1);
efree(result);
} else {
RETURN_FALSE;

View File

@ -61,12 +61,7 @@ PHP_NAMED_FUNCTION(php_if_md5)
RETURN_BINARYL(digest, 16, 1);
} else {
make_digest(md5str, digest);
if (UG(unicode)) {
UChar *u_temp = zend_ascii_to_unicode(md5str, 33 ZEND_FILE_LINE_CC);
RETVAL_UNICODE(u_temp, 0);
} else {
RETVAL_STRING(md5str, 1);
}
RETVAL_ASCII_STRING(md5str, 1);
}
}
@ -113,12 +108,7 @@ PHP_NAMED_FUNCTION(php_if_md5_file)
RETURN_BINARYL(digest, 16, 1);
} else {
make_digest(md5str, digest);
if (UG(unicode)) {
UChar *u_temp = zend_ascii_to_unicode(md5str, 33 ZEND_FILE_LINE_CC);
RETVAL_UNICODE(u_temp, 0);
} else {
RETVAL_STRING(md5str, 1);
}
RETVAL_ASCII_STRING(md5str, 1);
}
}
/* }}} */

View File

@ -1459,11 +1459,7 @@ PHP_FUNCTION(strtoupper)
WRONG_PARAM_COUNT;
}
if (Z_TYPE_PP(arg) != IS_STRING && Z_TYPE_PP(arg) != IS_UNICODE) {
if (UG(unicode)) {
convert_to_unicode_ex(arg);
} else {
convert_to_string_ex(arg);
}
convert_to_text_ex(arg);
}
RETVAL_ZVAL(*arg, 1, 0);
@ -1532,11 +1528,7 @@ PHP_FUNCTION(strtolower)
WRONG_PARAM_COUNT;
}
if (Z_TYPE_PP(str) != IS_STRING && Z_TYPE_PP(str) != IS_UNICODE) {
if (UG(unicode)) {
convert_to_unicode_ex(str);
} else {
convert_to_string_ex(str);
}
convert_to_text_ex(str);
}
RETVAL_ZVAL(*str, 1, 0);