Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Compare() [5/10]

static int System.String.Compare ( string? strA,
int indexA,
string? strB,
int indexB,
int length,
StringComparison comparisonType )
inlinestatic

Definition at line 316 of file String.cs.

317 {
319 if ((object)strA == null || (object)strB == null)
320 {
321 if ((object)strA == strB)
322 {
323 return 0;
324 }
325 if ((object)strA != null)
326 {
327 return 1;
328 }
329 return -1;
330 }
331 if (length < 0)
332 {
333 throw new ArgumentOutOfRangeException("length", SR.ArgumentOutOfRange_NegativeLength);
334 }
335 if (indexA < 0 || indexB < 0)
336 {
337 string paramName = ((indexA < 0) ? "indexA" : "indexB");
338 throw new ArgumentOutOfRangeException(paramName, SR.ArgumentOutOfRange_Index);
339 }
340 if (strA.Length - indexA < 0 || strB.Length - indexB < 0)
341 {
342 string paramName2 = ((strA.Length - indexA < 0) ? "indexA" : "indexB");
343 throw new ArgumentOutOfRangeException(paramName2, SR.ArgumentOutOfRange_Index);
344 }
345 if (length == 0 || ((object)strA == strB && indexA == indexB))
346 {
347 return 0;
348 }
349 int num = Math.Min(length, strA.Length - indexA);
350 int num2 = Math.Min(length, strB.Length - indexB);
351 switch (comparisonType)
352 {
353 case StringComparison.CurrentCulture:
354 case StringComparison.CurrentCultureIgnoreCase:
356 case StringComparison.InvariantCulture:
357 case StringComparison.InvariantCultureIgnoreCase:
359 case StringComparison.Ordinal:
361 default:
362 return Ordinal.CompareStringIgnoreCase(ref Unsafe.Add(ref strA.GetRawStringData(), indexA), num, ref Unsafe.Add(ref strB.GetRawStringData(), indexB), num2);
363 }
364 }
static readonly CompareInfo Invariant
static CultureInfo CurrentCulture
static int CompareStringIgnoreCase(ref char strA, int lengthA, ref char strB, int lengthB)
Definition Ordinal.cs:8
static void CheckStringComparison(StringComparison comparisonType)
Definition String.cs:882
static CompareOptions GetCaseCompareOfComparisonCulture(StringComparison comparisonType)
Definition String.cs:890
static int CompareOrdinalHelper(string strA, int indexA, int countA, string strB, int indexB, int countB)
Definition String.cs:116

References System.SR.ArgumentOutOfRange_Index, System.SR.ArgumentOutOfRange_NegativeLength, System.String.CheckStringComparison(), System.String.CompareOrdinalHelper(), System.Globalization.Ordinal.CompareStringIgnoreCase(), System.comparisonType, System.Globalization.CultureInfo.CurrentCulture, System.String.GetCaseCompareOfComparisonCulture(), System.Globalization.CompareInfo.Invariant, System.length, and System.Math.Min().