andrei          Tue May  9 18:21:27 2006 UTC

  Modified files:              
    /php-src/ext/unicode        php_property.h property.c unicode.c 
  Log:
  Add char_enum_types().
  
  
http://cvs.php.net/viewcvs.cgi/php-src/ext/unicode/php_property.h?r1=1.8&r2=1.9&diff_format=u
Index: php-src/ext/unicode/php_property.h
diff -u php-src/ext/unicode/php_property.h:1.8 
php-src/ext/unicode/php_property.h:1.9
--- php-src/ext/unicode/php_property.h:1.8      Tue May  9 00:06:08 2006
+++ php-src/ext/unicode/php_property.h  Tue May  9 18:21:27 2006
@@ -14,7 +14,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_property.h,v 1.8 2006/05/09 00:06:08 andrei Exp $ */ 
+/* $Id: php_property.h,v 1.9 2006/05/09 18:21:27 andrei Exp $ */ 
 
 #ifndef PHP_PROPERTY_H
 #define PHP_PROPERTY_H
@@ -84,6 +84,7 @@
 PHP_FUNCTION(char_get_property_value_from_name);
 
 PHP_FUNCTION(char_enum_names);
+PHP_FUNCTION(char_enum_types);
 
 #endif /* PHP_PROPERTY_H */
 
http://cvs.php.net/viewcvs.cgi/php-src/ext/unicode/property.c?r1=1.13&r2=1.14&diff_format=u
Index: php-src/ext/unicode/property.c
diff -u php-src/ext/unicode/property.c:1.13 php-src/ext/unicode/property.c:1.14
--- php-src/ext/unicode/property.c:1.13 Tue May  9 00:15:45 2006
+++ php-src/ext/unicode/property.c      Tue May  9 18:21:27 2006
@@ -14,7 +14,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: property.c,v 1.13 2006/05/09 00:15:45 andrei Exp $ */ 
+/* $Id: property.c,v 1.14 2006/05/09 18:21:27 andrei Exp $ */ 
 
 #include "php_unicode.h"
 
@@ -51,7 +51,6 @@
        RETURN_BOOL(result);
 }
 
-
 /* {{{ C/POSIX migration functions */
 
 PHP_FUNCTION(char_is_lower)
@@ -645,7 +644,7 @@
 
 /* {{{ Enumerator functions */
 
-static UBool php_enum_char_names(void *context,
+static UBool php_enum_char_names(const void *context,
                                                                 UChar32 code,
                                                                 
UCharNameChoice nameChoice,
                                                                 const char 
*name,
@@ -687,6 +686,44 @@
     return result;
 }
 
+static UBool php_enum_char_type_range(const void *context,
+                                                                         
UChar32 start,
+                                                                         
UChar32 limit,
+                                                                         
UCharCategory type)
+{
+    char_enum_context_t           *ctx = (char_enum_context_t *)context;
+    zval                                  *retval_ptr = NULL;
+    int                                                status;
+    UBool                                      result = FALSE;
+    TSRMLS_FETCH_FROM_CTX(ctx->thread_ctx);
+
+    convert_to_long_ex(ctx->args[0]);
+    convert_to_long_ex(ctx->args[1]);
+    convert_to_long_ex(ctx->args[2]);
+
+    ZVAL_LONG(*ctx->args[0], start);
+    ZVAL_LONG(*ctx->args[1], limit);
+    ZVAL_LONG(*ctx->args[2], type);
+
+    ctx->fci.retval_ptr_ptr = &retval_ptr;
+
+    status = zend_call_function(&ctx->fci, &ctx->fci_cache TSRMLS_CC);
+
+    if (status == SUCCESS && retval_ptr && !EG(exception)) {
+        convert_to_boolean(retval_ptr);
+        result = (UBool)Z_BVAL_P(retval_ptr);
+    } else {
+        if (!EG(exception)) {
+            php_error_docref(NULL TSRMLS_CC, E_WARNING, "Enumeration callback 
encountered an error");
+        }
+        result = FALSE;
+    }
+    if (retval_ptr) {
+        zval_ptr_dtor(&retval_ptr);
+    }
+    return result;
+}
+
 PHP_FUNCTION(char_enum_names)
 {
     zval                          *callback;
@@ -747,6 +784,52 @@
        }
 }
 
+PHP_FUNCTION(char_enum_types)
+{
+    zval                          *callback;
+    zval                          *zstart, *zlimit, *ztype;
+    char_enum_context_t ectx;
+    
+    if (zend_parse_parameters(ZEND_NUM_ARGS()TSRMLS_CC, "z", &callback)) {
+        return;               
+    }   
+    
+       if (!zend_is_callable(callback, 0, NULL)) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid 
enumeration callback");
+               return;
+       }
+
+    /* Do all the heavy lifing once, instead of in the callback */
+    MAKE_STD_ZVAL(zstart);
+    MAKE_STD_ZVAL(zlimit);
+    MAKE_STD_ZVAL(ztype);
+
+    ZVAL_LONG(zstart, 0);
+       ZVAL_LONG(zlimit, 0);
+       ZVAL_LONG(ztype,  0);
+
+    memset(&ectx, 0, sizeof(char_enum_context_t));
+    ectx.fci.size = sizeof(ectx.fci);
+    ectx.fci.function_table = EG(function_table);
+    ectx.fci.function_name = callback;
+    ectx.fci.no_separation = 1;
+    ectx.fci_cache = empty_fcall_info_cache;
+    ectx.args[0] = &zstart;
+    ectx.args[1] = &zlimit;
+    ectx.args[2] = &ztype;
+    ectx.fci.param_count = 3;
+    ectx.fci.params = ectx.args;
+    TSRMLS_SET_CTX(ectx.thread_ctx);
+
+       u_enumCharTypes((UCharEnumTypeRange *)php_enum_char_type_range, (void 
*)&ectx);
+
+    zval_ptr_dtor(&zstart);
+    zval_ptr_dtor(&zlimit);
+    zval_ptr_dtor(&ztype);
+
+       RETURN_TRUE;
+}
+
 /* }}} */
 
 /*
http://cvs.php.net/viewcvs.cgi/php-src/ext/unicode/unicode.c?r1=1.33&r2=1.34&diff_format=u
Index: php-src/ext/unicode/unicode.c
diff -u php-src/ext/unicode/unicode.c:1.33 php-src/ext/unicode/unicode.c:1.34
--- php-src/ext/unicode/unicode.c:1.33  Tue May  9 00:06:08 2006
+++ php-src/ext/unicode/unicode.c       Tue May  9 18:21:27 2006
@@ -15,7 +15,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: unicode.c,v 1.33 2006/05/09 00:06:08 andrei Exp $ */ 
+/* $Id: unicode.c,v 1.34 2006/05/09 18:21:27 andrei Exp $ */ 
 
 #include "php_unicode.h"
 #include "zend_unicode.h"
@@ -296,6 +296,7 @@
        PHP_FE(char_get_property_value_from_name, NULL)
 
        PHP_FE(char_enum_names, NULL)
+       PHP_FE(char_enum_types, NULL)
 
        { NULL, NULL, NULL }
 };

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to