import { fn } from "https://deno.land/x/ddc_vim@v4.0.2/deps.ts";
const { charidx } = fn;
Return the character index of the byte at {idx} in {string}. The index of the first character is zero. If there are no multibyte characters the returned value is equal to {idx}.
When {countcc} is omitted or FALSE
, then composing characters
are not counted separately, their byte length is added to the
preceding base character.
When {countcc} is TRUE
, then composing characters are
counted as separate characters.
When {utf16} is present and TRUE, {idx} is used as the UTF-16 index in the String {expr} instead of as the byte index.
Returns -1 if the arguments are invalid or if {idx} is greater than the index of the last byte in {string}. An error is given if the first argument is not a string, the second argument is not a number or when the third argument is present and is not zero or one.
See byteidx()
and byteidxcomp()
for getting the byte index
from the character index and utf16idx()
for getting the
UTF-16 index from the character index.
Refer to string-offset-encoding
for more information.
Examples:
echo charidx('áb́ć', 3) returns 1
echo charidx('áb́ć', 6, 1) returns 4
echo charidx('áb́ć', 16) returns -1
echo charidx('a😊😊', 4, 0, 1) returns 2
Can also be used as a method
:
GetName()->charidx(idx)