forked from Mirror/wren
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:
15
test/core/string_byte_sequence/count.wren
Normal file
15
test/core/string_byte_sequence/count.wren
Normal file
@ -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