Added the functions notmuch_tags_move_to_prevoius, notmuch_tags_move_to_last and notmuch_tags_move_to_first to notmuch library. With them is possible to iterate backwards on tags. * notmuch_tags_move_to_prevoius do the opposite than notmuch_tags_move_to_next, getting the tags iterator one position backwards. * notmuch_tags_move_to_last move the iterator to the first last tag. * notmuch_tags_move_to_first move the iterator to the first valid tag. --- lib/notmuch.h | 28 ++++++++++++++++++++++++++++ lib/tags.c | 21 +++++++++++++++++++++ 2 files changed, 49 insertions(+), 0 deletions(-) diff --git a/lib/notmuch.h b/lib/notmuch.h index b96b624..dc668dc 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -1022,6 +1022,15 @@ notmuch_tags_valid (notmuch_tags_t *tags); const char * notmuch_tags_get (notmuch_tags_t *tags); +/* Move the 'tags' iterator to the first tag. + * + * After that the 'tags' iterator will be set to the first valid + * tag, so it can be use to iterate with + * notmuch_tags_move_to_next. + */ +void +notmuch_tags_move_to_first (notmuch_tags_t *tags); + /* Move the 'tags' iterator to the next tag. * * If 'tags' is already pointing at the last tag then the iterator @@ -1035,6 +1044,25 @@ notmuch_tags_get (notmuch_tags_t *tags); void notmuch_tags_move_to_next (notmuch_tags_t *tags); +/* Move the 'tags' iterator to the last tag. + * + * After that the 'tags' iterator will be set to the last valid + * tag, so it can be use to iterate with + * notmuch_tags_move_to_previous. + */ +void +notmuch_tags_move_to_last (notmuch_tags_t *tags); + +/* Move the 'tags' iterator to the previous tag. + * + * If 'tags' is already pointing at the first tag then the + * iterator will be moved to a point just beyond that first tag, + * (where notmuch_tags_valid will return FALSE and + * notmuch_tags_get will return NULL). + */ +void +notmuch_tags_move_to_previous (notmuch_tags_t *tags); + /* Destroy a notmuch_tags_t object. * * It's not strictly necessary to call this function. All memory from diff --git a/lib/tags.c b/lib/tags.c index 8fe4a3f..9c9a897 100644 --- a/lib/tags.c +++ b/lib/tags.c @@ -105,6 +105,12 @@ notmuch_tags_get (notmuch_tags_t *tags) } void +notmuch_tags_move_to_first (notmuch_tags_t *tags) +{ + tags->iterator = g_list_first (tags->tags); +} + +void notmuch_tags_move_to_next (notmuch_tags_t *tags) { if (tags->iterator == NULL) @@ -114,6 +120,21 @@ notmuch_tags_move_to_next (notmuch_tags_t *tags) } void +notmuch_tags_move_to_last (notmuch_tags_t *tags) +{ + tags->iterator = g_list_last (tags->tags); +} + +void +notmuch_tags_move_to_previous (notmuch_tags_t *tags) +{ + if (tags->iterator == NULL) + return; + + tags->iterator = tags->iterator->prev; +} + +void notmuch_tags_destroy (notmuch_tags_t *tags) { talloc_free (tags); -- 1.7.0