mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-12 06:38:45 +01:00
Flesh out string byte handling a bit:
- Get rid of public byteAt(_) method on strings. It's redundant and longer than .bytes[_]. - Implement bytes.count natively so it's O(1).
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
var s = "\x00\x12\x34\x56\x78\xab\xCD\xfFf"
|
||||
var bytes = "\x00\x12\x34\x56\x78\xab\xCD\xfFf".bytes
|
||||
|
||||
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
|
||||
IO.print(bytes[0]) // expect: 0
|
||||
IO.print(bytes[1]) // expect: 18
|
||||
IO.print(bytes[2]) // expect: 52
|
||||
IO.print(bytes[3]) // expect: 86
|
||||
IO.print(bytes[4]) // expect: 120
|
||||
IO.print(bytes[5]) // expect: 171
|
||||
IO.print(bytes[6]) // expect: 205
|
||||
IO.print(bytes[7]) // expect: 255
|
||||
// "f".
|
||||
IO.print(s.byteAt(8)) // expect: 102
|
||||
IO.print(bytes[8]) // expect: 102
|
||||
|
||||
Reference in New Issue
Block a user