int charCount = Encoding.UTF8.GetChars(nameBytes, buffer);
ReadOnlySpan<char> value = buffer.Slice(0, charCount);
- Debug.Assert(NameLength != -1 || value.IndexOf('\0') == -1, "should not have embedded nulls if we parsed the end of string");
+ Debug.Assert(NameLength != -1 || !value.Contains('\0'), "should not have embedded nulls if we parsed the end of string");
return value;
}
}
}
// Now see if we have some arity. baseType could be null if this is an array type.
- if (_baseType != null && _baseType.IndexOf('`') != -1)
+ if (_baseType != null && _baseType.IndexOf('`') != -1) // string.Contains(char) is .NetCore2.1+ specific
{
_needsFixup = false;
}
bool compValue = s_connectionStringValidValueRegex.IsMatch(keyvalue);
Debug.Assert((-1 == keyvalue.IndexOf('\u0000')) == compValue, "IsValueValid mismatch with regex");
#endif
+ // string.Contains(char) is .NetCore2.1+ specific
return (-1 == keyvalue.IndexOf('\u0000'));
}
return true;
bool compValue = s_connectionStringValidKeyRegex.IsMatch(keyname);
Debug.Assert(((0 < keyname.Length) && (';' != keyname[0]) && !Char.IsWhiteSpace(keyname[0]) && (-1 == keyname.IndexOf('\u0000'))) == compValue, "IsValueValid mismatch with regex");
#endif
+ // string.Contains(char) is .NetCore2.1+ specific
return ((0 < keyname.Length) && (';' != keyname[0]) && !char.IsWhiteSpace(keyname[0]) && (-1 == keyname.IndexOf('\u0000')));
}
return false;
private static string FixupName(string name)
{
Debug.Assert(name != null, "[FixupName]name!=null");
+
+ // string.Contains(char) is .NetCore2.1+ specific
if (name.IndexOf('\\') == -1)
{
return name;
// If the string is short, use C style quoting (e.g "\r\n")
// Also do it if it is too long to fit in one line
// If the string contains '\0', verbatim style won't work.
- if (value.Length < 256 || value.Length > 1500 || (value.IndexOf('\0') != -1))
+ if (value.Length < 256 || value.Length > 1500 || (value.IndexOf('\0') != -1)) // string.Contains(char) is .NetCore2.1+ specific
return QuoteSnippetStringCStyle(value);
// Otherwise, use 'verbatim' style quoting (e.g. @"foo")
string typeName = GetTypeOutput(e.CreateType);
Output.Write(typeName);
- if (typeName.IndexOf('(') == -1)
+ if (typeName.IndexOf('(') == -1) // string.Contains(char) is .NetCore2.1+ specific
{
Output.Write("()");
}
{
try
{
- if (strValue.IndexOf(',') != -1)
+ if (strValue.Contains(','))
{
bool isUnderlyingTypeUInt64 = Enum.GetUnderlyingType(EnumType) == typeof(ulong);
long convertedValue = 0;
return false;
// Machine names shouldn't contain any "\"
- return (value.IndexOf('\\') == -1);
+ return !value.Contains('\\');
}
/// <summary>
if (trimmedConfigSource.Length != configSource.Length)
throw new ConfigurationErrorsException(SR.Config_source_invalid_format, errorInfo);
- if (configSource.IndexOf('/') != -1)
+ if (configSource.IndexOf('/') != -1) // string.Contains(char) is .NetCore2.1+ specific
throw new ConfigurationErrorsException(SR.Config_source_invalid_chars, errorInfo);
if (string.IsNullOrEmpty(configSource) || Path.IsPathRooted(configSource))
if (collectionAttribute != null)
{
- if (collectionAttribute.AddItemName.IndexOf(',') == -1) AddElementName = collectionAttribute.AddItemName;
+ if (collectionAttribute.AddItemName.IndexOf(',') == -1) AddElementName = collectionAttribute.AddItemName; // string.Contains(char) is .NetCore2.1+ specific
RemoveElementName = collectionAttribute.RemoveItemName;
ClearElementName = collectionAttribute.ClearItemsName;
}
}
}
}
-}
\ No newline at end of file
+}
throw ExceptionUtil.ParameterNullOrEmpty(nameof(name));
// prevent GetConfig from returning config not in this collection
- if (name.IndexOf('/') >= 0)
+ if (name.IndexOf('/') >= 0) // string.Contains(char) is .NetCore2.1+ specific
return null;
// get the section from the config record
Remove(GetKey(index));
}
}
-}
\ No newline at end of file
+}
throw ExceptionUtil.ParameterNullOrEmpty(nameof(name));
// prevent GetConfig from returning config not in this collection
- if (name.IndexOf('/') >= 0)
+ if (name.IndexOf('/') >= 0) // string.Contains(char) is .NetCore2.1+ specific
return null;
// get the section group
// Don't bother to look around if we've already got something that
// is clearly not a simple type name.
- if (string.IsNullOrEmpty(typeString) || typeString.IndexOf(',') != -1)
+ if (string.IsNullOrEmpty(typeString) || typeString.IndexOf(',') != -1) // string.Contains(char) is .NetCore2.1+ specific
return null;
// Ignore all exceptions, otherwise callers will get unexpected
}
// Mutate name if it contains space(s)
- if (columnName.IndexOf(' ') >= 0)
+ if (columnName.Contains(' '))
{
columnName = columnName.Replace(' ', '_');
isMutatedName = true;
if (useOdbcRules)
{
if ((0 < keyValue.Length) &&
+ // string.Contains(char) is .NetCore2.1+ specific
(('{' == keyValue[0]) || (0 <= keyValue.IndexOf(';')) || string.Equals(DbConnectionStringKeywords.Driver, keyName, StringComparison.OrdinalIgnoreCase)) &&
!s_connectionStringQuoteOdbcValueRegex.IsMatch(keyValue))
{
// <value> -> <value>
builder.Append(keyValue);
}
+ // string.Contains(char) is .NetCore2.1+ specific
else if ((-1 != keyValue.IndexOf('\"')) && (-1 == keyValue.IndexOf('\'')))
{
// <val"ue> -> <'val"ue'>
if ((QualifiedTableName == null) || (QualifiedTableName.Length == 0))
throw ExceptionBuilder.InvalidSelector(xpath);
- if (QualifiedTableName.IndexOf(':') != -1)
+ if (QualifiedTableName.Contains(':'))
prefix = QualifiedTableName.Substring(0, QualifiedTableName.IndexOf(':'));
else
return GetMsdataAttribute(key, Keywords.MSD_TABLENS);
if (useOdbcRules)
{
if ((0 < keyValue.Length) &&
+ // string.Contains(char) is .NetCore2.1+ specific
(('{' == keyValue[0]) || (0 <= keyValue.IndexOf(';')) || (0 == string.Compare(DbConnectionStringKeywords.Driver, keyName, StringComparison.OrdinalIgnoreCase))) &&
!s_connectionStringQuoteOdbcValueRegex.IsMatch(keyValue))
{
// <value> -> <value>
builder.Append(keyValue);
}
+ // string.Contains(char) is .NetCore2.1+ specific
else if ((-1 != keyValue.IndexOf('\"')) && (-1 == keyValue.IndexOf('\'')))
{
// <val"ue> -> <'val"ue'>
}
}
+ // string.Contains(char) is .NetCore2.1+ specific
if (0 <= _attachDBFileName.IndexOf('|'))
{
throw ADP.InvalidConnectionOptionValue(KEY.AttachDBFilename);
}
}
}
- if (uri.HostNameType != UriHostNameType.IPv6 && uri.IdnHost.IndexOf('.') == -1)
+ if (uri.HostNameType != UriHostNameType.IPv6 && !uri.IdnHost.Contains('.'))
{
// Not address and does not have a dot.
// Hosts without FQDN are considered local.
if (lp.Host != "*" && lp.Host != "+" && Uri.CheckHostName(lp.Host) == UriHostNameType.Unknown)
throw new HttpListenerException((int)HttpStatusCode.BadRequest, SR.net_listener_host);
- if (lp.Path.IndexOf('%') != -1)
+ if (lp.Path.Contains('%'))
throw new HttpListenerException((int)HttpStatusCode.BadRequest, SR.net_invalid_path);
if (lp.Path.IndexOf("//", StringComparison.Ordinal) != -1)
private static void RemovePrefixInternal(string prefix, HttpListener listener)
{
ListenerPrefix lp = new ListenerPrefix(prefix);
- if (lp.Path.IndexOf('%') != -1)
+ if (lp.Path.Contains('%'))
return;
if (lp.Path.IndexOf("//", StringComparison.Ordinal) != -1)
}
// Has dashes?
- if (address.IndexOf('-') >= 0)
+ if (address.Contains('-'))
{
hasDashes = true;
buffer = new byte[(address.Length + 1) / 3];
}
Uri hostUri;
- if ((value.IndexOf('/') != -1) || (!TryGetHostUri(value, out hostUri)))
+ if ((value.Contains('/')) || (!TryGetHostUri(value, out hostUri)))
{
throw new ArgumentException(SR.net_invalid_host, nameof(value));
}
{
_hostHasPort = true;
}
- else if (value.IndexOf(':') == -1)
+ else if (!value.Contains(':'))
{
_hostHasPort = false;
}
{
// RFC 6265: (for Set-Cookie header)
// If the name-value-pair string lacks a %x3D ("=") character, ignore the set-cookie-string entirely.
- if (isSetCookie && (value.IndexOf('=') < 0)) return Array.Empty<string>();
+ if (isSetCookie && (!value.Contains('='))) return Array.Empty<string>();
var tempStringCollection = new List<string>();
private static bool IsDuringExpiresAttributeParsing(string singleValue)
{
// Current cookie doesn't contain any attributes.
- if (singleValue.IndexOf(';') < 0) return false;
+ if (!singleValue.Contains(';')) return false;
string lastElement = singleValue.Split(';').Last();
- bool noComma = lastElement.IndexOf(',') < 0;
+ bool noComma = !lastElement.Contains(',');
string lastAttribute = lastElement.Split('=')[0].Trim();
bool isExpires = string.Equals(lastAttribute, "Expires", StringComparison.OrdinalIgnoreCase);
}
_host = value;
//probable ipv6 address - Note: this is only supported for cases where the authority is inet-based.
- if (_host.IndexOf(':') >= 0)
+ if (_host.Contains(':'))
{
//set brackets
if (_host[0] != '[')
public override string GetAttribute(string name)
{
int i;
- if (name.IndexOf(':') == -1)
+ if (!name.Contains(':'))
{
i = GetIndexOfAttributeWithoutPrefix(name);
}
public override bool MoveToAttribute(string name)
{
int i;
- if (name.IndexOf(':') == -1)
+ if (!name.Contains(':'))
{
i = GetIndexOfAttributeWithoutPrefix(name);
}
public override string GetAttribute(string name)
{
int i;
- if (name.IndexOf(':') == -1)
+ if (!name.Contains(':'))
{
i = GetAttributeIndexWithoutPrefix(name);
}
public override bool MoveToAttribute(string name)
{
int i;
- if (name.IndexOf(':') == -1)
+ if (!name.Contains(':'))
{
i = GetAttributeIndexWithoutPrefix(name);
}
{
systemId = GetValue();
- if (systemId.IndexOf('#') >= 0)
+ if (systemId.Contains('#'))
{
Throw(_curPos - systemId.Length - 1, SR.Xml_FragmentId, new string[] { systemId.Substring(systemId.IndexOf('#')), systemId });
}
{
systemId = GetValue();
- if (systemId.IndexOf('#') >= 0)
+ if (systemId.Contains('#'))
{
Throw(_curPos - systemId.Length - 1, SR.Xml_FragmentId, new string[] { systemId.Substring(systemId.IndexOf('#')), systemId });
}
{
_regStr.Append(")");
string tempStr = _regStr.ToString();
- if (tempStr.IndexOf('|') != -1)
+ if (tempStr.Contains('|'))
{ // ordinal compare
_regStr.Insert(0, "(");
_regStr.Append(")");
if (a.SoapType != null && a.SoapType.TypeName.Length > 0)
typeName = a.SoapType.TypeName;
- if (type.IsGenericType && typeName.IndexOf('{') >= 0)
+ if (type.IsGenericType && typeName.Contains('{'))
{
Type genType = type.GetGenericTypeDefinition();
Type[] names = genType.GetGenericArguments();
if (typeName.Contains(argument))
{
typeName = typeName.Replace(argument, XsdTypeName(types[i]));
- if (typeName.IndexOf('{') < 0)
+ if (!typeName.Contains('{'))
{
break;
}
if (a.XmlType != null && a.XmlType.TypeName.Length > 0)
typeName = a.XmlType.TypeName;
- if (type.IsGenericType && typeName.IndexOf('{') >= 0)
+ if (type.IsGenericType && typeName.Contains('{'))
{
Type genType = type.GetGenericTypeDefinition();
Type[] names = genType.GetGenericArguments();
if (typeName.Contains(argument))
{
typeName = typeName.Replace(argument, XsdTypeName(types[i]));
- if (typeName.IndexOf('{') < 0)
+ if (!typeName.Contains('{'))
{
break;
}
{
if (nmTokens == null)
return null;
- if (nmTokens.IndexOf(' ') < 0)
+ if (!nmTokens.Contains(' '))
return FromXmlNmToken(nmTokens);
else
{
builder.Length = (int)length;
// If we have a tilde in the path, make an attempt to expand 8.3 filenames
- return builder.AsSpan().IndexOf('~') >= 0
+ return builder.AsSpan().Contains('~')
? PathHelper.TryExpandShortFileName(ref builder, null)
: builder.ToString();
}
private static bool CheckMachineName(string value)
{
+ // string.Contains(char) is .NetCore2.1+ specific
return !string.IsNullOrWhiteSpace(value) && value.IndexOf('\\') == -1;
}
{
Guid guid = Guid.Empty;
- if (str.IndexOf('-') >= 0)
+ if (str.Contains('-'))
{ // GUID with dash
if (str.Length >= 36)
{
}
// Helper to encode spaces only
- internal static string UrlEncodeSpaces(string str) => str != null && str.IndexOf(' ') >= 0 ? str.Replace(" ", "%20") : str;
+ internal static string UrlEncodeSpaces(string str) => str != null && str.Contains(' ') ? str.Replace(" ", "%20") : str;
}
}