diff options
author | ZyX <kp-pav@yandex.ru> | 2017-04-01 23:57:34 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2017-05-10 15:52:48 +0300 |
commit | f4d5d5250a105b5593e3119f4ee37ea20272a34b (patch) | |
tree | 307cdf0118e0463266dca1c6637a487a8589078a /src/nvim/eval/typval.c | |
parent | d9023b84e63f51611cf55f72ca5e021d64ba7ce9 (diff) | |
download | rneovim-f4d5d5250a105b5593e3119f4ee37ea20272a34b.tar.gz rneovim-f4d5d5250a105b5593e3119f4ee37ea20272a34b.tar.bz2 rneovim-f4d5d5250a105b5593e3119f4ee37ea20272a34b.zip |
eval: Refactor get_user_input to support dictionary
Diffstat (limited to 'src/nvim/eval/typval.c')
-rw-r--r-- | src/nvim/eval/typval.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 786b766689..e721ebe345 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -1225,6 +1225,31 @@ const char *tv_dict_get_string_buf(const dict_T *const d, const char *const key, return tv_get_string_buf(&di->di_tv, numbuf); } +/// Get a string item from a dictionary +/// +/// @param[in] d Dictionary to get item from. +/// @param[in] key Dictionary key. +/// @param[in] key_len Key length. +/// @param[in] numbuf Numbuf for. +/// @param[in] def Default return when key does not exist. +/// +/// @return `def` when key does not exist, +/// NULL in case of type error, +/// string item value in case of success. +const char *tv_dict_get_string_buf_chk(const dict_T *const d, + const char *const key, + const ptrdiff_t key_len, + char *const numbuf, + const char *const def) + FUNC_ATTR_WARN_UNUSED_RESULT +{ + const dictitem_T *const di = tv_dict_find(d, key, key_len); + if (di == NULL) { + return def; + } + return tv_get_string_buf_chk(&di->di_tv, numbuf); +} + /// Get a function from a dictionary /// /// @param[in] d Dictionary to get callback from. |