1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-28 03:06:20 -04:00

DOM: Add allocated flag to struct dom_node; replaces subtype flags

Prepare for handling of allocated strings in the various nodes.
This commit is contained in:
Jonas Fonseca 2006-01-28 04:09:31 +01:00 committed by Jonas Fonseca
parent 3b183c1685
commit 24a9d103b4
3 changed files with 22 additions and 14 deletions

View File

@ -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)

View File

@ -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:

View File

@ -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;