Mercurial > vim
comparison runtime/doc/builtin.txt @ 32570:5d8cff99a027 v9.0.1617
patch 9.0.1617: charidx() result is not consistent with byteidx()
Commit: https://github.com/vim/vim/commit/577922b917e48285a7a312daf7b5bbc6e272939c
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Thu Jun 8 17:09:45 2023 +0100
patch 9.0.1617: charidx() result is not consistent with byteidx()
Problem: charidx() and utf16idx() result is not consistent with byteidx().
Solution: When the index is equal to the length of the text return the
lenght of the text instead of -1. (Yegappan Lakshmanan,
closes #12503)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 08 Jun 2023 18:15:04 +0200 |
parents | 2a17771529af |
children | 635de73eeb4c |
comparison
equal
deleted
inserted
replaced
32569:6b110a59975a | 32570:5d8cff99a027 |
---|---|
1526 counted as separate characters. | 1526 counted as separate characters. |
1527 | 1527 |
1528 When {utf16} is present and TRUE, {idx} is used as the UTF-16 | 1528 When {utf16} is present and TRUE, {idx} is used as the UTF-16 |
1529 index in the String {expr} instead of as the byte index. | 1529 index in the String {expr} instead of as the byte index. |
1530 | 1530 |
1531 Returns -1 if the arguments are invalid or if {idx} is greater | 1531 Returns -1 if the arguments are invalid or if there are less |
1532 than the index of the last byte in {string}. An error is | 1532 than {idx} bytes. If there are exactly {idx} bytes the length |
1533 given if the first argument is not a string, the second | 1533 of the string in characters is returned. |
1534 argument is not a number or when the third argument is present | 1534 |
1535 and is not zero or one. | 1535 An error is given and -1 is returned if the first argument is |
1536 not a string, the second argument is not a number or when the | |
1537 third argument is present and is not zero or one. | |
1536 | 1538 |
1537 See |byteidx()| and |byteidxcomp()| for getting the byte index | 1539 See |byteidx()| and |byteidxcomp()| for getting the byte index |
1538 from the character index and |utf16idx()| for getting the | 1540 from the character index and |utf16idx()| for getting the |
1539 UTF-16 index from the character index. | 1541 UTF-16 index from the character index. |
1540 Refer to |string-offset-encoding| for more information. | 1542 Refer to |string-offset-encoding| for more information. |
10117 Can also be used as a |method|: > | 10119 Can also be used as a |method|: > |
10118 mylist->uniq() | 10120 mylist->uniq() |
10119 < | 10121 < |
10120 *utf16idx()* | 10122 *utf16idx()* |
10121 utf16idx({string}, {idx} [, {countcc} [, {charidx}]]) | 10123 utf16idx({string}, {idx} [, {countcc} [, {charidx}]]) |
10122 Same as |charidx()| but returns the UTF-16 index of the byte | 10124 Same as |charidx()| but returns the UTF-16 code unit index of |
10123 at {idx} in {string} (after converting it to UTF-16). | 10125 the byte at {idx} in {string} (after converting it to UTF-16). |
10124 | 10126 |
10125 When {charidx} is present and TRUE, {idx} is used as the | 10127 When {charidx} is present and TRUE, {idx} is used as the |
10126 character index in the String {string} instead of as the byte | 10128 character index in the String {string} instead of as the byte |
10127 index. | 10129 index. |
10128 An {idx} in the middle of a UTF-8 sequence is rounded upwards | 10130 An {idx} in the middle of a UTF-8 sequence is rounded upwards |
10129 to the end of that sequence. | 10131 to the end of that sequence. |
10132 | |
10133 Returns -1 if the arguments are invalid or if there are less | |
10134 than {idx} bytes in {string}. If there are exactly {idx} bytes | |
10135 the length of the string in UTF-16 code units is returned. | |
10130 | 10136 |
10131 See |byteidx()| and |byteidxcomp()| for getting the byte index | 10137 See |byteidx()| and |byteidxcomp()| for getting the byte index |
10132 from the UTF-16 index and |charidx()| for getting the | 10138 from the UTF-16 index and |charidx()| for getting the |
10133 character index from the UTF-16 index. | 10139 character index from the UTF-16 index. |
10134 Refer to |string-offset-encoding| for more information. | 10140 Refer to |string-offset-encoding| for more information. |