Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
InternalEncoderBestFitFallbackBuffer.cs
Go to the documentation of this file.
2
3namespace System.Text;
4
6{
7 private char _cBestFit;
8
10
11 private int _iCount = -1;
12
13 private int _iSize;
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.GetBestFitUnicodeToBytesData();
54 }
55 }
56 }
57
58 public override bool Fallback(char charUnknown, int index)
59 {
60 _iCount = (_iSize = 1);
61 _cBestFit = TryBestFit(charUnknown);
62 if (_cBestFit == '\0')
63 {
64 _cBestFit = '?';
65 }
66 return true;
67 }
68
69 public override bool Fallback(char charUnknownHigh, char charUnknownLow, int index)
70 {
71 if (!char.IsHighSurrogate(charUnknownHigh))
72 {
73 throw new ArgumentOutOfRangeException("charUnknownHigh", System.SR.Format(System.SR.ArgumentOutOfRange_Range, 55296, 56319));
74 }
75 if (!char.IsLowSurrogate(charUnknownLow))
76 {
77 throw new ArgumentOutOfRangeException("charUnknownLow", System.SR.Format(System.SR.ArgumentOutOfRange_Range, 56320, 57343));
78 }
79 _cBestFit = '?';
80 _iCount = (_iSize = 2);
81 return true;
82 }
83
84 public override char GetNextChar()
85 {
86 _iCount--;
87 if (_iCount < 0)
88 {
89 return '\0';
90 }
91 if (_iCount == int.MaxValue)
92 {
93 _iCount = -1;
94 return '\0';
95 }
96 return _cBestFit;
97 }
98
99 public override bool MovePrevious()
100 {
101 if (_iCount >= 0)
102 {
103 _iCount++;
104 }
105 if (_iCount >= 0)
106 {
107 return _iCount <= _iSize;
108 }
109 return false;
110 }
111
112 public override void Reset()
113 {
114 _iCount = -1;
115 }
116
117 private char TryBestFit(char cUnknown)
118 {
119 int num = 0;
120 int num2 = _oFallback.arrayBestFit.Length;
121 int num3;
122 while ((num3 = num2 - num) > 6)
123 {
124 int num4 = (num3 / 2 + num) & 0xFFFE;
125 char c = _oFallback.arrayBestFit[num4];
126 if (c == cUnknown)
127 {
128 return _oFallback.arrayBestFit[num4 + 1];
129 }
130 if (c < cUnknown)
131 {
132 num = num4;
133 }
134 else
135 {
136 num2 = num4;
137 }
138 }
139 for (int num4 = num; num4 < num2; num4 += 2)
140 {
141 if (_oFallback.arrayBestFit[num4] == cUnknown)
142 {
143 return _oFallback.arrayBestFit[num4 + 1];
144 }
145 }
146 return '\0';
147 }
148}
static string ArgumentOutOfRange_Range
Definition SR.cs:1096
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
Definition SR.cs:7
InternalEncoderBestFitFallbackBuffer(InternalEncoderBestFitFallback fallback)
override bool Fallback(char charUnknownHigh, char charUnknownLow, int index)
static int CompareExchange(ref int location1, int value, int comparand)