objstrunicode: Implement iterator.
This commit is contained in:
parent
cdc020da4b
commit
79b7fe2ee5
@ -330,8 +330,10 @@ STATIC mp_obj_t str_it_iternext(mp_obj_t self_in) {
|
|||||||
mp_obj_str_it_t *self = self_in;
|
mp_obj_str_it_t *self = self_in;
|
||||||
GET_STR_DATA_LEN(self->str, str, len);
|
GET_STR_DATA_LEN(self->str, str, len);
|
||||||
if (self->cur < len) {
|
if (self->cur < len) {
|
||||||
mp_obj_t o_out = mp_obj_new_str((const char*)str + self->cur, 1, true);
|
const byte *cur = str + self->cur;
|
||||||
self->cur += 1;
|
const byte *end = utf8_next_char(str + self->cur);
|
||||||
|
mp_obj_t o_out = mp_obj_new_str((const char*)cur, end - cur, true);
|
||||||
|
self->cur += end - cur;
|
||||||
return o_out;
|
return o_out;
|
||||||
} else {
|
} else {
|
||||||
return MP_OBJ_STOP_ITERATION;
|
return MP_OBJ_STOP_ITERATION;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user