diff options
Diffstat (limited to '')
-rw-r--r-- | src/old/xmlwriter.cpp (renamed from src/xmlwriter.cpp) | 62 |
1 files changed, 28 insertions, 34 deletions
diff --git a/src/xmlwriter.cpp b/src/old/xmlwriter.cpp index 56880b6..7dc6ca9 100644 --- a/src/xmlwriter.cpp +++ b/src/old/xmlwriter.cpp | |||
@@ -2,17 +2,10 @@ | |||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include "xmlwriter.h" | 3 | #include "xmlwriter.h" |
4 | 4 | ||
5 | XmlWriter::XmlWriter( const char *sIndent, XmlNode *pRoot ) : | 5 | XmlWriter::XmlWriter( const Bu::FString &sIndent, XmlNode *pRoot ) : |
6 | XmlDocument( pRoot ) | 6 | XmlDocument( pRoot ), |
7 | sIndent( sIndent ) | ||
7 | { | 8 | { |
8 | if( sIndent == NULL ) | ||
9 | { | ||
10 | this->sIndent = ""; | ||
11 | } | ||
12 | else | ||
13 | { | ||
14 | this->sIndent = sIndent; | ||
15 | } | ||
16 | } | 9 | } |
17 | 10 | ||
18 | XmlWriter::~XmlWriter() | 11 | XmlWriter::~XmlWriter() |
@@ -24,7 +17,7 @@ void XmlWriter::write() | |||
24 | write( getRoot(), sIndent.c_str() ); | 17 | write( getRoot(), sIndent.c_str() ); |
25 | } | 18 | } |
26 | 19 | ||
27 | void XmlWriter::write( XmlNode *pRoot, const char *sIndent ) | 20 | void XmlWriter::write( XmlNode *pRoot, const Bu::FString &sIndent ) |
28 | { | 21 | { |
29 | writeNode( pRoot, 0, sIndent ); | 22 | writeNode( pRoot, 0, sIndent ); |
30 | } | 23 | } |
@@ -39,7 +32,7 @@ void XmlWriter::closeNode() | |||
39 | } | 32 | } |
40 | } | 33 | } |
41 | 34 | ||
42 | void XmlWriter::writeIndent( int nIndent, const char *sIndent ) | 35 | void XmlWriter::writeIndent( int nIndent, const Bu::FString &sIndent ) |
43 | { | 36 | { |
44 | if( sIndent == NULL ) return; | 37 | if( sIndent == NULL ) return; |
45 | for( int j = 0; j < nIndent; j++ ) | 38 | for( int j = 0; j < nIndent; j++ ) |
@@ -48,26 +41,27 @@ void XmlWriter::writeIndent( int nIndent, const char *sIndent ) | |||
48 | } | 41 | } |
49 | } | 42 | } |
50 | 43 | ||
51 | std::string XmlWriter::escape( std::string sIn ) | 44 | Bu::FString XmlWriter::escape( const Bu::FString &sIn ) |
52 | { | 45 | { |
53 | std::string sOut; | 46 | Bu::FString sOut; |
54 | 47 | ||
55 | std::string::const_iterator i; | 48 | int nMax = sIn.getSize(); |
56 | for( i = sIn.begin(); i != sIn.end(); i++ ) | 49 | for( int j = 0; j < nMax; j++ ) |
57 | { | 50 | { |
58 | if( ((*i >= ' ' && *i <= '9') || | 51 | char c = sIn[j]; |
59 | (*i >= 'a' && *i <= 'z') || | 52 | if( ((c >= ' ' && c <= '9') || |
60 | (*i >= 'A' && *i <= 'Z') ) && | 53 | (c >= 'a' && c <= 'z') || |
61 | (*i != '\"' && *i != '\'' && *i != '&') | 54 | (c >= 'A' && c <= 'Z') ) && |
55 | (c != '\"' && c != '\'' && c != '&') | ||
62 | ) | 56 | ) |
63 | { | 57 | { |
64 | sOut += *i; | 58 | sOut += c; |
65 | } | 59 | } |
66 | else | 60 | else |
67 | { | 61 | { |
68 | sOut += "&#"; | 62 | sOut += "&#"; |
69 | char buf[4]; | 63 | char buf[4]; |
70 | sprintf( buf, "%u", (unsigned char)*i ); | 64 | sprintf( buf, "%u", (unsigned char)c ); |
71 | sOut += buf; | 65 | sOut += buf; |
72 | sOut += ';'; | 66 | sOut += ';'; |
73 | } | 67 | } |
@@ -76,19 +70,19 @@ std::string XmlWriter::escape( std::string sIn ) | |||
76 | return sOut; | 70 | return sOut; |
77 | } | 71 | } |
78 | 72 | ||
79 | void XmlWriter::writeNodeProps( XmlNode *pNode, int nIndent, const char *sIndent ) | 73 | void XmlWriter::writeNodeProps( XmlNode *pNode, int nIndent, const Bu::FString &sIndent ) |
80 | { | 74 | { |
81 | for( int j = 0; j < pNode->getNumProperties(); j++ ) | 75 | for( int j = 0; j < pNode->getNumProperties(); j++ ) |
82 | { | 76 | { |
83 | writeString(" "); | 77 | writeString(" "); |
84 | writeString( pNode->getPropertyName( j ) ); | 78 | //writeString( pNode->getPropertyName( j ) ); |
85 | writeString("=\""); | 79 | writeString("=\""); |
86 | writeString( escape( pNode->getProperty( j ) ).c_str() ); | 80 | //writeString( escape( pNode->getProperty( j ) ).c_str() ); |
87 | writeString("\""); | 81 | writeString("\""); |
88 | } | 82 | } |
89 | } | 83 | } |
90 | 84 | ||
91 | void XmlWriter::writeNode( XmlNode *pNode, int nIndent, const char *sIndent ) | 85 | void XmlWriter::writeNode( XmlNode *pNode, int nIndent, const Bu::FString &sIndent ) |
92 | { | 86 | { |
93 | if( pNode->hasChildren() ) | 87 | if( pNode->hasChildren() ) |
94 | { | 88 | { |
@@ -96,15 +90,15 @@ void XmlWriter::writeNode( XmlNode *pNode, int nIndent, const char *sIndent ) | |||
96 | writeString("<"); | 90 | writeString("<"); |
97 | writeString( pNode->getName() ); | 91 | writeString( pNode->getName() ); |
98 | writeNodeProps( pNode, nIndent, sIndent ); | 92 | writeNodeProps( pNode, nIndent, sIndent ); |
99 | if( sIndent ) | 93 | if( sIndent != "" ) |
100 | writeString(">\n"); | 94 | writeString(">\n"); |
101 | else | 95 | else |
102 | writeString(">"); | 96 | writeString(">"); |
103 | 97 | /* | |
104 | if( pNode->getContent( 0 ) ) | 98 | if( pNode->getContent( 0 ) ) |
105 | { | 99 | { |
106 | writeIndent( nIndent+1, sIndent ); | 100 | writeIndent( nIndent+1, sIndent ); |
107 | if( sIndent ) | 101 | if( sIndent != "" ) |
108 | { | 102 | { |
109 | writeString( pNode->getContent( 0 ) ); | 103 | writeString( pNode->getContent( 0 ) ); |
110 | writeString("\n"); | 104 | writeString("\n"); |
@@ -129,9 +123,9 @@ void XmlWriter::writeNode( XmlNode *pNode, int nIndent, const char *sIndent ) | |||
129 | writeString( pNode->getContent( j+1 ) ); | 123 | writeString( pNode->getContent( j+1 ) ); |
130 | } | 124 | } |
131 | } | 125 | } |
132 | 126 | */ | |
133 | writeIndent( nIndent, sIndent ); | 127 | writeIndent( nIndent, sIndent ); |
134 | if( sIndent ) | 128 | if( sIndent != "" ) |
135 | { | 129 | { |
136 | writeString("</"); | 130 | writeString("</"); |
137 | writeString( pNode->getName() ); | 131 | writeString( pNode->getName() ); |
@@ -143,7 +137,7 @@ void XmlWriter::writeNode( XmlNode *pNode, int nIndent, const char *sIndent ) | |||
143 | writeString( pNode->getName() ); | 137 | writeString( pNode->getName() ); |
144 | writeString(">"); | 138 | writeString(">"); |
145 | } | 139 | } |
146 | } | 140 | }/* |
147 | else if( pNode->getContent() ) | 141 | else if( pNode->getContent() ) |
148 | { | 142 | { |
149 | writeIndent( nIndent, sIndent ); | 143 | writeIndent( nIndent, sIndent ); |
@@ -157,14 +151,14 @@ void XmlWriter::writeNode( XmlNode *pNode, int nIndent, const char *sIndent ) | |||
157 | writeString(">"); | 151 | writeString(">"); |
158 | if( sIndent ) | 152 | if( sIndent ) |
159 | writeString("\n"); | 153 | writeString("\n"); |
160 | } | 154 | }*/ |
161 | else | 155 | else |
162 | { | 156 | { |
163 | writeIndent( nIndent, sIndent ); | 157 | writeIndent( nIndent, sIndent ); |
164 | writeString("<"); | 158 | writeString("<"); |
165 | writeString( pNode->getName() ); | 159 | writeString( pNode->getName() ); |
166 | writeNodeProps( pNode, nIndent, sIndent ); | 160 | writeNodeProps( pNode, nIndent, sIndent ); |
167 | if( sIndent ) | 161 | if( sIndent != "" ) |
168 | writeString("/>\n"); | 162 | writeString("/>\n"); |
169 | else | 163 | else |
170 | writeString("/>"); | 164 | writeString("/>"); |