From a24e5d04f5e4fb51446c623d2352e1da5ea53a2b Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sat, 24 Mar 2012 16:26:55 +0000 Subject: Fixup _dom_node_get_text_content svn path=/trunk/libdom/; revision=13598 --- src/core/node.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/core/node.c b/src/core/node.c index 606f2b1..0660c53 100644 --- a/src/core/node.c +++ b/src/core/node.c @@ -1429,6 +1429,8 @@ dom_exception _dom_node_compare_document_position(dom_node_internal *node, * the responsibility of the caller to unref the string once it has * finished with it. * + * If there is no text content in the code, NULL will returned in \a result. + * * DOM3Core states that this can raise DOMSTRING_SIZE_ERR. It will not in * this implementation; dom_strings are unbounded. */ @@ -1436,17 +1438,22 @@ dom_exception _dom_node_get_text_content(dom_node_internal *node, dom_string **result) { dom_node_internal *n; - dom_string *str; - dom_string *ret; + dom_string *str = NULL; + dom_string *ret = NULL; assert(node->owner != NULL); - + for (n = node->first_child; n != NULL; n = n->next) { - dom_node_get_text_content(n, &ret); - dom_string_concat(str, ret, &str); + dom_node_get_text_content(n, (str == NULL) ? &str : &ret); + if (ret != NULL) { + dom_string *new_str; + dom_string_concat(str, ret, &new_str); + dom_string_unref(str); + dom_string_unref(ret); + str = new_str; + } } - - dom_string_ref(str); + *result = str; return DOM_NO_ERR; -- cgit v1.2.1