summaryrefslogtreecommitdiff
path: root/src/core/document.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2007-09-30 21:10:50 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2007-09-30 21:10:50 +0000
commite0e38d906c8974bb22a0368a9709af9590362927 (patch)
treef7f4c1acff769e9a7f6cd0f1c037ba2c28a66593 /src/core/document.c
parent49e419c9b75cc149e7f4c898c31aed33f4b2c960 (diff)
downloadlibdom-e0e38d906c8974bb22a0368a9709af9590362927.tar.gz
libdom-e0e38d906c8974bb22a0368a9709af9590362927.tar.bz2
DOM Strings are now capable of containing either UTF-8 or UTF-16 encoded data.
The charset used for strings within a document is specified at document creation time. Whilst it is possible to mix charsets within a document, it's not recommended. Things that need fixing: + dom_string_get_data() doesn't return the charset. Better would be to permit the client to request a charset for the data to be returned in. + Interned node name strings will break if the document is UTF-16 (dom_document_create()). In fact, these could quite happily be globals, rather than allocating a set for each document. + Other usage of dom string constructors need checking for sanity + DOM Strings need to gain more utility APIs (such as getting the character length of a string, string concatenation etc). svn path=/trunk/dom/; revision=3614
Diffstat (limited to 'src/core/document.c')
-rw-r--r--src/core/document.c44
1 files changed, 39 insertions, 5 deletions
diff --git a/src/core/document.c b/src/core/document.c
index 5148224..e188868 100644
--- a/src/core/document.c
+++ b/src/core/document.c
@@ -56,6 +56,8 @@ struct dom_doc_nnm {
struct dom_document {
struct dom_node base; /**< Base node */
+ dom_string_charset charset; /**< Charset of strings in document */
+
struct dom_implementation *impl; /**< Owning implementation */
struct dom_doc_nl *nodelists; /**< List of active nodelists */
@@ -73,10 +75,11 @@ struct dom_document {
/**
* Create a Document
*
- * \param impl The DOM implementation owning the document
- * \param alloc Memory (de)allocation function
- * \param pw Pointer to client-specific private data
- * \param doc Pointer to location to receive created document
+ * \param impl The DOM implementation owning the document
+ * \param charset The charset used for strings in the document
+ * \param alloc Memory (de)allocation function
+ * \param pw Pointer to client-specific private data
+ * \param doc Pointer to location to receive created document
* \return DOM_NO_ERR on success, DOM_NO_MEM_ERR on memory exhaustion.
*
* ::impl will have its reference count increased.
@@ -84,7 +87,8 @@ struct dom_document {
* The returned document will already be referenced.
*/
dom_exception dom_document_create(struct dom_implementation *impl,
- dom_alloc alloc, void *pw, struct dom_document **doc)
+ dom_string_charset charset, dom_alloc alloc, void *pw,
+ struct dom_document **doc)
{
static const char *names[DOM_NODE_TYPE_COUNT + 1] = {
NULL, /* Unused */
@@ -110,6 +114,7 @@ dom_exception dom_document_create(struct dom_implementation *impl,
return DOM_NO_MEM_ERR;
/* Set up document allocation context - must be first */
+ d->charset = charset;
d->alloc = alloc;
d->pw = pw;
@@ -994,6 +999,35 @@ const uint8_t *dom_document_get_base(struct dom_document *doc)
}
/**
+ * Set the document buffer pointer
+ *
+ * \param doc Document to set buffer pointer of
+ * \param buffer Pointer to buffer
+ * \param buffer_len Length of buffer, in bytes
+ *
+ * By calling this, ownership of the buffer is transferred to the document.
+ * It should be called once per document node.
+ */
+void dom_document_set_buffer(struct dom_document *doc, uint8_t *buffer,
+ size_t buffer_len)
+{
+ UNUSED(doc);
+ UNUSED(buffer);
+ UNUSED(buffer_len);
+}
+
+/**
+ * Retrieve the character set used to encode strings in the document
+ *
+ * \param doc The document to get the charset of
+ * \return The charset in use
+ */
+dom_string_charset dom_document_get_charset(struct dom_document *doc)
+{
+ return doc->charset;
+}
+
+/**
* (De)allocate memory with a document's context
*
* \param doc The document context to allocate from