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:
@@ -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