internal static string FixupName(string name)
{
Debug.Assert(name != null, "[FixupName]name!=null");
- if (name.IndexOf('\\') == -1)
+ if (!name.Contains('\\'))
return name;
StringBuilder sb = new StringBuilder(name);
{
throw new ArgumentException(SR.Argument_StringFirstCharIsZero, nameof(variable));
}
- if (variable.IndexOf('=') != -1)
+ if (variable.Contains('='))
{
throw new ArgumentException(SR.Argument_IllegalEnvVarName, nameof(variable));
}
{
return true;
}
- return (RFC3986ReservedMarks.IndexOf(c) >= 0);
+ return (RFC3986ReservedMarks.Contains(c));
}
internal static unsafe bool IsUnreserved(char c)
{
return true;
}
- return (RFC3986UnreservedMarks.IndexOf(c) >= 0);
+ return (RFC3986UnreservedMarks.Contains(c));
}
//Only consider ASCII characters
public static void CheckName(string name)
{
- if (name != null && 0 <= name.IndexOf('\0'))
+ if (name != null && name.Contains('\0'))
{
throw new ArgumentOutOfRangeException(nameof(name));
}
break;
default:
const string unsupportedDateFieldSymbols = "YuUrQqwWDFg";
- Debug.Assert(unsupportedDateFieldSymbols.IndexOf(input[index]) == -1,
+ Debug.Assert(!unsupportedDateFieldSymbols.Contains(input[index]),
string.Format(CultureInfo.InvariantCulture,
"Encountered an unexpected date field symbol '{0}' from ICU which has no known corresponding .NET equivalent.",
input[index]));
for (int i = startIndex; i < format.Length; ++i)
{
// See if we have a time Part
- if (!inQuote && timeParts.IndexOf(format[i]) != -1)
+ if (!inQuote && timeParts.Contains(format[i]))
{
return i;
}
}
// Check for braces
- bool bracesExistInString = (guidString.IndexOf('{') >= 0);
+ bool bracesExistInString = guidString.Contains('{');
if (bracesExistInString)
{
}
// Check for parenthesis
- bool parenthesisExistInString = (guidString.IndexOf('(') >= 0);
+ bool parenthesisExistInString = guidString.Contains('(');
if (parenthesisExistInString)
{
if (path.Length == 0)
throw new ArgumentException(SR.Arg_PathEmpty, nameof(path));
- if (path.IndexOf('\0') != -1)
+ if (path.Contains('\0'))
throw new ArgumentException(SR.Argument_InvalidPathChars, nameof(path));
// Expand with current directory if necessary
// Embedded null characters are the only invalid character case we trully care about.
// This is because the nulls will signal the end of the string to Win32 and therefore have
// unpredictable results.
- if (path.IndexOf('\0') != -1)
+ if (path.Contains('\0'))
throw new ArgumentException(SR.Argument_InvalidPathChars, nameof(path));
if (PathInternal.IsExtended(path.AsSpan()))
// If we have the exact same string we were passed in, don't allocate another string.
// TryExpandShortName does this input identity check.
- string result = builder.AsSpan().IndexOf('~') >= 0
+ string result = builder.AsSpan().Contains('~')
? TryExpandShortFileName(ref builder, originalPath: path)
: builder.AsSpan().Equals(path.AsSpan(), StringComparison.Ordinal) ? path : builder.ToString();
// Get the full path
GetFullPathName(path.AsSpan(terminate: true), ref builder);
- string result = builder.AsSpan().IndexOf('~') >= 0
+ string result = builder.AsSpan().Contains('~')
? TryExpandShortFileName(ref builder, originalPath: null)
: builder.ToString();
}
// Adapted from IndexOf(...)
- public static unsafe bool Contains<T>(ref T searchSpace, T value, int length)
+ public static bool Contains<T>(ref T searchSpace, T value, int length)
where T : IEquatable<T>
{
Debug.Assert(length >= 0);
return (IndexOf(value, comparisonType) >= 0);
}
- public bool Contains(char value)
- {
- return IndexOf(value) != -1;
- }
+ public bool Contains(char value) => SpanHelpers.Contains(ref _firstChar, value, Length);
public bool Contains(char value, StringComparison comparisonType)
{