/// <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 (value.Length == 0) { return(0); } if (span.Length == 0) { return(-1); } if (comparisonType == StringComparison.Ordinal) { return(SpanHelpers.IndexOf( ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(value), value.Length)); } if (GlobalizationMode.Invariant) { return(CompareInfo.InvariantIndexOf(span, value, string.GetCaseCompareOfComparisonCulture(comparisonType) != CompareOptions.None)); } 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(CompareInfo.Invariant.IndexOfOrdinalIgnoreCase(span, value)); } }
// Returns the index of the first occurrence of a specified character in the current instance. // The search starts at startIndex and runs thorough the next count characters. // public int IndexOf(char value) => SpanHelpers.IndexOf(ref _firstChar, value, Length);
public static int IndexOf <T>(this Span <T> span, ReadOnlySpan <T> value) where T : struct, IEquatable <T> { return(SpanHelpers.IndexOf <T>(ref span.DangerousGetPinnableReference(), span.Length, ref value.DangerousGetPinnableReference(), value.Length)); }
public static int IndexOf(this Span <char> span, ReadOnlySpan <char> value) { return(SpanHelpers.IndexOf(ref span.DangerousGetPinnableReference(), span.Length, ref value.DangerousGetPinnableReference(), value.Length)); }
public static int IndexOf(this Span <byte> span, byte value) { return(SpanHelpers.IndexOf(ref span.DangerousGetPinnableReference(), value, span.Length)); }