Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
InternalDecoderBestFitFallbackBuffer.cs
Go to the documentation of this file.
2
3namespace System.Text;
4
6{
7 internal char cBestFit;
8
9 internal int iCount = -1;
10
11 internal int iSize;
12
14
15 private static object s_InternalSyncObject;
16
17 private static object InternalSyncObject
18 {
19 get
20 {
21 if (s_InternalSyncObject == null)
22 {
23 object value = new object();
24 Interlocked.CompareExchange<object>(ref s_InternalSyncObject, value, (object)null);
25 }
27 }
28 }
29
30 public override int Remaining
31 {
32 get
33 {
34 if (iCount <= 0)
35 {
36 return 0;
37 }
38 return iCount;
39 }
40 }
41
43 {
44 _oFallback = fallback;
45 if (_oFallback.arrayBestFit != null)
46 {
47 return;
48 }
50 {
51 if (_oFallback.arrayBestFit == null)
52 {
53 _oFallback.arrayBestFit = fallback.encoding.GetBestFitBytesToUnicodeData();
54 }
55 }
56 }
57
58 public override bool Fallback(byte[] bytesUnknown, int index)
59 {
60 cBestFit = TryBestFit(bytesUnknown);
61 if (cBestFit == '\0')
62 {
64 }
65 iCount = (iSize = 1);
66 return true;
67 }
68
69 public override char GetNextChar()
70 {
71 iCount--;
72 if (iCount < 0)
73 {
74 return '\0';
75 }
76 if (iCount == int.MaxValue)
77 {
78 iCount = -1;
79 return '\0';
80 }
81 return cBestFit;
82 }
83
84 public override bool MovePrevious()
85 {
86 if (iCount >= 0)
87 {
88 iCount++;
89 }
90 if (iCount >= 0)
91 {
92 return iCount <= iSize;
93 }
94 return false;
95 }
96
97 public override void Reset()
98 {
99 iCount = -1;
100 }
101
102 private char TryBestFit(byte[] bytesCheck)
103 {
104 int num = 0;
105 int num2 = _oFallback.arrayBestFit.Length;
106 if (num2 == 0)
107 {
108 return '\0';
109 }
110 if (bytesCheck.Length == 0 || bytesCheck.Length > 2)
111 {
112 return '\0';
113 }
114 char c = ((bytesCheck.Length != 1) ? ((char)((bytesCheck[0] << 8) + bytesCheck[1])) : ((char)bytesCheck[0]));
115 if (c < _oFallback.arrayBestFit[0] || c > _oFallback.arrayBestFit[num2 - 2])
116 {
117 return '\0';
118 }
119 int num3;
120 while ((num3 = num2 - num) > 6)
121 {
122 int num4 = (num3 / 2 + num) & 0xFFFE;
123 char c2 = _oFallback.arrayBestFit[num4];
124 if (c2 == c)
125 {
126 return _oFallback.arrayBestFit[num4 + 1];
127 }
128 if (c2 < c)
129 {
130 num = num4;
131 }
132 else
133 {
134 num2 = num4;
135 }
136 }
137 for (int num4 = num; num4 < num2; num4 += 2)
138 {
139 if (_oFallback.arrayBestFit[num4] == c)
140 {
141 return _oFallback.arrayBestFit[num4 + 1];
142 }
143 }
144 return '\0';
145 }
146}
InternalDecoderBestFitFallbackBuffer(InternalDecoderBestFitFallback fallback)
static int CompareExchange(ref int location1, int value, int comparand)