Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
EncodingTable.cs
Go to the documentation of this file.
4
5namespace System.Text;
6
7internal static class EncodingTable
8{
9 private static readonly int[] s_encodingNameIndices = new int[43]
10 {
11 0, 14, 28, 33, 38, 43, 50, 61, 76, 82,
12 88, 103, 113, 123, 131, 140, 149, 165, 175, 190,
13 192, 198, 203, 210, 227, 244, 261, 278, 289, 291,
14 299, 305, 313, 321, 327, 335, 343, 348, 353, 372,
15 391, 410, 429
16 };
17
18 private static readonly ushort[] s_codePagesByName = new ushort[42]
19 {
20 20127, 20127, 20127, 20127, 28591, 20127, 28591, 65000, 20127, 28591,
21 1200, 28591, 28591, 20127, 20127, 28591, 20127, 28591, 28591, 28591,
22 28591, 1200, 1200, 65000, 65001, 65000, 65001, 1201, 20127, 20127,
23 1200, 1201, 1200, 12000, 12001, 12000, 65000, 65001, 65000, 65001,
24 65000, 65001
25 };
26
27 private static readonly ushort[] s_mappedCodePages = new ushort[8] { 1200, 1201, 12000, 12001, 20127, 28591, 65000, 65001 };
28
29 private static readonly int[] s_uiFamilyCodePages = new int[8] { 1200, 1200, 1200, 1200, 1252, 1252, 1200, 1200 };
30
31 private static readonly int[] s_webNameIndices = new int[9] { 0, 6, 14, 20, 28, 36, 46, 51, 56 };
32
33 private static readonly int[] s_englishNameIndices = new int[9] { 0, 7, 27, 43, 70, 78, 100, 115, 130 };
34
35 private static readonly uint[] s_flags = new uint[8] { 512u, 0u, 0u, 0u, 257u, 771u, 257u, 771u };
36
38
40
41 internal static int GetCodePageFromName(string name)
42 {
43 if (name == null)
44 {
45 throw new ArgumentNullException("name");
46 }
47 object obj = s_nameToCodePage[name];
48 if (obj != null)
49 {
50 return (int)obj;
51 }
52 int num = InternalGetCodePageFromName(name);
53 s_nameToCodePage[name] = num;
54 return num;
55 }
56
57 private static int InternalGetCodePageFromName(string name)
58 {
59 int i = 0;
60 int num = s_encodingNameIndices.Length - 2;
61 ReadOnlySpan<char> strA = name.ToLowerInvariant().AsSpan();
62 while (num - i > 3)
63 {
64 int num2 = (num - i) / 2 + i;
65 int num3 = string.CompareOrdinal(strA, "ansi_x3.4-1968ansi_x3.4-1986asciicp367cp819csasciicsisolatin1csunicode11utf7ibm367ibm819iso-10646-ucs-2iso-8859-1iso-ir-100iso-ir-6iso646-usiso8859-1iso_646.irv:1991iso_8859-1iso_8859-1:1987l1latin1ucs-2unicodeunicode-1-1-utf-7unicode-1-1-utf-8unicode-2-0-utf-7unicode-2-0-utf-8unicodefffeusus-asciiutf-16utf-16beutf-16leutf-32utf-32beutf-32leutf-7utf-8x-unicode-1-1-utf-7x-unicode-1-1-utf-8x-unicode-2-0-utf-7x-unicode-2-0-utf-8".AsSpan(s_encodingNameIndices[num2], s_encodingNameIndices[num2 + 1] - s_encodingNameIndices[num2]));
66 if (num3 == 0)
67 {
68 return s_codePagesByName[num2];
69 }
70 if (num3 < 0)
71 {
72 num = num2;
73 }
74 else
75 {
76 i = num2;
77 }
78 }
79 for (; i <= num; i++)
80 {
81 if (string.CompareOrdinal(strA, "ansi_x3.4-1968ansi_x3.4-1986asciicp367cp819csasciicsisolatin1csunicode11utf7ibm367ibm819iso-10646-ucs-2iso-8859-1iso-ir-100iso-ir-6iso646-usiso8859-1iso_646.irv:1991iso_8859-1iso_8859-1:1987l1latin1ucs-2unicodeunicode-1-1-utf-7unicode-1-1-utf-8unicode-2-0-utf-7unicode-2-0-utf-8unicodefffeusus-asciiutf-16utf-16beutf-16leutf-32utf-32beutf-32leutf-7utf-8x-unicode-1-1-utf-7x-unicode-1-1-utf-8x-unicode-2-0-utf-7x-unicode-2-0-utf-8".AsSpan(s_encodingNameIndices[i], s_encodingNameIndices[i + 1] - s_encodingNameIndices[i])) == 0)
82 {
83 return s_codePagesByName[i];
84 }
85 }
87 }
88
89 internal static EncodingInfo[] GetEncodings()
90 {
91 ushort[] array = s_mappedCodePages;
92 EncodingInfo[] array2 = new EncodingInfo[LocalAppContextSwitches.EnableUnsafeUTF7Encoding ? array.Length : (array.Length - 1)];
93 string text = "utf-16utf-16BEutf-32utf-32BEus-asciiiso-8859-1utf-7utf-8";
95 int num = 0;
96 for (int i = 0; i < array.Length; i++)
97 {
98 int num2 = array[i];
100 {
101 array2[num++] = new EncodingInfo(num2, text[array3[i]..array3[i + 1]], GetDisplayName(num2, i));
102 }
103 }
104 return array2;
105 }
106
108 {
109 ushort[] array = s_mappedCodePages;
110 string text = "utf-16utf-16BEutf-32utf-32BEus-asciiiso-8859-1utf-7utf-8";
111 int[] array2 = s_webNameIndices;
112 for (int i = 0; i < array.Length; i++)
113 {
114 int num = array[i];
116 {
117 encodingInfoList[num] = new EncodingInfo(num, text[array2[i]..array2[i + 1]], GetDisplayName(num, i));
118 }
119 }
121 {
123 }
125 int num2 = 0;
127 {
128 array3[num2++] = encodingInfo.Value;
129 }
130 return array3;
131 }
132
134 {
135 if (s_codePageToCodePageData == null)
136 {
138 }
139 int num;
140 switch (codePage)
141 {
142 case 1200:
143 num = 0;
144 break;
145 case 1201:
146 num = 1;
147 break;
148 case 12000:
149 num = 2;
150 break;
151 case 12001:
152 num = 3;
153 break;
154 case 20127:
155 num = 4;
156 break;
157 case 28591:
158 num = 5;
159 break;
160 case 65000:
161 num = 6;
162 break;
163 case 65001:
164 num = 7;
165 break;
166 default:
167 return null;
168 }
170 if (codePageDataItem == null)
171 {
174 }
175 return codePageDataItem;
176 }
177
179 {
181 string text = "utf-16utf-16BEutf-32utf-32BEus-asciiiso-8859-1utf-7utf-8"[s_webNameIndices[index]..s_webNameIndices[index + 1]];
182 string headerName = text;
183 string bodyName = text;
185 uint flags = s_flags[index];
187 }
188
189 private static string GetDisplayName(int codePage, int englishNameIndex)
190 {
191 string text = SR.GetResourceString("Globalization_cp_" + codePage);
192 if (string.IsNullOrEmpty(text))
193 {
194 text = "UnicodeUnicode (Big-Endian)Unicode (UTF-32)Unicode (UTF-32 Big-Endian)US-ASCIIWestern European (ISO)Unicode (UTF-7)Unicode (UTF-8)"[s_englishNameIndices[englishNameIndex]..s_englishNameIndices[englishNameIndex + 1]];
195 }
196 return text;
197 }
198}
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
static Hashtable Synchronized(Hashtable table)
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string GetResourceString(string resourceKey)
Definition SR.cs:101
static string Argument_EncodingNotSupported
Definition SR.cs:596
Definition SR.cs:7
static StringComparer OrdinalIgnoreCase
static readonly Hashtable s_nameToCodePage
static CodePageDataItem[] s_codePageToCodePageData
static readonly ushort[] s_mappedCodePages
static readonly int[] s_webNameIndices
static CodePageDataItem GetCodePageDataItem(int codePage)
static readonly ushort[] s_codePagesByName
static CodePageDataItem InternalGetCodePageDataItem(int codePage, int index)
static int InternalGetCodePageFromName(string name)
static EncodingInfo[] GetEncodings()
static string GetDisplayName(int codePage, int englishNameIndex)
static readonly int[] s_englishNameIndices
static readonly int[] s_encodingNameIndices
static int GetCodePageFromName(string name)
static int CompareOrdinal(string s1, string s2, int index, int length)
static readonly int[] s_uiFamilyCodePages
static readonly uint[] s_flags
static EncodingInfo[] GetEncodings(Dictionary< int, EncodingInfo > encodingInfoList)
static int CompareExchange(ref int location1, int value, int comparand)