Add String as a subclass of Sequence in core.wren and implement the iterator protocol for strings in wren_core.c. The string_iterate native advances through UTF-8 code point boundaries, while string_iteratorValue extracts the full code point at a given byte index. Includes comprehensive test coverage for iteration, edge cases (empty strings, mid-sequence positions), and error handling for invalid iterator types and out-of-bounds indices. Also updates documentation for String, List, and Sequence classes with iterator protocol details and usage examples.
8 lines
300 B
Plaintext
8 lines
300 B
Plaintext
var s = "abçd"
|
|
IO.print(s.iteratorValue(0)) // expect: a
|
|
IO.print(s.iteratorValue(1)) // expect: b
|
|
IO.print(s.iteratorValue(2)) // expect: ç
|
|
// Iterator value in middle of UTF sequence is an empty string.
|
|
IO.print(s.iteratorValue(3) == "") // expect: true
|
|
IO.print(s.iteratorValue(4)) // expect: d
|