From 7cbcc882de7d5747e2342f0829bbcc9f2bcca60f Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sat, 28 Jul 2007 14:34:59 +0000 Subject: Sort out somewhat messy object construction. We now have explicit types for all classes (rather than using the parent class for those which inherit but add no extra data content). svn path=/trunk/dom/; revision=3465 --- src/core/text.c | 52 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 18 deletions(-) (limited to 'src/core/text.c') diff --git a/src/core/text.c b/src/core/text.c index 5c2308a..05e2b7d 100644 --- a/src/core/text.c +++ b/src/core/text.c @@ -13,21 +13,10 @@ #include "core/text.h" #include "utils/utils.h" -/** - * A DOM text node - */ -struct dom_text { - struct dom_characterdata base; /**< Base node */ - - bool element_content_whitespace; /**< This node is element - * content whitespace */ -}; - /** * Create a text node * * \param doc The owning document - * \param type The type of text node to create * \param name The name of the node to create * \param value The text content of the node * \param result Pointer to location to receive created node @@ -38,33 +27,60 @@ struct dom_text { * * The returned node will already be referenced. */ -dom_exception dom_text_create(struct dom_document *doc, dom_node_type type, +dom_exception dom_text_create(struct dom_document *doc, struct dom_string *name, struct dom_string *value, struct dom_text **result) { struct dom_text *t; dom_exception err; - /* Allocate the element */ + /* Allocate the text node */ t = dom_document_alloc(doc, NULL, sizeof(struct dom_text)); if (t == NULL) return DOM_NO_MEM_ERR; - /* Initialise the base class */ - err = dom_characterdata_initialise(&t->base, doc, type, name, value); + /* And initialise the node */ + err = dom_text_initialise(t, doc, DOM_TEXT_NODE, name, value); if (err != DOM_NO_ERR) { dom_document_alloc(doc, t, 0); return err; } - /* Perform our type-specific initialisation */ - t->element_content_whitespace = false; - *result = t; return DOM_NO_ERR; } +/** + * Initialise a text node + * + * \param text The node to initialise + * \param doc The owning document + * \param type The type of the node + * \param name The name of the node to create + * \param value The text content of the node + * \return DOM_NO_ERR on success. + * + * ::doc, ::name and ::value will have their reference counts increased. + */ +dom_exception dom_text_initialise(struct dom_text *text, + struct dom_document *doc, dom_node_type type, + struct dom_string *name, struct dom_string *value) +{ + dom_exception err; + + /* Initialise the base class */ + err = dom_characterdata_initialise(&text->base, doc, type, + name, value); + if (err != DOM_NO_ERR) + return err; + + /* Perform our type-specific initialisation */ + text->element_content_whitespace = false; + + return DOM_NO_ERR; +} + /** * Split a text node at a given character offset * -- cgit v1.2.3