aboutsummaryrefslogtreecommitdiff
path: root/src/xmlwriter.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-04-03 03:49:53 +0000
committerMike Buland <eichlan@xagasoft.com>2007-04-03 03:49:53 +0000
commitf4c20290509d7ed3a8fd5304577e7a4cc0b9d974 (patch)
tree13cdf64f7cf134f397a7165b7a3fe0807e37026b /src/xmlwriter.cpp
parent74d4c8cd27334fc7204d5a8773deb3d424565778 (diff)
downloadlibbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.gz
libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.bz2
libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.tar.xz
libbu++-f4c20290509d7ed3a8fd5304577e7a4cc0b9d974.zip
Ok, no code is left in src, it's all in src/old. We'll gradually move code back
into src as it's fixed and re-org'd. This includes tests, which, I may write a unit test system into libbu++ just to make my life easier.
Diffstat (limited to 'src/xmlwriter.cpp')
-rw-r--r--src/xmlwriter.cpp173
1 files changed, 0 insertions, 173 deletions
diff --git a/src/xmlwriter.cpp b/src/xmlwriter.cpp
deleted file mode 100644
index 56880b6..0000000
--- a/src/xmlwriter.cpp
+++ /dev/null
@@ -1,173 +0,0 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include "xmlwriter.h"
4
5XmlWriter::XmlWriter( const char *sIndent, XmlNode *pRoot ) :
6 XmlDocument( pRoot )
7{
8 if( sIndent == NULL )
9 {
10 this->sIndent = "";
11 }
12 else
13 {
14 this->sIndent = sIndent;
15 }
16}
17
18XmlWriter::~XmlWriter()
19{
20}
21
22void XmlWriter::write()
23{
24 write( getRoot(), sIndent.c_str() );
25}
26
27void XmlWriter::write( XmlNode *pRoot, const char *sIndent )
28{
29 writeNode( pRoot, 0, sIndent );
30}
31
32void XmlWriter::closeNode()
33{
34 XmlDocument::closeNode();
35
36 if( isCompleted() )
37 {
38 write( getRoot(), sIndent.c_str() );
39 }
40}
41
42void XmlWriter::writeIndent( int nIndent, const char *sIndent )
43{
44 if( sIndent == NULL ) return;
45 for( int j = 0; j < nIndent; j++ )
46 {
47 writeString( sIndent );
48 }
49}
50
51std::string XmlWriter::escape( std::string sIn )
52{
53 std::string sOut;
54
55 std::string::const_iterator i;
56 for( i = sIn.begin(); i != sIn.end(); i++ )
57 {
58 if( ((*i >= ' ' && *i <= '9') ||
59 (*i >= 'a' && *i <= 'z') ||
60 (*i >= 'A' && *i <= 'Z') ) &&
61 (*i != '\"' && *i != '\'' && *i != '&')
62 )
63 {
64 sOut += *i;
65 }
66 else
67 {
68 sOut += "&#";
69 char buf[4];
70 sprintf( buf, "%u", (unsigned char)*i );
71 sOut += buf;
72 sOut += ';';
73 }
74 }
75
76 return sOut;
77}
78
79void XmlWriter::writeNodeProps( XmlNode *pNode, int nIndent, const char *sIndent )
80{
81 for( int j = 0; j < pNode->getNumProperties(); j++ )
82 {
83 writeString(" ");
84 writeString( pNode->getPropertyName( j ) );
85 writeString("=\"");
86 writeString( escape( pNode->getProperty( j ) ).c_str() );
87 writeString("\"");
88 }
89}
90
91void XmlWriter::writeNode( XmlNode *pNode, int nIndent, const char *sIndent )
92{
93 if( pNode->hasChildren() )
94 {
95 writeIndent( nIndent, sIndent );
96 writeString("<");
97 writeString( pNode->getName() );
98 writeNodeProps( pNode, nIndent, sIndent );
99 if( sIndent )
100 writeString(">\n");
101 else
102 writeString(">");
103
104 if( pNode->getContent( 0 ) )
105 {
106 writeIndent( nIndent+1, sIndent );
107 if( sIndent )
108 {
109 writeString( pNode->getContent( 0 ) );
110 writeString("\n");
111 }
112 else
113 writeString( pNode->getContent( 0 ) );
114 }
115
116 int nNumChildren = pNode->getNumChildren();
117 for( int j = 0; j < nNumChildren; j++ )
118 {
119 writeNode( pNode->getChild( j ), nIndent+1, sIndent );
120 if( pNode->getContent( j+1 ) )
121 {
122 writeIndent( nIndent+1, sIndent );
123 if( sIndent )
124 {
125 writeString( pNode->getContent( j+1 ) );
126 writeString("\n");
127 }
128 else
129 writeString( pNode->getContent( j+1 ) );
130 }
131 }
132
133 writeIndent( nIndent, sIndent );
134 if( sIndent )
135 {
136 writeString("</");
137 writeString( pNode->getName() );
138 writeString(">\n");
139 }
140 else
141 {
142 writeString("</");
143 writeString( pNode->getName() );
144 writeString(">");
145 }
146 }
147 else if( pNode->getContent() )
148 {
149 writeIndent( nIndent, sIndent );
150 writeString("<");
151 writeString( pNode->getName() );
152 writeNodeProps( pNode, nIndent, sIndent );
153 writeString(">");
154 writeString( pNode->getContent() );
155 writeString("</");
156 writeString( pNode->getName() );
157 writeString(">");
158 if( sIndent )
159 writeString("\n");
160 }
161 else
162 {
163 writeIndent( nIndent, sIndent );
164 writeString("<");
165 writeString( pNode->getName() );
166 writeNodeProps( pNode, nIndent, sIndent );
167 if( sIndent )
168 writeString("/>\n");
169 else
170 writeString("/>");
171 }
172}
173