@@ -127,6 +127,7 @@ typedef struct zoi_break_iter_parts {
127
127
zoi_with_current zoi_cur;
128
128
parts_iter_key_type key_type;
129
129
BreakIterator_object *bio; /* so we don't have to fetch it all the time */
130
+ zend_ulong index_right;
130
131
} zoi_break_iter_parts;
131
132
132
133
static void _breakiterator_parts_destroy_it (zend_object_iterator *iter)
@@ -136,8 +137,16 @@ static void _breakiterator_parts_destroy_it(zend_object_iterator *iter)
136
137
137
138
static void _breakiterator_parts_get_current_key (zend_object_iterator *iter, zval *key)
138
139
{
139
- /* the actual work is done in move_forward and rewind */
140
- ZVAL_LONG (key, iter->index );
140
+ // The engine resets the iterator index to -1 after rewinding. When using
141
+ // PARTS_ITERATOR_KEY_RIGHT we store it in zoi_break_iter_parts.index_right
142
+ // so it doesn't get lost.
143
+ zoi_break_iter_parts *zoi_bit = (zoi_break_iter_parts*)iter;
144
+
145
+ if (zoi_bit->key_type == PARTS_ITERATOR_KEY_RIGHT && iter->index == 0 ) {
146
+ ZVAL_LONG (key, zoi_bit->index_right );
147
+ } else {
148
+ ZVAL_LONG (key, iter->index );
149
+ }
141
150
}
142
151
143
152
static void _breakiterator_parts_move_forward (zend_object_iterator *iter)
@@ -163,6 +172,7 @@ static void _breakiterator_parts_move_forward(zend_object_iterator *iter)
163
172
iter->index = cur;
164
173
} else if (zoi_bit->key_type == PARTS_ITERATOR_KEY_RIGHT) {
165
174
iter->index = next;
175
+ zoi_bit->index_right = next;
166
176
}
167
177
/* else zoi_bit->key_type == PARTS_ITERATOR_KEY_SEQUENTIAL
168
178
* No need to do anything, the engine increments ->index */
@@ -229,6 +239,7 @@ void IntlIterator_from_BreakIterator_parts(zval *break_iter_zv,
229
239
assert (((zoi_break_iter_parts*)ii->iterator )->bio ->biter != NULL );
230
240
231
241
((zoi_break_iter_parts*)ii->iterator )->key_type = key_type;
242
+ ((zoi_break_iter_parts*)ii->iterator )->index_right = 0 ;
232
243
}
233
244
234
245
U_CFUNC PHP_METHOD (IntlPartsIterator, getBreakIterator)
0 commit comments