[notmuch] [PATCH] Added regress option to tags iterator
Ruben Pollan
meskio at sindominio.net
Wed Dec 9 05:10:06 PST 2009
Added the functions notmuch_tags_regress and notmuch_tags_is_first to
notmuch library. With them is possible to iterate backwards on tags.
* notmuch_tags_regress do the opposite than notmuch_tags_advance,
getting the tags iterator one position backwards.
* notmuch_tags_is_first return TRUE if the iterator is in the first
tag.
---
lib/notmuch.h | 8 ++++++++
lib/tags.c | 19 +++++++++++++++++++
2 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/lib/notmuch.h b/lib/notmuch.h
index e28ce46..db051c8 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -917,6 +917,10 @@ notmuch_message_destroy (notmuch_message_t *message);
notmuch_bool_t
notmuch_tags_has_more (notmuch_tags_t *tags);
+/* Is the given notmuch_tags_t object on the first tags */
+notmuch_bool_t
+notmuch_tags_is_first (notmuch_tags_t *tags);
+
/* Get the current tag from 'tags' as a string.
*
* Note: The returned string belongs to 'tags' and has a lifetime
@@ -936,6 +940,10 @@ notmuch_tags_get (notmuch_tags_t *tags);
void
notmuch_tags_advance (notmuch_tags_t *tags);
+/* Regress the 'tags' iterator to the previous result. */
+void
+notmuch_tags_regress (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 85507e9..cf9e030 100644
--- a/lib/tags.c
+++ b/lib/tags.c
@@ -25,6 +25,7 @@
struct _notmuch_tags {
int sorted;
GList *tags;
+ GList *previous_node;
GList *iterator;
};
@@ -55,6 +56,7 @@ _notmuch_tags_create (void *ctx)
tags->sorted = 1;
tags->tags = NULL;
+ tags->previous_node = NULL;
tags->iterator = NULL;
return tags;
@@ -94,6 +96,12 @@ notmuch_tags_has_more (notmuch_tags_t *tags)
return tags->iterator != NULL;
}
+notmuch_bool_t
+notmuch_tags_is_first (notmuch_tags_t *tags)
+{
+ return tags->previous_node == NULL;
+}
+
const char *
notmuch_tags_get (notmuch_tags_t *tags)
{
@@ -109,10 +117,21 @@ notmuch_tags_advance (notmuch_tags_t *tags)
if (tags->iterator == NULL)
return;
+ tags->previous_node = tags->iterator;
tags->iterator = tags->iterator->next;
}
void
+notmuch_tags_regress (notmuch_tags_t *tags)
+{
+ if (tags->previous_node == NULL)
+ return;
+
+ tags->iterator = tags->previous_node;
+ tags->previous_node = tags->iterator->prev;
+}
+
+void
notmuch_tags_destroy (notmuch_tags_t *tags)
{
talloc_free (tags);
--
1.6.5.4
More information about the notmuch
mailing list