| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Collections.Generic; |
| | | 5 | | |
| | | 6 | | namespace System.Buffers |
| | | 7 | | { |
| | | 8 | | internal sealed class MultiStringIgnoreCaseSearchValuesFallback : StringSearchValuesBase |
| | | 9 | | { |
| | | 10 | | private readonly string[] _values; |
| | | 11 | | |
| | 0 | 12 | | public MultiStringIgnoreCaseSearchValuesFallback(HashSet<string> uniqueValues) : base(uniqueValues) |
| | | 13 | | { |
| | 0 | 14 | | _values = new string[uniqueValues.Count]; |
| | 0 | 15 | | uniqueValues.CopyTo(_values, 0); |
| | 0 | 16 | | } |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// This method is intentionally implemented in a way that checks haystack positions one at a time. |
| | | 20 | | /// See the description in <see cref="SpanHelpers.IndexOfAny{T}(ref T, int, ref T, int)"/>. |
| | | 21 | | /// </summary> |
| | | 22 | | internal override int IndexOfAnyMultiString(ReadOnlySpan<char> span) |
| | | 23 | | { |
| | 0 | 24 | | string[] values = _values; |
| | | 25 | | |
| | 0 | 26 | | for (int i = 0; i < span.Length; i++) |
| | | 27 | | { |
| | 0 | 28 | | ReadOnlySpan<char> remaining = span.Slice(i); |
| | | 29 | | |
| | 0 | 30 | | foreach (string value in values) |
| | | 31 | | { |
| | 0 | 32 | | if (remaining.StartsWith(value, StringComparison.OrdinalIgnoreCase)) |
| | | 33 | | { |
| | 0 | 34 | | return i; |
| | | 35 | | } |
| | | 36 | | } |
| | | 37 | | } |
| | | 38 | | |
| | 0 | 39 | | return -1; |
| | | 40 | | } |
| | | 41 | | } |
| | | 42 | | } |
| | | 43 | | |