Clarify how string subscripting handles UTF-8.

This commit is contained in:
Bob Nystrom
2015-01-22 16:38:03 -08:00
parent a92e58c804
commit a5b00cebe7
8 changed files with 115 additions and 26 deletions
+3
View File
@@ -1,2 +1,5 @@
IO.print("".count) // expect: 0
IO.print("a string") // expect: a string
// Non-ASCII.
IO.print("A~¶Þॐஃ") // expect: A~¶Þॐஃ
+23 -2
View File
@@ -10,5 +10,26 @@ IO.print("abcd"[-3]) // expect: b
IO.print("abcd"[-2]) // expect: c
IO.print("abcd"[-1]) // expect: d
// Make sure the string's internal buffer size is correct.
IO.print("abcd"[1] == "b") // expect: true
// Regression: Make sure the string's internal buffer size is correct.
IO.print("abcd"[1] == "b") // expect: true
// Indexes by byte, not code point.
//
// Bytes: 11111
// 012345678901234
// Chars: sø mé ஃ thî ng
IO.print("søméஃthîng"[0]) // expect: s
IO.print("søméஃthîng"[1]) // expect: ø
IO.print("søméஃthîng"[3]) // expect: m
IO.print("søméஃthîng"[6]) // expect: ஃ
IO.print("søméஃthîng"[10]) // expect: h
IO.print("søméஃthîng"[-1]) // expect: g
IO.print("søméஃthîng"[-2]) // expect: n
IO.print("søméஃthîng"[-4]) // expect: î
// If the subscript is in the middle of a UTF-8 sequence, yield an empty string.
IO.print("søméஃthîng"[2] == "") // expect: true
IO.print("søméஃthîng"[7] == "") // expect: true
IO.print("søméஃthîng"[8] == "") // expect: true
IO.print("søméஃ"[-1] == "") // expect: true
IO.print("søméஃ"[-2] == "") // expect: true
-3
View File
@@ -1,3 +0,0 @@
IO.print("A~¶Þॐஃ") // expect: A~¶Þॐஃ
// TODO: Malformed UTF-8 source files.