From 8da1887d45032bb37438b080f1d80a305910b9a0 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Sun, 11 Oct 2026 23:18:14 +1100 Subject: [PATCH 1/2] Fix NullReferenceException in span *AnyExcept with null elements --- api_list.include.md | 48 +++++++++---------- .../Polyfill_Memory_ContainsAnyExcept.cs | 42 +++++++++++----- .../Polyfill_Memory_IndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_LastIndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_ContainsAnyExcept.cs | 40 +++++++++++----- .../Polyfill_Memory_IndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_LastIndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_ContainsAnyExcept.cs | 40 +++++++++++----- .../Polyfill_Memory_IndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_LastIndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_ContainsAnyExcept.cs | 40 +++++++++++----- .../net47/Polyfill_Memory_IndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_LastIndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_ContainsAnyExcept.cs | 40 +++++++++++----- .../Polyfill_Memory_IndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_LastIndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_ContainsAnyExcept.cs | 40 +++++++++++----- .../Polyfill_Memory_IndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_LastIndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_ContainsAnyExcept.cs | 40 +++++++++++----- .../net48/Polyfill_Memory_IndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_LastIndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_ContainsAnyExcept.cs | 40 +++++++++++----- .../Polyfill_Memory_IndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_LastIndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_ContainsAnyExcept.cs | 40 +++++++++++----- .../Polyfill_Memory_IndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_LastIndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_ContainsAnyExcept.cs | 40 +++++++++++----- .../Polyfill_Memory_IndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_LastIndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_ContainsAnyExcept.cs | 40 +++++++++++----- .../Polyfill_Memory_ContainsAnyExcept.cs | 40 +++++++++++----- .../Polyfill_Memory_IndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_LastIndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_ContainsAnyExcept.cs | 40 +++++++++++----- .../Polyfill_Memory_IndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_LastIndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_ContainsAnyExcept.cs | 40 +++++++++++----- .../Polyfill_Memory_IndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_LastIndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_ContainsAnyExcept.cs | 40 +++++++++++----- .../Polyfill_Memory_IndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_LastIndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_ContainsAnyExcept.cs | 40 +++++++++++----- .../Polyfill_Memory_IndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_LastIndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_ContainsAnyExcept.cs | 40 +++++++++++----- .../Polyfill_Memory_IndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_LastIndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_ContainsAnyExcept.cs | 40 +++++++++++----- .../Polyfill_Memory_IndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_LastIndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_ContainsAnyExcept.cs | 40 +++++++++++----- .../Polyfill_Memory_IndexOfAnyExcept.cs | 29 ++++++----- .../Polyfill_Memory_LastIndexOfAnyExcept.cs | 29 ++++++----- .../PolyfillTests_Memory_ContainsAnyExcept.cs | 42 ++++++++++++++++ .../PolyfillTests_Memory_IndexOfAnyExcept.cs | 36 ++++++++++++++ ...lyfillTests_Memory_LastIndexOfAnyExcept.cs | 36 ++++++++++++++ 59 files changed, 1284 insertions(+), 684 deletions(-) diff --git a/api_list.include.md b/api_list.include.md index f8bb02f0..6f1374f2 100644 --- a/api_list.include.md +++ b/api_list.include.md @@ -1057,10 +1057,10 @@ * `int CommonPrefixLength(ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.commonprefixlength?view=net-11.0#system-memoryextensions-commonprefixlength-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) * `bool Contains(T, IEqualityComparer?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.contains?view=net-11.0#system-memoryextensions-contains-1(system-readonlyspan((-0))-0-system-collections-generic-iequalitycomparer((-0)))) * `bool Contains(T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.contains?view=net-11.0#system-memoryextensions-contains-1(system-readonlyspan((-0))-0)) - * `bool ContainsAnyExcept(ReadOnlySpan) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) - * `bool ContainsAnyExcept(T, T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-readonlyspan((-0))-0-0-0)) - * `bool ContainsAnyExcept(T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-readonlyspan((-0))-0-0)) - * `bool ContainsAnyExcept(T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-readonlyspan((-0))-0)) + * `bool ContainsAnyExcept(ReadOnlySpan) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) + * `bool ContainsAnyExcept(T, T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-readonlyspan((-0))-0-0-0)) + * `bool ContainsAnyExcept(T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-readonlyspan((-0))-0-0)) + * `bool ContainsAnyExcept(T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-readonlyspan((-0))-0)) * `bool ContainsAnyExceptInRange(T, T) where T : IComparable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexceptinrange?view=net-11.0#system-memoryextensions-containsanyexceptinrange-1(system-readonlyspan((-0))-0-0)) * `bool ContainsAnyInRange(T, T) where T : IComparable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyinrange?view=net-11.0#system-memoryextensions-containsanyinrange-1(system-readonlyspan((-0))-0-0)) * `int CountAny(ReadOnlySpan, IEqualityComparer?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.countany?view=net-11.0#system-memoryextensions-countany-1(system-readonlyspan((-0))-system-readonlyspan((-0))-system-collections-generic-iequalitycomparer((-0)))) @@ -1069,14 +1069,14 @@ * `bool EndsWith(T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.endswith?view=net-11.0#system-memoryextensions-endswith-1(system-readonlyspan((-0))-0)) * `int IndexOf(T, IEqualityComparer?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexof?view=net-11.0#system-memoryextensions-indexof-1(system-readonlyspan((-0))-0-system-collections-generic-iequalitycomparer((-0)))) * `int IndexOfAny(ReadOnlySpan, IEqualityComparer?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.countany?view=net-11.0#system-memoryextensions-countany-1(system-readonlyspan((-0))-system-buffers-searchvalues((-0)))) - * `int IndexOfAnyExcept(ReadOnlySpan) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) - * `int IndexOfAnyExcept(T, T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-readonlyspan((-0))-0-0-0)) - * `int IndexOfAnyExcept(T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-readonlyspan((-0))-0-0)) - * `int IndexOfAnyExcept(T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-readonlyspan((-0))-0)) - * `int LastIndexOfAnyExcept(ReadOnlySpan) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) - * `int LastIndexOfAnyExcept(T, T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-readonlyspan((-0))-0-0-0)) - * `int LastIndexOfAnyExcept(T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-readonlyspan((-0))-0-0)) - * `int LastIndexOfAnyExcept(T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-readonlyspan((-0))-0)) + * `int IndexOfAnyExcept(ReadOnlySpan) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) + * `int IndexOfAnyExcept(T, T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-readonlyspan((-0))-0-0-0)) + * `int IndexOfAnyExcept(T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-readonlyspan((-0))-0-0)) + * `int IndexOfAnyExcept(T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-readonlyspan((-0))-0)) + * `int LastIndexOfAnyExcept(ReadOnlySpan) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) + * `int LastIndexOfAnyExcept(T, T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-readonlyspan((-0))-0-0-0)) + * `int LastIndexOfAnyExcept(T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-readonlyspan((-0))-0-0)) + * `int LastIndexOfAnyExcept(T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-readonlyspan((-0))-0)) * `T? Max(IComparer?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.max?view=net-11.0#system-memoryextensions-max-1(system-readonlyspan((-0))-system-collections-generic-icomparer((-0)))) * `T? Max()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.max?view=net-11.0#system-memoryextensions-max-1(system-readonlyspan((-0)))) * `T? Min(IComparer?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.min?view=net-11.0#system-memoryextensions-min-1(system-readonlyspan((-0))-system-collections-generic-icomparer((-0)))) @@ -1235,20 +1235,20 @@ * `int CommonPrefixLength(ReadOnlySpan, IEqualityComparer?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.commonprefixlength?view=net-11.0#system-memoryextensions-commonprefixlength-1(system-span((-0))-system-readonlyspan((-0))-system-collections-generic-iequalitycomparer((-0)))) * `int CommonPrefixLength(ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.commonprefixlength?view=net-11.0#system-memoryextensions-commonprefixlength-1(system-span((-0))-system-readonlyspan((-0)))) * `bool Contains(T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.contains?view=net-11.0#system-memoryextensions-contains-1(system-span((-0))-0)) - * `bool ContainsAnyExcept(ReadOnlySpan) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-span((-0))-system-readonlyspan((-0)))) - * `bool ContainsAnyExcept(T, T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-span((-0))-0-0-0)) - * `bool ContainsAnyExcept(T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-span((-0))-0-0)) - * `bool ContainsAnyExcept(T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-span((-0))-0)) + * `bool ContainsAnyExcept(ReadOnlySpan) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-span((-0))-system-readonlyspan((-0)))) + * `bool ContainsAnyExcept(T, T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-span((-0))-0-0-0)) + * `bool ContainsAnyExcept(T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-span((-0))-0-0)) + * `bool ContainsAnyExcept(T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-span((-0))-0)) * `bool ContainsAnyExceptInRange(T, T) where T : IComparable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexceptinrange?view=net-11.0#system-memoryextensions-containsanyexceptinrange-1(system-span((-0))-0-0)) * `bool ContainsAnyInRange(T, T) where T : IComparable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyinrange?view=net-11.0#system-memoryextensions-containsanyinrange-1(system-span((-0))-0-0)) - * `int IndexOfAnyExcept(ReadOnlySpan) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-span((-0))-system-readonlyspan((-0)))) - * `int IndexOfAnyExcept(T, T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-span((-0))-0-0-0)) - * `int IndexOfAnyExcept(T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-span((-0))-0-0)) - * `int IndexOfAnyExcept(T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-span((-0))-0)) - * `int LastIndexOfAnyExcept(ReadOnlySpan) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-span((-0))-system-readonlyspan((-0)))) - * `int LastIndexOfAnyExcept(T, T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-span((-0))-0-0-0)) - * `int LastIndexOfAnyExcept(T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-span((-0))-0-0)) - * `int LastIndexOfAnyExcept(T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-span((-0))-0)) + * `int IndexOfAnyExcept(ReadOnlySpan) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-span((-0))-system-readonlyspan((-0)))) + * `int IndexOfAnyExcept(T, T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-span((-0))-0-0-0)) + * `int IndexOfAnyExcept(T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-span((-0))-0-0)) + * `int IndexOfAnyExcept(T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-span((-0))-0)) + * `int LastIndexOfAnyExcept(ReadOnlySpan) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-span((-0))-system-readonlyspan((-0)))) + * `int LastIndexOfAnyExcept(T, T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-span((-0))-0-0-0)) + * `int LastIndexOfAnyExcept(T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-span((-0))-0-0)) + * `int LastIndexOfAnyExcept(T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-span((-0))-0)) * `void Sort(Comparison)` * `void Sort() where T : IComparable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.sort?view=net-11.0#system-memoryextensions-sort-1(system-span((-0)))) diff --git a/src/Polyfill/Polyfill_Memory_ContainsAnyExcept.cs b/src/Polyfill/Polyfill_Memory_ContainsAnyExcept.cs index 6b1d135c..9c7e462b 100644 --- a/src/Polyfill/Polyfill_Memory_ContainsAnyExcept.cs +++ b/src/Polyfill/Polyfill_Memory_ContainsAnyExcept.cs @@ -3,17 +3,19 @@ namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for any value other than the specified . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-readonlyspan((-0))-0) public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return true; } @@ -25,12 +27,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) /// Searches for any value other than or . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-readonlyspan((-0))-0-0) public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return true; } @@ -42,12 +45,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v /// Searches for any value other than , , or . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-readonlyspan((-0))-0-0-0) public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return true; } @@ -59,11 +63,12 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v /// Searches for any value other than the specified . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-readonlyspan((-0))-system-readonlyspan((-0))) public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return true; } @@ -75,26 +80,39 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan< /// Searches for any value other than the specified . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-span((-0))-0) public static bool ContainsAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value); /// Searches for any value other than or . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-span((-0))-0-0) public static bool ContainsAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for any value other than , , or . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-span((-0))-0-0-0) public static bool ContainsAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for any value other than the specified . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-span((-0))-system-readonlyspan((-0))) public static bool ContainsAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, values); + + static bool ContainsValue(ReadOnlySpan values, T value, EqualityComparer comparer) + { + for (var i = 0; i < values.Length; i++) + { + if (comparer.Equals(values[i], value)) + { + return true; + } + } + + return false; + } } #endif diff --git a/src/Polyfill/Polyfill_Memory_IndexOfAnyExcept.cs b/src/Polyfill/Polyfill_Memory_IndexOfAnyExcept.cs index a4d9779b..ee3bd577 100644 --- a/src/Polyfill/Polyfill_Memory_IndexOfAnyExcept.cs +++ b/src/Polyfill/Polyfill_Memory_IndexOfAnyExcept.cs @@ -3,17 +3,19 @@ namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for the first index of any value other than the specified . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-readonlyspan((-0))-0) public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -25,12 +27,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) /// Searches for the first index of any value other than or . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-readonlyspan((-0))-0-0) public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -42,12 +45,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val /// Searches for the first index of any value other than , , or . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-readonlyspan((-0))-0-0-0) public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -59,11 +63,12 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val /// Searches for the first index of any value other than the specified . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-readonlyspan((-0))-system-readonlyspan((-0))) public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -75,25 +80,25 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan /// Searches for the first index of any value other than the specified . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-span((-0))-0) public static int IndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches for the first index of any value other than or . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-span((-0))-0-0) public static int IndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for the first index of any value other than , , or . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-span((-0))-0-0-0) public static int IndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for the first index of any value other than the specified . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-span((-0))-system-readonlyspan((-0))) public static int IndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, values); } diff --git a/src/Polyfill/Polyfill_Memory_LastIndexOfAnyExcept.cs b/src/Polyfill/Polyfill_Memory_LastIndexOfAnyExcept.cs index 0e0f8d9e..18ead43c 100644 --- a/src/Polyfill/Polyfill_Memory_LastIndexOfAnyExcept.cs +++ b/src/Polyfill/Polyfill_Memory_LastIndexOfAnyExcept.cs @@ -3,17 +3,19 @@ namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches from the end for the first index of any value other than the specified . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-readonlyspan((-0))-0) public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -25,12 +27,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) /// Searches from the end for the first index of any value other than or . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-readonlyspan((-0))-0-0) public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -42,12 +45,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T /// Searches from the end for the first index of any value other than , , or . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-readonlyspan((-0))-0-0-0) public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -59,11 +63,12 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T /// Searches from the end for the first index of any value other than the specified . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-readonlyspan((-0))-system-readonlyspan((-0))) public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -75,25 +80,25 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpa /// Searches from the end for the first index of any value other than the specified . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-span((-0))-0) public static int LastIndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches from the end for the first index of any value other than or . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-span((-0))-0-0) public static int LastIndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches from the end for the first index of any value other than , , or . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-span((-0))-0-0-0) public static int LastIndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches from the end for the first index of any value other than the specified . //Link: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-span((-0))-system-readonlyspan((-0))) public static int LastIndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, values); } diff --git a/src/Split/net461/Polyfill_Memory_ContainsAnyExcept.cs b/src/Split/net461/Polyfill_Memory_ContainsAnyExcept.cs index cda3e7d0..6b67b6cf 100644 --- a/src/Split/net461/Polyfill_Memory_ContainsAnyExcept.cs +++ b/src/Split/net461/Polyfill_Memory_ContainsAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return true; } @@ -20,12 +22,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) } /// Searches for any value other than or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return true; } @@ -34,12 +37,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return true; } @@ -48,11 +52,12 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return true; } @@ -61,19 +66,30 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan< } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value); /// Searches for any value other than or . public static bool ContainsAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, values); + static bool ContainsValue(ReadOnlySpan values, T value, EqualityComparer comparer) + { + for (var i = 0; i < values.Length; i++) + { + if (comparer.Equals(values[i], value)) + { + return true; + } + } + return false; + } } #endif diff --git a/src/Split/net461/Polyfill_Memory_IndexOfAnyExcept.cs b/src/Split/net461/Polyfill_Memory_IndexOfAnyExcept.cs index d49c931b..565244a8 100644 --- a/src/Split/net461/Polyfill_Memory_IndexOfAnyExcept.cs +++ b/src/Split/net461/Polyfill_Memory_IndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/net461/Polyfill_Memory_LastIndexOfAnyExcept.cs b/src/Split/net461/Polyfill_Memory_LastIndexOfAnyExcept.cs index 591af601..06e3f381 100644 --- a/src/Split/net461/Polyfill_Memory_LastIndexOfAnyExcept.cs +++ b/src/Split/net461/Polyfill_Memory_LastIndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpa } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/net462/Polyfill_Memory_ContainsAnyExcept.cs b/src/Split/net462/Polyfill_Memory_ContainsAnyExcept.cs index cda3e7d0..6b67b6cf 100644 --- a/src/Split/net462/Polyfill_Memory_ContainsAnyExcept.cs +++ b/src/Split/net462/Polyfill_Memory_ContainsAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return true; } @@ -20,12 +22,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) } /// Searches for any value other than or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return true; } @@ -34,12 +37,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return true; } @@ -48,11 +52,12 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return true; } @@ -61,19 +66,30 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan< } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value); /// Searches for any value other than or . public static bool ContainsAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, values); + static bool ContainsValue(ReadOnlySpan values, T value, EqualityComparer comparer) + { + for (var i = 0; i < values.Length; i++) + { + if (comparer.Equals(values[i], value)) + { + return true; + } + } + return false; + } } #endif diff --git a/src/Split/net462/Polyfill_Memory_IndexOfAnyExcept.cs b/src/Split/net462/Polyfill_Memory_IndexOfAnyExcept.cs index d49c931b..565244a8 100644 --- a/src/Split/net462/Polyfill_Memory_IndexOfAnyExcept.cs +++ b/src/Split/net462/Polyfill_Memory_IndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/net462/Polyfill_Memory_LastIndexOfAnyExcept.cs b/src/Split/net462/Polyfill_Memory_LastIndexOfAnyExcept.cs index 591af601..06e3f381 100644 --- a/src/Split/net462/Polyfill_Memory_LastIndexOfAnyExcept.cs +++ b/src/Split/net462/Polyfill_Memory_LastIndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpa } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/net47/Polyfill_Memory_ContainsAnyExcept.cs b/src/Split/net47/Polyfill_Memory_ContainsAnyExcept.cs index cda3e7d0..6b67b6cf 100644 --- a/src/Split/net47/Polyfill_Memory_ContainsAnyExcept.cs +++ b/src/Split/net47/Polyfill_Memory_ContainsAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return true; } @@ -20,12 +22,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) } /// Searches for any value other than or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return true; } @@ -34,12 +37,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return true; } @@ -48,11 +52,12 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return true; } @@ -61,19 +66,30 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan< } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value); /// Searches for any value other than or . public static bool ContainsAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, values); + static bool ContainsValue(ReadOnlySpan values, T value, EqualityComparer comparer) + { + for (var i = 0; i < values.Length; i++) + { + if (comparer.Equals(values[i], value)) + { + return true; + } + } + return false; + } } #endif diff --git a/src/Split/net47/Polyfill_Memory_IndexOfAnyExcept.cs b/src/Split/net47/Polyfill_Memory_IndexOfAnyExcept.cs index d49c931b..565244a8 100644 --- a/src/Split/net47/Polyfill_Memory_IndexOfAnyExcept.cs +++ b/src/Split/net47/Polyfill_Memory_IndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/net47/Polyfill_Memory_LastIndexOfAnyExcept.cs b/src/Split/net47/Polyfill_Memory_LastIndexOfAnyExcept.cs index 591af601..06e3f381 100644 --- a/src/Split/net47/Polyfill_Memory_LastIndexOfAnyExcept.cs +++ b/src/Split/net47/Polyfill_Memory_LastIndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpa } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/net471/Polyfill_Memory_ContainsAnyExcept.cs b/src/Split/net471/Polyfill_Memory_ContainsAnyExcept.cs index cda3e7d0..6b67b6cf 100644 --- a/src/Split/net471/Polyfill_Memory_ContainsAnyExcept.cs +++ b/src/Split/net471/Polyfill_Memory_ContainsAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return true; } @@ -20,12 +22,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) } /// Searches for any value other than or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return true; } @@ -34,12 +37,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return true; } @@ -48,11 +52,12 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return true; } @@ -61,19 +66,30 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan< } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value); /// Searches for any value other than or . public static bool ContainsAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, values); + static bool ContainsValue(ReadOnlySpan values, T value, EqualityComparer comparer) + { + for (var i = 0; i < values.Length; i++) + { + if (comparer.Equals(values[i], value)) + { + return true; + } + } + return false; + } } #endif diff --git a/src/Split/net471/Polyfill_Memory_IndexOfAnyExcept.cs b/src/Split/net471/Polyfill_Memory_IndexOfAnyExcept.cs index d49c931b..565244a8 100644 --- a/src/Split/net471/Polyfill_Memory_IndexOfAnyExcept.cs +++ b/src/Split/net471/Polyfill_Memory_IndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/net471/Polyfill_Memory_LastIndexOfAnyExcept.cs b/src/Split/net471/Polyfill_Memory_LastIndexOfAnyExcept.cs index 591af601..06e3f381 100644 --- a/src/Split/net471/Polyfill_Memory_LastIndexOfAnyExcept.cs +++ b/src/Split/net471/Polyfill_Memory_LastIndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpa } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/net472/Polyfill_Memory_ContainsAnyExcept.cs b/src/Split/net472/Polyfill_Memory_ContainsAnyExcept.cs index cda3e7d0..6b67b6cf 100644 --- a/src/Split/net472/Polyfill_Memory_ContainsAnyExcept.cs +++ b/src/Split/net472/Polyfill_Memory_ContainsAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return true; } @@ -20,12 +22,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) } /// Searches for any value other than or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return true; } @@ -34,12 +37,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return true; } @@ -48,11 +52,12 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return true; } @@ -61,19 +66,30 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan< } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value); /// Searches for any value other than or . public static bool ContainsAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, values); + static bool ContainsValue(ReadOnlySpan values, T value, EqualityComparer comparer) + { + for (var i = 0; i < values.Length; i++) + { + if (comparer.Equals(values[i], value)) + { + return true; + } + } + return false; + } } #endif diff --git a/src/Split/net472/Polyfill_Memory_IndexOfAnyExcept.cs b/src/Split/net472/Polyfill_Memory_IndexOfAnyExcept.cs index d49c931b..565244a8 100644 --- a/src/Split/net472/Polyfill_Memory_IndexOfAnyExcept.cs +++ b/src/Split/net472/Polyfill_Memory_IndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/net472/Polyfill_Memory_LastIndexOfAnyExcept.cs b/src/Split/net472/Polyfill_Memory_LastIndexOfAnyExcept.cs index 591af601..06e3f381 100644 --- a/src/Split/net472/Polyfill_Memory_LastIndexOfAnyExcept.cs +++ b/src/Split/net472/Polyfill_Memory_LastIndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpa } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/net48/Polyfill_Memory_ContainsAnyExcept.cs b/src/Split/net48/Polyfill_Memory_ContainsAnyExcept.cs index cda3e7d0..6b67b6cf 100644 --- a/src/Split/net48/Polyfill_Memory_ContainsAnyExcept.cs +++ b/src/Split/net48/Polyfill_Memory_ContainsAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return true; } @@ -20,12 +22,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) } /// Searches for any value other than or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return true; } @@ -34,12 +37,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return true; } @@ -48,11 +52,12 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return true; } @@ -61,19 +66,30 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan< } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value); /// Searches for any value other than or . public static bool ContainsAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, values); + static bool ContainsValue(ReadOnlySpan values, T value, EqualityComparer comparer) + { + for (var i = 0; i < values.Length; i++) + { + if (comparer.Equals(values[i], value)) + { + return true; + } + } + return false; + } } #endif diff --git a/src/Split/net48/Polyfill_Memory_IndexOfAnyExcept.cs b/src/Split/net48/Polyfill_Memory_IndexOfAnyExcept.cs index d49c931b..565244a8 100644 --- a/src/Split/net48/Polyfill_Memory_IndexOfAnyExcept.cs +++ b/src/Split/net48/Polyfill_Memory_IndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/net48/Polyfill_Memory_LastIndexOfAnyExcept.cs b/src/Split/net48/Polyfill_Memory_LastIndexOfAnyExcept.cs index 591af601..06e3f381 100644 --- a/src/Split/net48/Polyfill_Memory_LastIndexOfAnyExcept.cs +++ b/src/Split/net48/Polyfill_Memory_LastIndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpa } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/net481/Polyfill_Memory_ContainsAnyExcept.cs b/src/Split/net481/Polyfill_Memory_ContainsAnyExcept.cs index cda3e7d0..6b67b6cf 100644 --- a/src/Split/net481/Polyfill_Memory_ContainsAnyExcept.cs +++ b/src/Split/net481/Polyfill_Memory_ContainsAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return true; } @@ -20,12 +22,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) } /// Searches for any value other than or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return true; } @@ -34,12 +37,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return true; } @@ -48,11 +52,12 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return true; } @@ -61,19 +66,30 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan< } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value); /// Searches for any value other than or . public static bool ContainsAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, values); + static bool ContainsValue(ReadOnlySpan values, T value, EqualityComparer comparer) + { + for (var i = 0; i < values.Length; i++) + { + if (comparer.Equals(values[i], value)) + { + return true; + } + } + return false; + } } #endif diff --git a/src/Split/net481/Polyfill_Memory_IndexOfAnyExcept.cs b/src/Split/net481/Polyfill_Memory_IndexOfAnyExcept.cs index d49c931b..565244a8 100644 --- a/src/Split/net481/Polyfill_Memory_IndexOfAnyExcept.cs +++ b/src/Split/net481/Polyfill_Memory_IndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/net481/Polyfill_Memory_LastIndexOfAnyExcept.cs b/src/Split/net481/Polyfill_Memory_LastIndexOfAnyExcept.cs index 591af601..06e3f381 100644 --- a/src/Split/net481/Polyfill_Memory_LastIndexOfAnyExcept.cs +++ b/src/Split/net481/Polyfill_Memory_LastIndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpa } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/net5.0/Polyfill_Memory_ContainsAnyExcept.cs b/src/Split/net5.0/Polyfill_Memory_ContainsAnyExcept.cs index cda3e7d0..6b67b6cf 100644 --- a/src/Split/net5.0/Polyfill_Memory_ContainsAnyExcept.cs +++ b/src/Split/net5.0/Polyfill_Memory_ContainsAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return true; } @@ -20,12 +22,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) } /// Searches for any value other than or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return true; } @@ -34,12 +37,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return true; } @@ -48,11 +52,12 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return true; } @@ -61,19 +66,30 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan< } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value); /// Searches for any value other than or . public static bool ContainsAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, values); + static bool ContainsValue(ReadOnlySpan values, T value, EqualityComparer comparer) + { + for (var i = 0; i < values.Length; i++) + { + if (comparer.Equals(values[i], value)) + { + return true; + } + } + return false; + } } #endif diff --git a/src/Split/net5.0/Polyfill_Memory_IndexOfAnyExcept.cs b/src/Split/net5.0/Polyfill_Memory_IndexOfAnyExcept.cs index d49c931b..565244a8 100644 --- a/src/Split/net5.0/Polyfill_Memory_IndexOfAnyExcept.cs +++ b/src/Split/net5.0/Polyfill_Memory_IndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/net5.0/Polyfill_Memory_LastIndexOfAnyExcept.cs b/src/Split/net5.0/Polyfill_Memory_LastIndexOfAnyExcept.cs index 591af601..06e3f381 100644 --- a/src/Split/net5.0/Polyfill_Memory_LastIndexOfAnyExcept.cs +++ b/src/Split/net5.0/Polyfill_Memory_LastIndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpa } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/net6.0/Polyfill_Memory_ContainsAnyExcept.cs b/src/Split/net6.0/Polyfill_Memory_ContainsAnyExcept.cs index cda3e7d0..6b67b6cf 100644 --- a/src/Split/net6.0/Polyfill_Memory_ContainsAnyExcept.cs +++ b/src/Split/net6.0/Polyfill_Memory_ContainsAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return true; } @@ -20,12 +22,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) } /// Searches for any value other than or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return true; } @@ -34,12 +37,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return true; } @@ -48,11 +52,12 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return true; } @@ -61,19 +66,30 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan< } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value); /// Searches for any value other than or . public static bool ContainsAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, values); + static bool ContainsValue(ReadOnlySpan values, T value, EqualityComparer comparer) + { + for (var i = 0; i < values.Length; i++) + { + if (comparer.Equals(values[i], value)) + { + return true; + } + } + return false; + } } #endif diff --git a/src/Split/net6.0/Polyfill_Memory_IndexOfAnyExcept.cs b/src/Split/net6.0/Polyfill_Memory_IndexOfAnyExcept.cs index d49c931b..565244a8 100644 --- a/src/Split/net6.0/Polyfill_Memory_IndexOfAnyExcept.cs +++ b/src/Split/net6.0/Polyfill_Memory_IndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/net6.0/Polyfill_Memory_LastIndexOfAnyExcept.cs b/src/Split/net6.0/Polyfill_Memory_LastIndexOfAnyExcept.cs index 591af601..06e3f381 100644 --- a/src/Split/net6.0/Polyfill_Memory_LastIndexOfAnyExcept.cs +++ b/src/Split/net6.0/Polyfill_Memory_LastIndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpa } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/net7.0/Polyfill_Memory_ContainsAnyExcept.cs b/src/Split/net7.0/Polyfill_Memory_ContainsAnyExcept.cs index cda3e7d0..6b67b6cf 100644 --- a/src/Split/net7.0/Polyfill_Memory_ContainsAnyExcept.cs +++ b/src/Split/net7.0/Polyfill_Memory_ContainsAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return true; } @@ -20,12 +22,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) } /// Searches for any value other than or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return true; } @@ -34,12 +37,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return true; } @@ -48,11 +52,12 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return true; } @@ -61,19 +66,30 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan< } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value); /// Searches for any value other than or . public static bool ContainsAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, values); + static bool ContainsValue(ReadOnlySpan values, T value, EqualityComparer comparer) + { + for (var i = 0; i < values.Length; i++) + { + if (comparer.Equals(values[i], value)) + { + return true; + } + } + return false; + } } #endif diff --git a/src/Split/netcoreapp2.0/Polyfill_Memory_ContainsAnyExcept.cs b/src/Split/netcoreapp2.0/Polyfill_Memory_ContainsAnyExcept.cs index cda3e7d0..6b67b6cf 100644 --- a/src/Split/netcoreapp2.0/Polyfill_Memory_ContainsAnyExcept.cs +++ b/src/Split/netcoreapp2.0/Polyfill_Memory_ContainsAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return true; } @@ -20,12 +22,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) } /// Searches for any value other than or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return true; } @@ -34,12 +37,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return true; } @@ -48,11 +52,12 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return true; } @@ -61,19 +66,30 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan< } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value); /// Searches for any value other than or . public static bool ContainsAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, values); + static bool ContainsValue(ReadOnlySpan values, T value, EqualityComparer comparer) + { + for (var i = 0; i < values.Length; i++) + { + if (comparer.Equals(values[i], value)) + { + return true; + } + } + return false; + } } #endif diff --git a/src/Split/netcoreapp2.0/Polyfill_Memory_IndexOfAnyExcept.cs b/src/Split/netcoreapp2.0/Polyfill_Memory_IndexOfAnyExcept.cs index d49c931b..565244a8 100644 --- a/src/Split/netcoreapp2.0/Polyfill_Memory_IndexOfAnyExcept.cs +++ b/src/Split/netcoreapp2.0/Polyfill_Memory_IndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/netcoreapp2.0/Polyfill_Memory_LastIndexOfAnyExcept.cs b/src/Split/netcoreapp2.0/Polyfill_Memory_LastIndexOfAnyExcept.cs index 591af601..06e3f381 100644 --- a/src/Split/netcoreapp2.0/Polyfill_Memory_LastIndexOfAnyExcept.cs +++ b/src/Split/netcoreapp2.0/Polyfill_Memory_LastIndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpa } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/netcoreapp2.1/Polyfill_Memory_ContainsAnyExcept.cs b/src/Split/netcoreapp2.1/Polyfill_Memory_ContainsAnyExcept.cs index cda3e7d0..6b67b6cf 100644 --- a/src/Split/netcoreapp2.1/Polyfill_Memory_ContainsAnyExcept.cs +++ b/src/Split/netcoreapp2.1/Polyfill_Memory_ContainsAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return true; } @@ -20,12 +22,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) } /// Searches for any value other than or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return true; } @@ -34,12 +37,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return true; } @@ -48,11 +52,12 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return true; } @@ -61,19 +66,30 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan< } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value); /// Searches for any value other than or . public static bool ContainsAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, values); + static bool ContainsValue(ReadOnlySpan values, T value, EqualityComparer comparer) + { + for (var i = 0; i < values.Length; i++) + { + if (comparer.Equals(values[i], value)) + { + return true; + } + } + return false; + } } #endif diff --git a/src/Split/netcoreapp2.1/Polyfill_Memory_IndexOfAnyExcept.cs b/src/Split/netcoreapp2.1/Polyfill_Memory_IndexOfAnyExcept.cs index d49c931b..565244a8 100644 --- a/src/Split/netcoreapp2.1/Polyfill_Memory_IndexOfAnyExcept.cs +++ b/src/Split/netcoreapp2.1/Polyfill_Memory_IndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/netcoreapp2.1/Polyfill_Memory_LastIndexOfAnyExcept.cs b/src/Split/netcoreapp2.1/Polyfill_Memory_LastIndexOfAnyExcept.cs index 591af601..06e3f381 100644 --- a/src/Split/netcoreapp2.1/Polyfill_Memory_LastIndexOfAnyExcept.cs +++ b/src/Split/netcoreapp2.1/Polyfill_Memory_LastIndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpa } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/netcoreapp2.2/Polyfill_Memory_ContainsAnyExcept.cs b/src/Split/netcoreapp2.2/Polyfill_Memory_ContainsAnyExcept.cs index cda3e7d0..6b67b6cf 100644 --- a/src/Split/netcoreapp2.2/Polyfill_Memory_ContainsAnyExcept.cs +++ b/src/Split/netcoreapp2.2/Polyfill_Memory_ContainsAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return true; } @@ -20,12 +22,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) } /// Searches for any value other than or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return true; } @@ -34,12 +37,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return true; } @@ -48,11 +52,12 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return true; } @@ -61,19 +66,30 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan< } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value); /// Searches for any value other than or . public static bool ContainsAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, values); + static bool ContainsValue(ReadOnlySpan values, T value, EqualityComparer comparer) + { + for (var i = 0; i < values.Length; i++) + { + if (comparer.Equals(values[i], value)) + { + return true; + } + } + return false; + } } #endif diff --git a/src/Split/netcoreapp2.2/Polyfill_Memory_IndexOfAnyExcept.cs b/src/Split/netcoreapp2.2/Polyfill_Memory_IndexOfAnyExcept.cs index d49c931b..565244a8 100644 --- a/src/Split/netcoreapp2.2/Polyfill_Memory_IndexOfAnyExcept.cs +++ b/src/Split/netcoreapp2.2/Polyfill_Memory_IndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/netcoreapp2.2/Polyfill_Memory_LastIndexOfAnyExcept.cs b/src/Split/netcoreapp2.2/Polyfill_Memory_LastIndexOfAnyExcept.cs index 591af601..06e3f381 100644 --- a/src/Split/netcoreapp2.2/Polyfill_Memory_LastIndexOfAnyExcept.cs +++ b/src/Split/netcoreapp2.2/Polyfill_Memory_LastIndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpa } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/netcoreapp3.0/Polyfill_Memory_ContainsAnyExcept.cs b/src/Split/netcoreapp3.0/Polyfill_Memory_ContainsAnyExcept.cs index cda3e7d0..6b67b6cf 100644 --- a/src/Split/netcoreapp3.0/Polyfill_Memory_ContainsAnyExcept.cs +++ b/src/Split/netcoreapp3.0/Polyfill_Memory_ContainsAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return true; } @@ -20,12 +22,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) } /// Searches for any value other than or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return true; } @@ -34,12 +37,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return true; } @@ -48,11 +52,12 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return true; } @@ -61,19 +66,30 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan< } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value); /// Searches for any value other than or . public static bool ContainsAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, values); + static bool ContainsValue(ReadOnlySpan values, T value, EqualityComparer comparer) + { + for (var i = 0; i < values.Length; i++) + { + if (comparer.Equals(values[i], value)) + { + return true; + } + } + return false; + } } #endif diff --git a/src/Split/netcoreapp3.0/Polyfill_Memory_IndexOfAnyExcept.cs b/src/Split/netcoreapp3.0/Polyfill_Memory_IndexOfAnyExcept.cs index d49c931b..565244a8 100644 --- a/src/Split/netcoreapp3.0/Polyfill_Memory_IndexOfAnyExcept.cs +++ b/src/Split/netcoreapp3.0/Polyfill_Memory_IndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/netcoreapp3.0/Polyfill_Memory_LastIndexOfAnyExcept.cs b/src/Split/netcoreapp3.0/Polyfill_Memory_LastIndexOfAnyExcept.cs index 591af601..06e3f381 100644 --- a/src/Split/netcoreapp3.0/Polyfill_Memory_LastIndexOfAnyExcept.cs +++ b/src/Split/netcoreapp3.0/Polyfill_Memory_LastIndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpa } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/netcoreapp3.1/Polyfill_Memory_ContainsAnyExcept.cs b/src/Split/netcoreapp3.1/Polyfill_Memory_ContainsAnyExcept.cs index cda3e7d0..6b67b6cf 100644 --- a/src/Split/netcoreapp3.1/Polyfill_Memory_ContainsAnyExcept.cs +++ b/src/Split/netcoreapp3.1/Polyfill_Memory_ContainsAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return true; } @@ -20,12 +22,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) } /// Searches for any value other than or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return true; } @@ -34,12 +37,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return true; } @@ -48,11 +52,12 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return true; } @@ -61,19 +66,30 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan< } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value); /// Searches for any value other than or . public static bool ContainsAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, values); + static bool ContainsValue(ReadOnlySpan values, T value, EqualityComparer comparer) + { + for (var i = 0; i < values.Length; i++) + { + if (comparer.Equals(values[i], value)) + { + return true; + } + } + return false; + } } #endif diff --git a/src/Split/netcoreapp3.1/Polyfill_Memory_IndexOfAnyExcept.cs b/src/Split/netcoreapp3.1/Polyfill_Memory_IndexOfAnyExcept.cs index d49c931b..565244a8 100644 --- a/src/Split/netcoreapp3.1/Polyfill_Memory_IndexOfAnyExcept.cs +++ b/src/Split/netcoreapp3.1/Polyfill_Memory_IndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/netcoreapp3.1/Polyfill_Memory_LastIndexOfAnyExcept.cs b/src/Split/netcoreapp3.1/Polyfill_Memory_LastIndexOfAnyExcept.cs index 591af601..06e3f381 100644 --- a/src/Split/netcoreapp3.1/Polyfill_Memory_LastIndexOfAnyExcept.cs +++ b/src/Split/netcoreapp3.1/Polyfill_Memory_LastIndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpa } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/netstandard2.0/Polyfill_Memory_ContainsAnyExcept.cs b/src/Split/netstandard2.0/Polyfill_Memory_ContainsAnyExcept.cs index cda3e7d0..6b67b6cf 100644 --- a/src/Split/netstandard2.0/Polyfill_Memory_ContainsAnyExcept.cs +++ b/src/Split/netstandard2.0/Polyfill_Memory_ContainsAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return true; } @@ -20,12 +22,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) } /// Searches for any value other than or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return true; } @@ -34,12 +37,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return true; } @@ -48,11 +52,12 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return true; } @@ -61,19 +66,30 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan< } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value); /// Searches for any value other than or . public static bool ContainsAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, values); + static bool ContainsValue(ReadOnlySpan values, T value, EqualityComparer comparer) + { + for (var i = 0; i < values.Length; i++) + { + if (comparer.Equals(values[i], value)) + { + return true; + } + } + return false; + } } #endif diff --git a/src/Split/netstandard2.0/Polyfill_Memory_IndexOfAnyExcept.cs b/src/Split/netstandard2.0/Polyfill_Memory_IndexOfAnyExcept.cs index d49c931b..565244a8 100644 --- a/src/Split/netstandard2.0/Polyfill_Memory_IndexOfAnyExcept.cs +++ b/src/Split/netstandard2.0/Polyfill_Memory_IndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/netstandard2.0/Polyfill_Memory_LastIndexOfAnyExcept.cs b/src/Split/netstandard2.0/Polyfill_Memory_LastIndexOfAnyExcept.cs index 591af601..06e3f381 100644 --- a/src/Split/netstandard2.0/Polyfill_Memory_LastIndexOfAnyExcept.cs +++ b/src/Split/netstandard2.0/Polyfill_Memory_LastIndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpa } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/netstandard2.1/Polyfill_Memory_ContainsAnyExcept.cs b/src/Split/netstandard2.1/Polyfill_Memory_ContainsAnyExcept.cs index cda3e7d0..6b67b6cf 100644 --- a/src/Split/netstandard2.1/Polyfill_Memory_ContainsAnyExcept.cs +++ b/src/Split/netstandard2.1/Polyfill_Memory_ContainsAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return true; } @@ -20,12 +22,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) } /// Searches for any value other than or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return true; } @@ -34,12 +37,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return true; } @@ -48,11 +52,12 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return true; } @@ -61,19 +66,30 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan< } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value); /// Searches for any value other than or . public static bool ContainsAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, values); + static bool ContainsValue(ReadOnlySpan values, T value, EqualityComparer comparer) + { + for (var i = 0; i < values.Length; i++) + { + if (comparer.Equals(values[i], value)) + { + return true; + } + } + return false; + } } #endif diff --git a/src/Split/netstandard2.1/Polyfill_Memory_IndexOfAnyExcept.cs b/src/Split/netstandard2.1/Polyfill_Memory_IndexOfAnyExcept.cs index d49c931b..565244a8 100644 --- a/src/Split/netstandard2.1/Polyfill_Memory_IndexOfAnyExcept.cs +++ b/src/Split/netstandard2.1/Polyfill_Memory_IndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/netstandard2.1/Polyfill_Memory_LastIndexOfAnyExcept.cs b/src/Split/netstandard2.1/Polyfill_Memory_LastIndexOfAnyExcept.cs index 591af601..06e3f381 100644 --- a/src/Split/netstandard2.1/Polyfill_Memory_LastIndexOfAnyExcept.cs +++ b/src/Split/netstandard2.1/Polyfill_Memory_LastIndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpa } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/uap10.0/Polyfill_Memory_ContainsAnyExcept.cs b/src/Split/uap10.0/Polyfill_Memory_ContainsAnyExcept.cs index cda3e7d0..6b67b6cf 100644 --- a/src/Split/uap10.0/Polyfill_Memory_ContainsAnyExcept.cs +++ b/src/Split/uap10.0/Polyfill_Memory_ContainsAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return true; } @@ -20,12 +22,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value) } /// Searches for any value other than or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return true; } @@ -34,12 +37,13 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return true; } @@ -48,11 +52,12 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, T value0, T v } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return true; } @@ -61,19 +66,30 @@ public static bool ContainsAnyExcept(this ReadOnlySpan span, ReadOnlySpan< } /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value); /// Searches for any value other than or . public static bool ContainsAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for any value other than , , or . public static bool ContainsAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for any value other than the specified . public static bool ContainsAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => ContainsAnyExcept((ReadOnlySpan)span, values); + static bool ContainsValue(ReadOnlySpan values, T value, EqualityComparer comparer) + { + for (var i = 0; i < values.Length; i++) + { + if (comparer.Equals(values[i], value)) + { + return true; + } + } + return false; + } } #endif diff --git a/src/Split/uap10.0/Polyfill_Memory_IndexOfAnyExcept.cs b/src/Split/uap10.0/Polyfill_Memory_IndexOfAnyExcept.cs index d49c931b..565244a8 100644 --- a/src/Split/uap10.0/Polyfill_Memory_IndexOfAnyExcept.cs +++ b/src/Split/uap10.0/Polyfill_Memory_IndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, T value0, T val } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = 0; i < span.Length; i++) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int IndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan } /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches for the first index of any value other than or . public static int IndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches for the first index of any value other than , , or . public static int IndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches for the first index of any value other than the specified . public static int IndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => IndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Split/uap10.0/Polyfill_Memory_LastIndexOfAnyExcept.cs b/src/Split/uap10.0/Polyfill_Memory_LastIndexOfAnyExcept.cs index 591af601..06e3f381 100644 --- a/src/Split/uap10.0/Polyfill_Memory_LastIndexOfAnyExcept.cs +++ b/src/Split/uap10.0/Polyfill_Memory_LastIndexOfAnyExcept.cs @@ -3,15 +3,17 @@ #if FeatureMemory namespace Polyfills; using System; +using System.Collections.Generic; static partial class Polyfill { /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!span[i].Equals(value)) + if (!comparer.Equals(span[i], value)) { return i; } @@ -20,12 +22,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value) } /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1)) { return i; } @@ -34,12 +37,13 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T value1, T value2) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { var item = span[i]; - if (!item.Equals(value0) && !item.Equals(value1) && !item.Equals(value2)) + if (!comparer.Equals(item, value0) && !comparer.Equals(item, value1) && !comparer.Equals(item, value2)) { return i; } @@ -48,11 +52,12 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, T value0, T } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpan values) - where T : IEquatable + where T : IEquatable? { + var comparer = EqualityComparer.Default; for (var i = span.Length - 1; i >= 0; i--) { - if (!values.Contains(span[i])) + if (!ContainsValue(values, span[i], comparer)) { return i; } @@ -61,19 +66,19 @@ public static int LastIndexOfAnyExcept(this ReadOnlySpan span, ReadOnlySpa } /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, T value) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value); /// Searches from the end for the first index of any value other than or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1); /// Searches from the end for the first index of any value other than , , or . public static int LastIndexOfAnyExcept(this Span span, T value0, T value1, T value2) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, value0, value1, value2); /// Searches from the end for the first index of any value other than the specified . public static int LastIndexOfAnyExcept(this Span span, ReadOnlySpan values) - where T : IEquatable => + where T : IEquatable? => LastIndexOfAnyExcept((ReadOnlySpan)span, values); } #endif diff --git a/src/Tests/PolyfillTests_Memory_ContainsAnyExcept.cs b/src/Tests/PolyfillTests_Memory_ContainsAnyExcept.cs index ee1adb42..078af690 100644 --- a/src/Tests/PolyfillTests_Memory_ContainsAnyExcept.cs +++ b/src/Tests/PolyfillTests_Memory_ContainsAnyExcept.cs @@ -108,4 +108,46 @@ public Task Span_ContainsAnyExcept_SingleValue() return Task.CompletedTask; } + + [Test] + public async Task ReadOnlySpan_ContainsAnyExcept_NullElements() + { + ReadOnlySpan span = new string?[] { null, "a", "b" }; + var one = span.ContainsAnyExcept((string?)null); + var two = span.ContainsAnyExcept(null, "a"); + var three = span.ContainsAnyExcept(null, "a", "b"); + var many = span.ContainsAnyExcept(new string?[] { "a", null }); + var none = span.ContainsAnyExcept(new string?[] { "a", null, "b" }); + ReadOnlySpan nulls = new string?[] { null, null }; + var onlyNulls = nulls.ContainsAnyExcept((string?)null); + var nullsExceptA = nulls.ContainsAnyExcept("a"); + await Assert.That(one).IsTrue(); + await Assert.That(two).IsTrue(); + await Assert.That(three).IsFalse(); + await Assert.That(many).IsTrue(); + await Assert.That(none).IsFalse(); + await Assert.That(onlyNulls).IsFalse(); + await Assert.That(nullsExceptA).IsTrue(); + } + + [Test] + public async Task Span_ContainsAnyExcept_NullElements() + { + Span span = new string?[] { null, "a", "b" }; + var one = span.ContainsAnyExcept((string?)null); + var two = span.ContainsAnyExcept(null, "a"); + var three = span.ContainsAnyExcept(null, "a", "b"); + var many = span.ContainsAnyExcept(new string?[] { "a", null }); + var none = span.ContainsAnyExcept(new string?[] { "a", null, "b" }); + Span nulls = new string?[] { null, null }; + var onlyNulls = nulls.ContainsAnyExcept((string?)null); + var nullsExceptA = nulls.ContainsAnyExcept("a"); + await Assert.That(one).IsTrue(); + await Assert.That(two).IsTrue(); + await Assert.That(three).IsFalse(); + await Assert.That(many).IsTrue(); + await Assert.That(none).IsFalse(); + await Assert.That(onlyNulls).IsFalse(); + await Assert.That(nullsExceptA).IsTrue(); + } } diff --git a/src/Tests/PolyfillTests_Memory_IndexOfAnyExcept.cs b/src/Tests/PolyfillTests_Memory_IndexOfAnyExcept.cs index f577e3de..b93e09f7 100644 --- a/src/Tests/PolyfillTests_Memory_IndexOfAnyExcept.cs +++ b/src/Tests/PolyfillTests_Memory_IndexOfAnyExcept.cs @@ -89,4 +89,40 @@ public async Task Span_IndexOfAnyExcept_SingleValue_NotFound() var result = span.IndexOfAnyExcept(1); await Assert.That(result).IsEqualTo(-1); } + + [Test] + public async Task ReadOnlySpan_IndexOfAnyExcept_NullElements() + { + ReadOnlySpan span = new string?[] { null, "a", "b", "c" }; + var one = span.IndexOfAnyExcept((string?)null); + var two = span.IndexOfAnyExcept(null, "a"); + var three = span.IndexOfAnyExcept(null, "a", "b"); + var many = span.IndexOfAnyExcept(new string?[] { "a", null }); + var none = span.IndexOfAnyExcept(new string?[] { "a", null, "b", "c" }); + var exceptC = span.IndexOfAnyExcept("c"); + await Assert.That(one).IsEqualTo(1); + await Assert.That(two).IsEqualTo(2); + await Assert.That(three).IsEqualTo(3); + await Assert.That(many).IsEqualTo(2); + await Assert.That(none).IsEqualTo(-1); + await Assert.That(exceptC).IsEqualTo(0); + } + + [Test] + public async Task Span_IndexOfAnyExcept_NullElements() + { + Span span = new string?[] { null, "a", "b", "c" }; + var one = span.IndexOfAnyExcept((string?)null); + var two = span.IndexOfAnyExcept(null, "a"); + var three = span.IndexOfAnyExcept(null, "a", "b"); + var many = span.IndexOfAnyExcept(new string?[] { "a", null }); + var none = span.IndexOfAnyExcept(new string?[] { "a", null, "b", "c" }); + var exceptC = span.IndexOfAnyExcept("c"); + await Assert.That(one).IsEqualTo(1); + await Assert.That(two).IsEqualTo(2); + await Assert.That(three).IsEqualTo(3); + await Assert.That(many).IsEqualTo(2); + await Assert.That(none).IsEqualTo(-1); + await Assert.That(exceptC).IsEqualTo(0); + } } diff --git a/src/Tests/PolyfillTests_Memory_LastIndexOfAnyExcept.cs b/src/Tests/PolyfillTests_Memory_LastIndexOfAnyExcept.cs index 2f79747d..f85c3907 100644 --- a/src/Tests/PolyfillTests_Memory_LastIndexOfAnyExcept.cs +++ b/src/Tests/PolyfillTests_Memory_LastIndexOfAnyExcept.cs @@ -89,4 +89,40 @@ public async Task Span_LastIndexOfAnyExcept_SingleValue_NotFound() var result = span.LastIndexOfAnyExcept(1); await Assert.That(result).IsEqualTo(-1); } + + [Test] + public async Task ReadOnlySpan_LastIndexOfAnyExcept_NullElements() + { + ReadOnlySpan span = new string?[] { null, "a", "b", "c" }; + var one = span.LastIndexOfAnyExcept((string?)null); + var two = span.LastIndexOfAnyExcept(null, "a"); + var three = span.LastIndexOfAnyExcept(null, "a", "b"); + var many = span.LastIndexOfAnyExcept(new string?[] { "a", null }); + var none = span.LastIndexOfAnyExcept(new string?[] { "a", null, "b", "c" }); + var exceptC = span.LastIndexOfAnyExcept("c"); + await Assert.That(one).IsEqualTo(3); + await Assert.That(two).IsEqualTo(3); + await Assert.That(three).IsEqualTo(3); + await Assert.That(many).IsEqualTo(3); + await Assert.That(none).IsEqualTo(-1); + await Assert.That(exceptC).IsEqualTo(2); + } + + [Test] + public async Task Span_LastIndexOfAnyExcept_NullElements() + { + Span span = new string?[] { null, "a", "b", "c" }; + var one = span.LastIndexOfAnyExcept((string?)null); + var two = span.LastIndexOfAnyExcept(null, "a"); + var three = span.LastIndexOfAnyExcept(null, "a", "b"); + var many = span.LastIndexOfAnyExcept(new string?[] { "a", null }); + var none = span.LastIndexOfAnyExcept(new string?[] { "a", null, "b", "c" }); + var exceptC = span.LastIndexOfAnyExcept("c"); + await Assert.That(one).IsEqualTo(3); + await Assert.That(two).IsEqualTo(3); + await Assert.That(three).IsEqualTo(3); + await Assert.That(many).IsEqualTo(3); + await Assert.That(none).IsEqualTo(-1); + await Assert.That(exceptC).IsEqualTo(2); + } } From 6da5513e92fa989fba56aca8dfe930597b27e921 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sun, 11 Oct 2026 12:19:10 +0000 Subject: [PATCH 2/2] Docs changes --- readme.md | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/readme.md b/readme.md index 0e206798..13dd7d23 100644 --- a/readme.md +++ b/readme.md @@ -1768,10 +1768,10 @@ The class `Polyfill` includes the following extension methods: * `int CommonPrefixLength(ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.commonprefixlength?view=net-11.0#system-memoryextensions-commonprefixlength-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) * `bool Contains(T, IEqualityComparer?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.contains?view=net-11.0#system-memoryextensions-contains-1(system-readonlyspan((-0))-0-system-collections-generic-iequalitycomparer((-0)))) * `bool Contains(T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.contains?view=net-11.0#system-memoryextensions-contains-1(system-readonlyspan((-0))-0)) - * `bool ContainsAnyExcept(ReadOnlySpan) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) - * `bool ContainsAnyExcept(T, T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-readonlyspan((-0))-0-0-0)) - * `bool ContainsAnyExcept(T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-readonlyspan((-0))-0-0)) - * `bool ContainsAnyExcept(T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-readonlyspan((-0))-0)) + * `bool ContainsAnyExcept(ReadOnlySpan) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) + * `bool ContainsAnyExcept(T, T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-readonlyspan((-0))-0-0-0)) + * `bool ContainsAnyExcept(T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-readonlyspan((-0))-0-0)) + * `bool ContainsAnyExcept(T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-readonlyspan((-0))-0)) * `bool ContainsAnyExceptInRange(T, T) where T : IComparable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexceptinrange?view=net-11.0#system-memoryextensions-containsanyexceptinrange-1(system-readonlyspan((-0))-0-0)) * `bool ContainsAnyInRange(T, T) where T : IComparable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyinrange?view=net-11.0#system-memoryextensions-containsanyinrange-1(system-readonlyspan((-0))-0-0)) * `int CountAny(ReadOnlySpan, IEqualityComparer?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.countany?view=net-11.0#system-memoryextensions-countany-1(system-readonlyspan((-0))-system-readonlyspan((-0))-system-collections-generic-iequalitycomparer((-0)))) @@ -1780,14 +1780,14 @@ The class `Polyfill` includes the following extension methods: * `bool EndsWith(T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.endswith?view=net-11.0#system-memoryextensions-endswith-1(system-readonlyspan((-0))-0)) * `int IndexOf(T, IEqualityComparer?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexof?view=net-11.0#system-memoryextensions-indexof-1(system-readonlyspan((-0))-0-system-collections-generic-iequalitycomparer((-0)))) * `int IndexOfAny(ReadOnlySpan, IEqualityComparer?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.countany?view=net-11.0#system-memoryextensions-countany-1(system-readonlyspan((-0))-system-buffers-searchvalues((-0)))) - * `int IndexOfAnyExcept(ReadOnlySpan) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) - * `int IndexOfAnyExcept(T, T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-readonlyspan((-0))-0-0-0)) - * `int IndexOfAnyExcept(T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-readonlyspan((-0))-0-0)) - * `int IndexOfAnyExcept(T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-readonlyspan((-0))-0)) - * `int LastIndexOfAnyExcept(ReadOnlySpan) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) - * `int LastIndexOfAnyExcept(T, T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-readonlyspan((-0))-0-0-0)) - * `int LastIndexOfAnyExcept(T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-readonlyspan((-0))-0-0)) - * `int LastIndexOfAnyExcept(T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-readonlyspan((-0))-0)) + * `int IndexOfAnyExcept(ReadOnlySpan) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) + * `int IndexOfAnyExcept(T, T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-readonlyspan((-0))-0-0-0)) + * `int IndexOfAnyExcept(T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-readonlyspan((-0))-0-0)) + * `int IndexOfAnyExcept(T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-readonlyspan((-0))-0)) + * `int LastIndexOfAnyExcept(ReadOnlySpan) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-readonlyspan((-0))-system-readonlyspan((-0)))) + * `int LastIndexOfAnyExcept(T, T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-readonlyspan((-0))-0-0-0)) + * `int LastIndexOfAnyExcept(T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-readonlyspan((-0))-0-0)) + * `int LastIndexOfAnyExcept(T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-readonlyspan((-0))-0)) * `T? Max(IComparer?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.max?view=net-11.0#system-memoryextensions-max-1(system-readonlyspan((-0))-system-collections-generic-icomparer((-0)))) * `T? Max()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.max?view=net-11.0#system-memoryextensions-max-1(system-readonlyspan((-0)))) * `T? Min(IComparer?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.min?view=net-11.0#system-memoryextensions-min-1(system-readonlyspan((-0))-system-collections-generic-icomparer((-0)))) @@ -1946,20 +1946,20 @@ The class `Polyfill` includes the following extension methods: * `int CommonPrefixLength(ReadOnlySpan, IEqualityComparer?)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.commonprefixlength?view=net-11.0#system-memoryextensions-commonprefixlength-1(system-span((-0))-system-readonlyspan((-0))-system-collections-generic-iequalitycomparer((-0)))) * `int CommonPrefixLength(ReadOnlySpan)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.commonprefixlength?view=net-11.0#system-memoryextensions-commonprefixlength-1(system-span((-0))-system-readonlyspan((-0)))) * `bool Contains(T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.contains?view=net-11.0#system-memoryextensions-contains-1(system-span((-0))-0)) - * `bool ContainsAnyExcept(ReadOnlySpan) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-span((-0))-system-readonlyspan((-0)))) - * `bool ContainsAnyExcept(T, T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-span((-0))-0-0-0)) - * `bool ContainsAnyExcept(T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-span((-0))-0-0)) - * `bool ContainsAnyExcept(T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-span((-0))-0)) + * `bool ContainsAnyExcept(ReadOnlySpan) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-span((-0))-system-readonlyspan((-0)))) + * `bool ContainsAnyExcept(T, T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-span((-0))-0-0-0)) + * `bool ContainsAnyExcept(T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-span((-0))-0-0)) + * `bool ContainsAnyExcept(T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexcept?view=net-11.0#system-memoryextensions-containsanyexcept-1(system-span((-0))-0)) * `bool ContainsAnyExceptInRange(T, T) where T : IComparable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyexceptinrange?view=net-11.0#system-memoryextensions-containsanyexceptinrange-1(system-span((-0))-0-0)) * `bool ContainsAnyInRange(T, T) where T : IComparable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.containsanyinrange?view=net-11.0#system-memoryextensions-containsanyinrange-1(system-span((-0))-0-0)) - * `int IndexOfAnyExcept(ReadOnlySpan) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-span((-0))-system-readonlyspan((-0)))) - * `int IndexOfAnyExcept(T, T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-span((-0))-0-0-0)) - * `int IndexOfAnyExcept(T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-span((-0))-0-0)) - * `int IndexOfAnyExcept(T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-span((-0))-0)) - * `int LastIndexOfAnyExcept(ReadOnlySpan) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-span((-0))-system-readonlyspan((-0)))) - * `int LastIndexOfAnyExcept(T, T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-span((-0))-0-0-0)) - * `int LastIndexOfAnyExcept(T, T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-span((-0))-0-0)) - * `int LastIndexOfAnyExcept(T) where T : IEquatable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-span((-0))-0)) + * `int IndexOfAnyExcept(ReadOnlySpan) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-span((-0))-system-readonlyspan((-0)))) + * `int IndexOfAnyExcept(T, T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-span((-0))-0-0-0)) + * `int IndexOfAnyExcept(T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-span((-0))-0-0)) + * `int IndexOfAnyExcept(T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.indexofanyexcept?view=net-11.0#system-memoryextensions-indexofanyexcept-1(system-span((-0))-0)) + * `int LastIndexOfAnyExcept(ReadOnlySpan) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-span((-0))-system-readonlyspan((-0)))) + * `int LastIndexOfAnyExcept(T, T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-span((-0))-0-0-0)) + * `int LastIndexOfAnyExcept(T, T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-span((-0))-0-0)) + * `int LastIndexOfAnyExcept(T) where T : IEquatable?` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.lastindexofanyexcept?view=net-11.0#system-memoryextensions-lastindexofanyexcept-1(system-span((-0))-0)) * `void Sort(Comparison)` * `void Sort() where T : IComparable` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.sort?view=net-11.0#system-memoryextensions-sort-1(system-span((-0))))