Fixup string iteration for unicode strings

This commit is contained in:
K Lange 2021-01-12 20:11:52 +09:00
parent de71ada519
commit 1f189ed82c
3 changed files with 14 additions and 2 deletions

View File

@ -19,3 +19,6 @@ print(len(bytes.decode()))
print(len(bytes))
print("テスト、テスト、日本語、おはよう".split("、"))
for c in hello:
print(c)

View File

@ -11,3 +11,12 @@ b'\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88\xe3\x81\x8a'
5
15
['テスト', 'テスト', '日本語', 'おはよう']

4
vm.c
View File

@ -2718,11 +2718,11 @@ static KrkValue _striter_call(int argc, KrkValue argv[]) {
goto _corrupt;
}
if ((size_t)AS_INTEGER(_counter) >= AS_STRING(_str)->length) {
if ((size_t)AS_INTEGER(_counter) >= AS_STRING(_str)->codesLength) {
return argv[0];
} else {
krk_attachNamedValue(&self->fields, "i", INTEGER_VAL(AS_INTEGER(_counter)+1));
return OBJECT_VAL(krk_copyString(&AS_CSTRING(_str)[AS_INTEGER(_counter)],1));
return _string_get(2,(KrkValue[]){_str,_counter});
}
_corrupt: