]> granicus.if.org Git - php/commitdiff
Some more work on property/names stuff.
authorAndrei Zmievski <andrei@php.net>
Thu, 4 May 2006 18:37:12 +0000 (18:37 +0000)
committerAndrei Zmievski <andrei@php.net>
Thu, 4 May 2006 18:37:12 +0000 (18:37 +0000)
ext/unicode/php_property.h
ext/unicode/property.c
ext/unicode/unicode.c

index b7c96fff77968314265dfcc892c6e484f70f308a..f2b183eb7e3b3b83ae9c63d3b989b67952a2f349 100644 (file)
@@ -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);
 
index 6b252cc1b211eea54d05efb9ae8a3d44d5af15bd..e322869e84299ccc62db8dc24a66f42711549ef4 100644 (file)
@@ -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);
+}
+
 /* }}} */
 
 /*
index 2ce4de8576b9df318cc9fd42d0b9ef27dbdc177b..5aac8dac4e3d629515febcd36b334233c1182577 100644 (file)
@@ -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 }
 };
 /* }}} */