Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
OrdinalComparer.cs
Go to the documentation of this file.
4
5namespace System;
6
8[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
10{
11 private readonly bool _ignoreCase;
12
13 internal OrdinalComparer(bool ignoreCase)
14 {
15 _ignoreCase = ignoreCase;
16 }
17
18 public override int Compare(string? x, string? y)
19 {
20 if ((object)x == y)
21 {
22 return 0;
23 }
24 if (x == null)
25 {
26 return -1;
27 }
28 if (y == null)
29 {
30 return 1;
31 }
32 if (_ignoreCase)
33 {
34 return string.Compare(x, y, StringComparison.OrdinalIgnoreCase);
35 }
36 return string.CompareOrdinal(x, y);
37 }
38
39 public override bool Equals(string? x, string? y)
40 {
41 if ((object)x == y)
42 {
43 return true;
44 }
45 if (x == null || y == null)
46 {
47 return false;
48 }
49 if (_ignoreCase)
50 {
51 if (x.Length != y.Length)
52 {
53 return false;
54 }
55 return System.Globalization.Ordinal.EqualsIgnoreCase(ref x.GetRawStringData(), ref y.GetRawStringData(), x.Length);
56 }
57 return x.Equals(y);
58 }
59
60 public override int GetHashCode(string obj)
61 {
62 if (obj == null)
63 {
65 }
66 if (_ignoreCase)
67 {
68 return obj.GetHashCodeOrdinalIgnoreCase();
69 }
70 return obj.GetHashCode();
71 }
72
73 public override bool Equals([NotNullWhen(true)] object? obj)
74 {
75 if (!(obj is OrdinalComparer ordinalComparer))
76 {
77 return false;
78 }
79 return _ignoreCase == ordinalComparer._ignoreCase;
80 }
81
82 public override int GetHashCode()
83 {
84 int hashCode = "OrdinalComparer".GetHashCode();
85 if (!_ignoreCase)
86 {
87 return hashCode;
88 }
89 return ~hashCode;
90 }
91
92 private protected override bool IsWellKnownOrdinalComparerCore(out bool ignoreCase)
93 {
94 ignoreCase = _ignoreCase;
95 return true;
96 }
97}
static bool EqualsIgnoreCase(ref char charA, ref char charB, int length)
Definition Ordinal.cs:57
OrdinalComparer(bool ignoreCase)
override bool IsWellKnownOrdinalComparerCore(out bool ignoreCase)
override bool Equals(string? x, string? y)
override int GetHashCode()
override int Compare(string? x, string? y)
override bool Equals([NotNullWhen(true)] object? obj)
override int GetHashCode(string obj)
static void ThrowArgumentNullException(string name)