1
0
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:
Bob Nystrom
2015-09-10 23:52:18 -07:00
parent adcb5bccba
commit bda9ad880a
9 changed files with 40 additions and 57 deletions

View 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