diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2022-04-04 15:16:54 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-04-04 15:16:54 +0100 |
commit | 4829c1c9e9095a3303caec9af7d02f6547f6df0e (patch) | |
tree | 2b3819cd2ea17b652ba29f3a8a6ea9945ec6c4bb /src/dict.c | |
parent | 7a411a306f90339d8686e42ac16e1ae4fc7533c5 (diff) | |
download | vim-git-4829c1c9e9095a3303caec9af7d02f6547f6df0e.tar.gz |
patch 8.2.4683: verbose check with dict_find() to see if a key is presentv8.2.4683
Problem: Verbose check with dict_find() to see if a key is present.
Solution: Add dict_has_key(). (Yegappan Lakshmanan, closes #10074)
Diffstat (limited to 'src/dict.c')
-rw-r--r-- | src/dict.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/dict.c b/src/dict.c index c2dc6a7c2..88cc4b3fc 100644 --- a/src/dict.c +++ b/src/dict.c @@ -649,6 +649,15 @@ dict_find(dict_T *d, char_u *key, int len) } /* + * Returns TRUE if "key" is present in Dictionary "d". + */ + int +dict_has_key(dict_T *d, char *key) +{ + return dict_find(d, (char_u *)key, -1) != NULL; +} + +/* * Get a typval_T item from a dictionary and copy it into "rettv". * Returns FAIL if the entry doesn't exist or out of memory. */ @@ -1582,8 +1591,8 @@ f_has_key(typval_T *argvars, typval_T *rettv) if (argvars[0].vval.v_dict == NULL) return; - rettv->vval.v_number = dict_find(argvars[0].vval.v_dict, - tv_get_string(&argvars[1]), -1) != NULL; + rettv->vval.v_number = dict_has_key(argvars[0].vval.v_dict, + (char *)tv_get_string(&argvars[1])); } #endif // defined(FEAT_EVAL) |