From f0640426cb102eb53f48f8721f99c9cea84eed3f Mon Sep 17 00:00:00 2001 From: Andrei Zmievski Date: Tue, 2 May 2006 21:39:15 +0000 Subject: [PATCH] Implement C/POSIX migration functions. --- ext/unicode/property.c | 84 ++++++++++++++++++++++++++++++++++++++++++ ext/unicode/unicode.c | 16 ++++++++ 2 files changed, 100 insertions(+) diff --git a/ext/unicode/property.c b/ext/unicode/property.c index e7f411afb9..c9ec9652e0 100644 --- a/ext/unicode/property.c +++ b/ext/unicode/property.c @@ -18,7 +18,91 @@ #include "php_unicode.h" +typedef UBool (*prop_check_func_t)(UChar32 ch); +static void check_property_impl(INTERNAL_FUNCTION_PARAMETERS, prop_check_func_t checker) +{ + UChar *str; + int str_len; + zend_bool result = 1; + int offset = 0; + UChar32 ch; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "u", &str, &str_len) == FAILURE) { + return; + } + + while (offset < str_len && result) { + U16_NEXT(str, offset, str_len, ch); + result = checker(ch); + } + + RETURN_BOOL(result); +} + +/* + * C/POSIX migration functinos + */ + +PHP_FUNCTION(unicode_is_lower) +{ + check_property_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, u_islower); +} + +PHP_FUNCTION(unicode_is_upper) +{ + check_property_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, u_isupper); +} + +PHP_FUNCTION(unicode_is_digit) +{ + check_property_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, u_isdigit); +} + +PHP_FUNCTION(unicode_is_alpha) +{ + check_property_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, u_isalpha); +} + +PHP_FUNCTION(unicode_is_alnum) +{ + check_property_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, u_isalnum); +} + +PHP_FUNCTION(unicode_is_xdigit) +{ + check_property_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, u_isxdigit); +} + +PHP_FUNCTION(unicode_is_punct) +{ + check_property_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, u_ispunct); +} + +PHP_FUNCTION(unicode_is_graph) +{ + check_property_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, u_isgraph); +} + +PHP_FUNCTION(unicode_is_blank) +{ + check_property_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, u_isblank); +} + +PHP_FUNCTION(unicode_is_space) +{ + check_property_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, u_isspace); +} + +PHP_FUNCTION(unicode_is_cntrl) +{ + check_property_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, u_iscntrl); +} + +PHP_FUNCTION(unicode_is_print) +{ + check_property_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, u_isprint); +} /* diff --git a/ext/unicode/unicode.c b/ext/unicode/unicode.c index 4f93e116f3..8ab19ec899 100644 --- a/ext/unicode/unicode.c +++ b/ext/unicode/unicode.c @@ -19,6 +19,7 @@ #include "php_unicode.h" #include "zend_unicode.h" +#include "php_property.h" void php_register_unicode_iterators(TSRMLS_D); @@ -246,6 +247,21 @@ zend_function_entry unicode_functions[] = { PHP_FE(collator_compare, NULL) PHP_FE(collator_get_default, NULL) PHP_FE(collator_set_default, NULL) + + /* character property functions */ + PHP_FE(unicode_is_lower, NULL) + PHP_FE(unicode_is_upper, NULL) + PHP_FE(unicode_is_digit, NULL) + PHP_FE(unicode_is_alpha, NULL) + PHP_FE(unicode_is_alnum, NULL) + PHP_FE(unicode_is_xdigit, NULL) + PHP_FE(unicode_is_punct, NULL) + PHP_FE(unicode_is_graph, NULL) + PHP_FE(unicode_is_blank, NULL) + PHP_FE(unicode_is_space, NULL) + PHP_FE(unicode_is_cntrl, NULL) + PHP_FE(unicode_is_print, NULL) + { NULL, NULL, NULL } }; /* }}} */ -- 2.50.1