Audacity  3.2.0
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 26 of file XMLWriter.h.

Constructor & Destructor Documentation

◆ XMLWriter()

XMLWriter::XMLWriter ( )

XMLWriter base class

Definition at line 69 of file XMLWriter.cpp.

70 {
71  mDepth = 0;
72  mInTag = false;
73  mHasKids.push_back(false);
74 }

References mDepth, mHasKids, and mInTag.

◆ ~XMLWriter()

XMLWriter::~XMLWriter ( )
virtual

Definition at line 76 of file XMLWriter.cpp.

77 {
78 }

Member Function Documentation

◆ EndTag()

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

Reimplemented in ProjectSerializer.

Definition at line 103 of file XMLWriter.cpp.

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

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

Referenced by ConvertLegacyTrack(), 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 80 of file XMLWriter.cpp.

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

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

Referenced by ConvertLegacyTrack(), 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 155 of file XMLWriter.cpp.

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

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 37 of file XMLWriter.h.

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

References Identifier::GET(), and name.

Referenced by ConvertLegacyTrack(), 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 141 of file XMLWriter.cpp.

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

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

135 {
136  Write(wxString::Format(wxT(" %s=\"%s\""),
137  name,
138  XMLEsc(value)));
139 }

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

197 {
198  Write(wxString::Format(wxT(" %s=\"%s\""),
199  name,
200  Internat::ToString(value, digits)));
201 }

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

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

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

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

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

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

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

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

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

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

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

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

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

Here is the call graph for this function:

◆ WriteSubTree()

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

Definition at line 215 of file XMLWriter.cpp.

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

References mHasKids, mInTag, and Write().

Here is the call graph for this function:

◆ XMLEsc()

wxString XMLWriter::XMLEsc ( const wxString &  s)

Definition at line 228 of file XMLWriter.cpp.

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

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 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:
MIN_LOW_SURROGATE
#define MIN_LOW_SURROGATE
Definition: XMLWriter.cpp:58
NONCHARACTER_FFFF
#define NONCHARACTER_FFFF
Definition: XMLWriter.cpp:63
XMLWriter::mInTag
bool mInTag
Definition: XMLWriter.h:65
charXMLCompatiblity
static int charXMLCompatiblity[]
Definition: XMLWriter.cpp:42
XMLWriter::mHasKids
std::vector< int > mHasKids
Definition: XMLWriter.h:68
XMLWriter::mTagstack
wxArrayString mTagstack
Definition: XMLWriter.h:67
XMLWriter::mDepth
int mDepth
Definition: XMLWriter.h:66
name
const TranslatableString name
Definition: Distortion.cpp:98
MAX_LOW_SURROGATE
#define MAX_LOW_SURROGATE
Definition: XMLWriter.cpp:59
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:62
MAX_HIGH_SURROGATE
#define MAX_HIGH_SURROGATE
Definition: XMLWriter.cpp:57
XMLWriter::WriteAttr
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:37
MIN_HIGH_SURROGATE
#define MIN_HIGH_SURROGATE
Definition: XMLWriter.cpp:56
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:228