2 * Copyright (C) 2008 by Sebastian Pipping.
3 * Copyright (C) 2008 Dimitri van Heesch.
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
14 * Sebastian Pipping <sebastian@pipping.org>
17 #include "qhpxmlwriter.h"
22 QhpXmlWriter::QhpXmlWriter()
23 : m_out(&m_backend), m_indentLevel(0),
24 m_curLineIndented(false), m_compress(false)
28 QhpXmlWriter::~QhpXmlWriter()
32 void QhpXmlWriter::setIndentLevel(int level)
34 m_indentLevel = level;
37 void QhpXmlWriter::setCompressionEnabled(bool enabled)
42 void QhpXmlWriter::insert(QhpXmlWriter const & source)
44 m_out << source.m_backend.data();
47 void QhpXmlWriter::dumpTo(QFile & file)
49 file.writeBlock(m_backend.data(), m_backend.length());
52 void QhpXmlWriter::open(char const * elementName,
53 char const * const * attributes)
56 openPure(elementName, attributes);
61 void QhpXmlWriter::openClose(char const * elementName,
62 char const * const * attributes)
65 openClosePure(elementName, attributes);
69 void QhpXmlWriter::openCloseContent(char const * elementName,
73 openPure(elementName);
74 m_out << convertToXML(content);
75 closePure(elementName);
79 void QhpXmlWriter::close(char const * elementName)
83 closePure(elementName);
87 void QhpXmlWriter::indent()
89 if (m_curLineIndented)
93 for (int i = 0; i < m_indentLevel; i++)
97 m_curLineIndented = true;
100 void QhpXmlWriter::newLine()
105 m_curLineIndented = false;
109 void QhpXmlWriter::openPureHelper(char const * elementName,
110 char const * const * attributes, bool close)
112 m_out << "<" << elementName;
115 for (char const * const * walker = attributes;
116 walker[0]; walker += 2)
118 char const * const key = walker[0];
119 char const * const value = walker[1];
124 m_out << " " << key << "=\"" << convertToXML(value) << "\"";
135 void QhpXmlWriter::openPure(char const * elementName,
136 char const * const * attributes)
138 openPureHelper(elementName, attributes, false);
141 void QhpXmlWriter::openClosePure(char const * elementName,
142 char const * const * attributes)
144 openPureHelper(elementName, attributes, true);
147 void QhpXmlWriter::closePure(char const * elementName)
149 m_out << "</" << elementName << ">";