cmark

My personal build of CMark ✏️

Commit
363c25c0a5584c0f936aaa9481b2130e29afa291
Parent
8713ff912aaf13926d799d7cbd61e5cf014ddb7e
Author
John MacFarlane <fiddlosopher@gmail.com>
Date

Added `cmark_iter_reset` and a note about handling destructive updates.

Diffstat

2 files changed, 22 insertions, 0 deletions

Status File Name N° Changes Insertions Deletions
Modified src/cmark.h 14 14 0
Modified src/iterator.c 8 8 0
diff --git a/src/cmark.h b/src/cmark.h
@@ -163,6 +163,11 @@ cmark_node_last_child(cmark_node *node);
  *
  *         cmark_iter_free(iter);
  *     }
+ *
+ * Note that if you delete the current node, its first child, or its
+ * next sibling, the iterator may point to a nonexistent note.
+ * Use 'cmark_iter_reset' to set its pointer to the next node that
+ * should be traversed.
  */
 
 /** Creates a new iterator starting at 'root'.
@@ -177,6 +182,15 @@ CMARK_EXPORT
 void
 cmark_iter_free(cmark_iter *iter);
 
+/** Resets the iterator so that the current node is 'current' and
+    the event type is 'event_type'.  Use this to resume after destructively
+    modifying the tree structure.
+ */
+CMARK_EXPORT
+void
+cmark_iter_reset(cmark_iter *iter, cmark_node *current,
+		 cmark_event_type event_type);
+
 /** Returns the event type (`CMARK_EVENT_ENTER`, `CMARK_EVENT_EXIT`,
  * or `CMARK_EVENT_DONE`) for the next node.
  */
diff --git a/src/iterator.c b/src/iterator.c
@@ -48,6 +48,14 @@ int S_is_leaf(cmark_node *node)
 	}
 }
 
+void
+cmark_iter_reset(cmark_iter *iter, cmark_node *current,
+		 cmark_event_type event_type)
+{
+	iter->event_type = event_type;
+	iter->current = current;
+}
+
 cmark_node*
 cmark_iter_get_node(cmark_iter *iter)
 {