mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-29 11:41:22 +03:00
fixing bug #84876 based on the xml working code. Daniel
* HTMLparser.c: fixing bug #84876 based on the xml working code. Daniel
This commit is contained in:
95
HTMLparser.c
95
HTMLparser.c
@ -3813,6 +3813,74 @@ htmlFreeParserCtxt(htmlParserCtxtPtr ctxt)
|
||||
xmlFreeParserCtxt(ctxt);
|
||||
}
|
||||
|
||||
/**
|
||||
* htmlNewParserCtxt:
|
||||
*
|
||||
* Allocate and initialize a new parser context.
|
||||
*
|
||||
* Returns the xmlParserCtxtPtr or NULL
|
||||
*/
|
||||
|
||||
static htmlParserCtxtPtr
|
||||
htmlNewParserCtxt(void)
|
||||
{
|
||||
xmlParserCtxtPtr ctxt;
|
||||
|
||||
ctxt = (xmlParserCtxtPtr) xmlMalloc(sizeof(xmlParserCtxt));
|
||||
if (ctxt == NULL) {
|
||||
xmlGenericError(xmlGenericErrorContext,
|
||||
"xmlNewParserCtxt : cannot allocate context\n");
|
||||
perror("malloc");
|
||||
return(NULL);
|
||||
}
|
||||
memset(ctxt, 0, sizeof(xmlParserCtxt));
|
||||
htmlInitParserCtxt(ctxt);
|
||||
return(ctxt);
|
||||
}
|
||||
|
||||
/**
|
||||
* htmlCreateMemoryParserCtxt:
|
||||
* @buffer: a pointer to a char array
|
||||
* @size: the size of the array
|
||||
*
|
||||
* Create a parser context for an HTML in-memory document.
|
||||
*
|
||||
* Returns the new parser context or NULL
|
||||
*/
|
||||
static htmlParserCtxtPtr
|
||||
htmlCreateMemoryParserCtxt(const char *buffer, int size) {
|
||||
xmlParserCtxtPtr ctxt;
|
||||
xmlParserInputPtr input;
|
||||
xmlParserInputBufferPtr buf;
|
||||
|
||||
if (buffer == NULL)
|
||||
return(NULL);
|
||||
if (size <= 0)
|
||||
return(NULL);
|
||||
|
||||
ctxt = htmlNewParserCtxt();
|
||||
if (ctxt == NULL)
|
||||
return(NULL);
|
||||
|
||||
buf = xmlParserInputBufferCreateMem(buffer, size, XML_CHAR_ENCODING_NONE);
|
||||
if (buf == NULL) return(NULL);
|
||||
|
||||
input = xmlNewInputStream(ctxt);
|
||||
if (input == NULL) {
|
||||
xmlFreeParserCtxt(ctxt);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
input->filename = NULL;
|
||||
input->buf = buf;
|
||||
input->base = input->buf->buffer->content;
|
||||
input->cur = input->buf->buffer->content;
|
||||
input->end = &input->buf->buffer->content[input->buf->buffer->use];
|
||||
|
||||
inputPush(ctxt, input);
|
||||
return(ctxt);
|
||||
}
|
||||
|
||||
/**
|
||||
* htmlCreateDocParserCtxt :
|
||||
* @cur: a pointer to an array of xmlChar
|
||||
@ -3826,31 +3894,12 @@ htmlFreeParserCtxt(htmlParserCtxtPtr ctxt)
|
||||
*/
|
||||
static htmlParserCtxtPtr
|
||||
htmlCreateDocParserCtxt(xmlChar *cur, const char *encoding ATTRIBUTE_UNUSED) {
|
||||
htmlParserCtxtPtr ctxt;
|
||||
htmlParserInputPtr input;
|
||||
/* htmlCharEncoding enc; */
|
||||
int len;
|
||||
|
||||
ctxt = (htmlParserCtxtPtr) xmlMalloc(sizeof(htmlParserCtxt));
|
||||
if (ctxt == NULL) {
|
||||
perror("malloc");
|
||||
if (cur == NULL)
|
||||
return(NULL);
|
||||
}
|
||||
htmlInitParserCtxt(ctxt);
|
||||
input = (htmlParserInputPtr) xmlMalloc(sizeof(htmlParserInput));
|
||||
if (input == NULL) {
|
||||
perror("malloc");
|
||||
xmlFree(ctxt);
|
||||
return(NULL);
|
||||
}
|
||||
memset(input, 0, sizeof(htmlParserInput));
|
||||
|
||||
input->line = 1;
|
||||
input->col = 1;
|
||||
input->base = cur;
|
||||
input->cur = cur;
|
||||
|
||||
inputPush(ctxt, input);
|
||||
return(ctxt);
|
||||
len = xmlStrlen(cur);
|
||||
return(htmlCreateMemoryParserCtxt((char *)cur, len));
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
|
Reference in New Issue
Block a user