Mercurial > vim
comparison src/dict.c @ 16447:54ffc82f38a8 v8.1.1228
patch 8.1.1228: not possible to process tags with a function
commit https://github.com/vim/vim/commit/45e18cbdc40afd8144d20dcc07ad2d981636f4c9
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Apr 28 18:05:35 2019 +0200
patch 8.1.1228: not possible to process tags with a function
Problem: Not possible to process tags with a function.
Solution: Add tagfunc() (Christian Brabandt, Andy Massimino, closes https://github.com/vim/vim/issues/4010)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 28 Apr 2019 18:15:07 +0200 |
parents | 0f65f2808470 |
children | ef00b6bc186b |
comparison
equal
deleted
inserted
replaced
16446:cee0719a1b4b | 16447:54ffc82f38a8 |
---|---|
447 } | 447 } |
448 return OK; | 448 return OK; |
449 } | 449 } |
450 | 450 |
451 /* | 451 /* |
452 * Initializes "iter" for iterating over dictionary items with | |
453 * dict_iterate_next(). | |
454 * If "var" is not a Dict or an empty Dict then there will be nothing to | |
455 * iterate over, no error is given. | |
456 * NOTE: The dictionary must not change until iterating is finished! | |
457 */ | |
458 void | |
459 dict_iterate_start(typval_T *var, dict_iterator_T *iter) | |
460 { | |
461 if (var->v_type != VAR_DICT || var->vval.v_dict == NULL) | |
462 iter->dit_todo = 0; | |
463 else | |
464 { | |
465 dict_T *d = var->vval.v_dict; | |
466 | |
467 iter->dit_todo = d->dv_hashtab.ht_used; | |
468 iter->dit_hi = d->dv_hashtab.ht_array; | |
469 } | |
470 } | |
471 | |
472 /* | |
473 * Iterate over the items referred to by "iter". It should be initialized with | |
474 * dict_iterate_start(). | |
475 * Returns a pointer to the key. | |
476 * "*tv_result" is set to point to the value for that key. | |
477 * If there are no more items, NULL is returned. | |
478 */ | |
479 char_u * | |
480 dict_iterate_next(dict_iterator_T *iter, typval_T **tv_result) | |
481 { | |
482 dictitem_T *di; | |
483 char_u *result; | |
484 | |
485 if (iter->dit_todo == 0) | |
486 return NULL; | |
487 | |
488 while (HASHITEM_EMPTY(iter->dit_hi)) | |
489 ++iter->dit_hi; | |
490 | |
491 di = HI2DI(iter->dit_hi); | |
492 result = di->di_key; | |
493 *tv_result = &di->di_tv; | |
494 | |
495 --iter->dit_todo; | |
496 ++iter->dit_hi; | |
497 return result; | |
498 } | |
499 | |
500 /* | |
452 * Add a dict entry to dictionary "d". | 501 * Add a dict entry to dictionary "d". |
453 * Returns FAIL when out of memory and when key already exists. | 502 * Returns FAIL when out of memory and when key already exists. |
454 */ | 503 */ |
455 int | 504 int |
456 dict_add_dict(dict_T *d, char *key, dict_T *dict) | 505 dict_add_dict(dict_T *d, char *key, dict_T *dict) |