Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 40b6090

Browse files
committed
System.Xml: String.Compare -> String.Equals
Per the Best Practices for Using Strings at http://msdn.microsoft.com/en-us/library/dd465121(v=vs.110).aspx * Use an overload of the String.Equals method to test whether two strings are equal. * Use the String.Compare and String.CompareTo methods to sort strings, not to check for equality.
1 parent d5a8825 commit 40b6090

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

src/System.Xml.ReaderWriter/src/System/Xml/Core/XmlTextReaderImpl.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,22 +2300,22 @@ private Encoding CheckEncoding(string newEncodingName)
23002300
return _ps.encoding;
23012301
}
23022302

2303-
if (0 == String.Compare(newEncodingName, "ucs-2", StringComparison.OrdinalIgnoreCase) ||
2304-
0 == String.Compare(newEncodingName, "utf-16", StringComparison.OrdinalIgnoreCase) ||
2305-
0 == String.Compare(newEncodingName, "iso-10646-ucs-2", StringComparison.OrdinalIgnoreCase) ||
2306-
0 == String.Compare(newEncodingName, "ucs-4", StringComparison.OrdinalIgnoreCase))
2303+
if (String.Equals(newEncodingName, "ucs-2", StringComparison.OrdinalIgnoreCase) ||
2304+
String.Equals(newEncodingName, "utf-16", StringComparison.OrdinalIgnoreCase) ||
2305+
String.Equals(newEncodingName, "iso-10646-ucs-2", StringComparison.OrdinalIgnoreCase) ||
2306+
String.Equals(newEncodingName, "ucs-4", StringComparison.OrdinalIgnoreCase))
23072307
{
23082308
if (_ps.encoding.WebName != "utf-16BE" &&
23092309
_ps.encoding.WebName != "utf-16" &&
2310-
0 != String.Compare(newEncodingName, "ucs-4", StringComparison.OrdinalIgnoreCase))
2310+
!String.Equals(newEncodingName, "ucs-4", StringComparison.OrdinalIgnoreCase))
23112311
{
23122312
ThrowWithoutLineInfo(SR.Xml_MissingByteOrderMark);
23132313
}
23142314
return _ps.encoding;
23152315
}
23162316

23172317
Encoding newEncoding = null;
2318-
if (0 == String.Compare(newEncodingName, "utf-8", StringComparison.OrdinalIgnoreCase))
2318+
if (String.Equals(newEncodingName, "utf-8", StringComparison.OrdinalIgnoreCase))
23192319
{
23202320
newEncoding = new UTF8Encoding(true, true);
23212321
}
@@ -5030,7 +5030,7 @@ private bool ParsePI(BufferBuilder piInDtdStringBuilder)
50305030
int nameEndPos = ParseName();
50315031
string target = _nameTable.Add(_ps.chars, _ps.charPos, nameEndPos - _ps.charPos);
50325032

5033-
if (string.Compare(target, "xml", StringComparison.OrdinalIgnoreCase) == 0)
5033+
if (string.Equals(target, "xml", StringComparison.OrdinalIgnoreCase))
50345034
{
50355035
Throw(target.Equals("xml") ? SR.Xml_XmlDeclNotFirst : SR.Xml_InvalidPIName, target);
50365036
}

src/System.Xml.ReaderWriter/src/System/Xml/Core/XmlTextReaderImplAsync.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3646,7 +3646,7 @@ private async Task<bool> ParsePIAsync(BufferBuilder piInDtdStringBuilder)
36463646
int nameEndPos = await ParseNameAsync().ConfigureAwait(false);
36473647
string target = _nameTable.Add(_ps.chars, _ps.charPos, nameEndPos - _ps.charPos);
36483648

3649-
if (string.Compare(target, "xml", StringComparison.OrdinalIgnoreCase) == 0)
3649+
if (string.Equals(target, "xml", StringComparison.OrdinalIgnoreCase))
36503650
{
36513651
Throw(target.Equals("xml") ? SR.Xml_XmlDeclNotFirst : SR.Xml_InvalidPIName, target);
36523652
}

src/System.Xml.ReaderWriter/src/System/Xml/Core/XmlTextReaderImplHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ public int Compare(object x, object y)
726726
}
727727
}
728728

729-
// string.Compare does reference euqality first for us, so we don't have to do it here
729+
// string.Compare does reference equality first for us, so we don't have to do it here
730730
int result = string.Compare(localName, localName2, StringComparison.Ordinal);
731731
if (result != 0)
732732
{

src/System.Xml.ReaderWriter/src/System/Xml/Core/XmlWellformedWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ public override void WriteProcessingInstruction(string name, string text)
954954
}
955955

956956
// xml declaration is a special case (not a processing instruction, but we allow WriteProcessingInstruction as a convenience)
957-
if (name.Length == 3 && string.Compare(name, "xml", StringComparison.OrdinalIgnoreCase) == 0)
957+
if (name.Length == 3 && string.Equals(name, "xml", StringComparison.OrdinalIgnoreCase))
958958
{
959959
if (_currentState != State.Start)
960960
{

src/System.Xml.ReaderWriter/src/System/Xml/Core/XmlWellformedWriterAsync.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ public override async Task WriteProcessingInstructionAsync(string name, string t
817817
}
818818

819819
// xml declaration is a special case (not a processing instruction, but we allow WriteProcessingInstruction as a convenience)
820-
if (name.Length == 3 && string.Compare(name, "xml", StringComparison.OrdinalIgnoreCase) == 0)
820+
if (name.Length == 3 && string.Equals(name, "xml", StringComparison.OrdinalIgnoreCase))
821821
{
822822
if (_currentState != State.Start)
823823
{

0 commit comments

Comments
 (0)