| 734 | } |
| 735 | |
| 736 | int cmark_node_insert_after(cmark_node *node, cmark_node *sibling) { |
| 737 | if (node == NULL || sibling == NULL) { |
| 738 | return 0; |
| 739 | } |
| 740 | |
| 741 | if (!node->parent || !S_can_contain(node->parent, sibling)) { |
| 742 | return 0; |
| 743 | } |
| 744 | |
| 745 | S_node_unlink(sibling); |
| 746 | |
| 747 | cmark_node *old_next = node->next; |
| 748 | |
| 749 | // Insert 'sibling' between 'node' and 'old_next'. |
| 750 | if (old_next) { |
| 751 | old_next->prev = sibling; |
| 752 | } |
| 753 | sibling->next = old_next; |
| 754 | sibling->prev = node; |
| 755 | node->next = sibling; |
| 756 | |
| 757 | // Set new parent. |
| 758 | cmark_node *parent = node->parent; |
| 759 | sibling->parent = parent; |
| 760 | |
| 761 | // Adjust last_child of parent if inserted as last child. |
| 762 | if (parent && !old_next) { |
| 763 | parent->last_child = sibling; |
| 764 | } |
| 765 | |
| 766 | return 1; |
| 767 | } |
| 768 | |
| 769 | int cmark_node_replace(cmark_node *oldnode, cmark_node *newnode) { |
| 770 | if (!cmark_node_insert_before(oldnode, newnode)) { |
no test coverage detected