From 24a9d103b4ee5ede577297bf49db93b83f8860a0 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sat, 28 Jan 2006 04:09:31 +0100 Subject: [PATCH] DOM: Add allocated flag to struct dom_node; replaces subtype flags Prepare for handling of allocated strings in the various nodes. --- src/dom/configuration.c | 10 +++++----- src/dom/node.c | 17 ++++++++++++++--- src/dom/node.h | 9 +++------ 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/dom/configuration.c b/src/dom/configuration.c index fb8f8c92..b228f02e 100644 --- a/src/dom/configuration.c +++ b/src/dom/configuration.c @@ -44,11 +44,11 @@ normalize_text_node_whitespace(struct dom_node *node) } } - if (node->data.text.allocated) + if (node->allocated) done_dom_string(&node->string); set_dom_string(&node->string, string.string, string.length); - node->data.text.allocated = 1; + node->allocated = 1; return DOM_STACK_CODE_OK; @@ -74,14 +74,14 @@ append_node_text(struct dom_config *config, struct dom_node *node) set_dom_string(&dest, NULL, 0); } else { - if (prev->data.text.allocated) { + if (prev->allocated) { copy_struct(&dest, &prev->string); } else { set_dom_string(&dest, NULL, 0); if (!add_to_dom_string(&dest, prev->string.string, prev->string.length)) return DOM_STACK_CODE_ERROR_MEM_ALLOC; set_dom_string(&prev->string, dest.string, dest.length); - prev->data.text.allocated = 1; + prev->allocated = 1; } } @@ -135,7 +135,7 @@ append_node_text(struct dom_config *config, struct dom_node *node) node->type = DOM_NODE_TEXT; memset(&node->data, 0, sizeof(node->data)); - node->data.text.allocated = 1; + node->allocated = 1; copy_struct(&node->string, &dest); if ((config->flags & DOM_CONFIG_NORMALIZE_WHITESPACE) diff --git a/src/dom/node.c b/src/dom/node.c index 9995c223..913397ae 100644 --- a/src/dom/node.c +++ b/src/dom/node.c @@ -202,7 +202,7 @@ struct dom_node * get_dom_node_map_entry(struct dom_node_list *list, enum dom_node_type type, uint16_t subtype, struct dom_string *name) { - struct dom_node node = { type, INIT_DOM_STRING(name->string, name->length) }; + struct dom_node node = { type, 0, INIT_DOM_STRING(name->string, name->length) }; struct dom_node_search search = INIT_DOM_NODE_SEARCH(&node, list); if (subtype) { @@ -359,8 +359,10 @@ done_dom_node_data(struct dom_node *node) switch (node->type) { case DOM_NODE_ATTRIBUTE: - if (data->attribute.allocated) + if (node->allocated) { done_dom_string(&node->string); + done_dom_string(&data->attribute.value); + } break; case DOM_NODE_DOCUMENT: @@ -380,16 +382,25 @@ done_dom_node_data(struct dom_node *node) if (data->element.map) done_dom_node_list(data->element.map); + + if (node->allocated) + done_dom_string(&node->string); break; case DOM_NODE_TEXT: - if (data->text.allocated) + case DOM_NODE_CDATA_SECTION: + case DOM_NODE_ENTITY_REFERENCE: + if (node->allocated) done_dom_string(&node->string); break; case DOM_NODE_PROCESSING_INSTRUCTION: if (data->proc_instruction.map) done_dom_node_list(data->proc_instruction.map); + if (node->allocated) { + done_dom_string(&node->string); + done_dom_string(&data->proc_instruction.instruction); + } break; default: diff --git a/src/dom/node.h b/src/dom/node.h index f7de061b..f1816dce 100644 --- a/src/dom/node.h +++ b/src/dom/node.h @@ -115,9 +115,6 @@ struct dom_attribute_node { * it added from the document source. */ unsigned int specified:1; - /* Was the node->string allocated */ - unsigned int allocated:1; - /* Has the node->string been converted to internal charset. */ unsigned int converted:1; @@ -140,9 +137,6 @@ struct dom_text_node { * In order to quickly identify such nodes this member is used. */ unsigned int only_space:1; - /* Was the node->string allocated */ - unsigned int allocated:1; - /* Has the node->string been converted to internal charset. */ unsigned int converted:1; }; @@ -197,6 +191,9 @@ struct dom_node { /* The type of the node */ uint16_t type; /* -> enum dom_node_type */ + /* Was the node string allocated? */ + unsigned int allocated:1; + /* Can contain either stuff like element name or for attributes the * attribute name. */ struct dom_string string;