comparison src/evalfunc.c @ 21935:62f933f64447 v8.2.1517

patch 8.2.1517: cannot easily get the character under the cursor Commit: https://github.com/vim/vim/commit/6c53fca02301ff871cddc1c74c388e23e53a424a Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 23 17:34:46 2020 +0200 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().
author Bram Moolenaar <Bram@vim.org>
date Sun, 23 Aug 2020 17:45:03 +0200
parents a427f5f26419
children bf68435a695a
comparison
equal deleted inserted replaced
21934:520a6af17d92 21935:62f933f64447
948 }, 948 },
949 {"strgetchar", 2, 2, FEARG_1, ret_number, f_strgetchar}, 949 {"strgetchar", 2, 2, FEARG_1, ret_number, f_strgetchar},
950 {"stridx", 2, 3, FEARG_1, ret_number, f_stridx}, 950 {"stridx", 2, 3, FEARG_1, ret_number, f_stridx},
951 {"string", 1, 1, FEARG_1, ret_string, f_string}, 951 {"string", 1, 1, FEARG_1, ret_string, f_string},
952 {"strlen", 1, 1, FEARG_1, ret_number, f_strlen}, 952 {"strlen", 1, 1, FEARG_1, ret_number, f_strlen},
953 {"strpart", 2, 3, FEARG_1, ret_string, f_strpart}, 953 {"strpart", 2, 4, FEARG_1, ret_string, f_strpart},
954 {"strptime", 2, 2, FEARG_1, ret_number, 954 {"strptime", 2, 2, FEARG_1, ret_number,
955 #ifdef HAVE_STRPTIME 955 #ifdef HAVE_STRPTIME
956 f_strptime 956 f_strptime
957 #else 957 #else
958 NULL 958 NULL
8268 else if (argvars[2].v_type != VAR_UNKNOWN) 8268 else if (argvars[2].v_type != VAR_UNKNOWN)
8269 len = (int)tv_get_number(&argvars[2]); 8269 len = (int)tv_get_number(&argvars[2]);
8270 else 8270 else
8271 len = slen - n; // default len: all bytes that are available. 8271 len = slen - n; // default len: all bytes that are available.
8272 8272
8273 /* 8273 // Only return the overlap between the specified part and the actual
8274 * Only return the overlap between the specified part and the actual 8274 // string.
8275 * string.
8276 */
8277 if (n < 0) 8275 if (n < 0)
8278 { 8276 {
8279 len += n; 8277 len += n;
8280 n = 0; 8278 n = 0;
8281 } 8279 }
8283 n = slen; 8281 n = slen;
8284 if (len < 0) 8282 if (len < 0)
8285 len = 0; 8283 len = 0;
8286 else if (n + len > slen) 8284 else if (n + len > slen)
8287 len = slen - n; 8285 len = slen - n;
8286
8287 if (argvars[2].v_type != VAR_UNKNOWN && argvars[3].v_type != VAR_UNKNOWN)
8288 {
8289 int off;
8290
8291 // length in characters
8292 for (off = n; off < slen && len > 0; --len)
8293 off += mb_ptr2len(p + off);
8294 len = off - n;
8295 }
8288 8296
8289 rettv->v_type = VAR_STRING; 8297 rettv->v_type = VAR_STRING;
8290 rettv->vval.v_string = vim_strnsave(p + n, len); 8298 rettv->vval.v_string = vim_strnsave(p + n, len);
8291 } 8299 }
8292 8300