Audacity  3.0.3
Public Member Functions | Protected Attributes | 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
 
wxString XMLEsc (const wxString &s)
 

Protected Attributes

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

Detailed Description

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

XMLWriter

Definition at line 23 of file XMLWriter.h.

Constructor & Destructor Documentation

◆ XMLWriter()

XMLWriter::XMLWriter ( )

XMLWriter base class

Definition at line 66 of file XMLWriter.cpp.

67 {
68  mDepth = 0;
69  mInTag = false;
70  mHasKids.push_back(false);
71 }

References mDepth, mHasKids, and mInTag.

◆ ~XMLWriter()

XMLWriter::~XMLWriter ( )
virtual

Definition at line 73 of file XMLWriter.cpp.

74 {
75 }

Member Function Documentation

◆ EndTag()

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

Reimplemented in ProjectSerializer.

Definition at line 100 of file XMLWriter.cpp.

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

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

Referenced by ConvertLegacyTrack(), ProjectSerializer::Decode(), XMLFileWriter::PreCommit(), LegacyAliasBlockFile::SaveXML(), LegacyBlockFile::SaveXML(), ODDecodeBlockFile::SaveXML(), ODPCMAliasBlockFile::SaveXML(), PCMAliasBlockFile::SaveXML(), SilentBlockFile::SaveXML(), SimpleBlockFile::SaveXML(), 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 77 of file XMLWriter.cpp.

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

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

Referenced by ConvertLegacyTrack(), ProjectSerializer::Decode(), LegacyAliasBlockFile::SaveXML(), LegacyBlockFile::SaveXML(), ODDecodeBlockFile::SaveXML(), ODPCMAliasBlockFile::SaveXML(), PCMAliasBlockFile::SaveXML(), SilentBlockFile::SaveXML(), SimpleBlockFile::SaveXML(), 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 XMLStringWriter, XMLFileWriter, and ProjectSerializer.

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 152 of file XMLWriter.cpp.

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

References name, and Write().

Here is the call graph for this function:

◆ WriteAttr() [2/10]

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

Definition at line 34 of file XMLWriter.h.

37  { WriteAttr( name, value.GET() ); }

References Identifier::GET(), and name.

Referenced by ConvertLegacyTrack(), ProjectSerializer::Decode(), LegacyAliasBlockFile::SaveXML(), LegacyBlockFile::SaveXML(), ODDecodeBlockFile::SaveXML(), ODPCMAliasBlockFile::SaveXML(), PCMAliasBlockFile::SaveXML(), SilentBlockFile::SaveXML(), SimpleBlockFile::SaveXML(), SqliteSampleBlock::SaveXML(), WriteAttr(), Track::WriteCommonXMLAttributes(), ProjectFileIO::WriteXML(), TrackView::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 138 of file XMLWriter.cpp.

140 {
141  WriteAttr(name, wxString(value));
142 }

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 130 of file XMLWriter.cpp.

132 {
133  Write(wxString::Format(wxT(" %s=\"%s\""),
134  name,
135  XMLEsc(value)));
136 }

References name, Write(), 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 192 of file XMLWriter.cpp.

194 {
195  Write(wxString::Format(wxT(" %s=\"%s\""),
196  name,
197  Internat::ToString(value, digits)));
198 }

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

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 184 of file XMLWriter.cpp.

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

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

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 144 of file XMLWriter.cpp.

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

References name, and Write().

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 168 of file XMLWriter.cpp.

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

References name, and Write().

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 160 of file XMLWriter.cpp.

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

References name, and Write().

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 176 of file XMLWriter.cpp.

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

References name, and Write().

Here is the call graph for this function:

◆ WriteData()

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

Reimplemented in ProjectSerializer.

Definition at line 200 of file XMLWriter.cpp.

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

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

Referenced by ProjectSerializer::Decode().

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

◆ WriteSubTree()

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

Definition at line 212 of file XMLWriter.cpp.

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

References mHasKids, mInTag, and Write().

Here is the call graph for this function:

◆ XMLEsc()

wxString XMLWriter::XMLEsc ( const wxString &  s)

Definition at line 225 of file XMLWriter.cpp.

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

References charXMLCompatiblity, MAX_HIGH_SURROGATE, MAX_LOW_SURROGATE, MIN_HIGH_SURROGATE, MIN_LOW_SURROGATE, NONCHARACTER_FFFE, and NONCHARACTER_FFFF.

Referenced by WriteAttr(), and WriteData().

Here is the caller graph for this function:

Member Data Documentation

◆ mDepth

int XMLWriter::mDepth
protected

Definition at line 63 of file XMLWriter.h.

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

◆ mHasKids

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

Definition at line 65 of file XMLWriter.h.

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

◆ mInTag

bool XMLWriter::mInTag
protected

Definition at line 62 of file XMLWriter.h.

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

◆ mTagstack

wxArrayString XMLWriter::mTagstack
protected

Definition at line 64 of file XMLWriter.h.

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


The documentation for this class was generated from the following files:
MIN_LOW_SURROGATE
#define MIN_LOW_SURROGATE
Definition: XMLWriter.cpp:55
NONCHARACTER_FFFF
#define NONCHARACTER_FFFF
Definition: XMLWriter.cpp:60
XMLWriter::mInTag
bool mInTag
Definition: XMLWriter.h:62
charXMLCompatiblity
static int charXMLCompatiblity[]
Definition: XMLWriter.cpp:39
XMLWriter::mHasKids
std::vector< int > mHasKids
Definition: XMLWriter.h:65
XMLWriter::mTagstack
wxArrayString mTagstack
Definition: XMLWriter.h:64
XMLWriter::mDepth
int mDepth
Definition: XMLWriter.h:63
name
const TranslatableString name
Definition: Distortion.cpp:98
MAX_LOW_SURROGATE
#define MAX_LOW_SURROGATE
Definition: XMLWriter.cpp:56
Identifier::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
XMLWriter::Write
virtual void Write(const wxString &data)=0
NONCHARACTER_FFFE
#define NONCHARACTER_FFFE
Definition: XMLWriter.cpp:59
MAX_HIGH_SURROGATE
#define MAX_HIGH_SURROGATE
Definition: XMLWriter.cpp:54
XMLWriter::WriteAttr
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:34
MIN_HIGH_SURROGATE
#define MIN_HIGH_SURROGATE
Definition: XMLWriter.cpp:53
Internat::ToString
static wxString ToString(double numberToConvert, int digitsAfterDecimalPoint=-1)
Convert a number to a string, always uses the dot as decimal separator.
Definition: Internat.cpp:150
XMLWriter::XMLEsc
wxString XMLEsc(const wxString &s)
Definition: XMLWriter.cpp:225