String.slice with negative index fails for non-ASCII code points
The following works fine, given an ASCII-compatible string:
let s = "hello"
let mut got = s.slice -1, 1
assert.equal(got, "o")
got = s.slice -3, 2
assert.equal(got, "ll")
However, with multi-byte code points, it doesn't work:
let s = "ß" # 0xC3 0x9F
let got = s.slice -1, 1
assert.equal(got, "ß") # returns an empty string
I think it's because of int_to_slice_index
in src/vm/machine.rs
, where $vec.len()
is used to get the reversed slice index, and this returns the bytes count instead of code points count. If I call with s.slice -2, 1
, it works (that code point is 2 bytes long).
Martin