/// <summary> /// Reports the zero-based index of the first occurrence of the specified <paramref name="value"/> in the current <paramref name="span"/>. /// <param name="span">The source span.</param> /// <param name="value">The value to seek within the source span.</param> /// <param name="comparisonType">One of the enumeration values that determines how the <paramref name="span"/> and <paramref name="value"/> are compared.</param> /// </summary> public static int IndexOf(this ReadOnlySpan <char> span, ReadOnlySpan <char> value, StringComparison comparisonType) { string.CheckStringComparison(comparisonType); if (comparisonType == StringComparison.Ordinal) { return(SpanHelpers.IndexOf(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(value), value.Length)); } switch (comparisonType) { case StringComparison.CurrentCulture: case StringComparison.CurrentCultureIgnoreCase: return(CultureInfo.CurrentCulture.CompareInfo.IndexOf(span, value, string.GetCaseCompareOfComparisonCulture(comparisonType))); case StringComparison.InvariantCulture: case StringComparison.InvariantCultureIgnoreCase: return(CompareInfo.Invariant.IndexOf(span, value, string.GetCaseCompareOfComparisonCulture(comparisonType))); default: Debug.Assert(comparisonType == StringComparison.OrdinalIgnoreCase); return(Ordinal.IndexOfOrdinalIgnoreCase(span, value)); } }