mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2024-12-25 23:21:26 +03:00
Convert the HTML tree module to the new buffers
The new input buffers induced a couple of changes, the others are related to the switch to xmlBuf in saving routines.
This commit is contained in:
parent
a78d803639
commit
7b9b07198f
59
HTMLtree.c
59
HTMLtree.c
@ -30,6 +30,8 @@
|
|||||||
#include <libxml/globals.h>
|
#include <libxml/globals.h>
|
||||||
#include <libxml/uri.h>
|
#include <libxml/uri.h>
|
||||||
|
|
||||||
|
#include "buf.h"
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* *
|
* *
|
||||||
* Getting/Setting encoding meta tags *
|
* Getting/Setting encoding meta tags *
|
||||||
@ -391,13 +393,9 @@ htmlSaveErr(int code, xmlNodePtr node, const char *extra)
|
|||||||
* *
|
* *
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
static int
|
|
||||||
htmlNodeDumpFormat(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur,
|
|
||||||
int format);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* htmlNodeDumpFormat:
|
* htmlBufNodeDumpFormat:
|
||||||
* @buf: the HTML buffer output
|
* @buf: the xmlBufPtr output
|
||||||
* @doc: the document
|
* @doc: the document
|
||||||
* @cur: the current node
|
* @cur: the current node
|
||||||
* @format: should formatting spaces been added
|
* @format: should formatting spaces been added
|
||||||
@ -406,10 +404,10 @@ htmlNodeDumpFormat(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur,
|
|||||||
*
|
*
|
||||||
* Returns the number of byte written or -1 in case of error
|
* Returns the number of byte written or -1 in case of error
|
||||||
*/
|
*/
|
||||||
static int
|
static size_t
|
||||||
htmlNodeDumpFormat(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur,
|
htmlBufNodeDumpFormat(xmlBufPtr buf, xmlDocPtr doc, xmlNodePtr cur,
|
||||||
int format) {
|
int format) {
|
||||||
unsigned int use;
|
size_t use;
|
||||||
int ret;
|
int ret;
|
||||||
xmlOutputBufferPtr outbuf;
|
xmlOutputBufferPtr outbuf;
|
||||||
|
|
||||||
@ -432,10 +430,10 @@ htmlNodeDumpFormat(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur,
|
|||||||
outbuf->context = NULL;
|
outbuf->context = NULL;
|
||||||
outbuf->written = 0;
|
outbuf->written = 0;
|
||||||
|
|
||||||
use = buf->use;
|
use = xmlBufUse(buf);
|
||||||
htmlNodeDumpFormatOutput(outbuf, doc, cur, NULL, format);
|
htmlNodeDumpFormatOutput(outbuf, doc, cur, NULL, format);
|
||||||
xmlFree(outbuf);
|
xmlFree(outbuf);
|
||||||
ret = buf->use - use;
|
ret = xmlBufUse(buf) - use;
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -452,9 +450,24 @@ htmlNodeDumpFormat(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur,
|
|||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
htmlNodeDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur) {
|
htmlNodeDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur) {
|
||||||
xmlInitParser();
|
xmlBufPtr buffer;
|
||||||
|
size_t ret;
|
||||||
|
|
||||||
return(htmlNodeDumpFormat(buf, doc, cur, 1));
|
if ((buf == NULL) || (cur == NULL))
|
||||||
|
return(-1);
|
||||||
|
|
||||||
|
xmlInitParser();
|
||||||
|
buffer = xmlBufFromBuffer(buf);
|
||||||
|
if (buffer == NULL)
|
||||||
|
return(-1);
|
||||||
|
|
||||||
|
ret = htmlBufNodeDumpFormat(buffer, doc, cur, 1);
|
||||||
|
|
||||||
|
xmlBufBackToBuffer(buffer);
|
||||||
|
|
||||||
|
if (ret > INT_MAX)
|
||||||
|
return(-1);
|
||||||
|
return((int) ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -595,11 +608,11 @@ htmlDocDumpMemoryFormat(xmlDocPtr cur, xmlChar**mem, int *size, int format) {
|
|||||||
|
|
||||||
xmlOutputBufferFlush(buf);
|
xmlOutputBufferFlush(buf);
|
||||||
if (buf->conv != NULL) {
|
if (buf->conv != NULL) {
|
||||||
*size = buf->conv->use;
|
*size = xmlBufUse(buf->conv);
|
||||||
*mem = xmlStrndup(buf->conv->content, *size);
|
*mem = xmlStrndup(xmlBufContent(buf->conv), *size);
|
||||||
} else {
|
} else {
|
||||||
*size = buf->buffer->use;
|
*size = xmlBufUse(buf->buffer);
|
||||||
*mem = xmlStrndup(buf->buffer->content, *size);
|
*mem = xmlStrndup(xmlBufContent(buf->buffer), *size);
|
||||||
}
|
}
|
||||||
(void)xmlOutputBufferClose(buf);
|
(void)xmlOutputBufferClose(buf);
|
||||||
}
|
}
|
||||||
@ -650,14 +663,14 @@ htmlDtdDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr doc,
|
|||||||
xmlOutputBufferWriteString(buf, (const char *)cur->name);
|
xmlOutputBufferWriteString(buf, (const char *)cur->name);
|
||||||
if (cur->ExternalID != NULL) {
|
if (cur->ExternalID != NULL) {
|
||||||
xmlOutputBufferWriteString(buf, " PUBLIC ");
|
xmlOutputBufferWriteString(buf, " PUBLIC ");
|
||||||
xmlBufferWriteQuotedString(buf->buffer, cur->ExternalID);
|
xmlBufWriteQuotedString(buf->buffer, cur->ExternalID);
|
||||||
if (cur->SystemID != NULL) {
|
if (cur->SystemID != NULL) {
|
||||||
xmlOutputBufferWriteString(buf, " ");
|
xmlOutputBufferWriteString(buf, " ");
|
||||||
xmlBufferWriteQuotedString(buf->buffer, cur->SystemID);
|
xmlBufWriteQuotedString(buf->buffer, cur->SystemID);
|
||||||
}
|
}
|
||||||
} else if (cur->SystemID != NULL) {
|
} else if (cur->SystemID != NULL) {
|
||||||
xmlOutputBufferWriteString(buf, " SYSTEM ");
|
xmlOutputBufferWriteString(buf, " SYSTEM ");
|
||||||
xmlBufferWriteQuotedString(buf->buffer, cur->SystemID);
|
xmlBufWriteQuotedString(buf->buffer, cur->SystemID);
|
||||||
}
|
}
|
||||||
xmlOutputBufferWriteString(buf, ">\n");
|
xmlOutputBufferWriteString(buf, ">\n");
|
||||||
}
|
}
|
||||||
@ -709,13 +722,13 @@ htmlAttrDumpOutput(xmlOutputBufferPtr buf, xmlDocPtr doc, xmlAttrPtr cur,
|
|||||||
|
|
||||||
escaped = xmlURIEscapeStr(tmp, BAD_CAST"@/:=?;#%&,+");
|
escaped = xmlURIEscapeStr(tmp, BAD_CAST"@/:=?;#%&,+");
|
||||||
if (escaped != NULL) {
|
if (escaped != NULL) {
|
||||||
xmlBufferWriteQuotedString(buf->buffer, escaped);
|
xmlBufWriteQuotedString(buf->buffer, escaped);
|
||||||
xmlFree(escaped);
|
xmlFree(escaped);
|
||||||
} else {
|
} else {
|
||||||
xmlBufferWriteQuotedString(buf->buffer, value);
|
xmlBufWriteQuotedString(buf->buffer, value);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
xmlBufferWriteQuotedString(buf->buffer, value);
|
xmlBufWriteQuotedString(buf->buffer, value);
|
||||||
}
|
}
|
||||||
xmlFree(value);
|
xmlFree(value);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user