diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-12-28 12:56:58 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-12-28 12:56:58 +0100 |
commit | 17793ef23aae0bc94539390ccfe5e63b0ad39ff2 (patch) | |
tree | 710a6d39741c88899dd9e06309e1a1cb5ec1385d /runtime/doc/eval.txt | |
parent | 9618a25b9c054f0ee4e267d2db96b6e7c113ed7a (diff) |
patch 8.2.2233: cannot convert a byte index into a character indexv8.2.2233
Problem: Cannot convert a byte index into a character index.
Solution: Add charidx(). (Yegappan Lakshmanan, closes #7561)
Diffstat (limited to 'runtime/doc/eval.txt')
-rw-r--r-- | runtime/doc/eval.txt | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 4c6636c614..8b85dad9cf 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2475,6 +2475,8 @@ ch_status({handle} [, {options}]) changenr() Number current change number char2nr({expr} [, {utf8}]) Number ASCII/UTF8 value of first char in {expr} charclass({string}) Number character class of {string} +charidx({string}, {idx} [, {countcc}]) + Number char index of byte {idx} in {string} chdir({dir}) String change current working directory cindent({lnum}) Number C indent for line {lnum} clearmatches([{win}]) none clear all matches @@ -3588,6 +3590,31 @@ charclass({string}) *charclass()* other specific Unicode class The class is used in patterns and word motions. + *charidx()* +charidx({string}, {idx} [, {countcc}]) + 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 zero, then composing characters + are not counted separately, their byte length is added to the + preceding base character. + When {countcc} is set to 1, then composing characters are + counted as separate characters. + 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. + Examples: > + echo charidx('áb́ć', 3) returns 1 + echo charidx('áb́ć', 6, 1) returns 4 + echo charidx('áb́ć', 16) returns -1 +< + Can also be used as a |method|: > + GetName()->charidx(idx) chdir({dir}) *chdir()* Change the current working directory to {dir}. The scope of |