From: Andrei Zmievski Date: Thu, 4 May 2006 18:37:12 +0000 (+0000) Subject: Some more work on property/names stuff. X-Git-Tag: BEFORE_NEW_OUTPUT_API~310 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c631205e0cc9b83cca1ed38aab03c393c736ae27;p=php Some more work on property/names stuff. --- diff --git a/ext/unicode/php_property.h b/ext/unicode/php_property.h index b7c96fff77..f2b183eb7e 100644 --- a/ext/unicode/php_property.h +++ b/ext/unicode/php_property.h @@ -61,6 +61,7 @@ PHP_FUNCTION(char_get_combining_class); PHP_FUNCTION(char_get_digit_value); PHP_FUNCTION(char_get_mirrored); PHP_FUNCTION(char_get_direction); +PHP_FUNCTION(char_get_age); PHP_FUNCTION(char_get_type); PHP_FUNCTION(char_is_valid); diff --git a/ext/unicode/property.c b/ext/unicode/property.c index 6b252cc1b2..e322869e84 100644 --- a/ext/unicode/property.c +++ b/ext/unicode/property.c @@ -218,10 +218,11 @@ PHP_FUNCTION(char_get_digit_value) { UChar *str; int str_len; + int radix = 0; int offset = 0; UChar32 ch; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "u", &str, &str_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "u|l", &str, &str_len, &radix) == FAILURE) { return; } @@ -230,16 +231,23 @@ PHP_FUNCTION(char_get_digit_value) } U16_NEXT(str, offset, str_len, ch); - RETURN_LONG(u_charDigitValue(ch)); + if (ZEND_NUM_ARGS() > 1) { + if (radix < 2 || radix > 36) { + php_error(E_WARNING, "Radix has to be in 2-36 range"); + return; + } + RETURN_LONG(u_digit(ch, radix)); + } else { + RETURN_LONG(u_charDigitValue(ch)); + } } PHP_FUNCTION(char_get_mirrored) { UChar *str; int str_len; - int offset = 0, buf_len; + int offset = 0; UChar32 ch; - UChar buf[3]; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "u", &str, &str_len) == FAILURE) { return; @@ -249,9 +257,8 @@ PHP_FUNCTION(char_get_mirrored) RETURN_FALSE; } U16_NEXT(str, offset, str_len, ch); - buf_len = zend_codepoint_to_uchar(u_charMirror(ch), buf); - RETURN_UNICODEL(buf, buf_len, 1); + RETURN_UCHAR32(u_charMirror(ch)); } PHP_FUNCTION(char_get_direction) @@ -273,6 +280,30 @@ PHP_FUNCTION(char_get_direction) RETURN_LONG((long)u_charDirection(ch)); } +PHP_FUNCTION(char_get_age) +{ + UChar *str; + int str_len; + int offset = 0; + UChar32 ch; + UVersionInfo version; + char buf[18] = { 0, }; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "u", &str, &str_len) == FAILURE) { + return; + } + + if (str_len == 0) { + RETURN_FALSE; + } + U16_NEXT(str, offset, str_len, ch); + + u_charAge(ch, version); + u_versionToString(version, buf); + + RETURN_ASCII_STRING(buf, ZSTR_DUPLICATE); +} + PHP_FUNCTION(char_get_type) { UChar *str; @@ -311,6 +342,75 @@ PHP_FUNCTION(char_is_valid) RETURN_BOOL(U_IS_UNICODE_CHAR(ch)); } +PHP_FUNCTION(char_from_digit) +{ + int digit; + int radix = 10; + UChar32 ch; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &digit, &radix) == FAILURE) { + return; + } + + if (ZEND_NUM_ARGS() > 1) { + if (radix < 2 || radix > 36) { + php_error(E_WARNING, "Radix has to be in 2-36 range"); + return; + } + } + ch = u_forDigit(digit, radix); + + if (ch == (UChar32)0) { + RETURN_FALSE; + } + + RETURN_UCHAR32(ch); +} + +PHP_FUNCTION(char_from_name) +{ +} + +PHP_FUNCTION(char_get_name) +{ + UChar *str; + int str_len; + int offset = 0; + UChar32 ch; + zend_bool extended = FALSE; + UCharNameChoice choice = U_UNICODE_CHAR_NAME; + char *buf; + int buf_len = 128; + UErrorCode status = U_ZERO_ERROR; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "u|b", &str, &str_len, &extended) == FAILURE) { + return; + } + + if (str_len == 0) { + RETURN_FALSE; + } + + if (extended) { + choice = U_EXTENDED_CHAR_NAME; + } + + U16_NEXT(str, offset, str_len, ch); + + buf = emalloc(buf_len); + buf_len = u_charName(ch, choice, buf, buf_len, &status); + if (buf_len == 0) { + efree(buf); + RETURN_FALSE; + } else if (status == U_BUFFER_OVERFLOW_ERROR) { + status = U_ZERO_ERROR; + buf = erealloc(buf, buf_len+1); + buf_len = u_charName(ch, choice, buf, buf_len+1, &status); + } + + RETURN_ASCII_STRINGL(buf, buf_len, ZSTR_AUTOFREE); +} + /* }}} */ /* diff --git a/ext/unicode/unicode.c b/ext/unicode/unicode.c index 2ce4de8576..5aac8dac4e 100644 --- a/ext/unicode/unicode.c +++ b/ext/unicode/unicode.c @@ -231,7 +231,6 @@ PHP_FUNCTION(unicode_get_subst_char) } /* }}} */ - /* {{{ unicode_functions[] */ zend_function_entry unicode_functions[] = { PHP_FE(locale_get_default, NULL) @@ -276,13 +275,18 @@ zend_function_entry unicode_functions[] = { PHP_FE(char_is_titlecase, NULL) PHP_FE(char_get_numeric_value, NULL) - PHP_FE(char_get_combining_class, NULL) PHP_FE(char_get_digit_value, NULL) + PHP_FE(char_get_combining_class, NULL) PHP_FE(char_get_mirrored, NULL) PHP_FE(char_get_direction, NULL) + PHP_FE(char_get_age, NULL) PHP_FE(char_get_type, NULL) PHP_FE(char_is_valid, NULL) + PHP_FE(char_from_digit, NULL) + PHP_FE(char_from_name, NULL) + PHP_FE(char_get_name, NULL) + { NULL, NULL, NULL } }; /* }}} */