From 6b110bebb8930b171145597cfa37ff1c1ac753f7 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Mon, 6 Dec 2010 23:15:39 +0000 Subject: Simplify DOMImplementation API by replacing dom_strings with const char * svn path=/trunk/libdom/; revision=11024 --- bindings/hubbub/parser.c | 34 +++++++++++++++------------------- bindings/xml/xmlparser.c | 45 ++++++--------------------------------------- 2 files changed, 21 insertions(+), 58 deletions(-) (limited to 'bindings') diff --git a/bindings/hubbub/parser.c b/bindings/hubbub/parser.c index 5566662..97d3e24 100644 --- a/bindings/hubbub/parser.c +++ b/bindings/hubbub/parser.c @@ -316,42 +316,38 @@ static hubbub_error create_doctype(void *parser, const hubbub_doctype *doctype, { dom_hubbub_parser *dom_parser = (dom_hubbub_parser *) parser; dom_exception err; - struct dom_string *qname, *public_id = NULL, *system_id = NULL; + char *qname, *public_id = NULL, *system_id = NULL; struct dom_document_type *dtype; *result = NULL; - err = dom_string_create(dom_parser->alloc, dom_parser->pw, - doctype->name.ptr, doctype->name.len, &qname); - if (err != DOM_NO_ERR) { + qname = strndup((const char *) doctype->name.ptr, + (size_t) doctype->name.len); + if (qname == NULL) { dom_parser->msg(DOM_MSG_CRITICAL, dom_parser->mctx, "Can't create doctype name"); goto fail; } if (doctype->public_missing == false) { - err = dom_string_create(dom_parser->alloc, dom_parser->pw, - doctype->public_id.ptr, - doctype->public_id.len, &public_id); + public_id = strndup((const char *) doctype->public_id.ptr, + (size_t) doctype->public_id.len); } else { - err = dom_string_create(dom_parser->alloc, dom_parser->pw, - NULL, 0, &public_id); + public_id = strdup(""); } - if (err != DOM_NO_ERR) { + if (public_id == NULL) { dom_parser->msg(DOM_MSG_CRITICAL, dom_parser->mctx, "Can't create doctype public id"); goto clean1; } if (doctype->system_missing == false) { - err = dom_string_create(dom_parser->alloc, dom_parser->pw, - doctype->system_id.ptr, - doctype->system_id.len, &system_id); + system_id = strndup((const char *) doctype->system_id.ptr, + (size_t) doctype->system_id.len); } else { - err = dom_string_create(dom_parser->alloc, dom_parser->pw, - NULL, 0, &system_id); + system_id = strdup(""); } - if (err != DOM_NO_ERR) { + if (system_id == NULL) { dom_parser->msg(DOM_MSG_CRITICAL, dom_parser->mctx, "Can't create doctype system id"); goto clean2; @@ -369,13 +365,13 @@ static hubbub_error create_doctype(void *parser, const hubbub_doctype *doctype, *result = dtype; clean3: - dom_string_unref(system_id); + free(system_id); clean2: - dom_string_unref(public_id); + free(public_id); clean1: - dom_string_unref(qname); + free(qname); fail: if (*result == NULL) diff --git a/bindings/xml/xmlparser.c b/bindings/xml/xmlparser.c index f8b3cb9..ff1f9d6 100644 --- a/bindings/xml/xmlparser.c +++ b/bindings/xml/xmlparser.c @@ -1163,63 +1163,30 @@ void xml_parser_add_document_type(dom_xml_parser *parser, { xmlDtdPtr dtd = (xmlDtdPtr) child; struct dom_document_type *doctype, *ins_doctype = NULL; - struct dom_string *qname, *public_id, *system_id; + const char *qname, *public_id, *system_id; dom_exception err; /* Create qname for doctype */ - 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, - "No memory for doctype name"); - return; - } + qname = (const char *) dtd->name; /* Create public ID for doctype */ - err = _dom_document_create_string(parser->doc, - dtd->ExternalID, - (dtd->ExternalID == NULL) ? 0 - : strlen((const char *) dtd->ExternalID), - &public_id); - if (err != DOM_NO_ERR) { - dom_string_unref(qname); - parser->msg(DOM_MSG_CRITICAL, parser->mctx, - "No memory for doctype public id"); - return; - } + public_id = dtd->ExternalID != NULL ? + (const char *) dtd->ExternalID : ""; /* Create system ID for doctype */ - err = _dom_document_create_string(parser->doc, - dtd->SystemID, - (dtd->SystemID == NULL) ? 0 - : strlen((const char *) dtd->SystemID), - &system_id); - if (err != DOM_NO_ERR) { - dom_string_unref(public_id); - dom_string_unref(qname); - parser->msg(DOM_MSG_CRITICAL, parser->mctx, - "No memory for doctype system id"); - return; - } + system_id = dtd->SystemID != NULL ? + (const char *) dtd->SystemID : ""; /* Create doctype */ err = dom_implementation_create_document_type( qname, public_id, system_id, parser->alloc, parser->pw, &doctype); if (err != DOM_NO_ERR) { - dom_string_unref(system_id); - dom_string_unref(public_id); - dom_string_unref(qname); parser->msg(DOM_MSG_CRITICAL, parser->mctx, "Failed to create document type"); return; } - /* No longer need qname, public_id, system_id */ - dom_string_unref(system_id); - dom_string_unref(public_id); - dom_string_unref(qname); - /* Add doctype to document */ err = dom_node_append_child(parent, (struct dom_node *) doctype, (struct dom_node **) (void *) &ins_doctype); -- cgit v1.2.3