Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Ordinal.cs
Go to the documentation of this file.
3
5
6internal static class Ordinal
7{
8 internal static int CompareStringIgnoreCase(ref char strA, int lengthA, ref char strB, int lengthB)
9 {
10 int num = Math.Min(lengthA, lengthB);
11 int num2 = num;
12 ref char reference = ref strA;
13 ref char reference2 = ref strB;
14 char c = '\u007f';
15 while (num != 0 && reference <= c && reference2 <= c)
16 {
17 if (reference == reference2 || ((reference | 0x20) == (reference2 | 0x20) && (uint)((reference | 0x20) - 97) <= 25u))
18 {
19 num--;
20 reference = ref Unsafe.Add(ref reference, 1);
21 reference2 = ref Unsafe.Add(ref reference2, 1);
22 continue;
23 }
24 int num3 = reference;
25 int num4 = reference2;
26 if ((uint)(reference - 97) <= 25u)
27 {
28 num3 -= 32;
29 }
30 if ((uint)(reference2 - 97) <= 25u)
31 {
32 num4 -= 32;
33 }
34 return num3 - num4;
35 }
36 if (num == 0)
37 {
38 return lengthA - lengthB;
39 }
40 num2 -= num;
41 return CompareStringIgnoreCaseNonAscii(ref reference, lengthA - num2, ref reference2, lengthB - num2);
42 }
43
44 internal static int CompareStringIgnoreCaseNonAscii(ref char strA, int lengthA, ref char strB, int lengthB)
45 {
47 {
48 return InvariantModeCasing.CompareStringIgnoreCase(ref strA, lengthA, ref strB, lengthB);
49 }
51 {
52 return CompareInfo.NlsCompareStringOrdinalIgnoreCase(ref strA, lengthA, ref strB, lengthB);
53 }
54 return OrdinalCasing.CompareStringIgnoreCase(ref strA, lengthA, ref strB, lengthB);
55 }
56
57 internal static bool EqualsIgnoreCase(ref char charA, ref char charB, int length)
58 {
59 IntPtr zero = IntPtr.Zero;
60 while (true)
61 {
62 if ((uint)length >= 4u)
63 {
64 ulong num = Unsafe.ReadUnaligned<ulong>(ref Unsafe.As<char, byte>(ref Unsafe.AddByteOffset(ref charA, zero)));
65 ulong num2 = Unsafe.ReadUnaligned<ulong>(ref Unsafe.As<char, byte>(ref Unsafe.AddByteOffset(ref charB, zero)));
66 ulong num3 = num | num2;
67 if (!Utf16Utility.AllCharsInUInt32AreAscii((uint)((int)num3 | (int)(num3 >> 32))))
68 {
69 break;
70 }
72 {
73 return false;
74 }
75 zero += 8;
76 length -= 4;
77 continue;
78 }
79 if ((uint)length >= 2u)
80 {
81 uint num4 = Unsafe.ReadUnaligned<uint>(ref Unsafe.As<char, byte>(ref Unsafe.AddByteOffset(ref charA, zero)));
82 uint num5 = Unsafe.ReadUnaligned<uint>(ref Unsafe.As<char, byte>(ref Unsafe.AddByteOffset(ref charB, zero)));
83 if (!Utf16Utility.AllCharsInUInt32AreAscii(num4 | num5))
84 {
85 break;
86 }
88 {
89 return false;
90 }
91 zero += 4;
92 length -= 2;
93 }
94 if (length != 0)
95 {
96 uint num6 = Unsafe.AddByteOffset(ref charA, zero);
97 uint num7 = Unsafe.AddByteOffset(ref charB, zero);
98 if ((num6 | num7) > 127)
99 {
100 break;
101 }
102 if (num6 == num7)
103 {
104 return true;
105 }
106 num6 |= 0x20u;
107 if (num6 - 97 > 25)
108 {
109 return false;
110 }
111 if (num6 != (num7 | 0x20))
112 {
113 return false;
114 }
115 return true;
116 }
117 return true;
118 }
119 return CompareStringIgnoreCase(ref Unsafe.AddByteOffset(ref charA, zero), length, ref Unsafe.AddByteOffset(ref charB, zero), length) == 0;
120 }
121
122 internal static int IndexOf(string source, string value, int startIndex, int count, bool ignoreCase)
123 {
124 if (source == null)
125 {
127 }
128 if (value == null)
129 {
131 }
132 if (!source.TryGetSpan(startIndex, count, out var slice))
133 {
134 if ((uint)startIndex > (uint)source.Length)
135 {
137 }
138 else
139 {
141 }
142 }
143 int num = (ignoreCase ? IndexOfOrdinalIgnoreCase(slice, value) : slice.IndexOf(value));
144 if (num < 0)
145 {
146 return num;
147 }
148 return num + startIndex;
149 }
150
152 {
153 if (value.Length == 0)
154 {
155 return 0;
156 }
157 if (value.Length > source.Length)
158 {
159 return -1;
160 }
162 {
164 }
166 {
167 return CompareInfo.NlsIndexOfOrdinalCore(source, value, ignoreCase: true, fromBeginning: true);
168 }
170 }
171
173 {
174 if (value.Length == 0)
175 {
176 return source.Length;
177 }
178 if (value.Length > source.Length)
179 {
180 return -1;
181 }
183 {
185 }
187 {
188 return CompareInfo.NlsIndexOfOrdinalCore(source, value, ignoreCase: true, fromBeginning: false);
189 }
191 }
192
194 {
195 if (source.Overlaps(destination))
196 {
198 }
199 if (destination.Length < source.Length)
200 {
201 return -1;
202 }
204 {
206 return source.Length;
207 }
209 {
210 TextInfo.Invariant.ChangeCaseToUpper(source, destination);
211 return source.Length;
212 }
214 return source.Length;
215 }
216}
static int NlsIndexOfOrdinalCore(ReadOnlySpan< char > source, ReadOnlySpan< char > value, bool ignoreCase, bool fromBeginning)
static unsafe int NlsCompareStringOrdinalIgnoreCase(ref char string1, int count1, ref char string2, int count2)
static unsafe int IndexOfIgnoreCase(ReadOnlySpan< char > source, ReadOnlySpan< char > value)
static unsafe int LastIndexOfIgnoreCase(ReadOnlySpan< char > source, ReadOnlySpan< char > value)
static int CompareStringIgnoreCase(ref char strA, int lengthA, ref char strB, int lengthB)
static void ToUpperOrdinal(ReadOnlySpan< char > source, Span< char > destination)
static unsafe int LastIndexOf(ReadOnlySpan< char > source, ReadOnlySpan< char > value)
static unsafe int IndexOf(ReadOnlySpan< char > source, ReadOnlySpan< char > value)
static int CompareStringIgnoreCase(ref char strA, int lengthA, ref char strB, int lengthB)
static int IndexOf(string source, string value, int startIndex, int count, bool ignoreCase)
Definition Ordinal.cs:122
static int IndexOfOrdinalIgnoreCase(ReadOnlySpan< char > source, ReadOnlySpan< char > value)
Definition Ordinal.cs:151
static bool EqualsIgnoreCase(ref char charA, ref char charB, int length)
Definition Ordinal.cs:57
static int LastIndexOfOrdinalIgnoreCase(ReadOnlySpan< char > source, ReadOnlySpan< char > value)
Definition Ordinal.cs:172
static int ToUpperOrdinal(ReadOnlySpan< char > source, Span< char > destination)
Definition Ordinal.cs:193
static int CompareStringIgnoreCase(ref char strA, int lengthA, ref char strB, int lengthB)
Definition Ordinal.cs:8
static int CompareStringIgnoreCaseNonAscii(ref char strA, int lengthA, ref char strB, int lengthB)
Definition Ordinal.cs:44
static readonly TextInfo Invariant
Definition TextInfo.cs:42
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static string InvalidOperation_SpanOverlappedOperation
Definition SR.cs:1676
Definition SR.cs:7
static bool UInt32OrdinalIgnoreCaseAscii(uint valueA, uint valueB)
static bool AllCharsInUInt32AreAscii(uint value)
static bool UInt64OrdinalIgnoreCaseAscii(ulong valueA, ulong valueB)
static void ThrowArgumentOutOfRangeException(System.ExceptionArgument argument)
static void ThrowArgumentNullException(string name)
static readonly IntPtr Zero
Definition IntPtr.cs:18