mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-21 14:53:44 +03:00
applied the patch from Lucas Brasilino to add indentation support to
* include/libxml/xmlwriter.h xmlwriter.c: applied the patch from Lucas Brasilino to add indentation support to xmlWriter Daniel
This commit is contained in:
@@ -1,3 +1,8 @@
|
|||||||
|
Fri Jan 2 21:03:17 CET 2004 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
|
* include/libxml/xmlwriter.h xmlwriter.c: applied the patch from
|
||||||
|
Lucas Brasilino to add indentation support to xmlWriter
|
||||||
|
|
||||||
Fri Jan 2 22:58:29 HKT 2004 William Brack <wbrack@mmm.com.hk>
|
Fri Jan 2 22:58:29 HKT 2004 William Brack <wbrack@mmm.com.hk>
|
||||||
|
|
||||||
* xinclude.c: fixed problem with "recursive" include (fallback
|
* xinclude.c: fixed problem with "recursive" include (fallback
|
||||||
|
@@ -405,6 +405,13 @@ XMLPUBFUN int XMLCALL
|
|||||||
const xmlChar * name,
|
const xmlChar * name,
|
||||||
const xmlChar * pubid,
|
const xmlChar * pubid,
|
||||||
const xmlChar * sysid);
|
const xmlChar * sysid);
|
||||||
|
/*
|
||||||
|
* Indentation
|
||||||
|
*/
|
||||||
|
XMLPUBFUN int XMLCALL
|
||||||
|
xmlTextWriterSetIndent (xmlTextWriterPtr writer, int indent);
|
||||||
|
XMLPUBFUN int XMLCALL
|
||||||
|
xmlTextWriterSetIndentString (xmlTextWriterPtr writer, xmlChar *str);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* misc
|
* misc
|
||||||
|
113
xmlwriter.c
113
xmlwriter.c
@@ -61,8 +61,9 @@ struct _xmlTextWriter {
|
|||||||
xmlListPtr nodes; /* element name stack */
|
xmlListPtr nodes; /* element name stack */
|
||||||
xmlListPtr nsstack; /* name spaces stack */
|
xmlListPtr nsstack; /* name spaces stack */
|
||||||
int level;
|
int level;
|
||||||
char indent; /* indent amount */
|
int indent; /* enable indent */
|
||||||
char ichar; /* indent character */
|
int doindent; /* internal indent flag */
|
||||||
|
xmlChar *ichar; /* indent character */
|
||||||
char qchar; /* character used for quoting attribute values */
|
char qchar; /* character used for quoting attribute values */
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -83,6 +84,7 @@ static xmlChar *xmlTextWriterVSprintf(const char *format, va_list argptr);
|
|||||||
static int xmlOutputBufferWriteBase64(xmlOutputBufferPtr out, int len,
|
static int xmlOutputBufferWriteBase64(xmlOutputBufferPtr out, int len,
|
||||||
const unsigned char *data);
|
const unsigned char *data);
|
||||||
static void xmlTextWriterStartDocumentCallback(void *ctx);
|
static void xmlTextWriterStartDocumentCallback(void *ctx);
|
||||||
|
static int xmlTextWriterWriteIndent (xmlTextWriterPtr writer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* xmlNewTextWriter:
|
* xmlNewTextWriter:
|
||||||
@@ -129,9 +131,11 @@ xmlNewTextWriter(xmlOutputBufferPtr out)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret->out = out;
|
ret->out = out;
|
||||||
ret->ichar = ' ';
|
ret->ichar = xmlStrdup (BAD_CAST " ");
|
||||||
ret->qchar = '"';
|
ret->qchar = '"';
|
||||||
|
|
||||||
|
if (!ret->ichar) return NULL;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,6 +169,8 @@ xmlNewTextWriterFilename(const char *uri, int compression)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret->indent = 0;
|
||||||
|
ret->doindent = 0;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -542,11 +548,12 @@ xmlTextWriterEndDocument(xmlTextWriterPtr writer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!writer->indent) {
|
||||||
count = xmlOutputBufferWriteString(writer->out, "\n");
|
count = xmlOutputBufferWriteString(writer->out, "\n");
|
||||||
if(count < 0)
|
if(count < 0)
|
||||||
return -1;
|
return -1;
|
||||||
sum += count;
|
sum += count;
|
||||||
|
}
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -653,6 +660,11 @@ xmlTextWriterWriteComment(xmlTextWriterPtr writer, const xmlChar * content)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (writer->indent) {
|
||||||
|
count = xmlOutputBufferWriteString (writer->out, "\n");
|
||||||
|
sum += count;
|
||||||
|
}
|
||||||
|
|
||||||
count = xmlOutputBufferWriteString(writer->out, "<!--");
|
count = xmlOutputBufferWriteString(writer->out, "<!--");
|
||||||
if (count < 0)
|
if (count < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@@ -667,6 +679,11 @@ xmlTextWriterWriteComment(xmlTextWriterPtr writer, const xmlChar * content)
|
|||||||
return -1;
|
return -1;
|
||||||
sum += count;
|
sum += count;
|
||||||
|
|
||||||
|
if (writer->indent) {
|
||||||
|
count = xmlOutputBufferWriteString (writer->out, "\n");
|
||||||
|
sum += count;
|
||||||
|
}
|
||||||
|
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -706,6 +723,8 @@ xmlTextWriterStartElement(xmlTextWriterPtr writer, const xmlChar * name)
|
|||||||
if (count < 0)
|
if (count < 0)
|
||||||
return -1;
|
return -1;
|
||||||
sum += count;
|
sum += count;
|
||||||
|
if (writer->indent)
|
||||||
|
count = xmlOutputBufferWriteString (writer->out, "\n");
|
||||||
p->state = XML_TEXTWRITER_TEXT;
|
p->state = XML_TEXTWRITER_TEXT;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -733,6 +752,11 @@ xmlTextWriterStartElement(xmlTextWriterPtr writer, const xmlChar * name)
|
|||||||
|
|
||||||
xmlListPushFront(writer->nodes, p);
|
xmlListPushFront(writer->nodes, p);
|
||||||
|
|
||||||
|
if (writer->indent) {
|
||||||
|
count = xmlTextWriterWriteIndent (writer);
|
||||||
|
sum += count;
|
||||||
|
}
|
||||||
|
|
||||||
count = xmlOutputBufferWriteString(writer->out, "<");
|
count = xmlOutputBufferWriteString(writer->out, "<");
|
||||||
if (count < 0)
|
if (count < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@@ -842,6 +866,11 @@ xmlTextWriterEndElement(xmlTextWriterPtr writer)
|
|||||||
sum += count;
|
sum += count;
|
||||||
break;
|
break;
|
||||||
case XML_TEXTWRITER_TEXT:
|
case XML_TEXTWRITER_TEXT:
|
||||||
|
if ((writer->indent) && (writer->doindent)) {
|
||||||
|
count = xmlTextWriterWriteIndent (writer);
|
||||||
|
sum += count;
|
||||||
|
writer->doindent = 1;
|
||||||
|
} else writer->doindent = 1;
|
||||||
count = xmlOutputBufferWriteString(writer->out, "</");
|
count = xmlOutputBufferWriteString(writer->out, "</");
|
||||||
if (count < 0)
|
if (count < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@@ -860,6 +889,11 @@ xmlTextWriterEndElement(xmlTextWriterPtr writer)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (writer->indent) {
|
||||||
|
count = xmlOutputBufferWriteString (writer->out, "\n");
|
||||||
|
sum += count;
|
||||||
|
}
|
||||||
|
|
||||||
xmlListPopFront(writer->nodes);
|
xmlListPopFront(writer->nodes);
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
@@ -1946,6 +1980,7 @@ xmlTextWriterWriteElement(xmlTextWriterPtr writer, const xmlChar * name,
|
|||||||
if (count == -1)
|
if (count == -1)
|
||||||
return -1;
|
return -1;
|
||||||
sum += count;
|
sum += count;
|
||||||
|
writer->doindent = 0;
|
||||||
count = xmlTextWriterEndElement(writer);
|
count = xmlTextWriterEndElement(writer);
|
||||||
if (count == -1)
|
if (count == -1)
|
||||||
return -1;
|
return -1;
|
||||||
@@ -3955,4 +3990,74 @@ xmlTextWriterStartDocumentCallback(void *ctx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xmlTextWriterSetIndent:
|
||||||
|
* @writer: the xmlTextWriterPtr
|
||||||
|
* @indent: do indentation?
|
||||||
|
*
|
||||||
|
* Set indentation output. indent = 0 do not indentation. indent > 0 do indentation.
|
||||||
|
*
|
||||||
|
* Returns -1 on error or 0 otherwise.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
xmlTextWriterSetIndent (xmlTextWriterPtr writer, int indent)
|
||||||
|
{
|
||||||
|
if (indent < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
writer->indent = indent;
|
||||||
|
writer->doindent = 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xmlTextWriterSetIndentString:
|
||||||
|
* @writer: the xmlTextWriterPtr
|
||||||
|
* @str: the xmlChar string
|
||||||
|
*
|
||||||
|
* Set string indentation.
|
||||||
|
*
|
||||||
|
* Returns -1 on error or 0 otherwise.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
xmlTextWriterSetIndentString (xmlTextWriterPtr writer, xmlChar *str)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!str)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
writer->ichar = xmlStrdup (str);
|
||||||
|
|
||||||
|
if (!writer->ichar)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xmlTextWriterWriteIndent:
|
||||||
|
* @writer: the xmlTextWriterPtr
|
||||||
|
*
|
||||||
|
* Write indent string.
|
||||||
|
*
|
||||||
|
* Returns -1 on error or the number of strings written.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
xmlTextWriterWriteIndent (xmlTextWriterPtr writer)
|
||||||
|
{
|
||||||
|
int lksize;
|
||||||
|
int i;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
lksize = xmlListSize (writer->nodes);
|
||||||
|
for (i = 0; i < (lksize-1); i++) {
|
||||||
|
ret = xmlOutputBufferWriteString (writer->out, writer->ichar);
|
||||||
|
if (ret == -1)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (ret == -1)?ret:i;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user