andrei Mon Feb 6 22:58:10 2006 UTC
Modified files:
/php-src/ext/unicode unicode_iterators.c
Log:
- Fix up a bunch of stuff.
- Register TextIterator type constants.
# Not sure if I like them as class constants. Cleaner, but also longer
# to type.
http://cvs.php.net/viewcvs.cgi/php-src/ext/unicode/unicode_iterators.c?r1=1.13&r2=1.14&diff_format=u
Index: php-src/ext/unicode/unicode_iterators.c
diff -u php-src/ext/unicode/unicode_iterators.c:1.13
php-src/ext/unicode/unicode_iterators.c:1.14
--- php-src/ext/unicode/unicode_iterators.c:1.13 Mon Feb 6 18:18:41 2006
+++ php-src/ext/unicode/unicode_iterators.c Mon Feb 6 22:58:10 2006
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: unicode_iterators.c,v 1.13 2006/02/06 18:18:41 andrei Exp $ */
+/* $Id: unicode_iterators.c,v 1.14 2006/02/06 22:58:10 andrei Exp $ */
/*
* TODO
@@ -28,14 +28,17 @@
#include "php.h"
#include "zend_interfaces.h"
#include "zend_exceptions.h"
-#include "ext/spl/spl_exceptions.h"
typedef enum {
ITER_CODE_UNIT,
ITER_CODE_POINT,
ITER_COMB_SEQUENCE,
+ ITER_TYPE_LAST,
} text_iter_type;
+const uint32_t ITER_REVERSE = 0x100;
+const uint32_t ITER_TYPE_MASK = 0xFF;
+
typedef struct {
zend_object std;
UChar* text;
@@ -78,10 +81,9 @@
static void text_iter_cu_current(text_iter_obj* object TSRMLS_DC)
{
- if (!object->current) {
- MAKE_STD_ZVAL(object->current);
- ZVAL_UNICODEL(object->current, object->text +
object->u.cu.index, 1, 1);
- }
+ u_memcpy(Z_USTRVAL_P(object->current), object->text +
object->u.cu.index, 1);
+ Z_USTRVAL_P(object->current)[1] = 0;
+ Z_USTRLEN_P(object->current) = 1;
}
static int text_iter_cu_key(text_iter_obj* object TSRMLS_DC)
@@ -92,19 +94,11 @@
static void text_iter_cu_next(text_iter_obj* object TSRMLS_DC)
{
object->u.cu.index++;
- if (object->current) {
- zval_ptr_dtor(&object->current);
- object->current = NULL;
- }
}
static void text_iter_cu_rewind(text_iter_obj *object TSRMLS_DC)
{
object->u.cu.index = 0;
- if (object->current) {
- zval_ptr_dtor(&object->current);
- object->current = NULL;
- }
}
static text_iter_ops text_iter_cu_ops = {
@@ -218,7 +212,7 @@
iter_ops[object->type]->rewind(object TSRMLS_CC);
}
-zend_object_iterator_funcs text_iter_cp_funcs = {
+zend_object_iterator_funcs text_iter_funcs = {
text_iter_dtor,
text_iter_valid,
text_iter_get_current_data,
@@ -240,7 +234,7 @@
ZVAL_ADDREF(object);
iterator->intern.data = (void *) object;
- iterator->intern.funcs = &text_iter_cp_funcs;
+ iterator->intern.funcs = &text_iter_funcs;
iterator->object = iter_object;
return (zend_object_iterator *) iterator;
@@ -256,7 +250,6 @@
if (intern->text) {
efree(intern->text);
}
- ZVAL_DELREF(intern->current);
zval_ptr_dtor(&intern->current);
efree(object);
}
@@ -278,8 +271,8 @@
intern->type = ITER_CODE_POINT;
MAKE_STD_ZVAL(intern->current); /* pre-allocate buffer for codepoint */
Z_USTRVAL_P(intern->current) = eumalloc(3);
+ Z_USTRVAL_P(intern->current)[0] = 0;
Z_TYPE_P(intern->current) = IS_UNICODE;
- ZVAL_ADDREF(intern->current);
retval.handle = zend_objects_store_put(intern,
(zend_objects_store_dtor_t)zend_objects_destroy_object,
(zend_objects_free_object_storage_t) text_iterator_free_storage, NULL
TSRMLS_CC);
retval.handlers = zend_get_std_object_handlers();
@@ -293,8 +286,10 @@
int32_t text_len;
zval *object = getThis();
text_iter_obj *intern;
+ text_iter_type ti_type;
+ long flags = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "u", &text,
&text_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "u|l", &text,
&text_len, &flags) == FAILURE) {
return;
}
@@ -302,8 +297,16 @@
intern->text = eustrndup(text, text_len);
intern->text_len = text_len;
+ if (ZEND_NUM_ARGS() > 1) {
+ ti_type = flags & ITER_TYPE_MASK;
+ if (flags < ITER_TYPE_LAST) {
+ intern->type = ti_type;
+ } else {
+ php_error(E_WARNING, "Invalid iterator type in
TextIterator constructor");
+ }
+ }
- text_iter_cp_rewind(intern TSRMLS_CC);
+ iter_ops[intern->type]->rewind(intern TSRMLS_CC);
}
PHP_METHOD(TextIterator, current)
@@ -344,7 +347,7 @@
zval *object = getThis();
text_iter_obj *intern = (text_iter_obj*)
zend_object_store_get_object(object TSRMLS_CC);
- iter_ops[object->type]->rewind(intern TSRMLS_CC);
+ iter_ops[intern->type]->rewind(intern TSRMLS_CC);
}
static zend_function_entry text_iterator_funcs[] = {
@@ -366,6 +369,10 @@
text_iterator_ce->create_object = text_iterator_new;
text_iterator_ce->get_iterator = text_iter_get_iterator;
zend_class_implements(text_iterator_ce TSRMLS_CC, 1,
zend_ce_traversable);
+
+ zend_declare_class_constant_long(text_iterator_ce, "CODE_UNIT",
sizeof("CODE_UNIT")-1, ITER_CODE_UNIT TSRMLS_CC);
+ zend_declare_class_constant_long(text_iterator_ce, "CODE_POINT",
sizeof("CODE_POINT")-1, ITER_CODE_POINT TSRMLS_CC);
+ zend_declare_class_constant_long(text_iterator_ce, "COMB_SEQUENCE",
sizeof("COMB_SEQUENCE")-1, ITER_COMB_SEQUENCE TSRMLS_CC);
}
/*
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php