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:
Bob Nystrom
2015-09-11 14:56:01 +00:00
parent 731e1f4b1d
commit 85750ca338
30 changed files with 202 additions and 76 deletions
+5
View File
@@ -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