Skip to main content
Deno 2 is finally here πŸŽ‰οΈ
Learn more
Module

x/denops_std/function/vim/mod.ts>utf16idx

πŸ“š Standard module for denops.vim
Go to Latest
function utf16idx
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('aą́c', 6)               returns 2
echo utf16idx('aą́c', 6, 1)    returns 4
echo utf16idx('a😊😊', 9) returns -1

Can also be used as a method:

GetName()->utf16idx(idx)

Parameters

denops: Denops
string: unknown
idx: unknown
optional
countcc: unknown
optional
charidx: unknown

Returns

Promise<number>