summaryrefslogtreecommitdiff
path: root/src/list.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-01-13 21:47:15 +0100
committerBram Moolenaar <Bram@vim.org>2021-01-13 21:47:15 +0100
commit6601b62943a19d4f8818c3638440663d67a17b6a (patch)
treeec8681cc9c635a6cb05eb30b4e1d7eb88a46dcf2 /src/list.c
parentc423ad77ed763c11ba67729bbf63c1cf0915231f (diff)
downloadvim-git-6601b62943a19d4f8818c3638440663d67a17b6a.tar.gz
patch 8.2.2344: using inclusive index for slice is not always desiredv8.2.2344
Problem: Using inclusive index for slice is not always desired. Solution: Add the slice() method, which has an exclusive index. (closes #7408)
Diffstat (limited to 'src/list.c')
-rw-r--r--src/list.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/list.c b/src/list.c
index f7842fa87..0bca0b553 100644
--- a/src/list.c
+++ b/src/list.c
@@ -905,14 +905,15 @@ list_slice(list_T *ol, long n1, long n2)
list_slice_or_index(
list_T *list,
int range,
- long n1_arg,
- long n2_arg,
+ varnumber_T n1_arg,
+ varnumber_T n2_arg,
+ int exclusive,
typval_T *rettv,
int verbose)
{
long len = list_len(list);
- long n1 = n1_arg;
- long n2 = n2_arg;
+ varnumber_T n1 = n1_arg;
+ varnumber_T n2 = n2_arg;
typval_T var1;
if (n1 < 0)
@@ -936,7 +937,9 @@ list_slice_or_index(
if (n2 < 0)
n2 = len + n2;
else if (n2 >= len)
- n2 = len - 1;
+ n2 = len - (exclusive ? 0 : 1);
+ if (exclusive)
+ --n2;
if (n2 < 0 || n2 + 1 < n1)
n2 = -1;
l = list_slice(list, n1, n2);