Mercurial > vim
comparison runtime/doc/eval.txt @ 24132:512f48dc7100 v8.2.2607
patch 8.2.2607: strcharpart() cannot include composing characters
Commit: https://github.com/vim/vim/commit/02b4d9b18a03549b68e364e428392b7a62766c74
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Mar 14 19:46:45 2021 +0100
patch 8.2.2607: strcharpart() cannot include composing characters
Problem: strcharpart() cannot include composing characters.
Solution: Add the {skipcc} argument.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 14 Mar 2021 20:00:02 +0100 |
parents | c3d1f65365c4 |
children | 9f64c420f280 |
comparison
equal
deleted
inserted
replaced
24131:81f596485c08 | 24132:512f48dc7100 |
---|---|
1185 byte under the cursor: > | 1185 byte under the cursor: > |
1186 :let c = getline(".")[col(".") - 1] | 1186 :let c = getline(".")[col(".") - 1] |
1187 | 1187 |
1188 In Vim9 script: | 1188 In Vim9 script: |
1189 If expr8 is a String this results in a String that contains the expr1'th | 1189 If expr8 is a String this results in a String that contains the expr1'th |
1190 single character from expr8. To use byte indexes use |strpart()|. | 1190 single character (including any composing characters) from expr8. To use byte |
1191 indexes use |strpart()|. | |
1191 | 1192 |
1192 Index zero gives the first byte or character. Careful: text column numbers | 1193 Index zero gives the first byte or character. Careful: text column numbers |
1193 start with one! | 1194 start with one! |
1194 | 1195 |
1195 If the length of the String is less than the index, the result is an empty | 1196 If the length of the String is less than the index, the result is an empty |
1215 | 1216 |
1216 In legacy Vim script the indexes are byte indexes. This doesn't recognize | 1217 In legacy Vim script the indexes are byte indexes. This doesn't recognize |
1217 multibyte encodings, see |byteidx()| for computing the indexes. If expr8 is | 1218 multibyte encodings, see |byteidx()| for computing the indexes. If expr8 is |
1218 a Number it is first converted to a String. | 1219 a Number it is first converted to a String. |
1219 | 1220 |
1220 In Vim9 script the indexes are character indexes. To use byte indexes use | 1221 In Vim9 script the indexes are character indexes and include composing |
1221 |strpart()|. | 1222 characters. To use byte indexes use |strpart()|. To use character indexes |
1223 without including composing characters use |strcharpart()|. | |
1222 | 1224 |
1223 The item at index expr1b is included, it is inclusive. For an exclusive index | 1225 The item at index expr1b is included, it is inclusive. For an exclusive index |
1224 use the |slice()| function. | 1226 use the |slice()| function. |
1225 | 1227 |
1226 If expr1a is omitted zero is used. If expr1b is omitted the length of the | 1228 If expr1a is omitted zero is used. If expr1b is omitted the length of the |
2922 str2list({expr} [, {utf8}]) List convert each character of {expr} to | 2924 str2list({expr} [, {utf8}]) List convert each character of {expr} to |
2923 ASCII/UTF8 value | 2925 ASCII/UTF8 value |
2924 str2nr({expr} [, {base} [, {quoted}]]) | 2926 str2nr({expr} [, {base} [, {quoted}]]) |
2925 Number convert String to Number | 2927 Number convert String to Number |
2926 strcharlen({expr}) Number character length of the String {expr} | 2928 strcharlen({expr}) Number character length of the String {expr} |
2927 strcharpart({str}, {start} [, {len}]) | 2929 strcharpart({str}, {start} [, {len} [, {skipcc}]]) |
2928 String {len} characters of {str} at | 2930 String {len} characters of {str} at |
2929 character {start} | 2931 character {start} |
2930 strchars({expr} [, {skipcc}]) Number character count of the String {expr} | 2932 strchars({expr} [, {skipcc}]) Number character count of the String {expr} |
2931 strdisplaywidth({expr} [, {col}]) Number display length of the String {expr} | 2933 strdisplaywidth({expr} [, {col}]) Number display length of the String {expr} |
2932 strftime({format} [, {time}]) String format time with a specified format | 2934 strftime({format} [, {time}]) String format time with a specified format |
9917 | 9919 |
9918 slice({expr}, {start} [, {end}]) *slice()* | 9920 slice({expr}, {start} [, {end}]) *slice()* |
9919 Similar to using a |slice| "expr[start : end]", but "end" is | 9921 Similar to using a |slice| "expr[start : end]", but "end" is |
9920 used exclusive. And for a string the indexes are used as | 9922 used exclusive. And for a string the indexes are used as |
9921 character indexes instead of byte indexes, like in | 9923 character indexes instead of byte indexes, like in |
9922 |vim9script|. | 9924 |vim9script|. Also, composing characters are not counted. |
9923 When {end} is omitted the slice continues to the last item. | 9925 When {end} is omitted the slice continues to the last item. |
9924 When {end} is -1 the last item is omitted. | 9926 When {end} is -1 the last item is omitted. |
9925 | 9927 |
9926 Can also be used as a |method|: > | 9928 Can also be used as a |method|: > |
9927 GetList()->slice(offset) | 9929 GetList()->slice(offset) |
10288 | 10290 |
10289 Can also be used as a |method|: > | 10291 Can also be used as a |method|: > |
10290 GetText()->strcharlen() | 10292 GetText()->strcharlen() |
10291 | 10293 |
10292 | 10294 |
10293 strcharpart({src}, {start} [, {len}]) *strcharpart()* | 10295 strcharpart({src}, {start} [, {len} [, {skipcc}]]) *strcharpart()* |
10294 Like |strpart()| but using character index and length instead | 10296 Like |strpart()| but using character index and length instead |
10295 of byte index and length. Composing characters are counted | 10297 of byte index and length. |
10296 separately. | 10298 When {skipcc} is omitted or zero, composing characters are |
10299 counted separately. | |
10300 When {skipcc} set to 1, Composing characters are ignored, | |
10301 similar to |slice()|. | |
10297 When a character index is used where a character does not | 10302 When a character index is used where a character does not |
10298 exist it is assumed to be one character. For example: > | 10303 exist it is omitted and counted as one character. For |
10304 example: > | |
10299 strcharpart('abc', -1, 2) | 10305 strcharpart('abc', -1, 2) |
10300 < results in 'a'. | 10306 < results in 'a'. |
10301 | 10307 |
10302 Can also be used as a |method|: > | 10308 Can also be used as a |method|: > |
10303 GetText()->strcharpart(5) | 10309 GetText()->strcharpart(5) |
10307 The result is a Number, which is the number of characters | 10313 The result is a Number, which is the number of characters |
10308 in String {expr}. | 10314 in String {expr}. |
10309 When {skipcc} is omitted or zero, composing characters are | 10315 When {skipcc} is omitted or zero, composing characters are |
10310 counted separately. | 10316 counted separately. |
10311 When {skipcc} set to 1, Composing characters are ignored. | 10317 When {skipcc} set to 1, Composing characters are ignored. |
10312 |strcharlen()| does the same. | 10318 |strcharlen()| always does this. |
10313 | 10319 |
10314 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|. | 10320 Also see |strlen()|, |strdisplaywidth()| and |strwidth()|. |
10315 | 10321 |
10316 {skipcc} is only available after 7.4.755. For backward | 10322 {skipcc} is only available after 7.4.755. For backward |
10317 compatibility, you can define a wrapper function: > | 10323 compatibility, you can define a wrapper function: > |