feat: add StringCodePointSequence class and expose codePoints property on String
Extract codePointAt() logic into a dedicated StringCodePointSequence class that wraps a string and implements the Sequence interface, enabling iteration over code points. Add a `codePoints` getter to String that returns a new instance of this sequence. Refactor the underlying C implementation of `codePointAt_` to decode UTF-8 into actual code point integers (returning raw bytes for invalid sequences) and rename the primitive to use trailing underscore convention. Update all related tests to reflect the new behavior where mid-sequence byte indices return the raw byte string instead of an empty string, and add new test files for the code point sequence iteration.
This commit is contained in:
@@ -22,3 +22,8 @@ IO.print("a\0b\0c".iterate(1)) // expect: 2
|
||||
IO.print("a\0b\0c".iterate(2)) // expect: 3
|
||||
IO.print("a\0b\0c".iterate(3)) // expect: 4
|
||||
IO.print("a\0b\0c".iterate(4)) // expect: false
|
||||
|
||||
// Iterates over invalid UTF-8 one byte at a time.
|
||||
IO.print("\xef\xf7".iterate(null)) // expect: 0
|
||||
IO.print("\xef\xf7".iterate(0)) // expect: 1
|
||||
IO.print("\xef\xf7".iterate(1)) // expect: false
|
||||
|
||||
Reference in New Issue
Block a user