1 /* tags.c - Iterator for tags returned from message or thread
3 * Copyright © 2009 Carl Worth
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see http://www.gnu.org/licenses/ .
18 * Author: Carl Worth <cworth@cworth.org>
21 #include "notmuch-private.h"
23 struct _notmuch_tags {
24 notmuch_string_node_t *iterator;
27 /* Create a new notmuch_tags_t object, with 'ctx' as its talloc owner.
28 * The returned iterator will talloc_steal the 'list', since the list
29 * is almost always transient.
31 * This function can return NULL in case of out-of-memory.
34 _notmuch_tags_create (const void *ctx, notmuch_string_list_t *list)
38 tags = talloc (ctx, notmuch_tags_t);
39 if (unlikely (tags == NULL))
42 tags->iterator = list->head;
43 (void) talloc_steal (tags, list);
49 notmuch_tags_valid (notmuch_tags_t *tags)
51 return tags->iterator != NULL;
55 notmuch_tags_get (notmuch_tags_t *tags)
57 if (tags->iterator == NULL)
60 return (char *) tags->iterator->string;
64 notmuch_tags_move_to_next (notmuch_tags_t *tags)
66 if (tags->iterator == NULL)
69 tags->iterator = tags->iterator->next;
73 notmuch_tags_destroy (notmuch_tags_t *tags)