import gleam/io
import gleam/string
pub fn main() {
io.println(string.drop_start("广州abcdefghijklmn", 0))
io.println(string.drop_start("广州abcdefghijklmn", 1))
io.println(string.drop_start("广州abcdefghijklmn", 2))
io.println(string.drop_start("广州abcdefghijklmn", 3))
}
outputs on the JS target:
广州abcdefghijklmn
bcdefghijklmn
efghijklmn
fghijklmn
So the first two characters are counted as 3 each. unsafe_byte_slice is used here with byte offsets:
|
unsafe_byte_slice(string, prefix_size, byte_size(string) - prefix_size) |
It calls string_byte_slice, which contrary to its name does not operate on bytes but UTF-16 code units:
|
export function string_byte_slice(string, index, length) { |
Thus the wrong offsets are sliced from the string.
outputs on the JS target:
So the first two characters are counted as 3 each.
unsafe_byte_sliceis used here with byte offsets:stdlib/src/gleam/string.gleam
Line 236 in c6f7cee
It calls
string_byte_slice, which contrary to its name does not operate on bytes but UTF-16 code units:stdlib/src/gleam_stdlib.mjs
Line 202 in c6f7cee
Thus the wrong offsets are sliced from the string.