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

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

References mDepth, mHasKids, and mInTag.

◆ ~XMLWriter()

XMLWriter::~XMLWriter ( )
virtual

Definition at line 72 of file XMLWriter.cpp.

73 {
74 }

Member Function Documentation

◆ EndTag()

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

Reimplemented in ProjectSerializer.

Definition at line 99 of file XMLWriter.cpp.

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

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

Referenced by ConvertLegacyTrack(), ProjectSerializer::Decode(), XMLFileWriter::PreCommit(), 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 76 of file XMLWriter.cpp.

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

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

Referenced by ConvertLegacyTrack(), ProjectSerializer::Decode(), 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, XMLStringWriter, and XMLFileWriter.

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

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

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(), 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 137 of file XMLWriter.cpp.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

References mHasKids, mInTag, and Write().

Here is the call graph for this function:

◆ XMLEsc()

wxString XMLWriter::XMLEsc ( const wxString &  s)

Definition at line 224 of file XMLWriter.cpp.

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

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:54
NONCHARACTER_FFFF
#define NONCHARACTER_FFFF
Definition: XMLWriter.cpp:59
XMLWriter::mInTag
bool mInTag
Definition: XMLWriter.h:62
charXMLCompatiblity
static int charXMLCompatiblity[]
Definition: XMLWriter.cpp:38
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:55
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:58
MAX_HIGH_SURROGATE
#define MAX_HIGH_SURROGATE
Definition: XMLWriter.cpp:53
XMLWriter::WriteAttr
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:34
MIN_HIGH_SURROGATE
#define MIN_HIGH_SURROGATE
Definition: XMLWriter.cpp:52
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:151
XMLWriter::XMLEsc
wxString XMLEsc(const wxString &s)
Definition: XMLWriter.cpp:224