/// <summary> /// Determines whether the beginning of the <paramref name="span"/> matches the specified <paramref name="value"/> when compared using the specified <paramref name="comparisonType"/> option. /// </summary> /// <param name="span">The source span.</param> /// <param name="value">The sequence to compare to the beginning of 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> public static bool StartsWith(this ReadOnlySpan <char> span, ReadOnlySpan <char> value, StringComparison comparisonType) { if (value.Length == 0) { string.CheckStringComparison(comparisonType); return(true); } switch (comparisonType) { case StringComparison.CurrentCulture: return(SpanHelpers.StartsWithCultureHelper(span, value, CultureInfo.CurrentCulture.CompareInfo)); case StringComparison.CurrentCultureIgnoreCase: return(SpanHelpers.StartsWithCultureIgnoreCaseHelper(span, value, CultureInfo.CurrentCulture.CompareInfo)); case StringComparison.InvariantCulture: return(SpanHelpers.StartsWithCultureHelper(span, value, CompareInfo.Invariant)); case StringComparison.InvariantCultureIgnoreCase: return(SpanHelpers.StartsWithCultureIgnoreCaseHelper(span, value, CompareInfo.Invariant)); case StringComparison.Ordinal: return(span.StartsWith(value)); //TODO: Optimize - https://github.com/dotnet/corefx/issues/27487 case StringComparison.OrdinalIgnoreCase: return(SpanHelpers.StartsWithOrdinalIgnoreCaseHelper(span, value)); default: throw new ArgumentException(SR.NotSupported_StringComparison, nameof(comparisonType)); } }