import { utf16idx } from "https://deno.land/x/denops_std@v5.0.2/function/vim/mod.ts";
Same as charidx()
but returns the UTF-16 index of the byte
at {idx} in {string} (after converting it to UTF-16).
When {charidx} is present and TRUE, {idx} is used as the character index in the String {string} instead of as the byte index. An {idx} in the middle of a UTF-8 sequence is rounded upwards to the end of that sequence.
See byteidx()
and byteidxcomp()
for getting the byte index
from the UTF-16 index and charidx()
for getting the
character index from the UTF-16 index.
Refer to string-offset-encoding
for more information.
Examples:
echo utf16idx('aππ', 3) returns 2
echo utf16idx('aππ', 7) returns 4
echo utf16idx('aππ', 1, 0, 1) returns 2
echo utf16idx('aππ', 2, 0, 1) returns 4
echo utf16idx('aaΜ¨Μc', 6) returns 2
echo utf16idx('aaΜ¨Μc', 6, 1) returns 4
echo utf16idx('aππ', 9) returns -1
Can also be used as a method
:
GetName()->utf16idx(idx)