[PATCH 15/19] WIP: add config values iterator

Subject: [PATCH 15/19] WIP: add config values iterator

Date: Sat, 8 Aug 2020 11:16:49 -0300

To: notmuch@notmuchmail.org

Cc: David Bremner

From: David Bremner


---
 lib/config.cc | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 lib/notmuch.h | 17 +++++++++++++++++
 2 files changed, 66 insertions(+)

diff --git a/lib/config.cc b/lib/config.cc
index ca7ac2a8..dd042ab2 100644
--- a/lib/config.cc
+++ b/lib/config.cc
@@ -31,6 +31,11 @@ struct _notmuch_config_list {
     char *current_val;
 };
 
+struct _notmuch_config_values {
+    const char *iterator;
+    size_t tok_len;
+};
+
 static int
 _notmuch_config_list_destroy (notmuch_config_list_t *list)
 {
@@ -232,6 +237,50 @@ notmuch_config_get (notmuch_database_t *notmuch, const char *key) {
     return _notmuch_string_map_get (notmuch->config, key);
 }
 
+notmuch_config_values_t *
+notmuch_config_get_values (notmuch_database_t *notmuch, const char *key)
+{
+    notmuch_config_values_t *values;
+
+    const char *str;
+    str  = _notmuch_string_map_get (notmuch->config, key);
+    if (! str)
+	return NULL;
+
+    values = talloc (notmuch, notmuch_config_values_t);
+    if (unlikely(! values))
+	return NULL;
+
+    values->iterator = str;
+    values->tok_len = 0;
+    return values;
+}
+
+notmuch_bool_t
+notmuch_config_values_valid (notmuch_config_values_t *values) {
+    if (! values)
+	return false;
+
+    return (values->iterator != NULL);
+}
+
+const char *
+notmuch_config_values_get (notmuch_config_values_t *values) {
+    return talloc_strndup (values, values->iterator, values->tok_len);
+}
+
+void
+notmuch_config_values_move_to_next (notmuch_config_values_t *values) {
+    values->iterator += values->tok_len;
+    values->iterator = strsplit_len (values->iterator, ';', &(values->tok_len));
+}
+
+void
+notmuch_config_values_destroy (notmuch_config_values_t *values) {
+    talloc_free (values);
+}
+
+
 notmuch_status_t
 notmuch_config_set (notmuch_database_t *notmuch,
 		    const char *key,
diff --git a/lib/notmuch.h b/lib/notmuch.h
index e147d5e6..7ae69265 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -236,6 +236,7 @@ typedef struct _notmuch_tags notmuch_tags_t;
 typedef struct _notmuch_directory notmuch_directory_t;
 typedef struct _notmuch_filenames notmuch_filenames_t;
 typedef struct _notmuch_config_list notmuch_config_list_t;
+typedef struct _notmuch_config_values notmuch_config_values_t;
 typedef struct _notmuch_indexopts notmuch_indexopts_t;
 #endif /* __DOXYGEN__ */
 
@@ -2405,6 +2406,22 @@ notmuch_config_set (notmuch_database_t *notmuch, const char *key,
 		    const char *val,
 		    notmuch_bool_t write_through);
 
+
+notmuch_config_values_t *
+notmuch_config_get_values (notmuch_database_t *notmuch, const char *key);
+
+notmuch_bool_t
+notmuch_config_values_valid (notmuch_config_values_t *values);
+
+const char *
+notmuch_config_values_get (notmuch_config_values_t *values);
+
+void
+notmuch_config_values_move_to_next (notmuch_config_values_t *values);
+
+void
+notmuch_config_values_destroy (notmuch_config_values_t *values);
+
 /**
  * get the current default indexing options for a given database.
  *
-- 
2.28.0
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: