From: Andrei Zmievski Date: Wed, 22 Nov 2006 22:18:46 +0000 (+0000) Subject: Unicode support in get_html_translation_table(). X-Git-Tag: RELEASE_1_0_0RC1~934 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f2ab79dfc7320f67987cbc6f8892c57aa0498a53;p=php Unicode support in get_html_translation_table(). --- diff --git a/ext/standard/html.c b/ext/standard/html.c index db4de38051..840becdff7 100644 --- a/ext/standard/html.c +++ b/ext/standard/html.c @@ -1383,7 +1383,7 @@ PHP_FUNCTION(htmlentities) } /* }}} */ -/* {{{ proto array get_html_translation_table([int table [, int quote_style]]) +/* {{{ proto array get_html_translation_table([int table [, int quote_style]]) U Returns the internal translation table used by htmlspecialchars and htmlentities */ PHP_FUNCTION(get_html_translation_table) { @@ -1391,11 +1391,18 @@ PHP_FUNCTION(get_html_translation_table) int i, j; char ind[2]; enum entity_charset charset = determine_charset(NULL TSRMLS_CC); + UChar32 cp; + UChar key[3]; + int key_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ll", &which, "e_style) == FAILURE) { return; } + if (UG(unicode)) { + charset = cs_utf_8; + } + array_init(return_value); ind[1] = 0; @@ -1410,11 +1417,19 @@ PHP_FUNCTION(get_html_translation_table) if (entity_map[j].table[i] == NULL) continue; - /* what about wide chars here ?? */ - ind[0] = i + entity_map[j].basechar; - sprintf(buffer, "&%s;", entity_map[j].table[i]); - add_assoc_string(return_value, ind, buffer, 1); + if (UG(unicode)) { + cp = (UChar)(i + entity_map[j].basechar); + key_len = zend_codepoint_to_uchar(cp, key); + key[key_len] = 0; + sprintf(buffer, "&%s;", entity_map[j].table[i]); + add_u_assoc_ascii_string_ex(return_value, IS_UNICODE, ZSTR(key), key_len+1, buffer, 1); + } else { + /* no wide chars here, because charset is always cs_8859_1 */ + ind[0] = i + entity_map[j].basechar; + sprintf(buffer, "&%s;", entity_map[j].table[i]); + add_assoc_string(return_value, ind, buffer, 1); + } } } /* break thru */ @@ -1426,9 +1441,9 @@ PHP_FUNCTION(get_html_translation_table) continue; ind[0] = (unsigned char)basic_entities[j].charcode; - add_assoc_stringl(return_value, ind, basic_entities[j].entity, basic_entities[j].entitylen, 1); + add_ascii_assoc_ascii_stringl(return_value, ind, basic_entities[j].entity, basic_entities[j].entitylen, 1); } - add_assoc_stringl(return_value, "&", "&", sizeof("&") - 1, 1); + add_ascii_assoc_ascii_stringl(return_value, "&", "&", sizeof("&") - 1, 1); break; }