import { utf16idx } from "https://deno.land/x/denops_std@v6.3.0/function/vim/mod.ts";
Same as charidx()
but returns the UTF-16 code unit 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 downwards to the beginning of that sequence.
Returns -1 if the arguments are invalid or if there are less than {idx} bytes in {string}. If there are exactly {idx} bytes the length of the string in UTF-16 code units is returned.
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)