feat: replace public byteAt with private byteAt_ and add O(1) bytes.count
Remove the public `byteAt(_)` method from String and its ByteSequence wrapper, renaming it to the private `byteAt_(_)` to eliminate redundancy with `.bytes[_]`. Add a native `byteCount_` primitive on String and expose it as `count` on StringByteSequence, enabling O(1) byte length queries. Update all test files to use the new `.bytes` subscript API and add a dedicated `count.wren` test for the new functionality.
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
// Bytes: 11111
|
||||
// 012345678901234
|
||||
// Chars: sø mé ஃ thî ng
|
||||
var s = "søméஃthîng"
|
||||
|
||||
IO.print(s.byteAt(0)) // expect: 115
|
||||
IO.print(s.byteAt(1)) // expect: 195
|
||||
IO.print(s.byteAt(2)) // expect: 184
|
||||
IO.print(s.byteAt(3)) // expect: 109
|
||||
IO.print(s.byteAt(4)) // expect: 195
|
||||
IO.print(s.byteAt(5)) // expect: 169
|
||||
IO.print(s.byteAt(6)) // expect: 224
|
||||
IO.print(s.byteAt(7)) // expect: 174
|
||||
IO.print(s.byteAt(8)) // expect: 131
|
||||
IO.print(s.byteAt(9)) // expect: 116
|
||||
IO.print(s.byteAt(10)) // expect: 104
|
||||
IO.print(s.byteAt(11)) // expect: 195
|
||||
IO.print(s.byteAt(12)) // expect: 174
|
||||
IO.print(s.byteAt(13)) // expect: 110
|
||||
IO.print(s.byteAt(14)) // expect: 103
|
||||
|
||||
IO.print(s.byteAt(-15)) // expect: 115
|
||||
IO.print(s.byteAt(-14)) // expect: 195
|
||||
IO.print(s.byteAt(-13)) // expect: 184
|
||||
IO.print(s.byteAt(-12)) // expect: 109
|
||||
IO.print(s.byteAt(-11)) // expect: 195
|
||||
IO.print(s.byteAt(-10)) // expect: 169
|
||||
IO.print(s.byteAt(-9)) // expect: 224
|
||||
IO.print(s.byteAt(-8)) // expect: 174
|
||||
IO.print(s.byteAt(-7)) // expect: 131
|
||||
IO.print(s.byteAt(-6)) // expect: 116
|
||||
IO.print(s.byteAt(-5)) // expect: 104
|
||||
IO.print(s.byteAt(-4)) // expect: 195
|
||||
IO.print(s.byteAt(-3)) // expect: 174
|
||||
IO.print(s.byteAt(-2)) // expect: 110
|
||||
IO.print(s.byteAt(-1)) // expect: 103
|
||||
|
||||
IO.print("\0".byteAt(0)) // expect: 0
|
||||
@@ -1 +0,0 @@
|
||||
IO.print("string".byteAt(12.34)) // expect runtime error: Index must be an integer.
|
||||
@@ -1 +0,0 @@
|
||||
IO.print("string".byteAt("not num")) // expect runtime error: Index must be a number.
|
||||
@@ -1 +0,0 @@
|
||||
IO.print("string".byteAt(6)) // expect runtime error: Index out of bounds.
|
||||
@@ -1 +0,0 @@
|
||||
IO.print("string".byteAt(-7)) // expect runtime error: Index out of bounds.
|
||||
@@ -0,0 +1,15 @@
|
||||
// Simple.
|
||||
IO.print("".bytes.count) // expect: 0
|
||||
IO.print("123".bytes.count) // expect: 3
|
||||
|
||||
// UTF-8.
|
||||
// Bytes:
|
||||
// 123456789
|
||||
// Chars: sø mé ஃ
|
||||
IO.print("søméஃ".bytes.count) // expect: 9
|
||||
|
||||
// Null bytes.
|
||||
IO.print("\0\0\0".bytes.count) // expect: 3
|
||||
|
||||
// Invalid UTF-8.
|
||||
IO.print("\xef\x00".bytes.count) // expect: 2
|
||||
Reference in New Issue
Block a user