Mercurial > vim
comparison src/dict.c @ 17530:ef23ec1eee54 v8.1.1763
patch 8.1.1763: evalfunc.c is still too big
commit https://github.com/vim/vim/commit/9f9fe37f6750f342255a51f158a7bb372c827f7f
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jul 27 23:12:12 2019 +0200
patch 8.1.1763: evalfunc.c is still too big
Problem: Evalfunc.c is still too big.
Solution: Move dict and list functions to a better place.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 27 Jul 2019 23:15:05 +0200 |
parents | 6604ecb7a615 |
children | 8f82b1ec99b7 |
comparison
equal
deleted
inserted
replaced
17529:4bd2e3339ba3 | 17530:ef23ec1eee54 |
---|---|
707 ga_append(&ga, NUL); | 707 ga_append(&ga, NUL); |
708 return (char_u *)ga.ga_data; | 708 return (char_u *)ga.ga_data; |
709 } | 709 } |
710 | 710 |
711 /* | 711 /* |
712 * Get the key for *{key: val} into "tv" and advance "arg". | 712 * Get the key for #{key: val} into "tv" and advance "arg". |
713 * Return FAIL when there is no valid key. | 713 * Return FAIL when there is no valid key. |
714 */ | 714 */ |
715 static int | 715 static int |
716 get_literal_key(char_u **arg, typval_T *tv) | 716 get_literal_key(char_u **arg, typval_T *tv) |
717 { | 717 { |
729 return OK; | 729 return OK; |
730 } | 730 } |
731 | 731 |
732 /* | 732 /* |
733 * Allocate a variable for a Dictionary and fill it from "*arg". | 733 * Allocate a variable for a Dictionary and fill it from "*arg". |
734 * "literal" is TRUE for *{key: val} | 734 * "literal" is TRUE for #{key: val} |
735 * Return OK or FAIL. Returns NOTDONE for {expr}. | 735 * Return OK or FAIL. Returns NOTDONE for {expr}. |
736 */ | 736 */ |
737 int | 737 int |
738 dict_get_tv(char_u **arg, typval_T *rettv, int evaluate, int literal) | 738 dict_get_tv(char_u **arg, typval_T *rettv, int evaluate, int literal) |
739 { | 739 { |
1032 } | 1032 } |
1033 } | 1033 } |
1034 } | 1034 } |
1035 | 1035 |
1036 /* | 1036 /* |
1037 * "items(dict)" function | |
1038 */ | |
1039 void | |
1040 f_items(typval_T *argvars, typval_T *rettv) | |
1041 { | |
1042 dict_list(argvars, rettv, 2); | |
1043 } | |
1044 | |
1045 /* | |
1046 * "keys()" function | |
1047 */ | |
1048 void | |
1049 f_keys(typval_T *argvars, typval_T *rettv) | |
1050 { | |
1051 dict_list(argvars, rettv, 0); | |
1052 } | |
1053 | |
1054 /* | |
1055 * "values(dict)" function | |
1056 */ | |
1057 void | |
1058 f_values(typval_T *argvars, typval_T *rettv) | |
1059 { | |
1060 dict_list(argvars, rettv, 1); | |
1061 } | |
1062 | |
1063 /* | |
1037 * Make each item in the dict readonly (not the value of the item). | 1064 * Make each item in the dict readonly (not the value of the item). |
1038 */ | 1065 */ |
1039 void | 1066 void |
1040 dict_set_items_ro(dict_T *di) | 1067 dict_set_items_ro(dict_T *di) |
1041 { | 1068 { |
1050 --todo; | 1077 --todo; |
1051 HI2DI(hi)->di_flags |= DI_FLAGS_RO | DI_FLAGS_FIX; | 1078 HI2DI(hi)->di_flags |= DI_FLAGS_RO | DI_FLAGS_FIX; |
1052 } | 1079 } |
1053 } | 1080 } |
1054 | 1081 |
1082 /* | |
1083 * "has_key()" function | |
1084 */ | |
1085 void | |
1086 f_has_key(typval_T *argvars, typval_T *rettv) | |
1087 { | |
1088 if (argvars[0].v_type != VAR_DICT) | |
1089 { | |
1090 emsg(_(e_dictreq)); | |
1091 return; | |
1092 } | |
1093 if (argvars[0].vval.v_dict == NULL) | |
1094 return; | |
1095 | |
1096 rettv->vval.v_number = dict_find(argvars[0].vval.v_dict, | |
1097 tv_get_string(&argvars[1]), -1) != NULL; | |
1098 } | |
1099 | |
1100 /* | |
1101 * "remove({dict})" function | |
1102 */ | |
1103 void | |
1104 dict_remove(typval_T *argvars, typval_T *rettv, char_u *arg_errmsg) | |
1105 { | |
1106 dict_T *d; | |
1107 char_u *key; | |
1108 dictitem_T *di; | |
1109 | |
1110 if (argvars[2].v_type != VAR_UNKNOWN) | |
1111 semsg(_(e_toomanyarg), "remove()"); | |
1112 else if ((d = argvars[0].vval.v_dict) != NULL | |
1113 && !var_check_lock(d->dv_lock, arg_errmsg, TRUE)) | |
1114 { | |
1115 key = tv_get_string_chk(&argvars[1]); | |
1116 if (key != NULL) | |
1117 { | |
1118 di = dict_find(d, key, -1); | |
1119 if (di == NULL) | |
1120 semsg(_(e_dictkey), key); | |
1121 else if (!var_check_fixed(di->di_flags, arg_errmsg, TRUE) | |
1122 && !var_check_ro(di->di_flags, arg_errmsg, TRUE)) | |
1123 { | |
1124 *rettv = di->di_tv; | |
1125 init_tv(&di->di_tv); | |
1126 dictitem_remove(d, di); | |
1127 } | |
1128 } | |
1129 } | |
1130 } | |
1131 | |
1055 #endif /* defined(FEAT_EVAL) */ | 1132 #endif /* defined(FEAT_EVAL) */ |