patch 8.2.4683: verbose check with dict_find() to see if a key is present
Problem: Verbose check with dict_find() to see if a key is present. Solution: Add dict_has_key(). (Yegappan Lakshmanan, closes #10074)
This commit is contained in:
committed by
Bram Moolenaar
parent
7a411a306f
commit
4829c1c9e9
13
src/dict.c
13
src/dict.c
@ -648,6 +648,15 @@ dict_find(dict_T *d, char_u *key, int len)
|
||||
return HI2DI(hi);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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)
|
||||
|
||||
Reference in New Issue
Block a user