Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlTextEncoder.cs
Go to the documentation of this file.
2using System.IO;
3using System.Text;
4
5namespace System.Xml;
6
7internal sealed class XmlTextEncoder
8{
9 private readonly TextWriter _textWriter;
10
11 private bool _inAttribute;
12
13 private char _quoteChar;
14
16
17 private bool _cacheAttrValue;
18
19 internal char QuoteChar
20 {
21 set
22 {
24 }
25 }
26
27 internal string AttributeValue
28 {
29 get
30 {
32 {
33 return _attrValue.ToString();
34 }
35 return string.Empty;
36 }
37 }
38
44
45 internal void StartAttribute(bool cacheAttrValue)
46 {
47 _inAttribute = true;
50 {
51 if (_attrValue == null)
52 {
54 }
55 else
56 {
58 }
59 }
60 }
61
62 internal void EndAttribute()
63 {
65 {
67 }
68 _inAttribute = false;
69 _cacheAttrValue = false;
70 }
71
81
82 internal void Write(char[] array, int offset, int count)
83 {
84 if (array == null)
85 {
86 throw new ArgumentNullException("array");
87 }
88 if (0 > offset)
89 {
90 throw new ArgumentOutOfRangeException("offset");
91 }
92 if (0 > count)
93 {
94 throw new ArgumentOutOfRangeException("count");
95 }
96 if (count > array.Length - offset)
97 {
98 throw new ArgumentOutOfRangeException("count");
99 }
100 if (_cacheAttrValue)
101 {
103 }
104 int num = offset + count;
105 int i = offset;
106 char c = '\0';
107 while (true)
108 {
109 int num2 = i;
110 for (; i < num; i++)
111 {
113 {
114 break;
115 }
116 }
117 if (num2 < i)
118 {
120 }
121 if (i == num)
122 {
123 break;
124 }
125 switch (c)
126 {
127 case '\t':
129 break;
130 case '\n':
131 case '\r':
132 if (_inAttribute)
133 {
135 }
136 else
137 {
139 }
140 break;
141 case '<':
142 WriteEntityRefImpl("lt");
143 break;
144 case '>':
145 WriteEntityRefImpl("gt");
146 break;
147 case '&':
148 WriteEntityRefImpl("amp");
149 break;
150 case '\'':
151 if (_inAttribute && _quoteChar == c)
152 {
153 WriteEntityRefImpl("apos");
154 }
155 else
156 {
157 _textWriter.Write('\'');
158 }
159 break;
160 case '"':
161 if (_inAttribute && _quoteChar == c)
162 {
163 WriteEntityRefImpl("quot");
164 }
165 else
166 {
167 _textWriter.Write('"');
168 }
169 break;
170 default:
172 {
173 if (i + 1 >= num)
174 {
176 }
177 WriteSurrogateChar(array[++i], c);
178 }
179 else
180 {
182 {
184 }
186 }
187 break;
188 }
189 i++;
190 }
191 }
192
209
210 internal void Write(string text)
211 {
212 if (text == null)
213 {
214 return;
215 }
216 if (_cacheAttrValue)
217 {
219 }
220 int length = text.Length;
221 int i = 0;
222 int num = 0;
223 char c = '\0';
224 while (true)
225 {
226 if (i < length && XmlCharType.IsAttributeValueChar(c = text[i]))
227 {
228 i++;
229 continue;
230 }
231 if (i == length)
232 {
234 return;
235 }
236 if (_inAttribute)
237 {
238 if (c != '\t')
239 {
240 break;
241 }
242 i++;
243 }
244 else
245 {
246 if (c != '\t' && c != '\n' && c != '\r' && c != '"' && c != '\'')
247 {
248 break;
249 }
250 i++;
251 }
252 }
253 char[] helperBuffer = new char[256];
254 while (true)
255 {
256 if (num < i)
257 {
258 WriteStringFragment(text, num, i - num, helperBuffer);
259 }
260 if (i == length)
261 {
262 break;
263 }
264 switch (c)
265 {
266 case '\t':
268 break;
269 case '\n':
270 case '\r':
271 if (_inAttribute)
272 {
274 }
275 else
276 {
278 }
279 break;
280 case '<':
281 WriteEntityRefImpl("lt");
282 break;
283 case '>':
284 WriteEntityRefImpl("gt");
285 break;
286 case '&':
287 WriteEntityRefImpl("amp");
288 break;
289 case '\'':
290 if (_inAttribute && _quoteChar == c)
291 {
292 WriteEntityRefImpl("apos");
293 }
294 else
295 {
296 _textWriter.Write('\'');
297 }
298 break;
299 case '"':
300 if (_inAttribute && _quoteChar == c)
301 {
302 WriteEntityRefImpl("quot");
303 }
304 else
305 {
306 _textWriter.Write('"');
307 }
308 break;
309 default:
311 {
312 if (i + 1 >= length)
313 {
315 }
316 WriteSurrogateChar(text[++i], c);
317 }
318 else
319 {
321 {
323 }
325 }
326 break;
327 }
328 i++;
329 num = i;
330 for (; i < length; i++)
331 {
333 {
334 break;
335 }
336 }
337 }
338 }
339
341 {
342 if (text == null)
343 {
344 return;
345 }
346 if (_cacheAttrValue)
347 {
349 }
350 int length = text.Length;
351 int num = 0;
352 char c = '\0';
353 while (true)
354 {
355 if (num < length && (XmlCharType.IsCharData(c = text[num]) || c < ' '))
356 {
357 num++;
358 continue;
359 }
360 if (num == length)
361 {
362 break;
363 }
365 {
366 if (num + 1 >= length)
367 {
369 }
370 char c2 = text[num + 1];
372 {
374 }
375 num += 2;
376 }
377 else
378 {
380 {
382 }
383 num++;
384 }
385 }
387 }
388
389 internal void WriteRaw(char[] array, int offset, int count)
390 {
391 if (array == null)
392 {
393 throw new ArgumentNullException("array");
394 }
395 if (0 > count)
396 {
397 throw new ArgumentOutOfRangeException("count");
398 }
399 if (0 > offset)
400 {
401 throw new ArgumentOutOfRangeException("offset");
402 }
403 if (count > array.Length - offset)
404 {
405 throw new ArgumentOutOfRangeException("count");
406 }
407 if (_cacheAttrValue)
408 {
410 }
412 }
413
414 internal void WriteCharEntity(char ch)
415 {
417 {
419 }
420 int num = ch;
421 string text = num.ToString("X", NumberFormatInfo.InvariantInfo);
422 if (_cacheAttrValue)
423 {
424 _attrValue.Append("&#x");
426 _attrValue.Append(';');
427 }
429 }
430
431 internal void WriteEntityRef(string name)
432 {
433 if (_cacheAttrValue)
434 {
435 _attrValue.Append('&');
436 _attrValue.Append(name);
437 _attrValue.Append(';');
438 }
439 WriteEntityRefImpl(name);
440 }
441
442 private void WriteStringFragment(string str, int offset, int count, char[] helperBuffer)
443 {
444 int num = helperBuffer.Length;
445 while (count > 0)
446 {
447 int num2 = count;
448 if (num2 > num)
449 {
450 num2 = num;
451 }
452 str.CopyTo(offset, helperBuffer, 0, num2);
454 offset += num2;
455 count -= num2;
456 }
457 }
458
459 private void WriteCharEntityImpl(char ch)
460 {
461 int num = ch;
463 }
464
465 private void WriteCharEntityImpl(string strVal)
466 {
467 _textWriter.Write("&#x");
469 _textWriter.Write(';');
470 }
471
472 private void WriteEntityRefImpl(string name)
473 {
474 _textWriter.Write('&');
475 _textWriter.Write(name);
476 _textWriter.Write(';');
477 }
478}
virtual void Write(char value)
static string Xml_SurrogatePairSplit
Definition SR.cs:360
static string Xml_InvalidSurrogateMissingLowChar
Definition SR.cs:324
Definition SR.cs:7
override string ToString()
StringBuilder Append(char value, int repeatCount)
static bool IsSurrogate(int ch)
static bool IsAttributeValueChar(char ch)
static bool IsLowSurrogate(int ch)
static int CombineSurrogateChar(int lowChar, int highChar)
static bool IsCharData(char ch)
static bool IsHighSurrogate(int ch)
static Exception CreateInvalidSurrogatePairException(char low, char hi)
static Exception CreateInvalidHighSurrogateCharException(char hi)
void StartAttribute(bool cacheAttrValue)
void WriteEntityRefImpl(string name)
XmlTextEncoder(TextWriter textWriter)
void WriteRawWithSurrogateChecking(string text)
void WriteSurrogateChar(char lowChar, char highChar)
void WriteCharEntityImpl(char ch)
void WriteStringFragment(string str, int offset, int count, char[] helperBuffer)
void WriteEntityRef(string name)
void Write(char[] array, int offset, int count)
void WriteSurrogateCharEntity(char lowChar, char highChar)
readonly TextWriter _textWriter
void WriteCharEntityImpl(string strVal)
void WriteRaw(char[] array, int offset, int count)