Terraria v1.4.4.9
Terraria source code documentation
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros
UTF16Decoder.cs
Go to the documentation of this file.
1using System.Text;
2
3namespace System.Xml;
4
5internal sealed class UTF16Decoder : Decoder
6{
7 private readonly bool _bigEndian;
8
9 private int _lastByte;
10
11 public UTF16Decoder(bool bigEndian)
12 {
13 _lastByte = -1;
14 _bigEndian = bigEndian;
15 }
16
17 public override int GetCharCount(byte[] bytes, int index, int count)
18 {
19 return GetCharCount(bytes, index, count, flush: false);
20 }
21
22 public override int GetCharCount(byte[] bytes, int index, int count, bool flush)
23 {
24 int num = count + ((_lastByte >= 0) ? 1 : 0);
25 if (flush && num % 2 != 0)
26 {
28 }
29 return num / 2;
30 }
31
32 public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
33 {
35 if (_lastByte >= 0)
36 {
37 if (byteCount == 0)
38 {
39 return charCount;
40 }
41 int num = bytes[byteIndex++];
42 byteCount--;
43 chars[charIndex++] = (_bigEndian ? ((char)((_lastByte << 8) | num)) : ((char)((num << 8) | _lastByte)));
44 _lastByte = -1;
45 }
46 if (((uint)byteCount & (true ? 1u : 0u)) != 0)
47 {
49 }
51 {
52 int num2 = byteIndex + byteCount;
53 if (_bigEndian)
54 {
55 while (byteIndex < num2)
56 {
57 int num3 = bytes[byteIndex++];
58 int num4 = bytes[byteIndex++];
59 chars[charIndex++] = (char)((num3 << 8) | num4);
60 }
61 }
62 else
63 {
64 while (byteIndex < num2)
65 {
66 int num5 = bytes[byteIndex++];
67 int num6 = bytes[byteIndex++];
68 chars[charIndex++] = (char)((num6 << 8) | num5);
69 }
70 }
71 }
72 else
73 {
75 }
76 return charCount;
77 }
78
79 public override void Convert(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, int charCount, bool flush, out int bytesUsed, out int charsUsed, out bool completed)
80 {
81 charsUsed = 0;
82 bytesUsed = 0;
83 if (_lastByte >= 0)
84 {
85 if (byteCount == 0)
86 {
87 completed = true;
88 return;
89 }
90 int num = bytes[byteIndex++];
91 byteCount--;
92 bytesUsed++;
93 chars[charIndex++] = (_bigEndian ? ((char)((_lastByte << 8) | num)) : ((char)((num << 8) | _lastByte)));
94 charCount--;
95 charsUsed++;
96 _lastByte = -1;
97 }
98 if (charCount * 2 < byteCount)
99 {
100 byteCount = charCount * 2;
101 completed = false;
102 }
103 else
104 {
105 completed = true;
106 }
108 {
109 int num2 = byteIndex;
110 int num3 = num2 + (byteCount & -2);
111 if (_bigEndian)
112 {
113 while (num2 < num3)
114 {
115 int num4 = bytes[num2++];
116 int num5 = bytes[num2++];
117 chars[charIndex++] = (char)((num4 << 8) | num5);
118 }
119 }
120 else
121 {
122 while (num2 < num3)
123 {
124 int num6 = bytes[num2++];
125 int num7 = bytes[num2++];
126 chars[charIndex++] = (char)((num7 << 8) | num6);
127 }
128 }
129 }
130 else
131 {
133 }
134 charsUsed += byteCount / 2;
135 bytesUsed += byteCount;
136 if (((uint)byteCount & (true ? 1u : 0u)) != 0)
137 {
139 }
140 }
141}
static readonly bool IsLittleEndian
static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
Definition Buffer.cs:102
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Enc_InvalidByteInEncoding
Definition SR.cs:1818
Definition SR.cs:7
readonly bool _bigEndian
override int GetCharCount(byte[] bytes, int index, int count, bool flush)
override int GetCharCount(byte[] bytes, int index, int count)
override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
UTF16Decoder(bool bigEndian)
override void Convert(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex, int charCount, bool flush, out int bytesUsed, out int charsUsed, out bool completed)