Mercurial > vim
comparison src/list.c @ 29978:34151eb6ae25 v9.0.0327
patch 9.0.0327: items() does not work on a list
Commit: https://github.com/vim/vim/commit/976f859763b215050a03248dbc2bb62fa5d0d059
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Aug 30 14:34:52 2022 +0100
patch 9.0.0327: items() does not work on a list
Problem: items() does not work on a list. (Sergey Vlasov)
Solution: Make items() work on a list. (closes https://github.com/vim/vim/issues/11013)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 30 Aug 2022 15:45:03 +0200 |
parents | 755ab148288b |
children | 0ad8b72af148 |
comparison
equal
deleted
inserted
replaced
29977:b6c19db0298b | 29978:34151eb6ae25 |
---|---|
1048 */ | 1048 */ |
1049 void | 1049 void |
1050 f_flattennew(typval_T *argvars, typval_T *rettv) | 1050 f_flattennew(typval_T *argvars, typval_T *rettv) |
1051 { | 1051 { |
1052 flatten_common(argvars, rettv, TRUE); | 1052 flatten_common(argvars, rettv, TRUE); |
1053 } | |
1054 | |
1055 /* | |
1056 * "items(list)" function | |
1057 * Caller must have already checked that argvars[0] is a List. | |
1058 */ | |
1059 void | |
1060 list2items(typval_T *argvars, typval_T *rettv) | |
1061 { | |
1062 list_T *l = argvars[0].vval.v_list; | |
1063 listitem_T *li; | |
1064 varnumber_T idx; | |
1065 | |
1066 if (rettv_list_alloc(rettv) == FAIL) | |
1067 return; | |
1068 | |
1069 if (l == NULL) | |
1070 return; // empty list behaves like an empty list | |
1071 | |
1072 // TODO: would be more efficient to not materialize the argument | |
1073 CHECK_LIST_MATERIALIZE(l); | |
1074 for (idx = 0, li = l->lv_first; li != NULL; li = li->li_next, ++idx) | |
1075 { | |
1076 list_T *l2 = list_alloc(); | |
1077 | |
1078 if (l2 == NULL) | |
1079 break; | |
1080 if (list_append_list(rettv->vval.v_list, l2) == FAIL | |
1081 || list_append_number(l2, idx) == FAIL | |
1082 || list_append_tv(l2, &li->li_tv) == FAIL) | |
1083 break; | |
1084 } | |
1053 } | 1085 } |
1054 | 1086 |
1055 /* | 1087 /* |
1056 * Extend "l1" with "l2". "l1" must not be NULL. | 1088 * Extend "l1" with "l2". "l1" must not be NULL. |
1057 * If "bef" is NULL append at the end, otherwise insert before this item. | 1089 * If "bef" is NULL append at the end, otherwise insert before this item. |