aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval/typval.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2017-05-13 21:17:33 +0200
committerGitHub <noreply@github.com>2017-05-13 21:17:33 +0200
commit17531ed0825c1bf5e24e78ae94020fb08ca06013 (patch)
tree244e6a9df696de14b4c1441c51d9fa93c0c33d29 /src/nvim/eval/typval.c
parent7383274f669fa01ba3028ca0dec2c6ad815339c1 (diff)
parentd01f140bb3d926486014ae6697c8a7cef241325b (diff)
downloadrneovim-17531ed0825c1bf5e24e78ae94020fb08ca06013.tar.gz
rneovim-17531ed0825c1bf5e24e78ae94020fb08ca06013.tar.bz2
rneovim-17531ed0825c1bf5e24e78ae94020fb08ca06013.zip
Merge #6480 from ZyX-I/colored-cmdline'/input-dict
Diffstat (limited to 'src/nvim/eval/typval.c')
-rw-r--r--src/nvim/eval/typval.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c
index 19d9d56058..f017f57b12 100644
--- a/src/nvim/eval/typval.c
+++ b/src/nvim/eval/typval.c
@@ -1210,7 +1210,8 @@ char *tv_dict_get_string(const dict_T *const d, const char *const key,
///
/// @param[in] d Dictionary to get item from.
/// @param[in] key Dictionary key.
-/// @param[in] numbuf Numbuf for.
+/// @param[in] numbuf Buffer for non-string items converted to strings, at
+/// least of #NUMBUFLEN length.
///
/// @return NULL if key does not exist, empty string in case of type error,
/// string item value otherwise.
@@ -1225,6 +1226,32 @@ 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 Buffer for non-string items converted to strings, at
+/// least of #NUMBUFLEN length.
+/// @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.