1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-09 04:58:16 +03:00

Create stream with buffer in xmlNewStringInputStream

Create an input stream with a buffer in xmlNewStringInputStream.
Otherwise, switching encodings won't work.

See #34.
This commit is contained in:
Nick Wellnhofer 2022-08-20 15:15:04 +02:00
parent 4ad71c2d72
commit b1b654171e

View File

@ -1345,6 +1345,7 @@ xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) {
xmlParserInputPtr
xmlNewStringInputStream(xmlParserCtxtPtr ctxt, const xmlChar *buffer) {
xmlParserInputPtr input;
xmlParserInputBufferPtr buf;
if (buffer == NULL) {
xmlErrInternal(ctxt, "xmlNewStringInputStream string = NULL\n",
@ -1354,15 +1355,21 @@ xmlNewStringInputStream(xmlParserCtxtPtr ctxt, const xmlChar *buffer) {
if (xmlParserDebugEntities)
xmlGenericError(xmlGenericErrorContext,
"new fixed input: %.30s\n", buffer);
buf = xmlParserInputBufferCreateMem((const char *) buffer,
strlen((const char *) buffer),
XML_CHAR_ENCODING_NONE);
if (buf == NULL) {
xmlErrMemory(ctxt, NULL);
return(NULL);
}
input = xmlNewInputStream(ctxt);
if (input == NULL) {
xmlErrMemory(ctxt, "couldn't allocate a new input stream\n");
xmlFreeParserInputBuffer(buf);
return(NULL);
}
input->base = buffer;
input->cur = buffer;
input->length = xmlStrlen(buffer);
input->end = &buffer[input->length];
input->buf = buf;
xmlBufResetInput(input->buf->buffer, input);
return(input);
}