From: Andrei Zmievski Date: Wed, 3 May 2006 22:03:10 +0000 (+0000) Subject: Some more property functions. X-Git-Tag: BEFORE_NEW_OUTPUT_API~315 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bbde23e24792d261f3b4fc0e6bc4b47a48fbff19;p=php Some more property functions. # I am pondering a different prefix.. --- diff --git a/ext/unicode/php_property.h b/ext/unicode/php_property.h index 3c3de57cdf..6136db095b 100644 --- a/ext/unicode/php_property.h +++ b/ext/unicode/php_property.h @@ -53,6 +53,17 @@ PHP_FUNCTION(unicode_is_u_alphabetic); PHP_FUNCTION(unicode_is_u_uppercase); PHP_FUNCTION(unicode_is_u_lowercase); +/* + * Single character property functions. + */ + +PHP_FUNCTION(unicode_get_numeric_value); +PHP_FUNCTION(unicode_get_combining_class); +PHP_FUNCTION(unicode_get_digit_value); +PHP_FUNCTION(unicode_get_mirror); +PHP_FUNCTION(unicode_get_direction); +PHP_FUNCTION(unicode_get_char_type); +PHP_FUNCTION(unicode_is_char_valid); #endif /* PHP_PROPERTY_H */ diff --git a/ext/unicode/property.c b/ext/unicode/property.c index 8daecd8cd4..fde55223dc 100644 --- a/ext/unicode/property.c +++ b/ext/unicode/property.c @@ -109,9 +109,7 @@ PHP_FUNCTION(unicode_is_print) /* }}} */ -/* - * Additional binary property functions - */ +/* {{{ Additional binary property functions */ PHP_FUNCTION(unicode_is_title) { @@ -178,6 +176,146 @@ PHP_FUNCTION(unicode_is_u_lowercase) check_property_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, u_isULowercase); } +/* }}} */ + +/* {{{ Single character properties */ + +PHP_FUNCTION(unicode_get_numeric_value) +{ + UChar *str; + int str_len; + int offset = 0; + UChar32 ch; + + 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); + + RETURN_DOUBLE(u_getNumericValue(ch)); +} + +PHP_FUNCTION(unicode_get_combining_class) +{ + UChar *str; + int str_len; + int offset = 0; + UChar32 ch; + + 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); + + RETURN_LONG((long)u_getCombiningClass(ch)); +} + +PHP_FUNCTION(unicode_get_digit_value) +{ + UChar *str; + int str_len; + int offset = 0; + UChar32 ch; + + 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); + + RETURN_LONG(u_charDigitValue(ch)); +} + +PHP_FUNCTION(unicode_get_mirror) +{ + UChar *str; + int str_len; + int offset = 0, buf_len; + UChar32 ch; + UChar buf[3]; + + 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); + buf_len = zend_codepoint_to_uchar(u_charMirror(ch), buf); + + RETURN_UNICODEL(buf, buf_len, 1); +} + +PHP_FUNCTION(unicode_get_direction) +{ + UChar *str; + int str_len; + int offset = 0; + UChar32 ch; + + 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); + + RETURN_LONG((long)u_charDirection(ch)); +} + +PHP_FUNCTION(unicode_get_char_type) +{ + UChar *str; + int str_len; + int offset = 0; + UChar32 ch; + + 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); + + RETURN_LONG(u_charType(ch)); +} + +PHP_FUNCTION(unicode_is_char_valid) +{ + UChar *str; + int str_len; + int offset = 0; + UChar32 ch; + + 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); + + RETURN_BOOL(U_IS_UNICODE_CHAR(ch)); +} + +/* }}} */ /* * Local variables: diff --git a/ext/unicode/unicode.c b/ext/unicode/unicode.c index dde3ef54af..f603aef415 100644 --- a/ext/unicode/unicode.c +++ b/ext/unicode/unicode.c @@ -276,6 +276,14 @@ zend_function_entry unicode_functions[] = { PHP_FE(unicode_is_u_uppercase, NULL) PHP_FE(unicode_is_u_lowercase, NULL) + PHP_FE(unicode_get_numeric_value, NULL) + PHP_FE(unicode_get_combining_class, NULL) + PHP_FE(unicode_get_digit_value, NULL) + PHP_FE(unicode_get_mirror, NULL) + PHP_FE(unicode_get_direction, NULL) + PHP_FE(unicode_get_char_type, NULL) + PHP_FE(unicode_is_char_valid, NULL) + { NULL, NULL, NULL } }; /* }}} */