aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/CXMLWriter.cpp
diff options
context:
space:
mode:
authorDavid Walter Seikel2013-01-13 18:54:10 +1000
committerDavid Walter Seikel2013-01-13 18:54:10 +1000
commit959831f4ef5a3e797f576c3de08cd65032c997ad (patch)
treee7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/CXMLWriter.cpp
parentAdd info about changes to Irrlicht. (diff)
downloadSledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CXMLWriter.cpp')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/CXMLWriter.cpp514
1 files changed, 257 insertions, 257 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CXMLWriter.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CXMLWriter.cpp
index cc294c5..c3972ee 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/CXMLWriter.cpp
+++ b/libraries/irrlicht-1.8/source/Irrlicht/CXMLWriter.cpp
@@ -1,257 +1,257 @@
1// Copyright (C) 2002-2012 Nikolaus Gebhardt 1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine". 2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h 3// For conditions of distribution and use, see copyright notice in irrlicht.h
4 4
5#include "CXMLWriter.h" 5#include "CXMLWriter.h"
6#include <wchar.h> 6#include <wchar.h>
7#include "irrString.h" 7#include "irrString.h"
8#include "IrrCompileConfig.h" 8#include "IrrCompileConfig.h"
9 9
10namespace irr 10namespace irr
11{ 11{
12namespace io 12namespace io
13{ 13{
14 14
15 15
16//! Constructor 16//! Constructor
17CXMLWriter::CXMLWriter(IWriteFile* file) 17CXMLWriter::CXMLWriter(IWriteFile* file)
18: File(file), Tabs(0), TextWrittenLast(false) 18: File(file), Tabs(0), TextWrittenLast(false)
19{ 19{
20 #ifdef _DEBUG 20 #ifdef _DEBUG
21 setDebugName("CXMLWriter"); 21 setDebugName("CXMLWriter");
22 #endif 22 #endif
23 23
24 if (File) 24 if (File)
25 File->grab(); 25 File->grab();
26} 26}
27 27
28 28
29 29
30//! Destructor 30//! Destructor
31CXMLWriter::~CXMLWriter() 31CXMLWriter::~CXMLWriter()
32{ 32{
33 if (File) 33 if (File)
34 File->drop(); 34 File->drop();
35} 35}
36 36
37 37
38 38
39//! Writes a xml 1.0 header like <?xml version="1.0"?> 39//! Writes a xml 1.0 header like <?xml version="1.0"?>
40void CXMLWriter::writeXMLHeader() 40void CXMLWriter::writeXMLHeader()
41{ 41{
42 if (!File) 42 if (!File)
43 return; 43 return;
44 44
45 if (sizeof(wchar_t)==2) 45 if (sizeof(wchar_t)==2)
46 { 46 {
47 const u16 h = 0xFEFF; 47 const u16 h = 0xFEFF;
48 File->write(&h, 2); 48 File->write(&h, 2);
49 } 49 }
50 else 50 else
51 { 51 {
52 const u32 h = 0x0000FEFF; 52 const u32 h = 0x0000FEFF;
53 File->write(&h, sizeof(wchar_t)); 53 File->write(&h, sizeof(wchar_t));
54 } 54 }
55 55
56 const wchar_t* const p = L"<?xml version=\"1.0\"?>"; 56 const wchar_t* const p = L"<?xml version=\"1.0\"?>";
57 File->write(p, wcslen(p)*sizeof(wchar_t)); 57 File->write(p, wcslen(p)*sizeof(wchar_t));
58 58
59 writeLineBreak(); 59 writeLineBreak();
60 TextWrittenLast = false; 60 TextWrittenLast = false;
61} 61}
62 62
63 63
64 64
65//! Writes an xml element with maximal 5 attributes 65//! Writes an xml element with maximal 5 attributes
66void CXMLWriter::writeElement(const wchar_t* name, bool empty, 66void CXMLWriter::writeElement(const wchar_t* name, bool empty,
67 const wchar_t* attr1Name, const wchar_t* attr1Value, 67 const wchar_t* attr1Name, const wchar_t* attr1Value,
68 const wchar_t* attr2Name, const wchar_t* attr2Value, 68 const wchar_t* attr2Name, const wchar_t* attr2Value,
69 const wchar_t* attr3Name, const wchar_t* attr3Value, 69 const wchar_t* attr3Name, const wchar_t* attr3Value,
70 const wchar_t* attr4Name, const wchar_t* attr4Value, 70 const wchar_t* attr4Name, const wchar_t* attr4Value,
71 const wchar_t* attr5Name, const wchar_t* attr5Value) 71 const wchar_t* attr5Name, const wchar_t* attr5Value)
72{ 72{
73 if (!File || !name) 73 if (!File || !name)
74 return; 74 return;
75 75
76 if (Tabs > 0) 76 if (Tabs > 0)
77 { 77 {
78 for (int i=0; i<Tabs; ++i) 78 for (int i=0; i<Tabs; ++i)
79 File->write(L"\t", sizeof(wchar_t)); 79 File->write(L"\t", sizeof(wchar_t));
80 } 80 }
81 81
82 // write name 82 // write name
83 83
84 File->write(L"<", sizeof(wchar_t)); 84 File->write(L"<", sizeof(wchar_t));
85 File->write(name, wcslen(name)*sizeof(wchar_t)); 85 File->write(name, wcslen(name)*sizeof(wchar_t));
86 86
87 // write attributes 87 // write attributes
88 88
89 writeAttribute(attr1Name, attr1Value); 89 writeAttribute(attr1Name, attr1Value);
90 writeAttribute(attr2Name, attr2Value); 90 writeAttribute(attr2Name, attr2Value);
91 writeAttribute(attr3Name, attr3Value); 91 writeAttribute(attr3Name, attr3Value);
92 writeAttribute(attr4Name, attr4Value); 92 writeAttribute(attr4Name, attr4Value);
93 writeAttribute(attr5Name, attr5Value); 93 writeAttribute(attr5Name, attr5Value);
94 94
95 // write closing tag 95 // write closing tag
96 if (empty) 96 if (empty)
97 File->write(L" />", 3*sizeof(wchar_t)); 97 File->write(L" />", 3*sizeof(wchar_t));
98 else 98 else
99 { 99 {
100 File->write(L">", sizeof(wchar_t)); 100 File->write(L">", sizeof(wchar_t));
101 ++Tabs; 101 ++Tabs;
102 } 102 }
103 103
104 TextWrittenLast = false; 104 TextWrittenLast = false;
105} 105}
106 106
107//! Writes an xml element with any number of attributes 107//! Writes an xml element with any number of attributes
108void CXMLWriter::writeElement(const wchar_t* name, bool empty, 108void CXMLWriter::writeElement(const wchar_t* name, bool empty,
109 core::array<core::stringw> &names, 109 core::array<core::stringw> &names,
110 core::array<core::stringw> &values) 110 core::array<core::stringw> &values)
111{ 111{
112 if (!File || !name) 112 if (!File || !name)
113 return; 113 return;
114 114
115 if (Tabs > 0) 115 if (Tabs > 0)
116 { 116 {
117 for (int i=0; i<Tabs; ++i) 117 for (int i=0; i<Tabs; ++i)
118 File->write(L"\t", sizeof(wchar_t)); 118 File->write(L"\t", sizeof(wchar_t));
119 } 119 }
120 120
121 // write name 121 // write name
122 122
123 File->write(L"<", sizeof(wchar_t)); 123 File->write(L"<", sizeof(wchar_t));
124 File->write(name, wcslen(name)*sizeof(wchar_t)); 124 File->write(name, wcslen(name)*sizeof(wchar_t));
125 125
126 // write attributes 126 // write attributes
127 u32 i=0; 127 u32 i=0;
128 for (; i < names.size() && i < values.size(); ++i) 128 for (; i < names.size() && i < values.size(); ++i)
129 writeAttribute(names[i].c_str(), values[i].c_str()); 129 writeAttribute(names[i].c_str(), values[i].c_str());
130 130
131 // write closing tag 131 // write closing tag
132 if (empty) 132 if (empty)
133 File->write(L" />", 3*sizeof(wchar_t)); 133 File->write(L" />", 3*sizeof(wchar_t));
134 else 134 else
135 { 135 {
136 File->write(L">", sizeof(wchar_t)); 136 File->write(L">", sizeof(wchar_t));
137 ++Tabs; 137 ++Tabs;
138 } 138 }
139 139
140 TextWrittenLast = false; 140 TextWrittenLast = false;
141} 141}
142 142
143 143
144void CXMLWriter::writeAttribute(const wchar_t* name, const wchar_t* value) 144void CXMLWriter::writeAttribute(const wchar_t* name, const wchar_t* value)
145{ 145{
146 if (!name || !value) 146 if (!name || !value)
147 return; 147 return;
148 148
149 File->write(L" ", sizeof(wchar_t)); 149 File->write(L" ", sizeof(wchar_t));
150 File->write(name, wcslen(name)*sizeof(wchar_t)); 150 File->write(name, wcslen(name)*sizeof(wchar_t));
151 File->write(L"=\"", 2*sizeof(wchar_t)); 151 File->write(L"=\"", 2*sizeof(wchar_t));
152 writeText(value); 152 writeText(value);
153 File->write(L"\"", sizeof(wchar_t)); 153 File->write(L"\"", sizeof(wchar_t));
154} 154}
155 155
156 156
157//! Writes a comment into the xml file 157//! Writes a comment into the xml file
158void CXMLWriter::writeComment(const wchar_t* comment) 158void CXMLWriter::writeComment(const wchar_t* comment)
159{ 159{
160 if (!File || !comment) 160 if (!File || !comment)
161 return; 161 return;
162 162
163 File->write(L"<!--", 4*sizeof(wchar_t)); 163 File->write(L"<!--", 4*sizeof(wchar_t));
164 writeText(comment); 164 writeText(comment);
165 File->write(L"-->", 3*sizeof(wchar_t)); 165 File->write(L"-->", 3*sizeof(wchar_t));
166} 166}
167 167
168 168
169//! Writes the closing tag for an element. Like </foo> 169//! Writes the closing tag for an element. Like </foo>
170void CXMLWriter::writeClosingTag(const wchar_t* name) 170void CXMLWriter::writeClosingTag(const wchar_t* name)
171{ 171{
172 if (!File || !name) 172 if (!File || !name)
173 return; 173 return;
174 174
175 --Tabs; 175 --Tabs;
176 176
177 if (Tabs > 0 && !TextWrittenLast) 177 if (Tabs > 0 && !TextWrittenLast)
178 { 178 {
179 for (int i=0; i<Tabs; ++i) 179 for (int i=0; i<Tabs; ++i)
180 File->write(L"\t", sizeof(wchar_t)); 180 File->write(L"\t", sizeof(wchar_t));
181 } 181 }
182 182
183 File->write(L"</", 2*sizeof(wchar_t)); 183 File->write(L"</", 2*sizeof(wchar_t));
184 File->write(name, wcslen(name)*sizeof(wchar_t)); 184 File->write(name, wcslen(name)*sizeof(wchar_t));
185 File->write(L">", sizeof(wchar_t)); 185 File->write(L">", sizeof(wchar_t));
186 TextWrittenLast = false; 186 TextWrittenLast = false;
187} 187}
188 188
189 189
190 190
191const CXMLWriter::XMLSpecialCharacters XMLWSChar[] = 191const CXMLWriter::XMLSpecialCharacters XMLWSChar[] =
192{ 192{
193 { L'&', L"&amp;" }, 193 { L'&', L"&amp;" },
194 { L'<', L"&lt;" }, 194 { L'<', L"&lt;" },
195 { L'>', L"&gt;" }, 195 { L'>', L"&gt;" },
196 { L'"', L"&quot;" }, 196 { L'"', L"&quot;" },
197 { L'\0', 0 } 197 { L'\0', 0 }
198}; 198};
199 199
200 200
201//! Writes a text into the file. All occurrences of special characters like 201//! Writes a text into the file. All occurrences of special characters like
202//! & (&amp;), < (&lt;), > (&gt;), and " (&quot;) are automaticly replaced. 202//! & (&amp;), < (&lt;), > (&gt;), and " (&quot;) are automaticly replaced.
203void CXMLWriter::writeText(const wchar_t* text) 203void CXMLWriter::writeText(const wchar_t* text)
204{ 204{
205 if (!File || !text) 205 if (!File || !text)
206 return; 206 return;
207 207
208 // TODO: we have to get rid of that reserve call as well as it slows down xml-writing seriously. 208 // TODO: we have to get rid of that reserve call as well as it slows down xml-writing seriously.
209 // Making a member-variable would work, but a lot of memory would stay around after writing. 209 // Making a member-variable would work, but a lot of memory would stay around after writing.
210 // So the correct solution is probably using fixed block here and always write when that is full. 210 // So the correct solution is probably using fixed block here and always write when that is full.
211 core::stringw s; 211 core::stringw s;
212 s.reserve(wcslen(text)+1); 212 s.reserve(wcslen(text)+1);
213 const wchar_t* p = text; 213 const wchar_t* p = text;
214 214
215 while(*p) 215 while(*p)
216 { 216 {
217 // check if it is matching 217 // check if it is matching
218 bool found = false; 218 bool found = false;
219 for (s32 i=0; XMLWSChar[i].Character != '\0'; ++i) 219 for (s32 i=0; XMLWSChar[i].Character != '\0'; ++i)
220 if (*p == XMLWSChar[i].Character) 220 if (*p == XMLWSChar[i].Character)
221 { 221 {
222 s.append(XMLWSChar[i].Symbol); 222 s.append(XMLWSChar[i].Symbol);
223 found = true; 223 found = true;
224 break; 224 break;
225 } 225 }
226 226
227 if (!found) 227 if (!found)
228 s.append(*p); 228 s.append(*p);
229 ++p; 229 ++p;
230 } 230 }
231 231
232 // write new string 232 // write new string
233 File->write(s.c_str(), s.size()*sizeof(wchar_t)); 233 File->write(s.c_str(), s.size()*sizeof(wchar_t));
234 TextWrittenLast = true; 234 TextWrittenLast = true;
235} 235}
236 236
237 237
238//! Writes a line break 238//! Writes a line break
239void CXMLWriter::writeLineBreak() 239void CXMLWriter::writeLineBreak()
240{ 240{
241 if (!File) 241 if (!File)
242 return; 242 return;
243 243
244#if defined(_IRR_OSX_PLATFORM_) 244#if defined(_IRR_OSX_PLATFORM_)
245 File->write(L"\r", sizeof(wchar_t)); 245 File->write(L"\r", sizeof(wchar_t));
246#elif defined(_IRR_WINDOWS_API_) 246#elif defined(_IRR_WINDOWS_API_)
247 File->write(L"\r\n", 2*sizeof(wchar_t)); 247 File->write(L"\r\n", 2*sizeof(wchar_t));
248#else 248#else
249 File->write(L"\n", sizeof(wchar_t)); 249 File->write(L"\n", sizeof(wchar_t));
250#endif 250#endif
251 251
252} 252}
253 253
254 254
255} // end namespace irr 255} // end namespace irr
256} // end namespace io 256} // end namespace io
257 257