summaryrefslogtreecommitdiff
path: root/src/core/comment.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/comment.c')
-rw-r--r--src/core/comment.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/core/comment.c b/src/core/comment.c
new file mode 100644
index 0000000..e29edda
--- /dev/null
+++ b/src/core/comment.c
@@ -0,0 +1,56 @@
+/*
+ * This file is part of libdom.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#include "core/characterdata.h"
+#include "core/comment.h"
+#include "core/document.h"
+
+/**
+ * A DOM comment node
+ */
+struct dom_comment {
+ struct dom_characterdata base; /**< Base node */
+};
+
+/**
+ * Create a comment node
+ *
+ * \param doc The owning document
+ * \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
+ * \return DOM_NO_ERR on success,
+ * DOM_NO_MEM_ERR on memory exhaustion.
+ *
+ * ::doc, ::name and ::value will have their reference counts increased.
+ *
+ * The returned node will already be referenced.
+ */
+dom_exception dom_comment_create(struct dom_document *doc,
+ struct dom_string *name, struct dom_string *value,
+ struct dom_comment **result)
+{
+ struct dom_comment *c;
+ dom_exception err;
+
+ /* Allocate the comment node */
+ c = dom_document_alloc(doc, NULL, sizeof(struct dom_comment));
+ if (c == NULL)
+ return DOM_NO_MEM_ERR;
+
+ /* And initialise the node */
+ err = dom_characterdata_initialise(&c->base, doc, DOM_COMMENT_NODE,
+ name, value);
+ if (err != DOM_NO_ERR) {
+ dom_document_alloc(doc, c, 0);
+ return err;
+ }
+
+ *result = c;
+
+ return DOM_NO_ERR;
+}