// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.Collections;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;
-using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using Internal.Runtime.CompilerServices;
{
public partial class String
{
- private static unsafe int CompareOrdinalIgnoreCaseHelper(String strA, String strB)
+ private static unsafe int CompareOrdinalIgnoreCaseHelper(string strA, string strB)
{
Debug.Assert(strA != null);
Debug.Assert(strB != null);
//
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool EqualsHelper(String strA, String strB)
+ private static bool EqualsHelper(string strA, string strB)
{
Debug.Assert(strA != null);
Debug.Assert(strB != null);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static int CompareOrdinalHelper(String strA, int indexA, int countA, String strB, int indexB, int countB)
+ private static int CompareOrdinalHelper(string strA, int indexA, int countA, string strB, int indexB, int countB)
{
Debug.Assert(strA != null);
Debug.Assert(strB != null);
return SpanHelpers.SequenceCompareTo(ref Unsafe.Add(ref strA.GetRawStringData(), indexA), countA, ref Unsafe.Add(ref strB.GetRawStringData(), indexB), countB);
}
- private static unsafe bool EqualsIgnoreCaseAsciiHelper(String strA, String strB)
+ private static unsafe bool EqualsIgnoreCaseAsciiHelper(string strA, string strB)
{
Debug.Assert(strA != null);
Debug.Assert(strB != null);
}
}
- private static unsafe int CompareOrdinalHelper(String strA, String strB)
+ private static unsafe int CompareOrdinalHelper(string strA, string strB)
{
Debug.Assert(strA != null);
Debug.Assert(strB != null);
// and 64-bit (16 bytes) platforms.
// For empty strings, the second char will be null due to padding.
- // The start of the string (not including sync block pointer)
- // is the method table pointer + string length, which takes up
- // 8 bytes on 32-bit, 12 on x64. For empty strings the null
+ // The start of the string is the type pointer + string length, which
+ // takes up 8 bytes on 32-bit, 12 on x64. For empty strings the null
// terminator immediately follows, leaving us with an object
// 10/14 bytes in size. Since everything needs to be a multiple
// of 4/8, this will get padded and zeroed out.
// to determine whether it is lexicographically less, equal, or greater, and then returns
// either a negative integer, 0, or a positive integer; respectively.
//
- public static int Compare(String strA, String strB)
+ public static int Compare(string strA, string strB)
{
return Compare(strA, strB, StringComparison.CurrentCulture);
}
// negative integer, 0, or a positive integer is returned; respectively.
// The case-sensitive option is set by ignoreCase
//
- public static int Compare(String strA, String strB, bool ignoreCase)
+ public static int Compare(string strA, string strB, bool ignoreCase)
{
var comparisonType = ignoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture;
return Compare(strA, strB, comparisonType);
}
- // Provides a more flexible function for string comparision. See StringComparison
+ // Provides a more flexible function for string comparison. See StringComparison
// for meaning of different comparisonType.
- public static int Compare(String strA, String strB, StringComparison comparisonType)
+ public static int Compare(string strA, string strB, StringComparison comparisonType)
{
if (object.ReferenceEquals(strA, strB))
{
// to determine whether it is lexicographically less, equal, or greater, and then a
// negative integer, 0, or a positive integer is returned; respectively.
//
- public static int Compare(String strA, String strB, CultureInfo culture, CompareOptions options)
+ public static int Compare(string strA, string strB, CultureInfo culture, CompareOptions options)
{
if (culture == null)
{
// The case-sensitive option is set by ignoreCase, and the culture is set
// by culture
//
- public static int Compare(String strA, String strB, bool ignoreCase, CultureInfo culture)
+ public static int Compare(string strA, string strB, bool ignoreCase, CultureInfo culture)
{
var options = ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None;
return Compare(strA, strB, culture, options);
}
// Determines whether two string regions match. The substring of strA beginning
- // at indexA of length count is compared with the substring of strB
+ // at indexA of given length is compared with the substring of strB
// beginning at indexB of the same length.
//
- public static int Compare(String strA, int indexA, String strB, int indexB, int length)
+ public static int Compare(string strA, int indexA, string strB, int indexB, int length)
{
// NOTE: It's important we call the boolean overload, and not the StringComparison
// one. The two have some subtly different behavior (see notes in the former).
}
// Determines whether two string regions match. The substring of strA beginning
- // at indexA of length count is compared with the substring of strB
+ // at indexA of given length is compared with the substring of strB
// beginning at indexB of the same length. Case sensitivity is determined by the ignoreCase boolean.
//
- public static int Compare(String strA, int indexA, String strB, int indexB, int length, bool ignoreCase)
+ public static int Compare(string strA, int indexA, string strB, int indexB, int length, bool ignoreCase)
{
// Ideally we would just forward to the string.Compare overload that takes
// a StringComparison parameter, and just pass in CurrentCulture/CurrentCultureIgnoreCase.
// beginning at indexB of the same length. Case sensitivity is determined by the ignoreCase boolean,
// and the culture is set by culture.
//
- public static int Compare(String strA, int indexA, String strB, int indexB, int length, bool ignoreCase, CultureInfo culture)
+ public static int Compare(string strA, int indexA, string strB, int indexB, int length, bool ignoreCase, CultureInfo culture)
{
var options = ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None;
return Compare(strA, indexA, strB, indexB, length, culture, options);
// at indexA of length length is compared with the substring of strB
// beginning at indexB of the same length.
//
- public static int Compare(String strA, int indexA, String strB, int indexB, int length, CultureInfo culture, CompareOptions options)
+ public static int Compare(string strA, int indexA, string strB, int indexB, int length, CultureInfo culture, CompareOptions options)
{
if (culture == null)
{
return culture.CompareInfo.Compare(strA, indexA, lengthA, strB, indexB, lengthB, options);
}
- public static int Compare(String strA, int indexA, String strB, int indexB, int length, StringComparison comparisonType)
+ public static int Compare(string strA, int indexA, string strB, int indexB, int length, StringComparison comparisonType)
{
CheckStringComparison(comparisonType);
// Compares strA and strB using an ordinal (code-point) comparison.
//
- public static int CompareOrdinal(String strA, String strB)
+ public static int CompareOrdinal(string strA, string strB)
{
if (object.ReferenceEquals(strA, strB))
{
// Compares strA and strB using an ordinal (code-point) comparison.
//
- public static int CompareOrdinal(String strA, int indexA, String strB, int indexB, int length)
+ public static int CompareOrdinal(string strA, int indexA, string strB, int indexB, int length)
{
if (strA == null || strB == null)
{
// indicates the relationship. This method returns a value less than 0 if this is less than value, 0
// if this is equal to value, or a value greater than 0 if this is greater than value.
//
- public int CompareTo(Object value)
+ public int CompareTo(object value)
{
if (value == null)
{
// Determines the sorting relation of StrB to the current instance.
//
- public int CompareTo(String strB)
+ public int CompareTo(string strB)
{
return string.Compare(this, strB, StringComparison.CurrentCulture);
}
// The case-sensitive and culture-sensitive option is set by options,
// and the default culture is used.
//
- public Boolean EndsWith(String value)
+ public bool EndsWith(string value)
{
return EndsWith(value, StringComparison.CurrentCulture);
}
- public Boolean EndsWith(String value, StringComparison comparisonType)
+ public bool EndsWith(string value, StringComparison comparisonType)
{
- if ((Object)value == null)
+ if ((object)value == null)
{
throw new ArgumentNullException(nameof(value));
}
- if ((Object)this == (Object)value)
+ if ((object)this == (object)value)
{
CheckStringComparison(comparisonType);
return true;
}
}
- public Boolean EndsWith(String value, Boolean ignoreCase, CultureInfo culture)
+ public bool EndsWith(string value, bool ignoreCase, CultureInfo culture)
{
if (null == value)
{
}
// Determines whether two strings match.
- public override bool Equals(Object obj)
+ public override bool Equals(object obj)
{
if (object.ReferenceEquals(this, obj))
return true;
}
// Determines whether two strings match.
- public bool Equals(String value)
+ public bool Equals(string value)
{
if (object.ReferenceEquals(this, value))
return true;
return EqualsHelper(this, value);
}
- public bool Equals(String value, StringComparison comparisonType)
+ public bool Equals(string value, StringComparison comparisonType)
{
- if ((Object)this == (Object)value)
+ if ((object)this == (object)value)
{
CheckStringComparison(comparisonType);
return true;
}
- if ((Object)value == null)
+ if ((object)value == null)
{
CheckStringComparison(comparisonType);
return false;
// Determines whether two Strings match.
- public static bool Equals(String a, String b)
+ public static bool Equals(string a, string b)
{
- if ((Object)a == (Object)b)
+ if ((object)a == (object)b)
{
return true;
}
- if ((Object)a == null || (Object)b == null || a.Length != b.Length)
+ if ((object)a == null || (object)b == null || a.Length != b.Length)
{
return false;
}
return EqualsHelper(a, b);
}
- public static bool Equals(String a, String b, StringComparison comparisonType)
+ public static bool Equals(string a, string b, StringComparison comparisonType)
{
- if ((Object)a == (Object)b)
+ if ((object)a == (object)b)
{
CheckStringComparison(comparisonType);
return true;
}
- if ((Object)a == null || (Object)b == null)
+ if ((object)a == null || (object)b == null)
{
CheckStringComparison(comparisonType);
return false;
}
}
- public static bool operator ==(String a, String b)
+ public static bool operator ==(string a, string b)
{
- return String.Equals(a, b);
+ return string.Equals(a, b);
}
- public static bool operator !=(String a, String b)
+ public static bool operator !=(string a, string b)
{
- return !String.Equals(a, b);
+ return !string.Equals(a, b);
}
// Gets a hash code for this string. If strings A and B are such that A.Equals(B), then
}
// Gets a hash code for this string and this comparison. If strings A and B and comparison C are such
- // that String.Equals(A, B, C), then they will return the same hash code with this comparison C.
+ // that string.Equals(A, B, C), then they will return the same hash code with this comparison C.
public int GetHashCode(StringComparison comparisonType) => StringComparer.FromComparison(comparisonType).GetHashCode(this);
// Use this if and only if you need the hashcode to not change across app domains (e.g. you have an app domain agile
hash1 = ((hash1 << 5) + hash1 + (hash1 >> 27)) ^ pint[0];
}
#endif
-#if DEBUG
- // We want to ensure we can change our hash function daily.
- // This is perfectly fine as long as you don't persist the
- // value from GetHashCode to disk or count on String A
- // hashing before string B. Those are bugs in your code.
- hash1 ^= ThisAssembly.DailyBuildNumber;
-#endif
return hash1 + (hash2 * 1566083941);
}
}
// Determines whether a specified string is a prefix of the current instance
//
- public Boolean StartsWith(String value)
+ public bool StartsWith(string value)
{
- if ((Object)value == null)
+ if ((object)value == null)
{
throw new ArgumentNullException(nameof(value));
}
return StartsWith(value, StringComparison.CurrentCulture);
}
- public Boolean StartsWith(String value, StringComparison comparisonType)
+ public bool StartsWith(string value, StringComparison comparisonType)
{
- if ((Object)value == null)
+ if ((object)value == null)
{
throw new ArgumentNullException(nameof(value));
}
- if ((Object)this == (Object)value)
+ if ((object)this == (object)value)
{
CheckStringComparison(comparisonType);
return true;
}
}
- public Boolean StartsWith(String value, Boolean ignoreCase, CultureInfo culture)
+ public bool StartsWith(string value, bool ignoreCase, CultureInfo culture)
{
if (null == value)
{