diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-04-30 01:26:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-30 01:26:33 +0200 |
commit | 63526f2eeee774c657270a1ec0cbd788480f14b7 (patch) | |
tree | bacf8807780792b4a8dfaf0480f80e91cf4fe35e /src/nvim/eval/typval.c | |
parent | a0d723db55cf2b81e3bd9271cda9b1b58a5c9f3c (diff) | |
parent | aac731c22b94117aea2257d4f19fd1f0930a2385 (diff) | |
download | rneovim-63526f2eeee774c657270a1ec0cbd788480f14b7.tar.gz rneovim-63526f2eeee774c657270a1ec0cbd788480f14b7.tar.bz2 rneovim-63526f2eeee774c657270a1ec0cbd788480f14b7.zip |
Merge #9956 from justinmk/vim-8.1.1231
vim-patch:8.1.1231, swap-related patches
Diffstat (limited to 'src/nvim/eval/typval.c')
-rw-r--r-- | src/nvim/eval/typval.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 912aecafec..ffb46abfea 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -1656,12 +1656,7 @@ int tv_dict_add_special(dict_T *const d, const char *const key, /// Add a string entry to dictionary /// -/// @param[out] d Dictionary to add entry to. -/// @param[in] key Key to add. -/// @param[in] key_len Key length. -/// @param[in] val String to add. -/// -/// @return OK in case of success, FAIL when key already exists. +/// @see tv_dict_add_allocated_str int tv_dict_add_str(dict_T *const d, const char *const key, const size_t key_len, const char *const val) @@ -1672,6 +1667,27 @@ int tv_dict_add_str(dict_T *const d, /// Add a string entry to dictionary /// +/// @param[out] d Dictionary to add entry to. +/// @param[in] key Key to add. +/// @param[in] key_len Key length. +/// @param[in] val String to add. NULL adds empty string. +/// @param[in] len Use this many bytes from `val`, or -1 for whole string. +/// +/// @return OK in case of success, FAIL when key already exists. +int tv_dict_add_str_len(dict_T *const d, + const char *const key, const size_t key_len, + char *const val, int len) + FUNC_ATTR_NONNULL_ARG(1, 2) +{ + char *s = val ? val : ""; + if (val != NULL) { + s = (len < 0) ? xstrdup(val) : xstrndup(val, (size_t)len); + } + return tv_dict_add_allocated_str(d, key, key_len, s); +} + +/// Add a string entry to dictionary +/// /// Unlike tv_dict_add_str() saves val to the new dictionary item in place of /// creating a new copy. /// |