From ee77b2fbb5f145aa91f71c0b6e4934c1f2939a0f Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Mon, 17 Sep 2007 17:33:03 +0000 Subject: Partial implementation of dom_node_insert_before. This has utterly no sanity checking at present so will probably break, badly. svn path=/trunk/dom/; revision=3546 --- src/core/node.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/core/node.c b/src/core/node.c index db4838b..c33e24d 100644 --- a/src/core/node.c +++ b/src/core/node.c @@ -537,12 +537,36 @@ dom_exception dom_node_insert_before(struct dom_node *node, struct dom_node *new_child, struct dom_node *ref_child, struct dom_node **result) { - UNUSED(node); - UNUSED(new_child); - UNUSED(ref_child); - UNUSED(result); + /** \todo sanity checking etc. */ - return DOM_NOT_SUPPORTED_ERR; + new_child->parent = node; + + if (ref_child == NULL) { + new_child->previous = node->last_child; + new_child->next = NULL; + + if (node->last_child != NULL) + node->last_child->next = new_child; + else + node->first_child = new_child; + + node->last_child = new_child; + } else { + new_child->previous = ref_child->previous; + new_child->next = ref_child; + + if (ref_child->previous != NULL) + ref_child->previous->next = new_child; + else + node->first_child = new_child; + + ref_child->previous = new_child; + } + + dom_node_ref(new_child); + *result = new_child; + + return DOM_NO_ERR; } /** -- cgit v1.2.3