docs: clarify string is byte array, move .count to codePoints.count, remove O(n) primitive

The string class is now documented as an immutable byte array rather than a
sequence of Unicode code points. The .count getter is removed from the string
primitive and replaced by .codePoints.count on the code point sequence
interface, making the O(n) cost explicit. Updated the doc site and test files
accordingly.
This commit is contained in:
Bob Nystrom
2015-09-12 04:33:26 +00:00
parent 85750ca338
commit c5cea469e3
4 changed files with 78 additions and 30 deletions
+10
View File
@@ -6,3 +6,13 @@ IO.print("\0".count) // expect: 1
IO.print("a\0b".count) // expect: 3
IO.print("\0c".count) // expect: 2
IO.print(("a\0b" + "\0c").count) // expect: 5
// Treats a UTF-8 sequence as a single item.
//
// Bytes: 11111
// 012345678901234
// Chars: sø mé ஃ thî ng
IO.print("søméஃthîng".count) // expect: 10
// Counts invalid UTF-8 one byte at a time.
IO.print("\xefok\xf7".count) // expect: 4
@@ -0,0 +1,18 @@
IO.print("".codePoints.count) // expect: 0
IO.print("a string".codePoints.count) // expect: 8
// 8-bit clean.
IO.print("\0".codePoints.count) // expect: 1
IO.print("a\0b".codePoints.count) // expect: 3
IO.print("\0c".codePoints.count) // expect: 2
IO.print(("a\0b" + "\0c").codePoints.count) // expect: 5
// Treats a UTF-8 sequence as a single item.
//
// Bytes: 11111
// 012345678901234
// Chars: sø mé ஃ thî ng
IO.print("søméஃthîng".codePoints.count) // expect: 10
// Counts invalid UTF-8 one byte at a time.
IO.print("\xefok\xf7".codePoints.count) // expect: 4