Mercurial > vim
comparison src/dict.c @ 17368:6604ecb7a615 v8.1.1683
patch 8.1.1683: dictionary with string keys is longer than needed
commit https://github.com/vim/vim/commit/d5abb4c87727eecb71b0e8ffdda60fc9598272f3
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jul 13 22:46:10 2019 +0200
patch 8.1.1683: dictionary with string keys is longer than needed
Problem: Dictionary with string keys is longer than needed.
Solution: Use *{key: val} for literaly keys.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 13 Jul 2019 23:00:05 +0200 |
parents | 3fd0765f454f |
children | ef23ec1eee54 |
comparison
equal
deleted
inserted
replaced
17367:d2959e9ddc7c | 17368:6604ecb7a615 |
---|---|
707 ga_append(&ga, NUL); | 707 ga_append(&ga, NUL); |
708 return (char_u *)ga.ga_data; | 708 return (char_u *)ga.ga_data; |
709 } | 709 } |
710 | 710 |
711 /* | 711 /* |
712 * Get the key for *{key: val} into "tv" and advance "arg". | |
713 * Return FAIL when there is no valid key. | |
714 */ | |
715 static int | |
716 get_literal_key(char_u **arg, typval_T *tv) | |
717 { | |
718 char_u *p; | |
719 | |
720 if (!ASCII_ISALNUM(**arg) && **arg != '_' && **arg != '-') | |
721 return FAIL; | |
722 | |
723 for (p = *arg; ASCII_ISALNUM(*p) || *p == '_' || *p == '-'; ++p) | |
724 ; | |
725 tv->v_type = VAR_STRING; | |
726 tv->vval.v_string = vim_strnsave(*arg, (int)(p - *arg)); | |
727 | |
728 *arg = skipwhite(p); | |
729 return OK; | |
730 } | |
731 | |
732 /* | |
712 * Allocate a variable for a Dictionary and fill it from "*arg". | 733 * Allocate a variable for a Dictionary and fill it from "*arg". |
734 * "literal" is TRUE for *{key: val} | |
713 * Return OK or FAIL. Returns NOTDONE for {expr}. | 735 * Return OK or FAIL. Returns NOTDONE for {expr}. |
714 */ | 736 */ |
715 int | 737 int |
716 dict_get_tv(char_u **arg, typval_T *rettv, int evaluate) | 738 dict_get_tv(char_u **arg, typval_T *rettv, int evaluate, int literal) |
717 { | 739 { |
718 dict_T *d = NULL; | 740 dict_T *d = NULL; |
719 typval_T tvkey; | 741 typval_T tvkey; |
720 typval_T tv; | 742 typval_T tv; |
721 char_u *key = NULL; | 743 char_u *key = NULL; |
748 tv.v_type = VAR_UNKNOWN; | 770 tv.v_type = VAR_UNKNOWN; |
749 | 771 |
750 *arg = skipwhite(*arg + 1); | 772 *arg = skipwhite(*arg + 1); |
751 while (**arg != '}' && **arg != NUL) | 773 while (**arg != '}' && **arg != NUL) |
752 { | 774 { |
753 if (eval1(arg, &tvkey, evaluate) == FAIL) /* recursive! */ | 775 if ((literal |
776 ? get_literal_key(arg, &tvkey) | |
777 : eval1(arg, &tvkey, evaluate)) == FAIL) // recursive! | |
754 goto failret; | 778 goto failret; |
779 | |
755 if (**arg != ':') | 780 if (**arg != ':') |
756 { | 781 { |
757 semsg(_("E720: Missing colon in Dictionary: %s"), *arg); | 782 semsg(_("E720: Missing colon in Dictionary: %s"), *arg); |
758 clear_tv(&tvkey); | 783 clear_tv(&tvkey); |
759 goto failret; | 784 goto failret; |