summaryrefslogtreecommitdiff
path: root/bindings
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-03-03 18:08:01 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2009-03-03 18:08:01 +0000
commit702d96e703473dbe4481a42c472b4aae423a51d1 (patch)
tree9dc767860ebea940f1d936d14d69073b4e289c92 /bindings
parenteeb651eadb47228ad41c21b80d75afc17c2924f8 (diff)
downloadlibdom-702d96e703473dbe4481a42c472b4aae423a51d1.tar.gz
libdom-702d96e703473dbe4481a42c472b4aae423a51d1.tar.bz2
Rationalise dom_string (some consideration is required as to what happens wrt interning -- lwc_strings should probably be used)
Purge charset handling -- a) documents are always converted to utf-8 b) use parserutils for utf-8 handling Fix Hubbub binding to compile. svn path=/trunk/dom/; revision=6682
Diffstat (limited to 'bindings')
-rw-r--r--bindings/hubbub/parser.c64
-rw-r--r--bindings/xml/xmlbinding.c5
-rw-r--r--bindings/xml/xmlparser.c36
3 files changed, 39 insertions, 66 deletions
diff --git a/bindings/hubbub/parser.c b/bindings/hubbub/parser.c
index 9473438..7b5e6ab 100644
--- a/bindings/hubbub/parser.c
+++ b/bindings/hubbub/parser.c
@@ -20,7 +20,6 @@
*/
struct dom_hubbub_parser {
hubbub_parser *parser; /**< Hubbub parser instance */
- const uint8_t *buffer; /**< Parser buffer pointer */
struct dom_document *doc; /**< DOM Document we're building */
@@ -35,9 +34,8 @@ struct dom_hubbub_parser {
void *mctx; /**< Pointer to client data */
};
-static void __dom_hubbub_buffer_handler(const uint8_t *buffer, size_t len,
+static hubbub_error __dom_hubbub_token_handler(const hubbub_token *token,
void *pw);
-static void __dom_hubbub_token_handler(const hubbub_token *token, void *pw);
static bool __initialised;
@@ -63,6 +61,8 @@ dom_hubbub_parser *dom_hubbub_parser_create(const char *aliases,
dom_exception err;
hubbub_error e;
+ UNUSED(int_enc);
+
if (__initialised == false) {
e = hubbub_initialise(aliases, (hubbub_alloc) alloc, pw);
if (e != HUBBUB_OK) {
@@ -80,23 +80,11 @@ dom_hubbub_parser *dom_hubbub_parser_create(const char *aliases,
return NULL;
}
- parser->parser = hubbub_parser_create(enc, int_enc,
- (hubbub_alloc) alloc, pw);
- if (parser->parser == NULL) {
- alloc(parser, 0, pw);
- msg(DOM_MSG_CRITICAL, mctx, "Failed to create hubbub parser");
- return NULL;
- }
-
- params.buffer_handler.handler = __dom_hubbub_buffer_handler;
- params.buffer_handler.pw = parser;
- e = hubbub_parser_setopt(parser->parser, HUBBUB_PARSER_BUFFER_HANDLER,
- &params);
+ e = hubbub_parser_create(enc, true, (hubbub_alloc) alloc, pw,
+ &parser->parser);
if (e != HUBBUB_OK) {
- hubbub_parser_destroy(parser->parser);
alloc(parser, 0, pw);
- msg(DOM_MSG_CRITICAL, mctx,
- "Failed registering hubbub buffer handler");
+ msg(DOM_MSG_CRITICAL, mctx, "Failed to create hubbub parser");
return NULL;
}
@@ -118,8 +106,7 @@ dom_hubbub_parser *dom_hubbub_parser_create(const char *aliases,
/* Get DOM implementation */
/* Create string representation of the features we want */
- err = dom_string_create_from_ptr_no_doc(alloc, pw,
- DOM_STRING_UTF8,
+ err = dom_string_create(alloc, pw,
(const uint8_t *) "HTML", SLEN("HTML"), &features);
if (err != DOM_NO_ERR) {
hubbub_parser_destroy(parser->parser);
@@ -202,17 +189,7 @@ struct dom_document *dom_hubbub_parser_get_document(dom_hubbub_parser *parser)
return (parser->complete ? parser->doc : NULL);
}
-void __dom_hubbub_buffer_handler(const uint8_t *buffer, size_t len,
- void *pw)
-{
- dom_hubbub_parser *parser = (dom_hubbub_parser *) pw;
-
- UNUSED(len);
-
- parser->buffer = buffer;
-}
-
-void __dom_hubbub_token_handler(const hubbub_token *token, void *pw)
+hubbub_error __dom_hubbub_token_handler(const hubbub_token *token, void *pw)
{
dom_hubbub_parser *parser = (dom_hubbub_parser *) pw;
static const char *token_names[] = {
@@ -221,55 +198,58 @@ void __dom_hubbub_token_handler(const hubbub_token *token, void *pw)
};
size_t i;
+ UNUSED(parser);
+
printf("%s: ", token_names[token->type]);
switch (token->type) {
case HUBBUB_TOKEN_DOCTYPE:
printf("'%.*s' (%svalid)\n",
(int) token->data.doctype.name.len,
- parser->buffer +
- token->data.doctype.name.data_off,
- token->data.doctype.correct ? "" : "in");
+ token->data.doctype.name.ptr,
+ token->data.doctype.force_quirks ? "in" : "");
break;
case HUBBUB_TOKEN_START_TAG:
printf("'%.*s' %s\n",
(int) token->data.tag.name.len,
- parser->buffer + token->data.tag.name.data_off,
+ token->data.tag.name.ptr,
(token->data.tag.n_attributes > 0) ?
"attributes:" : "");
for (i = 0; i < token->data.tag.n_attributes; i++) {
printf("\t'%.*s' = '%.*s'\n",
(int) token->data.tag.attributes[i].name.len,
- parser->buffer + token->data.tag.attributes[i].name.data_off,
+ token->data.tag.attributes[i].name.ptr,
(int) token->data.tag.attributes[i].value.len,
- parser->buffer + token->data.tag.attributes[i].value.data_off);
+ token->data.tag.attributes[i].value.ptr);
}
break;
case HUBBUB_TOKEN_END_TAG:
printf("'%.*s' %s\n",
(int) token->data.tag.name.len,
- parser->buffer + token->data.tag.name.data_off,
+ token->data.tag.name.ptr,
(token->data.tag.n_attributes > 0) ?
"attributes:" : "");
for (i = 0; i < token->data.tag.n_attributes; i++) {
printf("\t'%.*s' = '%.*s'\n",
(int) token->data.tag.attributes[i].name.len,
- parser->buffer + token->data.tag.attributes[i].name.data_off,
+ token->data.tag.attributes[i].name.ptr,
(int) token->data.tag.attributes[i].value.len,
- parser->buffer + token->data.tag.attributes[i].value.data_off);
+ token->data.tag.attributes[i].value.ptr);
}
break;
case HUBBUB_TOKEN_COMMENT:
printf("'%.*s'\n", (int) token->data.comment.len,
- parser->buffer + token->data.comment.data_off);
+ token->data.comment.ptr);
break;
case HUBBUB_TOKEN_CHARACTER:
printf("'%.*s'\n", (int) token->data.character.len,
- parser->buffer + token->data.character.data_off);
+ token->data.character.ptr);
break;
case HUBBUB_TOKEN_EOF:
printf("\n");
break;
}
+
+ return HUBBUB_OK;
}
diff --git a/bindings/xml/xmlbinding.c b/bindings/xml/xmlbinding.c
index 2bbfb7b..b03b7af 100644
--- a/bindings/xml/xmlbinding.c
+++ b/bindings/xml/xmlbinding.c
@@ -38,7 +38,6 @@ static dom_exception xml_dom_implementation_create_document(
struct dom_string *qname,
struct dom_document_type *doctype,
struct dom_document **doc,
- dom_string_charset charset,
dom_alloc alloc, void *pw);
static dom_exception xml_dom_implementation_get_feature(
struct dom_implementation *impl,
@@ -237,7 +236,6 @@ dom_exception xml_dom_implementation_create_document_type(
* \param qname The qualified name of the document element
* \param doctype The type of document to create
* \param doc Pointer to location to receive result
- * \param charset The charset to use for strings in the document
* \param alloc Memory (de)allocation function
* \param pw Pointer to client-specific private data
* \return DOM_NO_ERR on success,
@@ -274,14 +272,13 @@ dom_exception xml_dom_implementation_create_document(
struct dom_string *qname,
struct dom_document_type *doctype,
struct dom_document **doc,
- dom_string_charset charset,
dom_alloc alloc, void *pw)
{
struct dom_document *d;
dom_exception err;
/* Create document object */
- err = dom_document_create(impl, charset, alloc, pw, &d);
+ err = dom_document_create(impl, alloc, pw, &d);
if (err != DOM_NO_ERR)
return err;
diff --git a/bindings/xml/xmlparser.c b/bindings/xml/xmlparser.c
index 743a826..9e3786f 100644
--- a/bindings/xml/xmlparser.c
+++ b/bindings/xml/xmlparser.c
@@ -181,8 +181,7 @@ dom_xml_parser *dom_xml_parser_create(const char *enc, const char *int_enc,
parser->complete = false;
/* Create key for user data registration */
- err = dom_string_create_from_ptr_no_doc((dom_alloc) alloc, pw,
- DOM_STRING_UTF8,
+ err = dom_string_create((dom_alloc) alloc, pw,
(const uint8_t *) "__xmlnode", SLEN("__xmlnode"),
&parser->udkey);
if (err != DOM_NO_ERR) {
@@ -194,8 +193,7 @@ dom_xml_parser *dom_xml_parser_create(const char *enc, const char *int_enc,
/* Get DOM implementation */
/* Create a string representation of the features we want */
- err = dom_string_create_from_ptr_no_doc((dom_alloc) alloc, pw,
- DOM_STRING_UTF8,
+ err = dom_string_create((dom_alloc) alloc, pw,
(const uint8_t *) "XML", SLEN("XML"), &features);
if (err != DOM_NO_ERR) {
dom_string_unref(parser->udkey);
@@ -329,7 +327,6 @@ void xml_parser_start_document(void *ctx)
/* qname */ NULL,
/* doctype */ NULL,
&doc,
- DOM_STRING_UTF8,
(dom_alloc) parser->alloc,
parser->pw);
if (err != DOM_NO_ERR) {
@@ -650,9 +647,8 @@ void xml_parser_add_element_node(dom_xml_parser *parser,
struct dom_string *tag_name;
/* Create tag name DOM string */
- err = dom_string_create_from_const_ptr(parser->doc,
- child->name,
- strlen((const char *) child->name),
+ err = dom_document_create_string(parser->doc,
+ child->name, strlen((const char *) child->name),
&tag_name);
if (err != DOM_NO_ERR) {
parser->msg(DOM_MSG_CRITICAL, parser->mctx,
@@ -684,7 +680,7 @@ void xml_parser_add_element_node(dom_xml_parser *parser,
uint8_t qnamebuf[qnamelen + 1 /* '\0' */];
/* Create namespace DOM string */
- err = dom_string_create_from_const_ptr(parser->doc,
+ err = dom_document_create_string(parser->doc,
child->ns->href,
strlen((const char *) child->ns->href),
&namespace);
@@ -703,7 +699,7 @@ void xml_parser_add_element_node(dom_xml_parser *parser,
(const char *) child->name);
/* Create qname DOM string */
- err = dom_string_create_from_ptr(parser->doc,
+ err = dom_document_create_string(parser->doc,
qnamebuf,
qnamelen,
&qname);
@@ -742,7 +738,7 @@ void xml_parser_add_element_node(dom_xml_parser *parser,
struct dom_string *name;
/* Create attribute name DOM string */
- err = dom_string_create_from_const_ptr(parser->doc,
+ err = dom_document_create_string(parser->doc,
a->name,
strlen((const char *) a->name),
&name);
@@ -776,7 +772,7 @@ void xml_parser_add_element_node(dom_xml_parser *parser,
uint8_t qnamebuf[qnamelen + 1 /* '\0' */];
/* Create namespace DOM string */
- err = dom_string_create_from_const_ptr(parser->doc,
+ err = dom_document_create_string(parser->doc,
a->ns->href,
strlen((const char *) a->ns->href),
&namespace);
@@ -795,7 +791,7 @@ void xml_parser_add_element_node(dom_xml_parser *parser,
(const char *) a->name);
/* Create qname DOM string */
- err = dom_string_create_from_ptr(parser->doc,
+ err = dom_document_create_string(parser->doc,
qnamebuf,
qnamelen,
&qname);
@@ -904,7 +900,7 @@ void xml_parser_add_text_node(dom_xml_parser *parser, struct dom_node *parent,
dom_exception err;
/* Create DOM string data for text node */
- err = dom_string_create_from_const_ptr(parser->doc, child->content,
+ err = dom_document_create_string(parser->doc, child->content,
strlen((const char *) child->content), &data);
if (err != DOM_NO_ERR) {
parser->msg(DOM_MSG_CRITICAL, parser->mctx,
@@ -965,7 +961,7 @@ void xml_parser_add_cdata_section(dom_xml_parser *parser,
dom_exception err;
/* Create DOM string data for cdata section */
- err = dom_string_create_from_const_ptr(parser->doc, child->content,
+ err = dom_document_create_string(parser->doc, child->content,
strlen((const char *) child->content), &data);
if (err != DOM_NO_ERR) {
parser->msg(DOM_MSG_CRITICAL, parser->mctx,
@@ -1027,7 +1023,7 @@ void xml_parser_add_entity_reference(dom_xml_parser *parser,
dom_exception err;
/* Create name of entity reference */
- err = dom_string_create_from_const_ptr(parser->doc, child->name,
+ err = dom_document_create_string(parser->doc, child->name,
strlen((const char *) child->name), &name);
if (err != DOM_NO_ERR) {
parser->msg(DOM_MSG_CRITICAL, parser->mctx,
@@ -1094,7 +1090,7 @@ void xml_parser_add_comment(dom_xml_parser *parser, struct dom_node *parent,
dom_exception err;
/* Create DOM string data for comment */
- err = dom_string_create_from_const_ptr(parser->doc, child->content,
+ err = dom_document_create_string(parser->doc, child->content,
strlen((const char *) child->content), &data);
if (err != DOM_NO_ERR) {
parser->msg(DOM_MSG_CRITICAL, parser->mctx,
@@ -1156,7 +1152,7 @@ void xml_parser_add_document_type(dom_xml_parser *parser,
dom_exception err;
/* Create qname for doctype */
- err = dom_string_create_from_const_ptr(parser->doc, dtd->name,
+ err = dom_document_create_string(parser->doc, dtd->name,
strlen((const char *) dtd->name), &qname);
if (err != DOM_NO_ERR) {
parser->msg(DOM_MSG_CRITICAL, parser->mctx,
@@ -1165,7 +1161,7 @@ void xml_parser_add_document_type(dom_xml_parser *parser,
}
/* Create public ID for doctype */
- err = dom_string_create_from_const_ptr(parser->doc,
+ err = dom_document_create_string(parser->doc,
dtd->ExternalID,
(dtd->ExternalID == NULL) ? 0
: strlen((const char *) dtd->ExternalID),
@@ -1178,7 +1174,7 @@ void xml_parser_add_document_type(dom_xml_parser *parser,
}
/* Create system ID for doctype */
- err = dom_string_create_from_const_ptr(parser->doc,
+ err = dom_document_create_string(parser->doc,
dtd->SystemID,
(dtd->SystemID == NULL) ? 0
: strlen((const char *) dtd->SystemID),