Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ContainsAny{Except} #87621

Merged
merged 8 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ private static unsafe bool ParseNumber(ref char* str, char* strEnd, NumberStyles
[MethodImpl(MethodImplOptions.NoInlining)] // rare slow path that shouldn't impact perf of the main use case
private static bool TrailingZeros(ReadOnlySpan<char> s, int index) =>
// For compatibility, we need to allow trailing zeros at the end of a number string
s.Slice(index).IndexOfAnyExcept('\0') < 0;
!s.Slice(index).ContainsAnyExcept('\0');

internal static unsafe bool TryStringToNumber(ReadOnlySpan<char> str, NumberStyles options, scoped ref NumberBuffer number, StringBuilder sb, NumberFormatInfo numfmt, bool parseDecimal)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal static string CheckBadHeaderNameChars(string name)
}

internal static bool ContainsNonAsciiChars(string token) =>
token.AsSpan().IndexOfAnyExceptInRange((char)0x20, (char)0x7e) >= 0;
token.AsSpan().ContainsAnyExceptInRange((char)0x20, (char)0x7e);

internal static bool IsValidToken(string token)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal static class TargetHostNameHelper
SearchValues.Create("-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz");

private static bool IsSafeDnsString(ReadOnlySpan<char> name) =>
name.IndexOfAnyExcept(s_safeDnsChars) < 0;
!name.ContainsAnyExcept(s_safeDnsChars);

internal static string NormalizeHostName(string? targetHost)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public override void ImportParameters(RSAParameters parameters)
ValidateParameters(ref parameters);
ThrowIfDisposed();

if (parameters.Exponent == null || parameters.Modulus.AsSpan().IndexOfAnyExcept((byte)0) < 0)
if (parameters.Exponent == null || !parameters.Modulus.AsSpan().ContainsAnyExcept((byte)0))
{
throw new CryptographicException(SR.Cryptography_InvalidRsaParameters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ private static char[] GetInvalidFilterChars() => GetInvalidFileNameChars()

internal static bool HasInvalidPathChars(string path)
{
return path.AsSpan().IndexOfAny(_invalidFileNameChars) >= 0;
return path.AsSpan().ContainsAny(_invalidFileNameChars);
}

internal static bool HasInvalidFilterChars(string path)
{
return path.AsSpan().IndexOfAny(_invalidFilterChars) >= 0;
return path.AsSpan().ContainsAny(_invalidFilterChars);
}

internal static string EnsureTrailingSlash(string path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,7 @@ void ICollection.CopyTo(Array array, int index)
#endregion

private bool AreAllBucketsEmpty() =>
_tables._countPerLock.AsSpan().IndexOfAnyExcept(0) < 0;
!_tables._countPerLock.AsSpan().ContainsAnyExcept(0);

/// <summary>
/// Replaces the bucket table with a larger one. To prevent multiple threads from resizing the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private static bool ContainsAnyLetters(ReadOnlySpan<char> s)
Debug.Assert(IsAllAscii(s));

#if NET8_0_OR_GREATER
return s.IndexOfAny(s_asciiLetters) >= 0;
return s.ContainsAny(s_asciiLetters);
#else
foreach (char c in s)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ public bool HasAllSet()
}

const int AllSetBits = -1; // 0xFF_FF_FF_FF
if (m_array.AsSpan(0, intCount).IndexOfAnyExcept(AllSetBits) >= 0)
if (m_array.AsSpan(0, intCount).ContainsAnyExcept(AllSetBits))
{
return false;
}
Expand Down Expand Up @@ -954,7 +954,7 @@ public bool HasAnySet()
intCount--;
}

if (m_array.AsSpan(0, intCount).IndexOfAnyExcept(0) >= 0)
if (m_array.AsSpan(0, intCount).ContainsAnyExcept(0))
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ internal static int CalculatePadding(long size)

// Returns true if all the bytes in the specified array are nulls, false otherwise.
internal static bool IsAllNullBytes(Span<byte> buffer) =>
buffer.IndexOfAnyExcept((byte)0) < 0;
!buffer.ContainsAnyExcept((byte)0);

// Converts the specified number of seconds that have passed since the Unix Epoch to a DateTimeOffset.
internal static DateTimeOffset GetDateTimeOffsetFromSecondsSinceEpoch(long secondsSinceUnixEpoch) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal static class ZipHelper

internal static Encoding GetEncoding(string text)
{
if (text.AsSpan().IndexOfAnyExceptInRange((char)32, (char)126) >= 0)
if (text.AsSpan().ContainsAnyExceptInRange((char)32, (char)126))
{
// The Zip Format uses code page 437 when the Unicode bit is not set. This format
// is the same as ASCII for characters 32-126 but differs otherwise. If we can fit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,14 @@ internal static string GetPipePath(string serverName, string pipeName)
// cross-platform with Windows (which has only '\' as an invalid char).
if (Path.IsPathRooted(pipeName))
{
if (pipeName.IndexOfAny(s_invalidPathNameChars) >= 0 || pipeName.EndsWith(Path.DirectorySeparatorChar))
if (pipeName.ContainsAny(s_invalidPathNameChars) || pipeName.EndsWith(Path.DirectorySeparatorChar))
MihaZupan marked this conversation as resolved.
Show resolved Hide resolved
throw new PlatformNotSupportedException(SR.PlatformNotSupported_InvalidPipeNameChars);

// Caller is in full control of file location.
return pipeName;
}

if (pipeName.IndexOfAny(s_invalidFileNameChars) >= 0)
if (pipeName.ContainsAny(s_invalidFileNameChars))
MihaZupan marked this conversation as resolved.
Show resolved Hide resolved
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_InvalidPipeNameChars);
}
Expand Down
22 changes: 22 additions & 0 deletions src/libraries/System.Memory/ref/System.Memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,28 @@ public static partial class MemoryExtensions
public static bool Contains(this System.ReadOnlySpan<char> span, System.ReadOnlySpan<char> value, System.StringComparison comparisonType) { throw null; }
public static bool Contains<T>(this System.ReadOnlySpan<T> span, T value) where T : System.IEquatable<T>? { throw null; }
public static bool Contains<T>(this System.Span<T> span, T value) where T : System.IEquatable<T>? { throw null; }
public static bool ContainsAny<T>(this System.ReadOnlySpan<T> span, System.Buffers.SearchValues<T> values) where T : System.IEquatable<T>? { throw null; }
public static bool ContainsAny<T>(this System.ReadOnlySpan<T> span, System.ReadOnlySpan<T> values) where T : System.IEquatable<T>? { throw null; }
public static bool ContainsAny<T>(this System.ReadOnlySpan<T> span, T value0, T value1) where T : System.IEquatable<T>? { throw null; }
public static bool ContainsAny<T>(this System.ReadOnlySpan<T> span, T value0, T value1, T value2) where T : System.IEquatable<T>? { throw null; }
public static bool ContainsAny<T>(this System.Span<T> span, System.Buffers.SearchValues<T> values) where T : System.IEquatable<T>? { throw null; }
public static bool ContainsAny<T>(this System.Span<T> span, System.ReadOnlySpan<T> values) where T : System.IEquatable<T>? { throw null; }
public static bool ContainsAny<T>(this System.Span<T> span, T value0, T value1) where T : System.IEquatable<T>? { throw null; }
public static bool ContainsAny<T>(this System.Span<T> span, T value0, T value1, T value2) where T : System.IEquatable<T>? { throw null; }
public static bool ContainsAnyExcept<T>(this System.ReadOnlySpan<T> span, System.Buffers.SearchValues<T> values) where T : System.IEquatable<T>? { throw null; }
public static bool ContainsAnyExcept<T>(this System.ReadOnlySpan<T> span, System.ReadOnlySpan<T> values) where T : System.IEquatable<T>? { throw null; }
public static bool ContainsAnyExcept<T>(this System.ReadOnlySpan<T> span, T value) where T : System.IEquatable<T>? { throw null; }
public static bool ContainsAnyExcept<T>(this System.ReadOnlySpan<T> span, T value0, T value1) where T : System.IEquatable<T>? { throw null; }
public static bool ContainsAnyExcept<T>(this System.ReadOnlySpan<T> span, T value0, T value1, T value2) where T : System.IEquatable<T>? { throw null; }
public static bool ContainsAnyExcept<T>(this System.Span<T> span, System.Buffers.SearchValues<T> values) where T : System.IEquatable<T>? { throw null; }
public static bool ContainsAnyExcept<T>(this System.Span<T> span, System.ReadOnlySpan<T> values) where T : System.IEquatable<T>? { throw null; }
public static bool ContainsAnyExcept<T>(this System.Span<T> span, T value) where T : System.IEquatable<T>? { throw null; }
public static bool ContainsAnyExcept<T>(this System.Span<T> span, T value0, T value1) where T : System.IEquatable<T>? { throw null; }
public static bool ContainsAnyExcept<T>(this System.Span<T> span, T value0, T value1, T value2) where T : System.IEquatable<T>? { throw null; }
public static bool ContainsAnyExceptInRange<T>(this System.ReadOnlySpan<T> span, T lowInclusive, T highInclusive) where T : System.IComparable<T> { throw null; }
public static bool ContainsAnyExceptInRange<T>(this System.Span<T> span, T lowInclusive, T highInclusive) where T : System.IComparable<T> { throw null; }
public static bool ContainsAnyInRange<T>(this System.ReadOnlySpan<T> span, T lowInclusive, T highInclusive) where T : System.IComparable<T> { throw null; }
public static bool ContainsAnyInRange<T>(this System.Span<T> span, T lowInclusive, T highInclusive) where T : System.IComparable<T> { throw null; }
public static void CopyTo<T>(this T[]? source, System.Memory<T> destination) { }
public static void CopyTo<T>(this T[]? source, System.Span<T> destination) { }
public static int Count<T>(this System.Span<T> span, T value) where T : System.IEquatable<T>? { throw null; }
Expand Down
Loading