| 701 | } |
| 702 | |
| 703 | int cmark_node_insert_before(cmark_node *node, cmark_node *sibling) { |
| 704 | if (node == NULL || sibling == NULL) { |
| 705 | return 0; |
| 706 | } |
| 707 | |
| 708 | if (!node->parent || !S_can_contain(node->parent, sibling)) { |
| 709 | return 0; |
| 710 | } |
| 711 | |
| 712 | S_node_unlink(sibling); |
| 713 | |
| 714 | cmark_node *old_prev = node->prev; |
| 715 | |
| 716 | // Insert 'sibling' between 'old_prev' and 'node'. |
| 717 | if (old_prev) { |
| 718 | old_prev->next = sibling; |
| 719 | } |
| 720 | sibling->prev = old_prev; |
| 721 | sibling->next = node; |
| 722 | node->prev = sibling; |
| 723 | |
| 724 | // Set new parent. |
| 725 | cmark_node *parent = node->parent; |
| 726 | sibling->parent = parent; |
| 727 | |
| 728 | // Adjust first_child of parent if inserted as first child. |
| 729 | if (parent && !old_prev) { |
| 730 | parent->first_child = sibling; |
| 731 | } |
| 732 | |
| 733 | return 1; |
| 734 | } |
| 735 | |
| 736 | int cmark_node_insert_after(cmark_node *node, cmark_node *sibling) { |
| 737 | if (node == NULL || sibling == NULL) { |
no test coverage detected