Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlCollation.cs
Go to the documentation of this file.
3using System.IO;
4
6
8public sealed class XmlCollation
9{
10 private struct Options
11 {
12 private int _value;
13
14 public bool UpperFirst
15 {
16 get
17 {
18 return GetFlag(4096);
19 }
20 set
21 {
22 SetFlag(4096, value);
23 }
24 }
25
26 public bool EmptyGreatest => GetFlag(8192);
27
28 public bool DescendingOrder => GetFlag(16384);
29
30 public bool IgnoreCase => GetFlag(1);
31
32 public bool Ordinal => GetFlag(1073741824);
33
35 {
36 get
37 {
38 return (CompareOptions)(_value & -28673);
39 }
40 set
41 {
42 _value = (_value & 0x7000) | (int)value;
43 }
44 }
45
46 public Options(int value)
47 {
48 _value = value;
49 }
50
51 public bool GetFlag(int flag)
52 {
53 return (_value & flag) != 0;
54 }
55
56 public void SetFlag(int flag, bool value)
57 {
58 if (value)
59 {
60 _value |= flag;
61 }
62 else
63 {
64 _value &= ~flag;
65 }
66 }
67
68 public static implicit operator int(Options options)
69 {
70 return options._value;
71 }
72 }
73
74 private readonly CultureInfo _cultInfo;
75
77
78 private readonly CompareOptions _compops;
79
80 private static readonly XmlCollation s_cp = new XmlCollation(CultureInfo.InvariantCulture, new Options(1073741824));
81
83
84 internal bool UpperFirst => _options.UpperFirst;
85
87
89
91 {
92 get
93 {
94 if (_cultInfo == null)
95 {
97 }
98 return _cultInfo;
99 }
100 }
101
108
109 internal static XmlCollation Create(string collationLiteral)
110 {
111 return Create(collationLiteral, throwOnError: true);
112 }
113
114 internal static XmlCollation Create(string collationLiteral, bool throwOnError)
115 {
116 if (collationLiteral == "http://www.w3.org/2004/10/xpath-functions/collation/codepoint")
117 {
118 return CodePointCollation;
119 }
121 Options options = default(Options);
122 Uri result;
123 if (throwOnError)
124 {
125 result = new Uri(collationLiteral);
126 }
127 else if (!Uri.TryCreate(collationLiteral, UriKind.Absolute, out result))
128 {
129 return null;
130 }
131 string components = result.GetComponents(UriComponents.SchemeAndServer | UriComponents.UserInfo, UriFormat.UriEscaped);
132 if (components == "http://collations.microsoft.com")
133 {
134 string text = result.LocalPath.Substring(1);
135 if (text.Length != 0)
136 {
137 try
138 {
140 }
141 catch (ArgumentException)
142 {
143 if (!throwOnError)
144 {
145 return null;
146 }
148 }
149 }
150 }
151 else
152 {
153 if (!result.IsBaseOf(new Uri("http://www.w3.org/2004/10/xpath-functions/collation/codepoint")))
154 {
155 if (!throwOnError)
156 {
157 return null;
158 }
160 }
162 }
163 string query = result.Query;
164 string text2 = null;
165 if (query.Length != 0)
166 {
167 string[] array = query.Substring(1).Split('&');
168 foreach (string text3 in array)
169 {
170 string[] array2 = text3.Split('=');
171 if (array2.Length != 2)
172 {
173 if (!throwOnError)
174 {
175 return null;
176 }
178 }
179 string text4 = array2[0].ToUpperInvariant();
180 string text5 = array2[1].ToUpperInvariant();
181 if (text4 == "SORT")
182 {
183 text2 = text5;
184 continue;
185 }
186 int flag;
187 switch (text4)
188 {
189 case "IGNORECASE":
190 flag = 1;
191 break;
192 case "IGNORENONSPACE":
193 flag = 2;
194 break;
195 case "IGNORESYMBOLS":
196 flag = 4;
197 break;
198 case "IGNOREKANATYPE":
199 flag = 8;
200 break;
201 case "IGNOREWIDTH":
202 flag = 16;
203 break;
204 case "UPPERFIRST":
205 flag = 4096;
206 break;
207 case "EMPTYGREATEST":
208 flag = 8192;
209 break;
210 case "DESCENDINGORDER":
211 flag = 16384;
212 break;
213 default:
214 if (!throwOnError)
215 {
216 return null;
217 }
219 }
220 switch (text5)
221 {
222 case "0":
223 case "FALSE":
224 options.SetFlag(flag, value: false);
225 continue;
226 case "1":
227 case "TRUE":
228 options.SetFlag(flag, value: true);
229 continue;
230 }
231 if (!throwOnError)
232 {
233 return null;
234 }
236 }
237 }
238 if (options.UpperFirst && options.IgnoreCase)
239 {
240 options.UpperFirst = false;
241 }
242 if (options.Ordinal)
243 {
245 options.UpperFirst = false;
246 }
247 if (text2 != null && cultureInfo != null)
248 {
249 string name = cultureInfo.Name;
250 switch (text2)
251 {
252 case "bopo":
253 if (name == "zh-TW")
254 {
255 cultureInfo = new CultureInfo("zh-TW_pronun");
256 }
257 break;
258 case "strk":
259 switch (name)
260 {
261 case "zh-CN":
262 case "zh-HK":
263 case "zh-SG":
264 case "zh-MO":
265 cultureInfo = new CultureInfo(name);
266 break;
267 }
268 break;
269 case "uni":
270 if (name == "ja-JP" || name == "ko-KR")
271 {
272 cultureInfo = new CultureInfo(name);
273 }
274 break;
275 case "phn":
276 if (name == "de-DE")
277 {
278 cultureInfo = new CultureInfo("de-DE_phoneb");
279 }
280 break;
281 case "tech":
282 if (name == "hu-HU")
283 {
284 cultureInfo = new CultureInfo("hu-HU_technl");
285 }
286 break;
287 case "mod":
288 if (name == "ka-GE")
289 {
290 cultureInfo = new CultureInfo("ka-GE_modern");
291 }
292 break;
293 default:
294 if (!throwOnError)
295 {
296 return null;
297 }
299 case "pron":
300 case "dict":
301 case "trad":
302 break;
303 }
304 }
305 return new XmlCollation(cultureInfo, options);
306 }
307
308 public override bool Equals(object obj)
309 {
310 if (this == obj)
311 {
312 return true;
313 }
314 if (obj is XmlCollation xmlCollation && (int)_options == (int)xmlCollation._options)
315 {
316 return object.Equals(_cultInfo, xmlCollation._cultInfo);
317 }
318 return false;
319 }
320
321 public override int GetHashCode()
322 {
323 int num = _options;
324 if (_cultInfo != null)
325 {
326 num ^= _cultInfo.GetHashCode();
327 }
328 return num;
329 }
330
332 {
333 writer.Write((_cultInfo != null) ? _cultInfo.Name : "<!-- LOCALE CURRENT -->");
334 writer.Write(_options);
335 }
336
337 internal XmlCollation(BinaryReader reader)
338 {
339 string text = reader.ReadString();
340 _cultInfo = ((text != "<!-- LOCALE CURRENT -->") ? new CultureInfo(text) : null);
341 _options = new Options(reader.ReadInt32());
343 }
344
345 internal XmlSortKey CreateSortKey(string s)
346 {
348 if (!UpperFirst)
349 {
351 }
352 byte[] keyData = sortKey.KeyData;
353 if (UpperFirst && keyData.Length != 0)
354 {
355 int i;
356 for (i = 0; keyData[i] != 1; i++)
357 {
358 }
359 do
360 {
361 i++;
362 }
363 while (keyData[i] != 1);
364 do
365 {
366 i++;
367 keyData[i] ^= byte.MaxValue;
368 }
369 while (keyData[i] != 254);
370 }
372 }
373}
SortKey GetSortKey(string source, CompareOptions options)
virtual CompareInfo CompareInfo
static CultureInfo CurrentCulture
static CultureInfo InvariantCulture
virtual string ReadString()
virtual int ReadInt32()
static string Coll_UnsupportedOpt
Definition SR.cs:2022
static string Coll_UnsupportedOptVal
Definition SR.cs:2024
static string Coll_Unsupported
Definition SR.cs:2018
static string Coll_UnsupportedLanguage
Definition SR.cs:2020
static string Coll_UnsupportedSortOpt
Definition SR.cs:2026
static string Coll_BadOptFormat
Definition SR.cs:2016
Definition SR.cs:7
static bool TryCreate([NotNullWhen(true)] string? uriString, UriKind uriKind, [NotNullWhen(true)] out Uri? result)
Definition Uri.cs:3793
string Query
Definition Uri.cs:477
string LocalPath
Definition Uri.cs:280
string GetComponents(UriComponents components, UriFormat format)
Definition Uri.cs:3883
bool IsBaseOf(Uri uri)
Definition Uri.cs:4278
static XmlCollation Create(string collationLiteral)
static XmlCollation Create(string collationLiteral, bool throwOnError)
void GetObjectData(BinaryWriter writer)
static readonly XmlCollation s_cp
static XmlCollation CodePointCollation
readonly CompareOptions _compops
XmlCollation(CultureInfo cultureInfo, Options options)
override bool Equals(object obj)
UriKind
Definition UriKind.cs:4
UriFormat
Definition UriFormat.cs:4