diff options
author | John MacFarlane <jgm@berkeley.edu> | 2016-01-10 23:35:33 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2016-01-10 23:35:33 -0800 |
commit | 93843bd2fe8c91fe9e659c5b801f1a7d672dc223 (patch) | |
tree | 1b3af3c5fb8c4e7abc8491efd3570620eb4d8d91 /src | |
parent | e384149e683fd6ea950ba9318525563175ca9f47 (diff) |
Added cmark_node_replace(oldnode, newnode).
API change.
I've found in using the API that this is very often
wanted.
Diffstat (limited to 'src')
-rw-r--r-- | src/cmark.h | 5 | ||||
-rw-r--r-- | src/node.c | 9 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/cmark.h b/src/cmark.h index 5f9f294..6b5c385 100644 --- a/src/cmark.h +++ b/src/cmark.h @@ -387,6 +387,11 @@ CMARK_EXPORT int cmark_node_insert_before(cmark_node *node, */ CMARK_EXPORT int cmark_node_insert_after(cmark_node *node, cmark_node *sibling); +/** Replaces 'oldnode' with 'newnode' and frees the memory used by 'oldnode'. + * Returns 1 on success, 0 on failure. + */ +CMARK_EXPORT int cmark_node_replace(cmark_node *oldnode, cmark_node *newnode); + /** Adds 'child' to the beginning of the children of 'node'. * Returns 1 on success, 0 on failure. */ @@ -730,6 +730,15 @@ int cmark_node_insert_after(cmark_node *node, cmark_node *sibling) { return 1; } +int cmark_node_replace(cmark_node *oldnode, cmark_node *newnode) { + if (!cmark_node_insert_before(oldnode, newnode)) { + return 0; + } + cmark_node_unlink(oldnode); + cmark_node_free(oldnode); + return 1; +} + int cmark_node_prepend_child(cmark_node *node, cmark_node *child) { if (!S_can_contain(node, child)) { return 0; |