mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-03-09 04:58:16 +03:00
Cleanup function xmlBufResetInput() to set input from Buffer
This was scattered in a number of modules, xmlParserInputPtr have usually their base, cur and end pointer set from an xmlBuf used as input. * buf.c buf.h: add a new function implementing this setup * parser.c HTMLparser.c catalog.c parserInternals.c xmlreader.c use the new function instead of digging into the buffer in all those modules
This commit is contained in:
parent
145477d8ab
commit
61551a1eb7
12
HTMLparser.c
12
HTMLparser.c
@ -3519,9 +3519,7 @@ htmlCheckEncodingDirect(htmlParserCtxtPtr ctxt, const xmlChar *encoding) {
|
||||
"htmlCheckEncoding: encoder error\n",
|
||||
NULL, NULL);
|
||||
}
|
||||
ctxt->input->base =
|
||||
ctxt->input->cur = xmlBufContent(ctxt->input->buf->buffer);
|
||||
ctxt->input->end = xmlBufEnd(ctxt->input->buf->buffer);
|
||||
xmlBufResetInput(ctxt->input->buf->buffer, ctxt->input);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4906,9 +4904,7 @@ htmlCreateMemoryParserCtxt(const char *buffer, int size) {
|
||||
|
||||
input->filename = NULL;
|
||||
input->buf = buf;
|
||||
input->cur =
|
||||
input->base = xmlBufContent(input->buf->buffer);
|
||||
input->end = xmlBufEnd(input->buf->buffer);
|
||||
xmlBufResetInput(buf->buffer, input);
|
||||
|
||||
inputPush(ctxt, input);
|
||||
return(ctxt);
|
||||
@ -6106,9 +6102,7 @@ htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data,
|
||||
inputStream->filename = (char *)
|
||||
xmlCanonicPath((const xmlChar *) filename);
|
||||
inputStream->buf = buf;
|
||||
inputStream->cur =
|
||||
inputStream->base = xmlBufContent(buf->buffer);
|
||||
inputStream->end = xmlBufEnd(buf->buffer);
|
||||
xmlBufResetInput(buf->buffer, inputStream);
|
||||
|
||||
inputPush(ctxt, inputStream);
|
||||
|
||||
|
18
buf.c
18
buf.c
@ -1136,3 +1136,21 @@ xmlBufMergeBuffer(xmlBufPtr buf, xmlBufferPtr buffer) {
|
||||
xmlBufferFree(buffer);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlBufResetInput:
|
||||
* @buf: an xmlBufPtr
|
||||
* @input: an xmlParserInputPtr
|
||||
*
|
||||
* Update the input to use the current set of pointers from the buffer.
|
||||
*
|
||||
* Returns -1 in case of error, 0 otherwise, in any case @buffer is freed
|
||||
*/
|
||||
int
|
||||
xmlBufResetInput(xmlBufPtr buf, xmlParserInputPtr input) {
|
||||
if ((input == NULL) || (buf == NULL))
|
||||
return(-1);
|
||||
input->base = input->cur = buf->content;
|
||||
input->end = &buf->content[buf->use];
|
||||
return(0);
|
||||
}
|
||||
|
1
buf.h
1
buf.h
@ -57,6 +57,7 @@ xmlBufPtr xmlBufFromBuffer(xmlBufferPtr buffer);
|
||||
xmlBufferPtr xmlBufBackToBuffer(xmlBufPtr buf);
|
||||
int xmlBufMergeBuffer(xmlBufPtr buf, xmlBufferPtr buffer);
|
||||
|
||||
int xmlBufResetInput(xmlBufPtr buf, xmlParserInputPtr input);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -914,9 +914,7 @@ xmlParseCatalogFile(const char *filename) {
|
||||
|
||||
inputStream->filename = (char *) xmlCanonicPath((const xmlChar *)filename);
|
||||
inputStream->buf = buf;
|
||||
inputStream->cur =
|
||||
inputStream->base = xmlBufContent(buf->buffer);
|
||||
inputStream->end = xmlBufEnd(buf->buffer);
|
||||
xmlBufResetInput(buf->buffer, inputStream);
|
||||
|
||||
inputPush(ctxt, inputStream);
|
||||
if ((ctxt->directory == NULL) && (directory == NULL))
|
||||
|
13
parser.c
13
parser.c
@ -11925,10 +11925,7 @@ xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data,
|
||||
}
|
||||
}
|
||||
inputStream->buf = buf;
|
||||
inputStream->cur =
|
||||
inputStream->base = xmlBufContent(inputStream->buf->buffer);
|
||||
inputStream->end = xmlBufEnd(inputStream->buf->buffer);
|
||||
|
||||
xmlBufResetInput(inputStream->buf->buffer, inputStream);
|
||||
inputPush(ctxt, inputStream);
|
||||
|
||||
/*
|
||||
@ -13870,9 +13867,7 @@ xmlCreateMemoryParserCtxt(const char *buffer, int size) {
|
||||
|
||||
input->filename = NULL;
|
||||
input->buf = buf;
|
||||
input->cur =
|
||||
input->base = xmlBufContent(input->buf->buffer);
|
||||
input->end = xmlBufEnd(input->buf->buffer);
|
||||
xmlBufResetInput(input->buf->buffer, input);
|
||||
|
||||
inputPush(ctxt, input);
|
||||
return(ctxt);
|
||||
@ -14442,9 +14437,7 @@ xmlCtxtResetPush(xmlParserCtxtPtr ctxt, const char *chunk,
|
||||
inputStream->filename = (char *)
|
||||
xmlCanonicPath((const xmlChar *) filename);
|
||||
inputStream->buf = buf;
|
||||
inputStream->cur =
|
||||
inputStream->base = xmlBufContent(buf->buffer);
|
||||
inputStream->end = xmlBufEnd(buf->buffer);
|
||||
xmlBufResetInput(buf->buffer, inputStream);
|
||||
|
||||
inputPush(ctxt, inputStream);
|
||||
|
||||
|
@ -1218,9 +1218,7 @@ xmlSwitchInputEncodingInt(xmlParserCtxtPtr ctxt, xmlParserInputPtr input,
|
||||
return (-1);
|
||||
}
|
||||
input->buf->rawconsumed += use - xmlBufUse(input->buf->raw);
|
||||
input->base = input->cur = xmlBufContent(input->buf->buffer);
|
||||
input->end = xmlBufEnd(input->buf->buffer);
|
||||
|
||||
xmlBufResetInput(input->buf->buffer, input);
|
||||
}
|
||||
return (0);
|
||||
} else if (input->length == 0) {
|
||||
@ -1387,9 +1385,8 @@ xmlNewIOInputStream(xmlParserCtxtPtr ctxt, xmlParserInputBufferPtr input,
|
||||
}
|
||||
inputStream->filename = NULL;
|
||||
inputStream->buf = input;
|
||||
inputStream->cur =
|
||||
inputStream->base = xmlBufContent(inputStream->buf->buffer);
|
||||
inputStream->end = xmlBufEnd(inputStream->buf->buffer);
|
||||
xmlBufResetInput(inputStream->buf->buffer, inputStream);
|
||||
|
||||
if (enc != XML_CHAR_ENCODING_NONE) {
|
||||
xmlSwitchEncoding(ctxt, enc);
|
||||
}
|
||||
@ -1542,9 +1539,7 @@ xmlNewInputFromFile(xmlParserCtxtPtr ctxt, const char *filename) {
|
||||
if (URI != NULL) xmlFree((char *) URI);
|
||||
inputStream->directory = directory;
|
||||
|
||||
inputStream->base =
|
||||
inputStream->cur = xmlBufContent(inputStream->buf->buffer);
|
||||
inputStream->end = xmlBufEnd(inputStream->buf->buffer);
|
||||
xmlBufResetInput(inputStream->buf->buffer, inputStream);
|
||||
if ((ctxt->directory == NULL) && (directory != NULL))
|
||||
ctxt->directory = (char *) xmlStrdup((const xmlChar *) directory);
|
||||
return(inputStream);
|
||||
|
@ -5126,9 +5126,7 @@ xmlTextReaderSetup(xmlTextReaderPtr reader,
|
||||
inputStream->filename = (char *)
|
||||
xmlCanonicPath((const xmlChar *) URL);
|
||||
inputStream->buf = buf;
|
||||
inputStream->cur =
|
||||
inputStream->base = xmlBufContent(buf->buffer);
|
||||
inputStream->end = xmlBufEnd(buf->buffer);
|
||||
xmlBufResetInput(buf->buffer, inputStream);
|
||||
|
||||
inputPush(reader->ctxt, inputStream);
|
||||
reader->cur = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user