34 : xmlFile(
file), indent(
"\t"), currentLevel(0), currentState(Bare),
format(NewLine),
81 void XmlOutput::updateIndent()
83 currentIndent.
clear();
84 currentIndent.
reserve(currentLevel);
85 for (
int i = 0;
i < currentLevel; ++
i)
86 currentIndent.
append(indent);
89 void XmlOutput::increaseIndent()
95 void XmlOutput::decreaseIndent()
115 for (
int i=0;
i<
text.count(); ++
i) {
118 if ( (
i + 7) <
text.count() &&
122 output +=
text.at(
i);
131 if (
c.unicode() < 0x20) {
167 addDeclaration(
o.xo_text,
o.xo_value);
170 newTagOpen(
o.xo_text);
174 addRaw(doConversion(
o.xo_value));
178 addRaw(doConversion(
o.xo_text));
184 addRaw(
QString(
"\n%1<Import %2=\"%3\" />").
arg(currentIndent).
arg(
o.xo_text).arg(
o.xo_value));
187 if (
o.xo_value.count())
189 else if (
o.xo_text.count())
195 addAttribute(
o.xo_text,
o.xo_value);
198 addAttributeTag(
o.xo_text,
o.xo_value);
204 if (!
o.xo_text.count()) {
208 QString output = doConversion(
o.xo_text);
209 output.
replace(
'\n',
"\n" + currentIndent);
216 addRaw(output.
arg(
o.xo_text));
221 QString output(
"<![CDATA[\n%1\n]]>");
222 addRaw(output.
arg(
o.xo_text));
233 Q_ASSERT_X(
tag.count(),
"XmlOutput",
"Cannot open an empty tag");
238 void XmlOutput::newTagOpen(
const QString &
tag)
240 Q_ASSERT_X(
tag.count(),
"XmlOutput",
"Cannot open an empty tag");
244 xmlFile <<
Qt::endl << currentIndent;
245 xmlFile <<
'<' << doConversion(
tag);
251 void XmlOutput::closeOpen()
253 switch(currentState) {
264 void XmlOutput::closeTag()
266 switch(currentState) {
268 if (tagStack.count())
269 //warn_msg(WarnLogic, "<Root>: Cannot close tag in Bare state, %d tags on stack", tagStack.count());
270 qDebug("<Root>: Cannot close tag in Bare state, %d tags on stack", int(tagStack.count()));
272 //warn_msg(WarnLogic, "<Root>: Cannot close tag, no tags on stack");
273 qDebug("<Root>: Cannot close tag, no tags on stack");
276 decreaseIndent(); // <--- Pre-decrease indent
277 if (format == NewLine)
278 xmlFile << Qt::endl << currentIndent;
279 xmlFile << "</" << doConversion(tagStack.last()) << '>
';
286 decreaseIndent(); // <--- Post-decrease indent
291 void XmlOutput::closeTo(const QString &tag)
294 if (!tagStack.contains(tag) && !tag.isNull()) {
295 //warn_msg(WarnLogic, "<%s>: Cannot close to tag <%s>, not on stack", tagStack.last().latin1(), tag.latin1());
296 qDebug("<%s>: Cannot close to tag <%s>, not on stack", tagStack.last().toLatin1().constData(), tag.toLatin1().constData());
299 int left = tagStack.count();
300 while (left-- && cont) {
301 cont = tagStack.last().compare(tag) != 0;
306 void XmlOutput::closeAll()
308 if (!tagStack.count())
313 void XmlOutput::addDeclaration(const QString &version, const QString &encoding)
315 switch(currentState) {
320 //warn_msg(WarnLogic, "<%s>: Cannot add declaration when not in bare state", tagStack.last().toLatin1().constData());
321 qDebug("<%s>: Cannot add declaration when not in bare state", tagStack.last().toLatin1().constData());
324 QString outData = QString("<?xml version=\"%1\" encoding=\"%2\"?>")
325 .arg(doConversion(version))
326 .arg(doConversion(encoding));
330 void XmlOutput::addRaw(const QString &rawText)
336 void XmlOutput::addAttribute(const QString &attribute, const QString &value)
338 switch(currentState) {
341 //warn_msg(WarnLogic, "<%s>: Cannot add attribute since tags not open", tagStack.last().toLatin1().constData());
342 qDebug("<%s>: Cannot add attribute (%s) since tag's not
open",
343 (tagStack.count() ? tagStack.last().toLatin1().constData() : "Root
"),
344 attribute.toLatin1().constData());
349 if (format == NewLine)
351 xmlFile << currentIndent << doConversion(attribute) << "=\
"" << doConversion(
value) <<
"\"";
356 switch(currentState) {
360 qDebug(
"<%s>: Cannot add attribute (%s) since tag's not open",
367 xmlFile <<
" " << doConversion(
attribute) <<
"=\"" << doConversion(
value) <<
"\"";
small capitals from c petite p scientific i
[1]
const char * constData() const noexcept
The QChar class provides a 16-bit Unicode character.
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
qsizetype count() const noexcept
void append(parameter_type t)
The QString class provides a Unicode character string.
QByteArray toLatin1() const &
QString & replace(qsizetype i, qsizetype len, QChar after)
void reserve(qsizetype size)
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=QLatin1Char(' ')) const
QString & append(QChar c)
The QTextStream class provides a convenient interface for reading and writing text.
void setState(XMLState state)
void setFormat(XMLFormat newFormat)
void setIndentLevel(int level)
XmlOutput & operator<<(const QString &o)
void setIndentString(const QString &indentString)
XmlOutput(QTextStream &file, ConverstionType type=XMLConversion)
QTextStream & endl(QTextStream &stream)
EGLOutputLayerEXT EGLint EGLAttrib value
EGLOutputLayerEXT EGLint attribute
GLenum GLuint GLint level
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei GLsizei GLenum format
#define Q_ASSERT_X(cond, x, msg)
file open(QIODevice::ReadOnly)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
XmlOutput::xml_output tag(const QString &name)