< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 19
Coverable lines: 19
Total lines: 68
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%110%
GetValues()100%110%
Contains(...)100%110%
ContainsCore(...)100%110%
IndexOfAny(...)100%110%
IndexOfAnyExcept(...)100%110%
LastIndexOfAny(...)100%110%
LastIndexOfAnyExcept(...)100%110%
ContainsAny(...)100%110%
ContainsAnyExcept(...)100%110%
IndexOfAnyMultiString(...)100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Private.CoreLib/src/System/SearchValues/SearchValues.T.cs

#LineLine coverage
 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
 4using System.Diagnostics;
 5using System.Runtime.CompilerServices;
 6
 7namespace System.Buffers
 8{
 9    /// <summary>
 10    /// Provides an immutable, read-only set of values optimized for efficient searching.
 11    /// Instances are created by <see cref="SearchValues.Create(ReadOnlySpan{byte})"/>, <see cref="SearchValues.Create(R
 12    /// <see cref="SearchValues.Create(ReadOnlySpan{string}, StringComparison)"/>.
 13    /// </summary>
 14    /// <typeparam name="T">The type of the values to search for.</typeparam>
 15    /// <remarks>
 16    /// <see cref="SearchValues{T}"/> are optimized for situations where the same set of values is frequently used for s
 17    /// </remarks>
 18    [DebuggerDisplay("{DebuggerDisplay,nq}")]
 19    [DebuggerTypeProxy(typeof(SearchValuesDebugView<>))]
 20    public class SearchValues<T> where T : IEquatable<T>?
 21    {
 22        // Only CoreLib can create derived types
 023        private protected SearchValues() { }
 24
 25        /// <summary>Used by <see cref="DebuggerDisplay"/>s and <see cref="DebuggerTypeProxyAttribute"/>s for <see cref=
 026        internal virtual T[] GetValues() => throw new UnreachableException();
 27
 28        /// <summary>
 29        /// Searches for the specified value and returns true if found. If not found, returns false.
 30        /// </summary>
 31        /// <param name="value">The value to search for.</param>
 32        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 033        public bool Contains(T value) => ContainsCore(value);
 34
 035        internal virtual bool ContainsCore(T value) => throw new UnreachableException();
 36
 037        internal virtual int IndexOfAny(ReadOnlySpan<T> span) => throw new UnreachableException();
 038        internal virtual int IndexOfAnyExcept(ReadOnlySpan<T> span) => throw new UnreachableException();
 039        internal virtual int LastIndexOfAny(ReadOnlySpan<T> span) => throw new UnreachableException();
 040        internal virtual int LastIndexOfAnyExcept(ReadOnlySpan<T> span) => throw new UnreachableException();
 41
 042        internal virtual bool ContainsAny(ReadOnlySpan<T> span) => IndexOfAny(span) >= 0;
 043        internal virtual bool ContainsAnyExcept(ReadOnlySpan<T> span) => IndexOfAnyExcept(span) >= 0;
 44
 45        // This is only implemented and used by SearchValues<string>.
 046        internal virtual int IndexOfAnyMultiString(ReadOnlySpan<char> span) => throw new UnreachableException();
 47
 48        private string DebuggerDisplay
 49        {
 50            get
 51            {
 052                T[] values = GetValues();
 53
 054                string display = $"{GetType().Name}, Count = {values.Length}";
 055                if (values.Length > 0)
 56                {
 057                    display += ", Values = ";
 058                    display += typeof(T) == typeof(char) ?
 059                        "\"" + new string(Unsafe.As<T[], char[]>(ref values)) + "\"" :
 060                        string.Join(",", values);
 61                }
 62
 063                return display;
 64            }
 65        }
 66    }
 67}
 68