mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-24 13:33:01 +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:
@@ -1345,6 +1345,7 @@ xmlNewEntityInputStream(xmlParserCtxtPtr ctxt, xmlEntityPtr entity) {
|
|||||||
xmlParserInputPtr
|
xmlParserInputPtr
|
||||||
xmlNewStringInputStream(xmlParserCtxtPtr ctxt, const xmlChar *buffer) {
|
xmlNewStringInputStream(xmlParserCtxtPtr ctxt, const xmlChar *buffer) {
|
||||||
xmlParserInputPtr input;
|
xmlParserInputPtr input;
|
||||||
|
xmlParserInputBufferPtr buf;
|
||||||
|
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
xmlErrInternal(ctxt, "xmlNewStringInputStream string = NULL\n",
|
xmlErrInternal(ctxt, "xmlNewStringInputStream string = NULL\n",
|
||||||
@@ -1354,15 +1355,21 @@ xmlNewStringInputStream(xmlParserCtxtPtr ctxt, const xmlChar *buffer) {
|
|||||||
if (xmlParserDebugEntities)
|
if (xmlParserDebugEntities)
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
"new fixed input: %.30s\n", buffer);
|
"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);
|
input = xmlNewInputStream(ctxt);
|
||||||
if (input == NULL) {
|
if (input == NULL) {
|
||||||
xmlErrMemory(ctxt, "couldn't allocate a new input stream\n");
|
xmlErrMemory(ctxt, "couldn't allocate a new input stream\n");
|
||||||
|
xmlFreeParserInputBuffer(buf);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
input->base = buffer;
|
input->buf = buf;
|
||||||
input->cur = buffer;
|
xmlBufResetInput(input->buf->buffer, input);
|
||||||
input->length = xmlStrlen(buffer);
|
|
||||||
input->end = &buffer[input->length];
|
|
||||||
return(input);
|
return(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user