andrei Wed Feb 8 00:16:50 2006 UTC
Modified files:
/php-src/ext/unicode unicode_iterators.c
Log:
Reverse iteration for combining sequences.
http://cvs.php.net/viewcvs.cgi/php-src/ext/unicode/unicode_iterators.c?r1=1.16&r2=1.17&diff_format=u
Index: php-src/ext/unicode/unicode_iterators.c
diff -u php-src/ext/unicode/unicode_iterators.c:1.16
php-src/ext/unicode/unicode_iterators.c:1.17
--- php-src/ext/unicode/unicode_iterators.c:1.16 Tue Feb 7 20:01:28 2006
+++ php-src/ext/unicode/unicode_iterators.c Wed Feb 8 00:16:50 2006
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: unicode_iterators.c,v 1.16 2006/02/07 20:01:28 andrei Exp $ */
+/* $Id: unicode_iterators.c,v 1.17 2006/02/08 00:16:50 andrei Exp $ */
/*
* TODO
@@ -49,16 +49,16 @@
long flags;
union {
struct {
- uint32_t index;
- uint32_t offset;
+ int32_t index;
+ int32_t offset;
} cp;
struct {
int32_t index;
} cu;
struct {
- uint32_t index;
- uint32_t start;
- uint32_t end;
+ int32_t index;
+ int32_t start;
+ int32_t end;
} cs;
} u;
} text_iter_obj;
@@ -200,7 +200,11 @@
static int text_iter_cs_valid(text_iter_obj* object TSRMLS_DC)
{
- return (object->u.cs.end <= object->text_len);
+ if (object->flags & ITER_REVERSE) {
+ return (object->u.cs.end > 0);
+ } else {
+ return (object->u.cs.end <= object->text_len);
+ }
}
static void text_iter_cs_current(text_iter_obj* object TSRMLS_DC)
@@ -223,18 +227,28 @@
static void text_iter_cs_next(text_iter_obj* object TSRMLS_DC)
{
UChar32 cp;
- uint32_t end;
+ uint32_t tmp;
- object->u.cs.start = object->u.cs.end;
- U16_NEXT(object->text, object->u.cs.end, object->text_len, cp);
- if (u_getCombiningClass(cp) == 0) {
- end = object->u.cs.end;
- while (end < object->text_len) {
- U16_NEXT(object->text, end, object->text_len, cp);
- if (u_getCombiningClass(cp) == 0) {
- break;
- } else {
- object->u.cs.end = end;
+ if (object->flags & ITER_REVERSE) {
+ object->u.cs.end = object->u.cs.start;
+ U16_PREV(object->text, 0, object->u.cs.start, cp);
+ if (u_getCombiningClass(cp) != 0) {
+ do {
+ U16_PREV(object->text, 0, object->u.cs.start,
cp);
+ } while (object->u.cs.start > 0 &&
u_getCombiningClass(cp) != 0);
+ }
+ } else {
+ object->u.cs.start = object->u.cs.end;
+ U16_NEXT(object->text, object->u.cs.end, object->text_len, cp);
+ if (u_getCombiningClass(cp) == 0) {
+ tmp = object->u.cs.end;
+ while (tmp < object->text_len) {
+ U16_NEXT(object->text, tmp, object->text_len,
cp);
+ if (u_getCombiningClass(cp) == 0) {
+ break;
+ } else {
+ object->u.cs.end = tmp;
+ }
}
}
}
@@ -243,8 +257,11 @@
static void text_iter_cs_rewind(text_iter_obj *object TSRMLS_DC)
{
- object->u.cs.start = 0;
- object->u.cs.end = 0;
+ if (object->flags & ITER_REVERSE) {
+ object->u.cs.start = object->u.cs.end = object->text_len;
+ } else {
+ object->u.cs.start = object->u.cs.end = 0;
+ }
text_iter_cs_next(object TSRMLS_CC); /* find first sequence */
object->u.cs.index = 0; /* because _next increments index */
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php