2013-11-24 10:45:07 -08:00
|
|
|
// Returns characters (as strings).
|
2015-09-15 07:46:09 -07:00
|
|
|
System.print("abcd"[0]) // expect: a
|
|
|
|
|
System.print("abcd"[1]) // expect: b
|
|
|
|
|
System.print("abcd"[2]) // expect: c
|
|
|
|
|
System.print("abcd"[3]) // expect: d
|
2013-11-24 10:45:07 -08:00
|
|
|
|
|
|
|
|
// Allows indexing backwards from the end.
|
2015-09-15 07:46:09 -07:00
|
|
|
System.print("abcd"[-4]) // expect: a
|
|
|
|
|
System.print("abcd"[-3]) // expect: b
|
|
|
|
|
System.print("abcd"[-2]) // expect: c
|
|
|
|
|
System.print("abcd"[-1]) // expect: d
|
2015-01-09 07:12:25 -08:00
|
|
|
|
2015-01-22 16:38:03 -08:00
|
|
|
// Regression: Make sure the string's internal buffer size is correct.
|
2015-09-15 07:46:09 -07:00
|
|
|
System.print("abcd"[1] == "b") // expect: true
|
2015-01-22 16:38:03 -08:00
|
|
|
|
|
|
|
|
// Indexes by byte, not code point.
|
|
|
|
|
//
|
|
|
|
|
// Bytes: 11111
|
|
|
|
|
// 012345678901234
|
|
|
|
|
// Chars: sø mé ஃ thî ng
|
2015-09-15 07:46:09 -07:00
|
|
|
System.print("søméஃthîng"[0]) // expect: s
|
|
|
|
|
System.print("søméஃthîng"[1]) // expect: ø
|
|
|
|
|
System.print("søméஃthîng"[3]) // expect: m
|
|
|
|
|
System.print("søméஃthîng"[6]) // expect: ஃ
|
|
|
|
|
System.print("søméஃthîng"[10]) // expect: h
|
|
|
|
|
System.print("søméஃthîng"[-1]) // expect: g
|
|
|
|
|
System.print("søméஃthîng"[-2]) // expect: n
|
|
|
|
|
System.print("søméஃthîng"[-4]) // expect: î
|
2015-01-22 16:38:03 -08:00
|
|
|
|
2015-09-11 07:56:01 -07:00
|
|
|
// If the subscript is in the middle of a UTF-8 sequence, return the raw byte.
|
2015-09-15 07:46:09 -07:00
|
|
|
System.print("søméஃthîng"[2] == "\xb8") // expect: true
|
|
|
|
|
System.print("søméஃthîng"[7] == "\xae") // expect: true
|
|
|
|
|
System.print("søméஃthîng"[8] == "\x83") // expect: true
|
|
|
|
|
System.print("søméஃ"[-1] == "\x83") // expect: true
|
|
|
|
|
System.print("søméஃ"[-2] == "\xae") // expect: true
|
2015-02-04 13:58:16 +01:00
|
|
|
|
2015-02-04 20:26:29 -08:00
|
|
|
// 8-bit clean.
|
2015-09-15 07:46:09 -07:00
|
|
|
System.print("a\0b\0c"[0] == "a") // expect: true
|
|
|
|
|
System.print("a\0b\0c"[1] == "\0") // expect: true
|
|
|
|
|
System.print("a\0b\0c"[2] == "b") // expect: true
|
|
|
|
|
System.print("a\0b\0c"[3] == "\0") // expect: true
|
|
|
|
|
System.print("a\0b\0c"[4] == "c") // expect: true
|
2015-09-11 07:56:01 -07:00
|
|
|
|
|
|
|
|
// Returns single byte strings for invalid UTF-8 sequences.
|
2015-09-15 07:46:09 -07:00
|
|
|
System.print("\xef\xf7"[0] == "\xef") // expect: true
|
|
|
|
|
System.print("\xef\xf7"[1] == "\xf7") // expect: true
|