Audacity 3.2.0
Public Member Functions | Protected Attributes | Static Private Member Functions | List of all members
XMLWriter Class Referenceabstract

Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating XML in UTF8 encoding. More...

#include <XMLWriter.h>

Inheritance diagram for XMLWriter:
[legend]
Collaboration diagram for XMLWriter:
[legend]

Public Member Functions

 XMLWriter ()
 
virtual ~XMLWriter ()
 
virtual void StartTag (const wxString &name)
 
virtual void EndTag (const wxString &name)
 
void WriteAttr (const wxString &name, const Identifier &value)
 
virtual void WriteAttr (const wxString &name, const wxString &value)
 
virtual void WriteAttr (const wxString &name, const wxChar *value)
 
virtual void WriteAttr (const wxString &name, int value)
 
virtual void WriteAttr (const wxString &name, bool value)
 
virtual void WriteAttr (const wxString &name, long value)
 
virtual void WriteAttr (const wxString &name, long long value)
 
virtual void WriteAttr (const wxString &name, size_t value)
 
virtual void WriteAttr (const wxString &name, float value, int digits=-1)
 
virtual void WriteAttr (const wxString &name, double value, int digits=-1)
 
virtual void WriteData (const wxString &value)
 
virtual void WriteSubTree (const wxString &value)
 
virtual void Write (const wxString &data)=0
 

Protected Attributes

bool mInTag
 
int mDepth
 
wxArrayString mTagstack
 
std::vector< int > mHasKids
 

Static Private Member Functions

static wxString XMLEsc (const wxString &s)
 

Detailed Description

Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating XML in UTF8 encoding.

XMLWriter

Definition at line 25 of file XMLWriter.h.

Constructor & Destructor Documentation

◆ XMLWriter()

XMLWriter::XMLWriter ( )

XMLWriter base class

Definition at line 68 of file XMLWriter.cpp.

69{
70 mDepth = 0;
71 mInTag = false;
72 mHasKids.push_back(false);
73}
std::vector< int > mHasKids
Definition: XMLWriter.h:68
bool mInTag
Definition: XMLWriter.h:65
int mDepth
Definition: XMLWriter.h:66

References mDepth, mHasKids, and mInTag.

◆ ~XMLWriter()

XMLWriter::~XMLWriter ( )
virtual

Definition at line 75 of file XMLWriter.cpp.

76{
77}

Member Function Documentation

◆ EndTag()

void XMLWriter::EndTag ( const wxString &  name)
virtual

Reimplemented in ProjectSerializer.

Definition at line 102 of file XMLWriter.cpp.

104{
105 int i;
106
107 if (mTagstack.size() > 0) {
108 if (mTagstack[0] == name) {
109 if (mHasKids[1]) { // There will always be at least 2 at this point
110 if (mInTag) {
111 Write(wxT("/>\n"));
112 }
113 else {
114 for (i = 0; i < mDepth - 1; i++) {
115 Write(wxT("\t"));
116 }
117 Write(wxString::Format(wxT("</%s>\n"), name));
118 }
119 }
120 else {
121 Write(wxT(">\n"));
122 }
123 mTagstack.erase( mTagstack.begin() );
124 mHasKids.erase(mHasKids.begin());
125 }
126 }
127
128 mDepth--;
129 mInTag = false;
130}
wxT("CloseDown"))
wxString name
Definition: TagsEditor.cpp:166
wxArrayString mTagstack
Definition: XMLWriter.h:67
virtual void Write(const wxString &data)=0

References mDepth, mHasKids, mInTag, mTagstack, name, Write(), and wxT().

Referenced by ConvertLegacyTrack(), XMLFileWriter::PreCommit(), WaveTrack::WriteOneXML(), PluginDescriptor::WriteXML(), detail::PluginValidationResult::WriteXML(), RealtimeEffectState::WriteXML(), RealtimeEffectList::WriteXML(), and ProjectFileIO::WriteXML().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ StartTag()

void XMLWriter::StartTag ( const wxString &  name)
virtual

Reimplemented in ProjectSerializer.

Definition at line 79 of file XMLWriter.cpp.

81{
82 int i;
83
84 if (mInTag) {
85 Write(wxT(">\n"));
86 mInTag = false;
87 }
88
89 for (i = 0; i < mDepth; i++) {
90 Write(wxT("\t"));
91 }
92
93 Write(wxString::Format(wxT("<%s"), name));
94
95 mTagstack.insert(mTagstack.begin(), name);
96 mHasKids[0] = true;
97 mHasKids.insert(mHasKids.begin(), false);
98 mDepth++;
99 mInTag = true;
100}

References mDepth, mHasKids, mInTag, mTagstack, name, Write(), and wxT().

Referenced by ConvertLegacyTrack(), WaveTrack::WriteOneXML(), PluginDescriptor::WriteXML(), detail::PluginValidationResult::WriteXML(), RealtimeEffectState::WriteXML(), RealtimeEffectList::WriteXML(), and ProjectFileIO::WriteXML().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Write()

virtual void XMLWriter::Write ( const wxString &  data)
pure virtual

Implemented in ProjectSerializer, XMLFileWriter, and XMLStringWriter.

Referenced by EndTag(), StartTag(), WriteAttr(), WriteData(), WriteSubTree(), and ProjectFileIO::WriteXMLHeader().

Here is the caller graph for this function:

◆ WriteAttr() [1/10]

void XMLWriter::WriteAttr ( const wxString &  name,
bool  value 
)
virtual

Reimplemented in ProjectSerializer.

Definition at line 154 of file XMLWriter.cpp.

156{
157 Write(wxString::Format(wxT(" %s=\"%d\""),
158 name,
159 value));
160}

References name, Write(), and wxT().

Here is the call graph for this function:

◆ WriteAttr() [2/10]

void XMLWriter::WriteAttr ( const wxString &  name,
const Identifier value 
)
inline

Definition at line 36 of file XMLWriter.h.

39 { WriteAttr( name, value.GET() ); }
const wxString & GET() const
Explicit conversion to wxString, meant to be ugly-looking and demanding of a comment why it's correct...
Definition: Identifier.h:66
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:36

References Identifier::GET(), and name.

Referenced by ConvertLegacyTrack(), SqliteSampleBlock::SaveXML(), WriteAttr(), Track::WriteCommonXMLAttributes(), WaveTrack::WriteOneXML(), PluginDescriptor::WriteXML(), detail::PluginValidationResult::WriteXML(), RealtimeEffectState::WriteXML(), RealtimeEffectList::WriteXML(), NoteTrackRange::WriteXML(), ProjectFileIO::WriteXML(), WaveformAppearance::WriteXMLAttributes(), WaveColorAttachment::WriteXMLAttributes(), ChannelView::WriteXMLAttributes(), and PlayableTrack::WriteXMLAttributes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteAttr() [3/10]

void XMLWriter::WriteAttr ( const wxString &  name,
const wxChar *  value 
)
virtual

Reimplemented in ProjectSerializer.

Definition at line 140 of file XMLWriter.cpp.

142{
143 WriteAttr(name, wxString(value));
144}

References name, and WriteAttr().

Here is the call graph for this function:

◆ WriteAttr() [4/10]

void XMLWriter::WriteAttr ( const wxString &  name,
const wxString &  value 
)
virtual

Reimplemented in ProjectSerializer.

Definition at line 132 of file XMLWriter.cpp.

134{
135 Write(wxString::Format(wxT(" %s=\"%s\""),
136 name,
137 XMLEsc(value)));
138}
static wxString XMLEsc(const wxString &s)
Definition: XMLWriter.cpp:227

References name, Write(), wxT(), and XMLEsc().

Here is the call graph for this function:

◆ WriteAttr() [5/10]

void XMLWriter::WriteAttr ( const wxString &  name,
double  value,
int  digits = -1 
)
virtual

Reimplemented in ProjectSerializer.

Definition at line 194 of file XMLWriter.cpp.

196{
197 Write(wxString::Format(wxT(" %s=\"%s\""),
198 name,
199 Internat::ToString(value, digits)));
200}
static wxString ToString(double numberToConvert, int digitsAfterDecimalPoint=-1)
Convert a number to a string, always uses the dot as decimal separator.
Definition: Internat.cpp:126

References name, Internat::ToString(), Write(), and wxT().

Here is the call graph for this function:

◆ WriteAttr() [6/10]

void XMLWriter::WriteAttr ( const wxString &  name,
float  value,
int  digits = -1 
)
virtual

Reimplemented in ProjectSerializer.

Definition at line 186 of file XMLWriter.cpp.

188{
189 Write(wxString::Format(wxT(" %s=\"%s\""),
190 name,
191 Internat::ToString(value, digits)));
192}

References name, Internat::ToString(), Write(), and wxT().

Here is the call graph for this function:

◆ WriteAttr() [7/10]

void XMLWriter::WriteAttr ( const wxString &  name,
int  value 
)
virtual

Reimplemented in ProjectSerializer.

Definition at line 146 of file XMLWriter.cpp.

148{
149 Write(wxString::Format(wxT(" %s=\"%d\""),
150 name,
151 value));
152}

References name, Write(), and wxT().

Here is the call graph for this function:

◆ WriteAttr() [8/10]

void XMLWriter::WriteAttr ( const wxString &  name,
long long  value 
)
virtual

Reimplemented in ProjectSerializer.

Definition at line 170 of file XMLWriter.cpp.

172{
173 Write(wxString::Format(wxT(" %s=\"%lld\""),
174 name,
175 value));
176}

References name, Write(), and wxT().

Here is the call graph for this function:

◆ WriteAttr() [9/10]

void XMLWriter::WriteAttr ( const wxString &  name,
long  value 
)
virtual

Reimplemented in ProjectSerializer.

Definition at line 162 of file XMLWriter.cpp.

164{
165 Write(wxString::Format(wxT(" %s=\"%ld\""),
166 name,
167 value));
168}

References name, Write(), and wxT().

Here is the call graph for this function:

◆ WriteAttr() [10/10]

void XMLWriter::WriteAttr ( const wxString &  name,
size_t  value 
)
virtual

Reimplemented in ProjectSerializer.

Definition at line 178 of file XMLWriter.cpp.

180{
181 Write(wxString::Format(wxT(" %s=\"%lld\""),
182 name,
183 (long long) value));
184}

References name, Write(), and wxT().

Here is the call graph for this function:

◆ WriteData()

void XMLWriter::WriteData ( const wxString &  value)
virtual

Reimplemented in ProjectSerializer.

Definition at line 202 of file XMLWriter.cpp.

204{
205 int i;
206
207 for (i = 0; i < mDepth; i++) {
208 Write(wxT("\t"));
209 }
210
211 Write(XMLEsc(value));
212}

References mDepth, Write(), wxT(), and XMLEsc().

Here is the call graph for this function:

◆ WriteSubTree()

void XMLWriter::WriteSubTree ( const wxString &  value)
virtual

Definition at line 214 of file XMLWriter.cpp.

216{
217 if (mInTag) {
218 Write(wxT(">\n"));
219 mInTag = false;
220 mHasKids[0] = true;
221 }
222
223 Write(value);
224}

References mHasKids, mInTag, Write(), and wxT().

Here is the call graph for this function:

◆ XMLEsc()

wxString XMLWriter::XMLEsc ( const wxString &  s)
staticprivate

Definition at line 227 of file XMLWriter.cpp.

228{
229 wxString result;
230 int len = s.length();
231
232 for(int i=0; i<len; i++) {
233 wxUChar c = s.GetChar(i);
234
235 switch (c) {
236 case wxT('\''):
237 result += wxT("&apos;");
238 break;
239
240 case wxT('"'):
241 result += wxT("&quot;");
242 break;
243
244 case wxT('&'):
245 result += wxT("&amp;");
246 break;
247
248 case wxT('<'):
249 result += wxT("&lt;");
250 break;
251
252 case wxT('>'):
253 result += wxT("&gt;");
254 break;
255
256 default:
257 if (sizeof(c) == 2 && c >= MIN_HIGH_SURROGATE && c <= MAX_HIGH_SURROGATE && i < len - 1) {
258 // If wxUChar is 2 bytes, then supplementary characters (those greater than U+FFFF) are represented
259 // with a high surrogate (U+D800..U+DBFF) followed by a low surrogate (U+DC00..U+DFFF).
260 // Handle those here.
261 wxUChar c2 = s.GetChar(++i);
262 if (c2 >= MIN_LOW_SURROGATE && c2 <= MAX_LOW_SURROGATE) {
263 // Surrogate pair found; simply add it to the output string.
264 result += c;
265 result += c2;
266 }
267 else {
268 // That high surrogate isn't paired, so ignore it.
269 i--;
270 }
271 }
272 else if (!wxIsprint(c)) {
273 //ignore several characters such ase eot (0x04) and stx (0x02) because it makes expat parser bail
274 //see xmltok.c in expat checkCharRefNumber() to see how expat bails on these chars.
275 //also see wxWidgets-2.8.12/src/expat/lib/asciitab.h to see which characters are nonxml compatible
276 //post decode (we can still encode '&' and '<' with this table, but it prevents us from encoding eot)
277 //everything is compatible past ascii 0x20 except for surrogates and the noncharacters U+FFFE and U+FFFF,
278 //so we don't check the compatibility table higher than this.
279 if((c> 0x1F || charXMLCompatiblity[c]!=0) &&
280 (c < MIN_HIGH_SURROGATE || c > MAX_LOW_SURROGATE) &&
282 result += wxString::Format(wxT("&#x%04x;"), c);
283 }
284 else {
285 result += c;
286 }
287 break;
288 }
289 }
290
291 return result;
292}
#define MIN_HIGH_SURROGATE
Definition: XMLWriter.cpp:55
#define NONCHARACTER_FFFE
Definition: XMLWriter.cpp:61
#define MAX_LOW_SURROGATE
Definition: XMLWriter.cpp:58
static int charXMLCompatiblity[]
Definition: XMLWriter.cpp:41
#define NONCHARACTER_FFFF
Definition: XMLWriter.cpp:62
#define MAX_HIGH_SURROGATE
Definition: XMLWriter.cpp:56
#define MIN_LOW_SURROGATE
Definition: XMLWriter.cpp:57

References charXMLCompatiblity, MAX_HIGH_SURROGATE, MAX_LOW_SURROGATE, MIN_HIGH_SURROGATE, MIN_LOW_SURROGATE, NONCHARACTER_FFFE, NONCHARACTER_FFFF, and wxT().

Referenced by WriteAttr(), and WriteData().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mDepth

int XMLWriter::mDepth
protected

Definition at line 66 of file XMLWriter.h.

Referenced by EndTag(), StartTag(), WriteData(), and XMLWriter().

◆ mHasKids

std::vector<int> XMLWriter::mHasKids
protected

Definition at line 68 of file XMLWriter.h.

Referenced by EndTag(), StartTag(), WriteSubTree(), and XMLWriter().

◆ mInTag

bool XMLWriter::mInTag
protected

Definition at line 65 of file XMLWriter.h.

Referenced by EndTag(), StartTag(), WriteSubTree(), and XMLWriter().

◆ mTagstack

wxArrayString XMLWriter::mTagstack
protected

Definition at line 67 of file XMLWriter.h.

Referenced by EndTag(), XMLFileWriter::PreCommit(), and StartTag().


The documentation for this class was generated from the following files: