internal static bool EqualsOrdinalIgnoreCase(this ReadOnlySpan <char> span, ReadOnlySpan <char> value) { if (span.Length != value.Length) { return(false); } if (value.Length == 0) // span.Length == value.Length == 0 { return(true); } return(CompareInfo.EqualsOrdinalIgnoreCase(ref MemoryMarshal.GetReference(span), ref MemoryMarshal.GetReference(value), span.Length)); }
public bool StartsWith(string value, StringComparison comparisonType) { if (value is null) { throw new ArgumentNullException(nameof(value)); } if ((object)this == (object)value) { CheckStringComparison(comparisonType); return(true); } if (value.Length == 0) { CheckStringComparison(comparisonType); return(true); } switch (comparisonType) { case StringComparison.CurrentCulture: case StringComparison.CurrentCultureIgnoreCase: return(CultureInfo.CurrentCulture.CompareInfo.IsPrefix(this, value, GetCaseCompareOfComparisonCulture(comparisonType))); case StringComparison.InvariantCulture: case StringComparison.InvariantCultureIgnoreCase: return(CompareInfo.Invariant.IsPrefix(this, value, GetCaseCompareOfComparisonCulture(comparisonType))); case StringComparison.Ordinal: if (this.Length < value.Length || _firstChar != value._firstChar) { return(false); } return((value.Length == 1) ? true : // First char is the same and thats all there is to compare SpanHelpers.SequenceEqual( ref Unsafe.As <char, byte>(ref this.GetRawStringData()), ref Unsafe.As <char, byte>(ref value.GetRawStringData()), ((nuint)value.Length) * 2)); case StringComparison.OrdinalIgnoreCase: if (this.Length < value.Length) { return(false); } return(CompareInfo.EqualsOrdinalIgnoreCase(ref this.GetRawStringData(), ref value.GetRawStringData(), value.Length)); default: throw new ArgumentException(SR.NotSupported_StringComparison, nameof(comparisonType)); } }
public override bool Equals(string?x, string?y) { if (ReferenceEquals(x, y)) { return(true); } if (x is null || y is null) { return(false); } if (x.Length != y.Length) { return(false); } return(CompareInfo.EqualsOrdinalIgnoreCase(ref x.GetRawStringData(), ref y.GetRawStringData(), x.Length)); }
private static bool EqualsOrdinalIgnoreCase(string strA, string strB) { Debug.Assert(strA.Length == strB.Length); return(CompareInfo.EqualsOrdinalIgnoreCase(ref strA.GetRawStringData(), ref strB.GetRawStringData(), strB.Length)); }
internal static bool StartsWithOrdinalIgnoreCase(this ReadOnlySpan <char> span, ReadOnlySpan <char> value) => value.Length <= span.Length && CompareInfo.EqualsOrdinalIgnoreCase(ref MemoryMarshal.GetReference(span), ref MemoryMarshal.GetReference(value), value.Length);