@@ -127,6 +127,7 @@ typedef struct zoi_break_iter_parts {
127127 zoi_with_current zoi_cur;
128128 parts_iter_key_type key_type;
129129 BreakIterator_object *bio; /* so we don't have to fetch it all the time */
130+ zend_ulong index_right;
130131} zoi_break_iter_parts;
131132
132133static void _breakiterator_parts_destroy_it (zend_object_iterator *iter)
@@ -136,8 +137,16 @@ static void _breakiterator_parts_destroy_it(zend_object_iterator *iter)
136137
137138static void _breakiterator_parts_get_current_key (zend_object_iterator *iter, zval *key)
138139{
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+ }
141150}
142151
143152static void _breakiterator_parts_move_forward (zend_object_iterator *iter)
@@ -163,6 +172,7 @@ static void _breakiterator_parts_move_forward(zend_object_iterator *iter)
163172 iter->index = cur;
164173 } else if (zoi_bit->key_type == PARTS_ITERATOR_KEY_RIGHT) {
165174 iter->index = next;
175+ zoi_bit->index_right = next;
166176 }
167177 /* else zoi_bit->key_type == PARTS_ITERATOR_KEY_SEQUENTIAL
168178 * No need to do anything, the engine increments ->index */
@@ -229,6 +239,7 @@ void IntlIterator_from_BreakIterator_parts(zval *break_iter_zv,
229239 assert (((zoi_break_iter_parts*)ii->iterator )->bio ->biter != NULL );
230240
231241 ((zoi_break_iter_parts*)ii->iterator )->key_type = key_type;
242+ ((zoi_break_iter_parts*)ii->iterator )->index_right = 0 ;
232243}
233244
234245U_CFUNC PHP_METHOD (IntlPartsIterator, getBreakIterator)
0 commit comments