mirror of
https://github.com/neovim/neovim.git
synced 2025-10-05 01:16:31 +00:00
vim-patch:8.2.1517: cannot easily get the character under the cursor
Problem: Cannot easily get the character under the cursor.
Solution: Add the {chars} argument to strpart().
6c53fca023
This commit is contained in:
@@ -336,7 +336,7 @@ return {
|
||||
stridx={args={2, 3}},
|
||||
string={args=1},
|
||||
strlen={args=1},
|
||||
strpart={args={2, 3}},
|
||||
strpart={args={2, 4}},
|
||||
strridx={args={2, 3}},
|
||||
strtrans={args=1},
|
||||
strwidth={args=1},
|
||||
|
@@ -9946,6 +9946,16 @@ static void f_strpart(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
len = slen - n;
|
||||
}
|
||||
|
||||
if (argvars[2].v_type != VAR_UNKNOWN && argvars[3].v_type != VAR_UNKNOWN) {
|
||||
int off;
|
||||
|
||||
// length in characters
|
||||
for (off = n; off < (int)slen && len > 0; len--) {
|
||||
off += utfc_ptr2len((char_u *)p + off);
|
||||
}
|
||||
len = off - n;
|
||||
}
|
||||
|
||||
rettv->v_type = VAR_STRING;
|
||||
rettv->vval.v_string = (char_u *)xmemdupz(p + n, (size_t)len);
|
||||
}
|
||||
|
@@ -334,6 +334,10 @@ func Test_strpart()
|
||||
|
||||
call assert_equal('lép', strpart('éléphant', 2, 4))
|
||||
call assert_equal('léphant', strpart('éléphant', 2))
|
||||
|
||||
call assert_equal('é', strpart('éléphant', 0, 1, 1))
|
||||
call assert_equal('ép', strpart('éléphant', 3, 2, v:true))
|
||||
call assert_equal('ó', strpart('cómposed', 1, 1, 1))
|
||||
endfunc
|
||||
|
||||
func Test_tolower()
|
||||
|
Reference in New Issue
Block a user