1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-29 11:41:22 +03:00

- speedup of IS_CHAR like macros, significant overall improvement

- More interfaces for new I/O functions: xmlNewIOInputStream,
  xmlParserInputBufferCreateIO, xmlCreateIOParserCtxt
- added I/O test to xmllint
Daniel
This commit is contained in:
Daniel Veillard
2000-04-12 13:27:38 +00:00
parent fc708e2b7c
commit 5e873c4627
13 changed files with 936 additions and 683 deletions

118
parser.c
View File

@ -921,11 +921,13 @@ xmlNewInputStream(xmlParserCtxtPtr ctxt) {
input = (xmlParserInputPtr) xmlMalloc(sizeof(xmlParserInput));
if (input == NULL) {
ctxt->errNo = XML_ERR_NO_MEMORY;
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
ctxt->sax->error(ctxt->userData,
"malloc: couldn't allocate a new input stream\n");
ctxt->errNo = XML_ERR_NO_MEMORY;
if (ctxt != NULL) {
ctxt->errNo = XML_ERR_NO_MEMORY;
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
ctxt->sax->error(ctxt->userData,
"malloc: couldn't allocate a new input stream\n");
ctxt->errNo = XML_ERR_NO_MEMORY;
}
return(NULL);
}
memset(input, 0, sizeof(xmlParserInput));
@ -935,6 +937,37 @@ xmlNewInputStream(xmlParserCtxtPtr ctxt) {
return(input);
}
/**
* xmlNewIOInputStream:
* @ctxt: an XML parser context
* @input: an I/O Input
* @enc: the charset encoding if known
*
* Create a new input stream structure encapsulating the @input into
* a stream suitable for the parser.
*
* Returns the new input stream or NULL
*/
xmlParserInputPtr
xmlNewIOInputStream(xmlParserCtxtPtr ctxt, xmlParserInputBufferPtr input,
xmlCharEncoding enc) {
xmlParserInputPtr inputStream;
inputStream = xmlNewInputStream(ctxt);
if (inputStream == NULL) {
return(NULL);
}
inputStream->filename = NULL;
inputStream->buf = input;
inputStream->base = inputStream->buf->buffer->content;
inputStream->cur = inputStream->buf->buffer->content;
if (enc != XML_CHAR_ENCODING_NONE) {
xmlSwitchEncoding(ctxt, enc);
}
return(inputStream);
}
/**
* xmlNewEntityInputStream:
* @ctxt: an XML parser context
@ -3403,16 +3436,18 @@ xmlParseName(xmlParserCtxtPtr ctxt) {
GROW;
c = CUR_CHAR(l);
if (!IS_LETTER(c) && (c != '_') &&
(c != ':')) {
if ((c == ' ') || (c == '>') || (c == '/') || /* accelerators */
(!IS_LETTER(c) && (c != '_') &&
(c != ':'))) {
return(NULL);
}
while ((IS_LETTER(c)) || (IS_DIGIT(c)) ||
(c == '.') || (c == '-') ||
(c == '_') || (c == ':') ||
(IS_COMBINING(c)) ||
(IS_EXTENDER(c))) {
while ((c != ' ') && (c != '>') && (c != '/') && /* accelerators */
((IS_LETTER(c)) || (IS_DIGIT(c)) ||
(c == '.') || (c == '-') ||
(c == '_') || (c == ':') ||
(IS_COMBINING(c)) ||
(IS_EXTENDER(c)))) {
COPY_BUF(l,buf,len,c);
NEXTL(l);
c = CUR_CHAR(l);
@ -4041,8 +4076,9 @@ xmlParseCharData(xmlParserCtxtPtr ctxt, int cdata) {
SHRINK;
cur = CUR_CHAR(l);
while ((IS_CHAR(cur)) && ((cur != '<') || (ctxt->token == '<')) &&
((cur != '&') || (ctxt->token == '&'))) {
while (((cur != '<') || (ctxt->token == '<')) &&
((cur != '&') || (ctxt->token == '&')) &&
(IS_CHAR(cur))) {
if ((cur == ']') && (NXT(1) == ']') &&
(NXT(2) == '>')) {
if (cdata) break;
@ -9524,6 +9560,60 @@ xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data,
return(ctxt);
}
/**
* xmlCreateIOParserCtxt:
* @sax: a SAX handler
* @user_data: The user data returned on SAX callbacks
* @ioread: an I/O read function
* @ioclose: an I/O close function
* @ioctx: an I/O handler
* @enc: the charset encoding if known
*
* Create a parser context for using the XML parser with an existing
* I/O stream
*
* Returns the new parser context or NULL
*/
xmlParserCtxtPtr
xmlCreateIOParserCtxt(xmlSAXHandlerPtr sax, void *user_data,
xmlInputReadCallback ioread, xmlInputCloseCallback ioclose,
void *ioctx, xmlCharEncoding enc) {
xmlParserCtxtPtr ctxt;
xmlParserInputPtr inputStream;
xmlParserInputBufferPtr buf;
buf = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, enc);
if (buf == NULL) return(NULL);
ctxt = xmlNewParserCtxt();
if (ctxt == NULL) {
xmlFree(buf);
return(NULL);
}
if (sax != NULL) {
if (ctxt->sax != &xmlDefaultSAXHandler)
xmlFree(ctxt->sax);
ctxt->sax = (xmlSAXHandlerPtr) xmlMalloc(sizeof(xmlSAXHandler));
if (ctxt->sax == NULL) {
xmlFree(buf);
xmlFree(ctxt);
return(NULL);
}
memcpy(ctxt->sax, sax, sizeof(xmlSAXHandler));
if (user_data != NULL)
ctxt->userData = user_data;
}
inputStream = xmlNewIOInputStream(ctxt, buf, enc);
if (inputStream == NULL) {
xmlFreeParserCtxt(ctxt);
return(NULL);
}
inputPush(ctxt, inputStream);
return(ctxt);
}
/**
* xmlCreateDocParserCtxt:
* @cur: a pointer to an array of xmlChar