1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-12-25 23:21:26 +03:00

second pass on escaping handling, start to looks better, need to be

* xmlIO.c xmlsave.c include/libxml/xmlIO.h: second pass on escaping
  handling, start to looks better, need to be completed and added
  directly at the saving context level.
Daniel
This commit is contained in:
Daniel Veillard 2004-05-14 03:25:14 +00:00
parent 5d1a4d81bf
commit ee8960bcab
4 changed files with 21 additions and 11 deletions

View File

@ -1,3 +1,9 @@
Thu May 13 23:19:00 CEST 2004 Daniel Veillard <daniel@veillard.com>
* xmlIO.c xmlsave.c include/libxml/xmlIO.h: second pass on escaping
handling, start to looks better, need to be completed and added
directly at the saving context level.
Thu May 13 10:31:28 CEST 2004 Daniel Veillard <daniel@veillard.com> Thu May 13 10:31:28 CEST 2004 Daniel Veillard <daniel@veillard.com>
* xmlIO.c xmlsave.c include/libxml/xmlIO.h: first pass at refactoring * xmlIO.c xmlsave.c include/libxml/xmlIO.h: first pass at refactoring

View File

@ -245,7 +245,8 @@ XMLPUBFUN int XMLCALL
const char *str); const char *str);
XMLPUBFUN int XMLCALL XMLPUBFUN int XMLCALL
xmlOutputBufferWriteEscape (xmlOutputBufferPtr out, xmlOutputBufferWriteEscape (xmlOutputBufferPtr out,
const xmlChar *str); const xmlChar *str,
xmlCharEncodingOutputFunc escaping);
XMLPUBFUN int XMLCALL XMLPUBFUN int XMLCALL
xmlOutputBufferFlush (xmlOutputBufferPtr out); xmlOutputBufferFlush (xmlOutputBufferPtr out);

15
xmlIO.c
View File

@ -2929,6 +2929,7 @@ xmlEscapeContent(unsigned char* out, int *outlen,
* xmlOutputBufferWriteEscape: * xmlOutputBufferWriteEscape:
* @out: a buffered parser output * @out: a buffered parser output
* @str: a zero terminated UTF-8 string * @str: a zero terminated UTF-8 string
* @escaping: an optional escaping function (or NULL)
* *
* Write the content of the string in the output I/O buffer * Write the content of the string in the output I/O buffer
* This routine escapes the caracters and then handle the I18N * This routine escapes the caracters and then handle the I18N
@ -2940,7 +2941,8 @@ xmlEscapeContent(unsigned char* out, int *outlen,
* in case of error. * in case of error.
*/ */
int int
xmlOutputBufferWriteEscape(xmlOutputBufferPtr out, const xmlChar *str) { xmlOutputBufferWriteEscape(xmlOutputBufferPtr out, const xmlChar *str,
xmlCharEncodingOutputFunc escaping) {
int nbchars = 0; /* number of chars to output to I/O */ int nbchars = 0; /* number of chars to output to I/O */
int ret; /* return from function call */ int ret; /* return from function call */
int written = 0; /* number of char written to I/O so far */ int written = 0; /* number of char written to I/O so far */
@ -2949,9 +2951,10 @@ xmlOutputBufferWriteEscape(xmlOutputBufferPtr out, const xmlChar *str) {
int cons; /* byte from str consumed */ int cons; /* byte from str consumed */
if ((out == NULL) || (out->error) || (str == NULL)) return(-1); if ((out == NULL) || (out->error) || (str == NULL)) return(-1);
len = strlen(str); len = strlen((const char *)str);
if (len < 0) return(0); if (len < 0) return(0);
if (out->error) return(-1); if (out->error) return(-1);
if (escaping == NULL) escaping = xmlEscapeContent;
do { do {
/* /*
@ -2970,8 +2973,8 @@ xmlOutputBufferWriteEscape(xmlOutputBufferPtr out, const xmlChar *str) {
if (out->conv == NULL) { if (out->conv == NULL) {
out->conv = xmlBufferCreate(); out->conv = xmlBufferCreate();
} }
ret = xmlEscapeContent(out->buffer->content + out->buffer->use , ret = escaping(out->buffer->content + out->buffer->use ,
&chunk, str, &cons); &chunk, str, &cons);
if (ret < 0) if (ret < 0)
return(-1); return(-1);
out->buffer->use += chunk; out->buffer->use += chunk;
@ -2991,8 +2994,8 @@ xmlOutputBufferWriteEscape(xmlOutputBufferPtr out, const xmlChar *str) {
} }
nbchars = out->conv->use; nbchars = out->conv->use;
} else { } else {
ret = xmlEscapeContent(out->buffer->content + out->buffer->use , ret = escaping(out->buffer->content + out->buffer->use ,
&chunk, str, &cons); &chunk, str, &cons);
if (ret < 0) if (ret < 0)
return(-1); return(-1);
out->buffer->use += chunk; out->buffer->use += chunk;

View File

@ -481,7 +481,7 @@ xmlNodeDumpOutputInternal(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) {
xmlFree(buffer); xmlFree(buffer);
} }
} else { } else {
xmlOutputBufferWriteEscape(buf, cur->content); xmlOutputBufferWriteEscape(buf, cur->content, NULL);
} }
} else { } else {
/* /*
@ -594,7 +594,7 @@ xmlNodeDumpOutputInternal(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) {
xmlFree(buffer); xmlFree(buffer);
} }
} else { } else {
xmlOutputBufferWriteEscape(buf, cur->content); xmlOutputBufferWriteEscape(buf, cur->content, NULL);
} }
} }
if (cur->children != NULL) { if (cur->children != NULL) {
@ -941,7 +941,7 @@ xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) {
xmlFree(buffer); xmlFree(buffer);
} }
} else { } else {
xmlOutputBufferWriteEscape(buf, cur->content); xmlOutputBufferWriteEscape(buf, cur->content, NULL);
} }
} else { } else {
/* /*
@ -1068,7 +1068,7 @@ xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) {
xmlFree(buffer); xmlFree(buffer);
} }
} else { } else {
xmlOutputBufferWriteEscape(buf, cur->content); xmlOutputBufferWriteEscape(buf, cur->content, NULL);
} }
} }