コード例 #1
0
        /// <summary>
        /// Determines whether the end 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 end 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 EndsWith(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.EndsWithCultureHelper(span, value, CultureInfo.CurrentCulture.CompareInfo));

            case StringComparison.CurrentCultureIgnoreCase:
                return(SpanHelpers.EndsWithCultureIgnoreCaseHelper(span, value, CultureInfo.CurrentCulture.CompareInfo));

            case StringComparison.InvariantCulture:
                return(SpanHelpers.EndsWithCultureHelper(span, value, CompareInfo.Invariant));

            case StringComparison.InvariantCultureIgnoreCase:
                return(SpanHelpers.EndsWithCultureIgnoreCaseHelper(span, value, CompareInfo.Invariant));

            case StringComparison.Ordinal:
                return(span.EndsWith(value));    //TODO: Optimize - https://github.com/dotnet/corefx/issues/27487

            case StringComparison.OrdinalIgnoreCase:
                return(SpanHelpers.EndsWithOrdinalIgnoreCaseHelper(span, value));

            default:
                throw new ArgumentException(SR.NotSupported_StringComparison, nameof(comparisonType));
            }
        }