Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
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@v5.1.0/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('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>