22 Private(QIODevice* dev_,
int indentLevel = 0)
24 , baseIndentLevel(indentLevel)
28 delete[] indentBuffer;
29 delete[] escapeBuffer;
43 : d(new
Private(dev, indentLevel))
47 *
d->indentBuffer =
'\n';
50 if (!
d->dev->isOpen())
51 d->dev->open(QIODevice::WriteOnly);
62 Q_ASSERT(
d->tags.isEmpty());
63 writeCString(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
82 Q_ASSERT(
d->tags.isEmpty());
88 if (!
d->tags.isEmpty()) {
89 Tag& parent =
d->tags.top();
90 if (!parent.hasChildren) {
92 parent.hasChildren =
true;
93 parent.lastChildIsText =
false;
95 if (parent.indentInside && indentInside) {
98 return parent.indentInside && indentInside;
105 if (
d->tags.isEmpty())
107 Tag& parent =
d->tags.top();
108 if (!parent.hasChildren) {
110 parent.hasChildren =
true;
111 parent.lastChildIsText =
true;
117 Q_ASSERT(tagName != 0);
122 d->tags.push(
Tag(tagName, indentInside));
131 const bool wasOpen = indev->isOpen();
134 const bool openOk = indev->open(QIODevice::ReadOnly);
137 warnStore <<
"Failed to re-open the device! wasOpen=" << wasOpen;
141 QString indentString;
142 indentString.fill((
' '),
d->tags.size() +
d->baseIndentLevel);
143 QByteArray indentBuf(indentString.toUtf8());
146 while (!indev->atEnd()) {
147 buffer = indev->readLine();
149 d->dev->write(indentBuf);
150 d->dev->write(buffer);
161 if (
d->tags.isEmpty())
162 warnStore <<
"EndElement() was called more times than startElement(). "
163 "The generated XML will be invalid! "
164 "Please report this bug (by saving the document to another format...)" << Qt::endl;
166 Tag tag =
d->tags.pop();
238 d->dev->write(
d->indentBuffer, qMin(
d->tags.size() +
d->baseIndentLevel + 1,
250 char* destination =
d->escapeBuffer;
251 char* output =
d->escapeBuffer;
254 if (destination >= destBoundary) {
262 char* buffer =
new char[ newLength ];
263 destBoundary = buffer + newLength;
264 uint amountOfCharsAlreadyCopied = destination -
d->escapeBuffer;
265 memcpy(buffer,
d->escapeBuffer, amountOfCharsAlreadyCopied);
267 destination = buffer + amountOfCharsAlreadyCopied;
271 memcpy(destination,
"<", 4);
275 memcpy(destination,
">", 4);
279 memcpy(destination,
""", 6);
284 memcpy(destination,
"'", 6);
289 memcpy(destination,
"&", 5);
299 *destination++ = *src++;
303 if (*src > 0 && *src < 32) {
306 *destination++ = *src++;
326 d->dev->write(cstr, qstrlen(cstr));
qreal length(const QPointF &vec)
float value(const T *src, size_t ch)
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
static const int s_escapeBufferLen
static const int s_indentBufferLength
~KoXmlWriter()
Destructor.
void addCompleteElement(QIODevice *dev)
void addManifestEntry(const QString &fullPath, const QString &mediaType)
bool prepareForChild(bool indentInside=true)
void startElement(const char *tagName, bool indentInside=true)
char * escapeForXML(const char *source, int length) const
KoXmlWriter(QIODevice *dev, int indentLevel=0)
void endDocument()
Call this to terminate an XML document.
void writeCString(const char *cstr)
Private(QIODevice *dev_, int indentLevel=0)
void startDocument(const char *rootElemName, const char *publicId=0, const char *systemId=0)
void prepareForTextNode()
void addTextNode(const QString &str)
void closeStartElement(Tag &tag)
void writeIndent()
Write out followed by the number of spaces required.
void addAttribute(const char *attrName, const QString &value)
const QMap< char, char > escaped
QString toString(const QString &value)
bool indentInside
whether to indent the contents of this tag
bool lastChildIsText
last child is a text node
bool hasChildren
element or text children