mirror of
https://github.com/php/php-src.git
synced 2025-08-18 06:58:55 +02:00
Implement to-Unicode conversion error behavior. Note the adjusted APIs.
This commit is contained in:
parent
a64789a452
commit
1709428494
9 changed files with 119 additions and 68 deletions
|
@ -136,6 +136,8 @@ PHP_FUNCTION(unicode_set_error_mode)
|
|||
|
||||
if (direction == ZEND_FROM_UNICODE) {
|
||||
UG(from_error_mode) = mode;
|
||||
} else {
|
||||
UG(to_error_mode) = mode;
|
||||
}
|
||||
|
||||
zend_update_converters_error_behavior(TSRMLS_C);
|
||||
|
@ -143,25 +145,17 @@ PHP_FUNCTION(unicode_set_error_mode)
|
|||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool unicode_set_subst_char(int direction, string character) U
|
||||
Sets global substitution character for the specified conversion direction */
|
||||
/* {{{ proto bool unicode_set_subst_char(string character) U
|
||||
Sets global substitution character for conversion from Unicode to codepage */
|
||||
PHP_FUNCTION(unicode_set_subst_char)
|
||||
{
|
||||
zend_conv_direction direction;
|
||||
UChar *subst_char;
|
||||
UChar32 cp;
|
||||
int subst_char_len;
|
||||
long tmp;
|
||||
int subst_char_len, len;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lu", &tmp, &subst_char, &subst_char_len) == FAILURE) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "u", &subst_char, &subst_char_len) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
direction = (zend_conv_direction) tmp;
|
||||
|
||||
if (direction != ZEND_FROM_UNICODE && direction != ZEND_TO_UNICODE) {
|
||||
php_error(E_WARNING, "Invalid conversion direction value");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (subst_char_len < 1 ) {
|
||||
php_error(E_WARNING, "Empty substitution character");
|
||||
|
@ -175,12 +169,8 @@ PHP_FUNCTION(unicode_set_subst_char)
|
|||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (direction == ZEND_FROM_UNICODE) {
|
||||
int len;
|
||||
len = zend_codepoint_to_uchar(cp, UG(from_subst_char));
|
||||
UG(from_subst_char)[len] = 0;
|
||||
}
|
||||
|
||||
len = zend_codepoint_to_uchar(cp, UG(from_subst_char));
|
||||
UG(from_subst_char)[len] = 0;
|
||||
zend_update_converters_error_behavior(TSRMLS_C);
|
||||
RETURN_TRUE;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue