summaryrefslogtreecommitdiffstats
path: root/src/dict.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-07-13 22:46:10 +0200
committerBram Moolenaar <Bram@vim.org>2019-07-13 22:46:10 +0200
commitd5abb4c87727eecb71b0e8ffdda60fc9598272f3 (patch)
tree0166ed6641ae120fe56c807f90a88e071aa74bbd /src/dict.c
parent809ce4d317fe12db0b2c17f16b4f77200fb060c4 (diff)
patch 8.1.1683: dictionary with string keys is longer than neededv8.1.1683
Problem: Dictionary with string keys is longer than needed. Solution: Use *{key: val} for literaly keys.
Diffstat (limited to 'src/dict.c')
-rw-r--r--src/dict.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/dict.c b/src/dict.c
index 96c58c1f2a..a80fb352d9 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -709,11 +709,33 @@ dict2string(typval_T *tv, int copyID, int restore_copyID)
}
/*
+ * Get the key for *{key: val} into "tv" and advance "arg".
+ * Return FAIL when there is no valid key.
+ */
+ static int
+get_literal_key(char_u **arg, typval_T *tv)
+{
+ char_u *p;
+
+ if (!ASCII_ISALNUM(**arg) && **arg != '_' && **arg != '-')
+ return FAIL;
+
+ for (p = *arg; ASCII_ISALNUM(*p) || *p == '_' || *p == '-'; ++p)
+ ;
+ tv->v_type = VAR_STRING;
+ tv->vval.v_string = vim_strnsave(*arg, (int)(p - *arg));
+
+ *arg = skipwhite(p);
+ return OK;
+}
+
+/*
* Allocate a variable for a Dictionary and fill it from "*arg".
+ * "literal" is TRUE for *{key: val}
* Return OK or FAIL. Returns NOTDONE for {expr}.
*/
int
-dict_get_tv(char_u **arg, typval_T *rettv, int evaluate)
+dict_get_tv(char_u **arg, typval_T *rettv, int evaluate, int literal)
{
dict_T *d = NULL;
typval_T tvkey;
@@ -750,8 +772,11 @@ dict_get_tv(char_u **arg, typval_T *rettv, int evaluate)
*arg = skipwhite(*arg + 1);
while (**arg != '}' && **arg != NUL)
{
- if (eval1(arg, &tvkey, evaluate) == FAIL) /* recursive! */
+ if ((literal
+ ? get_literal_key(arg, &tvkey)
+ : eval1(arg, &tvkey, evaluate)) == FAIL) // recursive!
goto failret;
+
if (**arg != ':')
{
semsg(_("E720: Missing colon in Dictionary: %s"), *arg);