diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-04-28 18:05:35 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-04-28 18:05:35 +0200 |
commit | 45e18cbdc40afd8144d20dcc07ad2d981636f4c9 (patch) | |
tree | 11762469ca5d6c4bd49ca50381160afd30dcb2f3 /src/dict.c | |
parent | 7a9df9dd00bac462a2942dc798e298f365779fd0 (diff) |
patch 8.1.1228: not possible to process tags with a functionv8.1.1228
Problem: Not possible to process tags with a function.
Solution: Add tagfunc() (Christian Brabandt, Andy Massimino, closes #4010)
Diffstat (limited to 'src/dict.c')
-rw-r--r-- | src/dict.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/dict.c b/src/dict.c index 7d49599efa..007a7ff851 100644 --- a/src/dict.c +++ b/src/dict.c @@ -449,6 +449,55 @@ dict_add_list(dict_T *d, char *key, list_T *list) } /* + * Initializes "iter" for iterating over dictionary items with + * dict_iterate_next(). + * If "var" is not a Dict or an empty Dict then there will be nothing to + * iterate over, no error is given. + * NOTE: The dictionary must not change until iterating is finished! + */ + void +dict_iterate_start(typval_T *var, dict_iterator_T *iter) +{ + if (var->v_type != VAR_DICT || var->vval.v_dict == NULL) + iter->dit_todo = 0; + else + { + dict_T *d = var->vval.v_dict; + + iter->dit_todo = d->dv_hashtab.ht_used; + iter->dit_hi = d->dv_hashtab.ht_array; + } +} + +/* + * Iterate over the items referred to by "iter". It should be initialized with + * dict_iterate_start(). + * Returns a pointer to the key. + * "*tv_result" is set to point to the value for that key. + * If there are no more items, NULL is returned. + */ + char_u * +dict_iterate_next(dict_iterator_T *iter, typval_T **tv_result) +{ + dictitem_T *di; + char_u *result; + + if (iter->dit_todo == 0) + return NULL; + + while (HASHITEM_EMPTY(iter->dit_hi)) + ++iter->dit_hi; + + di = HI2DI(iter->dit_hi); + result = di->di_key; + *tv_result = &di->di_tv; + + --iter->dit_todo; + ++iter->dit_hi; + return result; +} + +/* * Add a dict entry to dictionary "d". * Returns FAIL when out of memory and when key already exists. */ |