qhpxmlwriter.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008 by Sebastian Pipping.
3  * Copyright (C) 2008 Dimitri van Heesch.
4  *
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.
10  *
11  * Documents produced by Doxygen are derivative works derived from the
12  * input used in their production; they are not affected by this license.
13  *
14  * Sebastian Pipping <sebastian@pipping.org>
15  */
16 
17 #include "qhpxmlwriter.h"
18 #include "util.h"
19 
20 #include <qfile.h>
21 
23  : m_out(&m_backend), m_indentLevel(0),
24  m_curLineIndented(false), m_compress(false)
25 {
26 }
27 
29 {
30 }
31 
33 {
35 }
36 
38 {
39  m_compress = enabled;
40 }
41 
42 void QhpXmlWriter::insert(QhpXmlWriter const & source)
43 {
44  m_out << source.m_backend.data();
45 }
46 
48 {
50 }
51 
52 void QhpXmlWriter::open(char const * elementName,
53  char const * const * attributes)
54 {
55  indent();
56  openPure(elementName, attributes);
57  newLine();
58  m_indentLevel++;
59 }
60 
61 void QhpXmlWriter::openClose(char const * elementName,
62  char const * const * attributes)
63 {
64  indent();
65  openClosePure(elementName, attributes);
66  newLine();
67 }
68 
69 void QhpXmlWriter::openCloseContent(char const * elementName,
70  char const * content)
71 {
72  indent();
73  openPure(elementName);
74  m_out << convertToXML(content);
75  closePure(elementName);
76  newLine();
77 }
78 
79 void QhpXmlWriter::close(char const * elementName)
80 {
81  m_indentLevel--;
82  indent();
83  closePure(elementName);
84  newLine();
85 }
86 
87 void QhpXmlWriter::declaration(char const * version, char const * encoding)
88 {
89  m_out << "<?xml version=\"" << version << "\" encoding=\"" << encoding << "\"?>";
90  newLine();
91 }
92 
94 {
96  {
97  return;
98  }
99  for (int i = 0; i < m_indentLevel; i++)
100  {
101  m_out << " ";
102  }
103  m_curLineIndented = true;
104 }
105 
107 {
108  if (!m_compress)
109  {
110  m_out << "\n";
111  m_curLineIndented = false;
112  }
113 }
114 
115 void QhpXmlWriter::openPureHelper(char const * elementName,
116  char const * const * attributes, bool close)
117 {
118  m_out << "<" << elementName;
119  if (attributes)
120  {
121  for (char const * const * walker = attributes;
122  walker[0]; walker += 2)
123  {
124  char const * const key = walker[0];
125  char const * const value = walker[1];
126  if (!value)
127  {
128  continue;
129  }
130  m_out << " " << key << "=\"" << convertToXML(value) << "\"";
131  }
132  }
133 
134  if (close)
135  {
136  m_out << " /";
137  }
138  m_out << ">";
139 }
140 
141 void QhpXmlWriter::openPure(char const * elementName,
142  char const * const * attributes)
143 {
144  openPureHelper(elementName, attributes, false);
145 }
146 
147 void QhpXmlWriter::openClosePure(char const * elementName,
148  char const * const * attributes)
149 {
150  openPureHelper(elementName, attributes, true);
151 }
152 
153 void QhpXmlWriter::closePure(char const * elementName)
154 {
155  m_out << "</" << elementName << ">";
156 }
157 
bool m_curLineIndented
Definition: qhpxmlwriter.h:59
QCString convertToXML(const char *s)
Definition: util.cpp:5717
void setIndentLevel(int level)
char * data() const
Definition: qgstring.h:42
uint length() const
Definition: qgstring.h:40
void close(char const *elementName)
void closePure(char const *elementName)
void openPureHelper(char const *elementName, char const *const *attributes, bool close)
void declaration(char const *version, char const *encoding)
void setCompressionEnabled(bool enabled)
void openClosePure(char const *elementName, char const *const *attributes=0)
void open(char const *elementName, char const *const *attributes=0)
FTextStream m_out
Definition: qhpxmlwriter.h:57
int writeBlock(const char *data, uint len)
Definition: qfile_unix.cpp:537
void openCloseContent(char const *elementName, char const *content)
def key(type, name=None)
Definition: graph.py:13
void dumpTo(QFile &file)
A bunch of utility functions.
The QFile class is an I/O device that operates on files.
Definition: qfile.h:50
QGString m_backend
Definition: qhpxmlwriter.h:56
static QCString encoding
Definition: config.cpp:1052
void openPure(char const *elementName, char const *const *attributes=0)
void openClose(char const *elementName, char const *const *attributes=0)
void insert(QhpXmlWriter const &source)