diff --git a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.Sorting.cs b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.Sorting.cs index 8b189245e27c10..7123ed268ba16e 100644 --- a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.Sorting.cs +++ b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.Sorting.cs @@ -36,7 +36,7 @@ public int CompareTo(EcmaModule other) // Multi-module assembly: compare two modules that are part of same assembly string thisName = _metadataReader.GetString(_metadataReader.GetModuleDefinition().Name); string otherName = other._metadataReader.GetString(other._metadataReader.GetModuleDefinition().Name); - Debug.Assert(StringComparer.Ordinal.Compare(thisName, otherName) != 0); + Debug.Assert(!StringComparer.Ordinal.Equals(thisName, otherName)); return StringComparer.Ordinal.Compare(thisName, otherName); } } diff --git a/src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/AssemblyQualifiedToken.cs b/src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/AssemblyQualifiedToken.cs index 6ccf7e69451f62..b9083ae7b99c2f 100644 --- a/src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/AssemblyQualifiedToken.cs +++ b/src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/AssemblyQualifiedToken.cs @@ -51,7 +51,7 @@ public AssemblyQualifiedToken(IMemberDefinition member) => public override int GetHashCode() => AssemblyName == null ? 0 : AssemblyName.GetHashCode() ^ Token.GetHashCode(); public override string ToString() => $"{AssemblyName}: {Token}"; public bool Equals(AssemblyQualifiedToken other) => - string.CompareOrdinal(AssemblyName, other.AssemblyName) == 0 && Token == other.Token; + AssemblyName == other.AssemblyName && Token == other.Token; public override bool Equals([NotNullWhen(true)] object? obj) => ((AssemblyQualifiedToken?)obj)?.Equals(this) == true; public bool IsNil => AssemblyName == null; diff --git a/src/coreclr/tools/dotnet-pgo/Program.cs b/src/coreclr/tools/dotnet-pgo/Program.cs index a1d6fd403d66fb..19971296c16ccc 100644 --- a/src/coreclr/tools/dotnet-pgo/Program.cs +++ b/src/coreclr/tools/dotnet-pgo/Program.cs @@ -207,8 +207,8 @@ internal static void UnZipIfNecessary(ref string inputFileName, TextWriter log) } var extension = Path.GetExtension(inputFileName); - if (string.Compare(extension, ".zip", StringComparison.OrdinalIgnoreCase) == 0 || - string.Compare(extension, ".vspx", StringComparison.OrdinalIgnoreCase) == 0) + if (string.Equals(extension, ".zip", StringComparison.OrdinalIgnoreCase) || + string.Equals(extension, ".vspx", StringComparison.OrdinalIgnoreCase)) { string unzipedEtlFile; if (inputFileName.EndsWith(".etl.zip", StringComparison.OrdinalIgnoreCase)) diff --git a/src/libraries/Common/src/System/Net/CredentialCacheKey.cs b/src/libraries/Common/src/System/Net/CredentialCacheKey.cs index b84ec32774c611..fd6c85ed03f2d2 100644 --- a/src/libraries/Common/src/System/Net/CredentialCacheKey.cs +++ b/src/libraries/Common/src/System/Net/CredentialCacheKey.cs @@ -70,7 +70,7 @@ private bool IsPrefix(Uri uri, int prefixLen) return false; } - return string.Compare(uri.AbsolutePath, 0, uriPrefix.AbsolutePath, 0, UriPrefixLength, StringComparison.OrdinalIgnoreCase) == 0; + return uri.AbsolutePath.AsSpan(0, UriPrefixLength).Equals(uriPrefix.AbsolutePath.AsSpan(0, UriPrefixLength), StringComparison.OrdinalIgnoreCase); } public override int GetHashCode() => diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ComponentResourceManager.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ComponentResourceManager.cs index 0633fe471ebf3a..44d5bd954f6277 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ComponentResourceManager.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ComponentResourceManager.cs @@ -141,19 +141,9 @@ private void ApplyResources(object value, Type typeFromValue, string objectName, // See if this key matches our object. string key = kvp.Key; - if (IgnoreCase) + if (!key.StartsWith(objectName, IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal)) { - if (string.Compare(key, 0, objectName, 0, objectName.Length, StringComparison.OrdinalIgnoreCase) != 0) - { - continue; - } - } - else - { - if (string.CompareOrdinal(key, 0, objectName, 0, objectName.Length) != 0) - { - continue; - } + continue; } // Character after objectName.Length should be a "." or a '-', or else we should continue. diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/DesignerOptionService.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/DesignerOptionService.cs index 29e3c3b37c407d..860f5838a9c107 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/DesignerOptionService.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/DesignerOptionService.cs @@ -229,7 +229,7 @@ public DesignerOptionCollection? this[string name] EnsurePopulated(); foreach (DesignerOptionCollection child in _children) { - if (string.Compare(child.Name, name, true, CultureInfo.InvariantCulture) == 0) + if (string.Equals(child.Name, name, StringComparison.InvariantCultureIgnoreCase)) { return child; } diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectPropertyDescriptor.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectPropertyDescriptor.cs index 14816e30eaf8da..7bdcbfba6f2d99 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectPropertyDescriptor.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectPropertyDescriptor.cs @@ -951,7 +951,7 @@ protected override void FillAttributes(IList attributes) internal void OnINotifyPropertyChanged(object? component, PropertyChangedEventArgs e) { if (string.IsNullOrEmpty(e.PropertyName) || - string.Compare(e.PropertyName, Name, true, CultureInfo.InvariantCulture) == 0) + string.Equals(e.PropertyName, Name, StringComparison.InvariantCultureIgnoreCase)) { OnValueChanged(component, e); } diff --git a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/AppSettingsReader.cs b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/AppSettingsReader.cs index 2e4fbe3211bde1..e67493b7edeb6e 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/AppSettingsReader.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/AppSettingsReader.cs @@ -84,7 +84,7 @@ private static int GetNoneNesting(string val) { count++; } - if (count > 0 && string.Compare(NullString, 0, val, count, len - 2 * count, StringComparison.Ordinal) != 0) + if (count > 0 && !val.AsSpan(count, len - 2 * count).Equals(NullString, StringComparison.Ordinal)) { // the stuff between the parens is not "None" count = 0; diff --git a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/StringUtil.cs b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/StringUtil.cs index 5bb89677b6c3be..bcf8c44a11eebc 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/StringUtil.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/StringUtil.cs @@ -17,14 +17,14 @@ internal static bool EqualsIgnoreCase(string s1, string s2) internal static bool StartsWithOrdinal(string s1, string s2) { - if (s2 == null) return false; - return 0 == string.Compare(s1, 0, s2, 0, s2.Length, StringComparison.Ordinal); + if (s1 is null || s2 is null) return false; + return s1.StartsWith(s2, StringComparison.Ordinal); } internal static bool StartsWithOrdinalIgnoreCase(string s1, string s2) { - if (s2 == null) return false; - return 0 == string.Compare(s1, 0, s2, 0, s2.Length, StringComparison.OrdinalIgnoreCase); + if (s1 is null || s2 is null) return false; + return s1.StartsWith(s2, StringComparison.OrdinalIgnoreCase); } internal static string[] ObjectArrayToStringArray(object[] objectArray) diff --git a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/UrlPath.cs b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/UrlPath.cs index 7fe4fc2d359777..c88969a998b62c 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/UrlPath.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/UrlPath.cs @@ -36,7 +36,7 @@ internal static bool IsEqualOrSubdirectory(string dir, string subdir) if (lSubdir < lDir) return false; - if (string.Compare(dir, 0, subdir, 0, lDir, StringComparison.OrdinalIgnoreCase) != 0) + if (!dir.AsSpan(0, lDir).Equals(subdir.AsSpan(0, lDir), StringComparison.OrdinalIgnoreCase)) return false; // Check subdir that character following length of dir is a backslash @@ -84,7 +84,7 @@ private static bool IsEqualOrSubpathImpl(string path, string subpath, bool exclu if (excludeEqual && (lSubpath == lPath)) return false; - if (string.Compare(path, 0, subpath, 0, lPath, StringComparison.OrdinalIgnoreCase) != 0) + if (!path.AsSpan(0, lPath).Equals(subpath.AsSpan(0, lPath), StringComparison.OrdinalIgnoreCase)) return false; // Check subpath that character following length of path is a slash diff --git a/src/libraries/System.Data.Common/src/System/Data/DataTable.cs b/src/libraries/System.Data.Common/src/System/Data/DataTable.cs index 52bc8c57c2c34a..f1c6e04e367646 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataTable.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataTable.cs @@ -3717,11 +3717,11 @@ internal IndexField[] ParseSortString(string? sortString) // handle ASC and DESC. int length = current.Length; bool descending = false; - if (length >= 5 && string.Compare(current, length - 4, " ASC", 0, 4, StringComparison.OrdinalIgnoreCase) == 0) + if (length >= 5 && current.EndsWith(" ASC", StringComparison.OrdinalIgnoreCase)) { current = current.AsSpan(0, length - 4).Trim().ToString(); } - else if (length >= 6 && string.Compare(current, length - 5, " DESC", 0, 5, StringComparison.OrdinalIgnoreCase) == 0) + else if (length >= 6 && current.EndsWith(" DESC", StringComparison.OrdinalIgnoreCase)) { descending = true; current = current.AsSpan(0, length - 5).Trim().ToString(); diff --git a/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcUtils.cs b/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcUtils.cs index f4e81cac67f39b..2da064b5f6087b 100644 --- a/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcUtils.cs +++ b/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcUtils.cs @@ -540,7 +540,7 @@ internal bool StartsWith(string tokenString) return false; } - if (0 == string.Compare(_sqlstatement, tempidx, tokenString, 0, tokenString.Length, StringComparison.OrdinalIgnoreCase)) + if (_sqlstatement.AsSpan(tempidx).StartsWith(tokenString, StringComparison.OrdinalIgnoreCase)) { // Reset current position and token _idx = 0; diff --git a/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLog.cs b/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLog.cs index bd756ee6acc8ec..5e4a0d61058174 100644 --- a/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLog.cs +++ b/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLog.cs @@ -460,7 +460,7 @@ public static void DeleteEventSource(string source, string machineName) // The reason: each log registry key must always contain subkey (i.e. source) with the same name. string keyname = key.Name; int index = keyname.LastIndexOf('\\'); - if (string.Compare(keyname, index + 1, source, 0, keyname.Length - index, StringComparison.Ordinal) == 0) + if (keyname.AsSpan(index + 1).Equals(source, StringComparison.Ordinal)) throw new InvalidOperationException(SR.Format(SR.CannotDeleteEqualSource, source)); } diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Utils.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Utils.cs index 8d634bbb03f974..0a670754edcab8 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Utils.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Utils.cs @@ -1542,7 +1542,7 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string? parti // multivalues attribute we can stop here. foundPartitionEntry = true; - if (string.Compare(dnString, 10, "0", 0, 1, StringComparison.OrdinalIgnoreCase) == 0) + if (dnString[10] == '0') { // this server has the partition fully instantiated ntdsaNames.Add(ntdsaName); @@ -1648,7 +1648,7 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string? parti // find the property name with the range info foreach (string property in res.Properties.PropertyNames) { - if (string.Compare(property, 0, PropertyManager.MsDSHasInstantiatedNCs, 0, PropertyManager.MsDSHasInstantiatedNCs.Length, StringComparison.OrdinalIgnoreCase) == 0) + if (property.AsSpan().StartsWith(PropertyManager.MsDSHasInstantiatedNCs, StringComparison.OrdinalIgnoreCase)) { propertyName = property; break; @@ -1677,7 +1677,7 @@ internal static ArrayList GetReplicaList(DirectoryContext context, string? parti { foundPartitionEntry = true; - if (string.Compare(dnString, 10, "0", 0, 1, StringComparison.OrdinalIgnoreCase) == 0) + if (dnString[10] == '0') { ntdsaNames.Add(ntdsaName); if (isADAM) diff --git a/src/libraries/System.Management/src/System/Management/ManagementQuery.cs b/src/libraries/System.Management/src/System/Management/ManagementQuery.cs index 14b5457d38027b..febaf4d97e62a2 100644 --- a/src/libraries/System.Management/src/System/Management/ManagementQuery.cs +++ b/src/libraries/System.Management/src/System/Management/ManagementQuery.cs @@ -974,7 +974,7 @@ protected internal override void ParseQuery(string query) { //Find "select" clause and get the property list if exists string keyword = TokenSelect; - if ((q.Length >= keyword.Length) && (string.Compare(q, 0, keyword, 0, keyword.Length, StringComparison.OrdinalIgnoreCase) == 0)) //select clause found + if (q.StartsWith(keyword, StringComparison.OrdinalIgnoreCase)) //select clause found { ParseToken(ref q, keyword, ref bFound); if (q[0] != '*') //we have properties @@ -1017,14 +1017,14 @@ protected internal override void ParseQuery(string query) //Find "from" clause, get the class name and remove the clause keyword = "from "; bFound = false; - if ((q.Length >= keyword.Length) && (string.Compare(q, 0, keyword, 0, keyword.Length, StringComparison.OrdinalIgnoreCase) == 0)) //from clause found + if (q.StartsWith(keyword, StringComparison.OrdinalIgnoreCase)) //from clause found ParseToken(ref q, keyword, null, ref bFound, ref className); else //from clause has to be there, otherwise the parsing fails throw new ArgumentException(SR.InvalidQuery); //Find "where" clause, get the condition out and remove the clause keyword = "where "; - if ((q.Length >= keyword.Length) && (string.Compare(q, 0, keyword, 0, keyword.Length, StringComparison.OrdinalIgnoreCase) == 0)) //where clause exists + if (q.StartsWith(keyword, StringComparison.OrdinalIgnoreCase)) //where clause exists { condition = q.Substring(keyword.Length).Trim(); } @@ -1035,8 +1035,7 @@ protected internal override void ParseQuery(string query) string keyword = "select"; // Should start with "select" - if ((q.Length < keyword.Length) || - (0 != string.Compare(q, 0, keyword, 0, keyword.Length, StringComparison.OrdinalIgnoreCase))) + if (!q.StartsWith(keyword, StringComparison.OrdinalIgnoreCase)) throw new ArgumentException(SR.Format(SR.InvalidQueryTokenExpected, keyword), nameof(query)); q = q.Remove(0, keyword.Length).TrimStart(null); @@ -1050,8 +1049,7 @@ protected internal override void ParseQuery(string query) // Next should be "from" keyword = "from"; - if ((q.Length < keyword.Length) || - (0 != string.Compare(q, 0, keyword, 0, keyword.Length, StringComparison.OrdinalIgnoreCase))) + if (!q.StartsWith(keyword, StringComparison.OrdinalIgnoreCase)) throw new ArgumentException(SR.Format(SR.InvalidQueryTokenExpected, keyword), nameof(query)); q = q.Remove(0, keyword.Length).TrimStart(null); @@ -1059,8 +1057,7 @@ protected internal override void ParseQuery(string query) // Next should be "meta_class" keyword = "meta_class"; - if ((q.Length < keyword.Length) || - (0 != string.Compare(q, 0, keyword, 0, keyword.Length, StringComparison.OrdinalIgnoreCase))) + if (!q.StartsWith(keyword, StringComparison.OrdinalIgnoreCase)) throw new ArgumentException(SR.Format(SR.InvalidQueryTokenExpected, keyword), nameof(query)); q = q.Remove(0, keyword.Length).TrimStart(null); @@ -1071,8 +1068,7 @@ protected internal override void ParseQuery(string query) //Find "where" clause, and get the condition out keyword = "where"; - if ((q.Length < keyword.Length) || - (0 != string.Compare(q, 0, keyword, 0, keyword.Length, StringComparison.OrdinalIgnoreCase))) + if (!q.StartsWith(keyword, StringComparison.OrdinalIgnoreCase)) throw new ArgumentException(SR.Format(SR.InvalidQueryTokenExpected, keyword), nameof(query)); q = q.Remove(0, keyword.Length); @@ -1646,7 +1642,7 @@ protected internal override void ParseQuery(string query) int i; //Find "associators" clause - if (0 != string.Compare(q, 0, TokenAssociators, 0, TokenAssociators.Length, StringComparison.OrdinalIgnoreCase)) + if (!q.StartsWith(TokenAssociators, StringComparison.OrdinalIgnoreCase)) throw new ArgumentException(SR.Format(SR.InvalidQueryTokenExpected, TokenAssociators), nameof(query)); // Invalid query // Strip off the clause @@ -1659,7 +1655,7 @@ protected internal override void ParseQuery(string query) q = q.TrimStart(null); // Remove the leading whitespace // Next token should be "of" - if (0 != string.Compare(q, 0, TokenOf, 0, TokenOf.Length, StringComparison.OrdinalIgnoreCase)) + if (!q.StartsWith(TokenOf, StringComparison.OrdinalIgnoreCase)) throw new ArgumentException(SR.Format(SR.InvalidQueryTokenExpected, TokenOf), nameof(query)); // Invalid query // Strip off the clause and leading WS @@ -1683,7 +1679,7 @@ protected internal override void ParseQuery(string query) if (0 < q.Length) { // Next should be the "where" clause - if (0 != string.Compare(q, 0, TokenWhere, 0, TokenWhere.Length, StringComparison.OrdinalIgnoreCase)) + if (!q.StartsWith(TokenWhere, StringComparison.OrdinalIgnoreCase)) throw new ArgumentException(SR.Format(SR.InvalidQueryTokenExpected, TokenWhere), nameof(query)); // Invalid query q = q.Remove(0, TokenWhere.Length); @@ -1707,24 +1703,24 @@ protected internal override void ParseQuery(string query) // Keep looking for tokens until we are done while (true) { - if ((q.Length >= TokenResultClass.Length) && (0 == string.Compare(q, 0, TokenResultClass, 0, TokenResultClass.Length, StringComparison.OrdinalIgnoreCase))) + if (q.StartsWith(TokenResultClass, StringComparison.OrdinalIgnoreCase)) ParseToken(ref q, TokenResultClass, "=", ref bResultClassFound, ref tempRelatedClass); - else if ((q.Length >= TokenAssocClass.Length) && (0 == string.Compare(q, 0, TokenAssocClass, 0, TokenAssocClass.Length, StringComparison.OrdinalIgnoreCase))) + else if (q.StartsWith(TokenAssocClass, StringComparison.OrdinalIgnoreCase)) ParseToken(ref q, TokenAssocClass, "=", ref bAssocClassFound, ref tempRelationshipClass); - else if ((q.Length >= TokenResultRole.Length) && (0 == string.Compare(q, 0, TokenResultRole, 0, TokenResultRole.Length, StringComparison.OrdinalIgnoreCase))) + else if (q.StartsWith(TokenResultRole, StringComparison.OrdinalIgnoreCase)) ParseToken(ref q, TokenResultRole, "=", ref bResultRoleFound, ref tempRelatedRole); - else if ((q.Length >= TokenRole.Length) && (0 == string.Compare(q, 0, TokenRole, 0, TokenRole.Length, StringComparison.OrdinalIgnoreCase))) + else if (q.StartsWith(TokenRole, StringComparison.OrdinalIgnoreCase)) ParseToken(ref q, TokenRole, "=", ref bRoleFound, ref tempThisRole); - else if ((q.Length >= TokenRequiredQualifier.Length) && (0 == string.Compare(q, 0, TokenRequiredQualifier, 0, TokenRequiredQualifier.Length, StringComparison.OrdinalIgnoreCase))) + else if (q.StartsWith(TokenRequiredQualifier, StringComparison.OrdinalIgnoreCase)) ParseToken(ref q, TokenRequiredQualifier, "=", ref bRequiredQualifierFound, ref tempRelatedQualifier); - else if ((q.Length >= TokenRequiredAssocQualifier.Length) && (0 == string.Compare(q, 0, TokenRequiredAssocQualifier, 0, TokenRequiredAssocQualifier.Length, StringComparison.OrdinalIgnoreCase))) + else if (q.StartsWith(TokenRequiredAssocQualifier, StringComparison.OrdinalIgnoreCase)) ParseToken(ref q, TokenRequiredAssocQualifier, "=", ref bRequiredAssocQualifierFound, ref tempRelationshipQualifier); - else if ((q.Length >= TokenSchemaOnly.Length) && (0 == string.Compare(q, 0, TokenSchemaOnly, 0, TokenSchemaOnly.Length, StringComparison.OrdinalIgnoreCase))) + else if (q.StartsWith(TokenSchemaOnly, StringComparison.OrdinalIgnoreCase)) { ParseToken(ref q, TokenSchemaOnly, ref bSchemaOnlyFound); tempIsSchemaQuery = true; } - else if ((q.Length >= TokenClassDefsOnly.Length) && (0 == string.Compare(q, 0, TokenClassDefsOnly, 0, TokenClassDefsOnly.Length, StringComparison.OrdinalIgnoreCase))) + else if (q.StartsWith(TokenClassDefsOnly, StringComparison.OrdinalIgnoreCase)) { ParseToken(ref q, TokenClassDefsOnly, ref bClassDefsOnlyFound); tempClassDefsOnly = true; @@ -2163,7 +2159,7 @@ protected internal override void ParseQuery(string query) int i; //Find "references" clause - if (0 != string.Compare(q, 0, TokenReferences, 0, TokenReferences.Length, StringComparison.OrdinalIgnoreCase)) + if (!q.StartsWith(TokenReferences, StringComparison.OrdinalIgnoreCase)) throw new ArgumentException(SR.Format(SR.InvalidQueryTokenExpected, TokenReferences), nameof(query)); // Invalid query // Strip off the clause @@ -2176,7 +2172,7 @@ protected internal override void ParseQuery(string query) q = q.TrimStart(null); // Remove the leading whitespace // Next token should be "of" - if (0 != string.Compare(q, 0, TokenOf, 0, TokenOf.Length, StringComparison.OrdinalIgnoreCase)) + if (!q.StartsWith(TokenOf, StringComparison.OrdinalIgnoreCase)) throw new ArgumentException(SR.Format(SR.InvalidQueryTokenExpected, TokenOf), nameof(query)); // Invalid query // Strip off the clause and leading WS @@ -2200,7 +2196,7 @@ protected internal override void ParseQuery(string query) if (0 < q.Length) { // Next should be the "where" clause - if (0 != string.Compare(q, 0, TokenWhere, 0, TokenWhere.Length, StringComparison.OrdinalIgnoreCase)) + if (!q.StartsWith(TokenWhere, StringComparison.OrdinalIgnoreCase)) throw new ArgumentException(SR.Format(SR.InvalidQueryTokenExpected, TokenWhere), nameof(query)); // Invalid query q = q.Remove(0, TokenWhere.Length); @@ -2221,18 +2217,18 @@ protected internal override void ParseQuery(string query) // Keep looking for tokens until we are done while (true) { - if ((q.Length >= TokenResultClass.Length) && (0 == string.Compare(q, 0, TokenResultClass, 0, TokenResultClass.Length, StringComparison.OrdinalIgnoreCase))) + if (q.StartsWith(TokenResultClass, StringComparison.OrdinalIgnoreCase)) ParseToken(ref q, TokenResultClass, "=", ref bResultClassFound, ref tempRelationshipClass); - else if ((q.Length >= TokenRole.Length) && (0 == string.Compare(q, 0, TokenRole, 0, TokenRole.Length, StringComparison.OrdinalIgnoreCase))) + else if (q.StartsWith(TokenRole, StringComparison.OrdinalIgnoreCase)) ParseToken(ref q, TokenRole, "=", ref bRoleFound, ref tempThisRole); - else if ((q.Length >= TokenRequiredQualifier.Length) && (0 == string.Compare(q, 0, TokenRequiredQualifier, 0, TokenRequiredQualifier.Length, StringComparison.OrdinalIgnoreCase))) + else if (q.StartsWith(TokenRequiredQualifier, StringComparison.OrdinalIgnoreCase)) ParseToken(ref q, TokenRequiredQualifier, "=", ref bRequiredQualifierFound, ref tempRelationshipQualifier); - else if ((q.Length >= TokenClassDefsOnly.Length) && (0 == string.Compare(q, 0, TokenClassDefsOnly, 0, TokenClassDefsOnly.Length, StringComparison.OrdinalIgnoreCase))) + else if (q.StartsWith(TokenClassDefsOnly, StringComparison.OrdinalIgnoreCase)) { ParseToken(ref q, TokenClassDefsOnly, ref bClassDefsOnlyFound); tempClassDefsOnly = true; } - else if ((q.Length >= TokenSchemaOnly.Length) && (0 == string.Compare(q, 0, TokenSchemaOnly, 0, TokenSchemaOnly.Length, StringComparison.OrdinalIgnoreCase))) + else if (q.StartsWith(TokenSchemaOnly, StringComparison.OrdinalIgnoreCase)) { ParseToken(ref q, TokenSchemaOnly, ref bSchemaOnlyFound); tempSchemaOnly = true; @@ -3034,7 +3030,7 @@ protected internal override void ParseQuery(string query) //Find "select" clause and make sure it's a select * string keyword = TokenSelect; - if ((q.Length < keyword.Length) || (0 != string.Compare(q, 0, keyword, 0, keyword.Length, StringComparison.OrdinalIgnoreCase))) + if (!q.StartsWith(keyword, StringComparison.OrdinalIgnoreCase)) throw new ArgumentException(SR.InvalidQuery); q = q.Remove(0, keyword.Length).TrimStart(null); @@ -3044,13 +3040,13 @@ protected internal override void ParseQuery(string query) //Find "from" clause keyword = "from "; - if ((q.Length < keyword.Length) || (0 != string.Compare(q, 0, keyword, 0, keyword.Length, StringComparison.OrdinalIgnoreCase))) + if (!q.StartsWith(keyword, StringComparison.OrdinalIgnoreCase)) throw new ArgumentException(SR.Format(SR.InvalidQueryTokenExpected, keyword), nameof(query)); ParseToken(ref q, keyword, null, ref bFound, ref eventClassName); //Find "within" clause keyword = "within "; - if ((q.Length >= keyword.Length) && (0 == string.Compare(q, 0, keyword, 0, keyword.Length, StringComparison.OrdinalIgnoreCase))) + if (q.StartsWith(keyword, StringComparison.OrdinalIgnoreCase)) { string intervalString = null; bFound = false; ParseToken(ref q, keyword, null, ref bFound, ref intervalString); @@ -3071,7 +3067,7 @@ protected internal override void ParseQuery(string query) //Find "By" subclause keyword = "by "; - if ((q.Length >= keyword.Length) && (0 == string.Compare(q, 0, keyword, 0, keyword.Length, StringComparison.OrdinalIgnoreCase))) + if (q.StartsWith(keyword, StringComparison.OrdinalIgnoreCase)) { q = q.Remove(0, keyword.Length); if (null != groupByPropertyList) @@ -3110,7 +3106,7 @@ protected internal override void ParseQuery(string query) //Find "Having" subclause keyword = "having "; bFound = false; - if ((q.Length >= keyword.Length) && (0 == string.Compare(q, 0, keyword, 0, keyword.Length, StringComparison.OrdinalIgnoreCase))) + if (q.StartsWith(keyword, StringComparison.OrdinalIgnoreCase)) { //the rest until the end is assumed to be the having condition q = q.Remove(0, keyword.Length); @@ -3126,7 +3122,7 @@ protected internal override void ParseQuery(string query) //Find "where" clause keyword = "where "; - if ((w.Length >= keyword.Length) && (0 == string.Compare(w, 0, keyword, 0, keyword.Length, StringComparison.OrdinalIgnoreCase))) //where clause exists + if (w.StartsWith(keyword, StringComparison.OrdinalIgnoreCase)) //where clause exists { condition = w.Substring(keyword.Length); } diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/AuthenticationHeaderValue.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/AuthenticationHeaderValue.cs index d83514a6da2a7a..49725e52680f03 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/AuthenticationHeaderValue.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/AuthenticationHeaderValue.cs @@ -142,7 +142,7 @@ internal static int GetAuthenticationLength(string? input, int startIndex, out o case 9: targetScheme = "Negotiate"; break; } - string scheme = targetScheme != null && string.CompareOrdinal(input, startIndex, targetScheme, 0, schemeLength) == 0 ? + string scheme = targetScheme != null && input.AsSpan(startIndex, schemeLength).Equals(targetScheme, StringComparison.Ordinal) ? targetScheme : input.Substring(startIndex, schemeLength); diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpWindowsProxy.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpWindowsProxy.cs index caf9104abc8d13..0b26a0aff6d262 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpWindowsProxy.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpWindowsProxy.cs @@ -119,11 +119,11 @@ private void UpdateConfiguration(WinInetProxyHelper? proxyHelper = null) { // Strip leading spaces and scheme if any. while (idx < proxyHelper.ProxyBypass.Length && proxyHelper.ProxyBypass[idx] == ' ') { idx += 1; }; - if (string.Compare(proxyHelper.ProxyBypass, idx, "http://", 0, 7, StringComparison.OrdinalIgnoreCase) == 0) + if (proxyHelper.ProxyBypass.AsSpan(idx).StartsWith("http://", StringComparison.OrdinalIgnoreCase)) { idx += 7; } - else if (string.Compare(proxyHelper.ProxyBypass, idx, "https://", 0, 8, StringComparison.OrdinalIgnoreCase) == 0) + else if (proxyHelper.ProxyBypass.AsSpan(idx).StartsWith("https://", StringComparison.OrdinalIgnoreCase)) { idx += 8; } @@ -142,7 +142,7 @@ private void UpdateConfiguration(WinInetProxyHelper? proxyHelper = null) // Empty string. tmp = null; } - else if (string.Compare(proxyHelper.ProxyBypass, start, "", 0, 7, StringComparison.OrdinalIgnoreCase) == 0) + else if (proxyHelper.ProxyBypass.AsSpan(start).StartsWith("", StringComparison.OrdinalIgnoreCase)) { bypassLocal = true; tmp = null; diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/HttpListener.cs b/src/libraries/System.Net.HttpListener/src/System/Net/HttpListener.cs index dec754253c3805..8fcc46a652c2e2 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/HttpListener.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/HttpListener.cs @@ -113,11 +113,11 @@ internal void AddPrefix(string uriPrefix) { CheckDisposed(); int i; - if (string.Compare(uriPrefix, 0, "http://", 0, 7, StringComparison.OrdinalIgnoreCase) == 0) + if (uriPrefix.StartsWith("http://", StringComparison.OrdinalIgnoreCase)) { i = 7; } - else if (string.Compare(uriPrefix, 0, "https://", 0, 8, StringComparison.OrdinalIgnoreCase) == 0) + else if (uriPrefix.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) { i = 8; } diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Managed/HttpListenerContext.Managed.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Managed/HttpListenerContext.Managed.cs index da278ee7da01b2..8bf5222c2b3899 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/Managed/HttpListenerContext.Managed.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/Managed/HttpListenerContext.Managed.cs @@ -53,7 +53,7 @@ internal void ParseAuthentication(AuthenticationSchemes expectedSchemes) internal static bool IsBasicHeader(string header) => header.Length >= 6 && header[5] == ' ' && - string.Compare(header, 0, AuthenticationTypes.Basic, 0, 5, StringComparison.OrdinalIgnoreCase) == 0; + header.AsSpan(0, 5).Equals(AuthenticationTypes.Basic, StringComparison.OrdinalIgnoreCase); internal static bool TryParseBasicAuth(string headerValue, out HttpStatusCode errorCode, [NotNullWhen(true)] out string? username, [NotNullWhen(true)] out string? password) { diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListener.Windows.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListener.Windows.cs index 5e0e6b4648a899..9bab9eea36d97c 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListener.Windows.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListener.Windows.cs @@ -806,17 +806,17 @@ public HttpListenerContext EndGetContext(IAsyncResult asyncResult) if (index < authorizationHeader.Length) { if ((authenticationScheme & AuthenticationSchemes.Negotiate) != AuthenticationSchemes.None && - string.Compare(authorizationHeader, 0, AuthenticationTypes.Negotiate, 0, index, StringComparison.OrdinalIgnoreCase) == 0) + authorizationHeader.AsSpan(0, index).Equals(AuthenticationTypes.Negotiate, StringComparison.OrdinalIgnoreCase)) { headerScheme = AuthenticationSchemes.Negotiate; } else if ((authenticationScheme & AuthenticationSchemes.Ntlm) != AuthenticationSchemes.None && - string.Compare(authorizationHeader, 0, AuthenticationTypes.NTLM, 0, index, StringComparison.OrdinalIgnoreCase) == 0) + authorizationHeader.AsSpan(0, index).Equals(AuthenticationTypes.NTLM, StringComparison.OrdinalIgnoreCase)) { headerScheme = AuthenticationSchemes.Ntlm; } else if ((authenticationScheme & AuthenticationSchemes.Basic) != AuthenticationSchemes.None && - string.Compare(authorizationHeader, 0, AuthenticationTypes.Basic, 0, index, StringComparison.OrdinalIgnoreCase) == 0) + authorizationHeader.AsSpan(0, index).Equals(AuthenticationTypes.Basic, StringComparison.OrdinalIgnoreCase)) { headerScheme = AuthenticationSchemes.Basic; } diff --git a/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpConnection.Auth.cs b/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpConnection.Auth.cs index 0fa1b892fd9a5d..3177a7eb916c07 100644 --- a/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpConnection.Auth.cs +++ b/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpConnection.Auth.cs @@ -45,8 +45,12 @@ internal void ParseExtensions(string[] extensions) _supportedAuth = SupportedAuth.None; foreach (string extension in extensions) { - if (string.Compare(extension, 0, AuthExtension, 0, - SizeOfAuthExtension, StringComparison.OrdinalIgnoreCase) == 0) + if (extension is null) + { + continue; + } + + if (extension.StartsWith(AuthExtension, StringComparison.OrdinalIgnoreCase)) { // remove the AUTH text including the following character // to ensure that split only gets the modules supported @@ -67,15 +71,15 @@ internal void ParseExtensions(string[] extensions) } } } - else if (string.Compare(extension, 0, "dsn ", 0, 3, StringComparison.OrdinalIgnoreCase) == 0) + else if (extension.StartsWith("dsn", StringComparison.OrdinalIgnoreCase)) { _dsnEnabled = true; } - else if (string.Compare(extension, 0, "STARTTLS", 0, 8, StringComparison.OrdinalIgnoreCase) == 0) + else if (extension.StartsWith("STARTTLS", StringComparison.OrdinalIgnoreCase)) { _serverSupportsStartTls = true; } - else if (string.Compare(extension, 0, "SMTPUTF8", 0, 8, StringComparison.OrdinalIgnoreCase) == 0) + else if (extension.StartsWith("SMTPUTF8", StringComparison.OrdinalIgnoreCase)) { _serverSupportsEai = true; } diff --git a/src/libraries/System.Net.WebProxy/src/System/Net/WebProxy.NonWasm.cs b/src/libraries/System.Net.WebProxy/src/System/Net/WebProxy.NonWasm.cs index 7d35d4310317f9..83ef1903d691fc 100644 --- a/src/libraries/System.Net.WebProxy/src/System/Net/WebProxy.NonWasm.cs +++ b/src/libraries/System.Net.WebProxy/src/System/Net/WebProxy.NonWasm.cs @@ -39,9 +39,7 @@ private static bool IsLocal(Uri host) // If it matches the primary domain, it's local (whether or not the hostname matches). EnsureNetworkChangeRegistration(); string local = s_domainName ??= "." + IPGlobalProperties.GetIPGlobalProperties().DomainName; - return - local.Length == (hostString.Length - dot) && - string.Compare(local, 0, hostString, dot, local.Length, StringComparison.OrdinalIgnoreCase) == 0; + return hostString.AsSpan(dot).Equals(local, StringComparison.OrdinalIgnoreCase); } /// Ensures we've registered with NetworkChange to clear out statically-cached state upon a network change notification. diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.GetFolderPathCore.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.GetFolderPathCore.Unix.cs index 9d7cf66b226dc8..9bb364def2a723 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Environment.GetFolderPathCore.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Environment.GetFolderPathCore.Unix.cs @@ -201,7 +201,7 @@ private static string ReadXdgDirectory(string homeDir, string key, string fallba if (pos >= line.Length) continue; // Skip past requested key name - if (string.CompareOrdinal(line, pos, key, 0, key.Length) != 0) continue; + if (!line.AsSpan(pos).StartsWith(key, StringComparison.Ordinal)) continue; pos += key.Length; // Skip past whitespace and past '=' @@ -217,7 +217,7 @@ private static string ReadXdgDirectory(string homeDir, string key, string fallba // Skip past relative prefix if one exists bool relativeToHome = false; const string RelativeToHomePrefix = "$HOME/"; - if (string.CompareOrdinal(line, pos, RelativeToHomePrefix, 0, RelativeToHomePrefix.Length) == 0) + if (line.AsSpan(pos).StartsWith(RelativeToHomePrefix, StringComparison.Ordinal)) { relativeToHome = true; pos += RelativeToHomePrefix.Length; diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/HijriCalendar.Win32.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/HijriCalendar.Win32.cs index 7d01915375a643..b9083384886d1f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/HijriCalendar.Win32.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/HijriCalendar.Win32.cs @@ -54,9 +54,9 @@ private static int GetAdvanceHijriDate() int hijriAdvance = 0; string? str = value.ToString(); - if (string.Compare(str, 0, HijriAdvanceRegKeyEntry, 0, HijriAdvanceRegKeyEntry.Length, StringComparison.OrdinalIgnoreCase) == 0) + if (str is not null && str.StartsWith(HijriAdvanceRegKeyEntry, StringComparison.OrdinalIgnoreCase)) { - if (str!.Length == HijriAdvanceRegKeyEntry.Length) + if (str.Length == HijriAdvanceRegKeyEntry.Length) { hijriAdvance = -1; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.cs index f6d3822bb07ca5..bb862ace0ee170 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.cs @@ -763,8 +763,7 @@ private static string PunycodeDecode(string ascii) throw new ArgumentException(SR.Argument_IdnBadLabelSize, nameof(ascii)); // See if this section's ASCII or ACE - if (ascii.Length < c_strAcePrefix.Length + iAfterLastDot || - string.Compare(ascii, iAfterLastDot, c_strAcePrefix, 0, c_strAcePrefix.Length, StringComparison.OrdinalIgnoreCase) != 0) + if (!ascii.AsSpan(iAfterLastDot).StartsWith(c_strAcePrefix, StringComparison.OrdinalIgnoreCase)) { // Its ASCII, copy it output.Append(ascii, iAfterLastDot, iNextDot - iAfterLastDot); diff --git a/src/libraries/System.Private.CoreLib/src/System/Security/SecurityElement.cs b/src/libraries/System.Private.CoreLib/src/System/Security/SecurityElement.cs index 267ed51252c8d3..3af8723f205f61 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Security/SecurityElement.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Security/SecurityElement.cs @@ -340,8 +340,6 @@ private static string GetEscapeSequence(char c) private static string GetUnescapeSequence(string str, int index, out int newIndex) { - int maxCompareLength = str.Length - index; - int iMax = s_escapeStringPairs.Length; Debug.Assert(iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly"); @@ -350,9 +348,7 @@ private static string GetUnescapeSequence(string str, int index, out int newInde string strEscSeq = s_escapeStringPairs[i]; string strEscValue = s_escapeStringPairs[i + 1]; - int length = strEscValue.Length; - - if (length <= maxCompareLength && string.Compare(strEscValue, 0, str, index, length, StringComparison.Ordinal) == 0) + if (str.AsSpan(index).StartsWith(strEscValue, StringComparison.Ordinal)) { newIndex = index + strEscValue.Length; return strEscSeq; diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/EnumDataContract.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/EnumDataContract.cs index 9b73639c4d1a97..e090bcebf50df2 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/EnumDataContract.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/EnumDataContract.cs @@ -378,7 +378,7 @@ private long ReadEnumValue(string value, int index, int count) for (int i = 0; i < Members.Count; i++) { string memberName = Members[i].Name; - if (memberName.Length == count && string.CompareOrdinal(value, index, memberName, 0, count) == 0) + if (value.AsSpan(index, count).Equals(memberName, StringComparison.Ordinal)) { return Values![i]; } diff --git a/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XHashtable.cs b/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XHashtable.cs index d4f448976cc10e..44490bae889ab3 100644 --- a/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XHashtable.cs +++ b/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XHashtable.cs @@ -371,7 +371,7 @@ private bool FindEntry(int hashCode, string key, int index, int count, ref int e else { // Valid key, so compare keys - if (count == keyCompare.Length && string.CompareOrdinal(key, index, keyCompare, 0, count) == 0) + if (key.AsSpan(index, count).Equals(keyCompare, StringComparison.Ordinal)) { // Found match, so return true and matching entry in list entryIndex = currentIndex; diff --git a/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XNamespace.cs b/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XNamespace.cs index 34ca0b49dd7ca6..eb77a0077d0714 100644 --- a/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XNamespace.cs +++ b/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XNamespace.cs @@ -251,8 +251,8 @@ internal static XNamespace Get(string namespaceName, int index, int count) if (!s_namespaces.TryGetValue(namespaceName, index, count, out refNamespace)) { // If it is not there, first determine whether it's a special namespace - if (count == xmlPrefixNamespace.Length && string.CompareOrdinal(namespaceName, index, xmlPrefixNamespace, 0, count) == 0) return Xml; - if (count == xmlnsPrefixNamespace.Length && string.CompareOrdinal(namespaceName, index, xmlnsPrefixNamespace, 0, count) == 0) return Xmlns; + if (namespaceName.AsSpan(index, count).Equals(xmlPrefixNamespace, StringComparison.Ordinal)) return Xml; + if (namespaceName.AsSpan(index, count).Equals(xmlnsPrefixNamespace, StringComparison.Ordinal)) return Xmlns; // Go ahead and create the namespace and add it to the table refNamespace = s_namespaces.Add(new WeakReference(new XNamespace(namespaceName.Substring(index, count)))); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XdrBuilder.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XdrBuilder.cs index e950d74aacccea..68a083a8658e11 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XdrBuilder.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XdrBuilder.cs @@ -548,8 +548,7 @@ private bool LoadSchema(string uri) internal static bool IsXdrSchema(string uri) { - return uri.Length >= x_schema.Length && - 0 == string.Compare(uri, 0, x_schema, 0, x_schema.Length, StringComparison.Ordinal) && + return uri.StartsWith(x_schema, StringComparison.Ordinal) && !uri.StartsWith("x-schema:#", StringComparison.Ordinal); } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/StringFunctions.cs b/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/StringFunctions.cs index 4dc9c791fbc6c6..a3c759292543b0 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/StringFunctions.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/StringFunctions.cs @@ -131,7 +131,7 @@ private bool StartsWith(XPathNodeIterator nodeIterator) Debug.Assert(_argList.Count > 1); string s1 = _argList[0].Evaluate(nodeIterator).ToString()!; string s2 = _argList[1].Evaluate(nodeIterator).ToString()!; - return s1.Length >= s2.Length && string.CompareOrdinal(s1, 0, s2, 0, s2.Length) == 0; + return s1.StartsWith(s2, StringComparison.Ordinal); } private bool Contains(XPathNodeIterator nodeIterator) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XsltFunctions.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XsltFunctions.cs index 4efa9417fd1d06..84bed3581ce71c 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XsltFunctions.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XsltFunctions.cs @@ -28,7 +28,7 @@ public static class XsltFunctions public static bool StartsWith(string s1, string s2) { //return collation.IsPrefix(s1, s2); - return s1.Length >= s2.Length && string.CompareOrdinal(s1, 0, s2, 0, s2.Length) == 0; + return s1.StartsWith(s2, StringComparison.Ordinal); } public static bool Contains(string s1, string s2) diff --git a/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/FileChangeNotificationSystem.cs b/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/FileChangeNotificationSystem.cs index ca290776200788..aeabaaba853379 100644 --- a/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/FileChangeNotificationSystem.cs +++ b/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/FileChangeNotificationSystem.cs @@ -45,11 +45,7 @@ private static bool EqualsIgnoreCase(string s1, string s2) { return false; } - if (s2.Length != s1.Length) - { - return false; - } - return 0 == string.Compare(s1, 0, s2, 0, s2.Length, StringComparison.OrdinalIgnoreCase); + return s1.Equals(s2, StringComparison.OrdinalIgnoreCase); } private void OnChanged(object sender, FileSystemEventArgs e) diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeModuleBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeModuleBuilder.Mono.cs index 91ba1108493274..e563a44584d71f 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeModuleBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeModuleBuilder.Mono.cs @@ -313,7 +313,7 @@ protected override EnumBuilder DefineEnumCore(string name, TypeAttributes visibi int i; for (i = 0; i < validElementsInArray; ++i) { - if (string.Compare(className.DisplayName, arr[i].FullName, true, CultureInfo.InvariantCulture) == 0) + if (string.Equals(className.DisplayName, arr[i].FullName, StringComparison.InvariantCultureIgnoreCase)) { return arr[i]; } @@ -326,7 +326,7 @@ protected override EnumBuilder DefineEnumCore(string name, TypeAttributes visibi int i; for (i = 0; i < validElementsInArray; ++i) { - if (string.Compare(className.DisplayName, arr[i].Name, true, CultureInfo.InvariantCulture) == 0) + if (string.Equals(className.DisplayName, arr[i].Name, StringComparison.InvariantCultureIgnoreCase)) return arr[i]; } return null;