feat: add raw byte access methods and \x escape to String class

Add `byteAt(index)`, `codePointAt(index)`, and `bytes` sequence to String,
enabling direct byte-level manipulation of UTF-8 encoded strings. Introduce
`\x` hex escape sequence in string literals for specifying raw byte values.
Refactor Unicode escape parsing into a generic `readHexEscape` function
supporting variable digit counts. Implement `wrenUtf8Decode` utility for
decoding UTF-8 sequences from byte buffers. Add comprehensive tests for
`byteAt` including boundary conditions and error cases.
This commit is contained in:
Bob Nystrom
2015-03-28 03:44:07 +00:00
parent b7904a89c9
commit c3d0b66630
36 changed files with 402 additions and 15 deletions
+12
View File
@@ -0,0 +1,12 @@
var s = "\x00\x12\x34\x56\x78\xab\xCD\xfFf"
IO.print(s.byteAt(0)) // expect: 0
IO.print(s.byteAt(1)) // expect: 18
IO.print(s.byteAt(2)) // expect: 52
IO.print(s.byteAt(3)) // expect: 86
IO.print(s.byteAt(4)) // expect: 120
IO.print(s.byteAt(5)) // expect: 171
IO.print(s.byteAt(6)) // expect: 205
IO.print(s.byteAt(7)) // expect: 255
// "f".
IO.print(s.byteAt(8)) // expect: 102
@@ -0,0 +1,2 @@
// expect error line 2
"\x0"
@@ -0,0 +1,2 @@
// expect error line 2
"\x0
@@ -0,0 +1,2 @@
// expect error line 2
"\x0!"