* xmlAddSibling: * @node: the target node * @cur: the new node * * Unlinks @cur and inserts it as last sibling of @node. * * If @cur is a text node, it may be merged with an adjacent text * node and freed. In this case the text node containing the merged * content is returned. * * If @cur is an attribute node, it is appended to the attribute * list containing @node. If the attribute l
| 3254 | * if arguments are invalid or a memory allocation failed. |
| 3255 | */ |
| 3256 | xmlNodePtr |
| 3257 | xmlAddSibling(xmlNodePtr node, xmlNodePtr cur) { |
| 3258 | if ((node == NULL) || (node->type == XML_NAMESPACE_DECL) || |
| 3259 | (cur == NULL) || (cur->type == XML_NAMESPACE_DECL) || |
| 3260 | (cur == node)) |
| 3261 | return(NULL); |
| 3262 | |
| 3263 | /* |
| 3264 | * Constant time is we can rely on the ->parent->last to find |
| 3265 | * the last sibling. |
| 3266 | */ |
| 3267 | if ((node->type != XML_ATTRIBUTE_NODE) && (node->parent != NULL)) { |
| 3268 | if (node->parent->last != NULL) |
| 3269 | node = node->parent->last; |
| 3270 | } else { |
| 3271 | while (node->next != NULL) |
| 3272 | node = node->next; |
| 3273 | } |
| 3274 | |
| 3275 | if (cur == node) |
| 3276 | return(cur); |
| 3277 | |
| 3278 | return(xmlInsertNode(node->doc, cur, node->parent, node, NULL, 1)); |
| 3279 | } |
| 3280 | |
| 3281 | /** |
| 3282 | * xmlAddChildList: |
no test coverage detected