[libxml2] Create stream with buffer in xmlNewStringInputStream



commit b1b654171e44dba90bbc6836ca05dd4e1161b4b0
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Sat Aug 20 15:15:04 2022 +0200

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

 parserInternals.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
---
diff --git a/parserInternals.c b/parserInternals.c
index 31d94680..7dc06c88 100644
--- a/parserInternals.c
+++ b/parserInternals.c
@@ -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);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]