diff options
author | kuuote <36663503+kuuote@users.noreply.github.com> | 2021-02-23 10:13:14 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-22 20:13:14 -0500 |
commit | 0450e155d48cb2d8a73358e193931d8966a9d2e0 (patch) | |
tree | a1b0c4a2591447a25a3e735529d253206f05849a /runtime | |
parent | 9d5f842807c56d6265a5557cbb4bf3e951210425 (diff) | |
download | rneovim-0450e155d48cb2d8a73358e193931d8966a9d2e0.tar.gz rneovim-0450e155d48cb2d8a73358e193931d8966a9d2e0.tar.bz2 rneovim-0450e155d48cb2d8a73358e193931d8966a9d2e0.zip |
vim-patch:8.2.2233: cannot convert a byte index into a character index (#13978)
Problem: Cannot convert a byte index into a character index.
Solution: Add charidx(). (Yegappan Lakshmanan, closes vim/vim#7561)
https://github.com/vim/vim/commit/17793ef23aae0bc94539390ccfe5e63b0ad39ff2
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/eval.txt | 25 | ||||
-rw-r--r-- | runtime/doc/usr_41.txt | 1 |
2 files changed, 26 insertions, 0 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index b5ea2ea5b3..22963a372b 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2077,6 +2077,8 @@ changenr() Number current change number chanclose({id}[, {stream}]) Number Closes a channel or one of its streams chansend({id}, {data}) Number Writes {data} to channel char2nr({expr}[, {utf8}]) Number ASCII/UTF8 value of first char in {expr} +charidx({string}, {idx} [, {countcc}]) + Number char index of byte {idx} in {string} cindent({lnum}) Number C indent for line {lnum} clearmatches([{win}]) none clear all matches col({expr}) Number column nr of cursor or mark @@ -3027,6 +3029,29 @@ char2nr({expr} [, {utf8}]) *char2nr()* A combining character is a separate character. |nr2char()| does the opposite. + *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 + cindent({lnum}) *cindent()* Get the amount of indent for line {lnum} according the C indenting rules, as with 'cindent'. diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt index e92e464c6a..63c899da0c 100644 --- a/runtime/doc/usr_41.txt +++ b/runtime/doc/usr_41.txt @@ -613,6 +613,7 @@ String manipulation: *string-functions* iconv() convert text from one encoding to another byteidx() byte index of a character in a string byteidxcomp() like byteidx() but count composing characters + charidx() character index of a byte in a string repeat() repeat a string multiple times eval() evaluate a string expression execute() execute an Ex command and get the output |