Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
BinHexDecoder.cs
Go to the documentation of this file.
1namespace System.Xml;
2
3internal sealed class BinHexDecoder : IncrementalReadDecoder
4{
5 private byte[] _buffer;
6
7 private int _startIndex;
8
9 private int _curIndex;
10
11 private int _endIndex;
12
13 private bool _hasHalfByteCached;
14
15 private byte _cachedHalfByte;
16
17 internal override int DecodedCount => _curIndex - _startIndex;
18
19 internal override bool IsFull => _curIndex == _endIndex;
20
21 internal override int Decode(char[] chars, int startPos, int len)
22 {
23 if (chars == null)
24 {
25 throw new ArgumentNullException("chars");
26 }
27 if (len < 0)
28 {
29 throw new ArgumentOutOfRangeException("len");
30 }
31 if (startPos < 0)
32 {
33 throw new ArgumentOutOfRangeException("startPos");
34 }
35 if (chars.Length - startPos < len)
36 {
37 throw new ArgumentOutOfRangeException("len");
38 }
39 if (len == 0)
40 {
41 return 0;
42 }
45 return charsDecoded;
46 }
47
48 internal override int Decode(string str, int startPos, int len)
49 {
50 if (str == null)
51 {
52 throw new ArgumentNullException("str");
53 }
54 if (len < 0)
55 {
56 throw new ArgumentOutOfRangeException("len");
57 }
58 if (startPos < 0)
59 {
60 throw new ArgumentOutOfRangeException("startPos");
61 }
62 if (str.Length - startPos < len)
63 {
64 throw new ArgumentOutOfRangeException("len");
65 }
66 if (len == 0)
67 {
68 return 0;
69 }
72 return charsDecoded;
73 }
74
75 internal override void Reset()
76 {
77 _hasHalfByteCached = false;
79 }
80
81 internal override void SetNextOutputBuffer(Array buffer, int index, int count)
82 {
83 _buffer = (byte[])buffer;
87 }
88
89 public static byte[] Decode(char[] chars, bool allowOddChars)
90 {
91 if (chars == null)
92 {
93 throw new ArgumentNullException("chars");
94 }
95 int num = chars.Length;
96 if (num == 0)
97 {
98 return Array.Empty<byte>();
99 }
100 byte[] array = new byte[(num + 1) / 2];
101 bool hasHalfByteCached = false;
102 byte cachedHalfByte = 0;
105 {
107 }
108 if (bytesDecoded < array.Length)
109 {
110 Array.Resize(ref array, bytesDecoded);
111 }
112 return array;
113 }
114
116 {
117 int num = 0;
118 int i;
119 for (i = 0; i < chars.Length; i++)
120 {
121 if ((uint)num >= (uint)bytes.Length)
122 {
123 break;
124 }
125 char c = chars[i];
127 if (num2 != 255)
128 {
129 byte b = (byte)num2;
131 {
132 bytes[num++] = (byte)((cachedHalfByte << 4) + b);
133 hasHalfByteCached = false;
134 }
135 else
136 {
138 hasHalfByteCached = true;
139 }
140 }
141 else if (!XmlCharType.IsWhiteSpace(c))
142 {
143 throw new XmlException(System.SR.Xml_InvalidBinHexValue, chars.ToString());
144 }
145 }
146 bytesDecoded = num;
147 charsDecoded = i;
148 }
149}
static int FromChar(int c)
static string Xml_InvalidBinHexValue
Definition SR.cs:112
static string Xml_InvalidBinHexValueOddCount
Definition SR.cs:114
Definition SR.cs:7
static byte[] Decode(char[] chars, bool allowOddChars)
override int Decode(string str, int startPos, int len)
static void Decode(ReadOnlySpan< char > chars, Span< byte > bytes, ref bool hasHalfByteCached, ref byte cachedHalfByte, out int charsDecoded, out int bytesDecoded)
override int Decode(char[] chars, int startPos, int len)
override void SetNextOutputBuffer(Array buffer, int index, int count)
static bool IsWhiteSpace(char ch)