/// <summary> /// Compares two strings. /// </summary> /// <param name="a">The first string to compare.</param> /// <param name="b">The second string to compare.</param> /// <returns>True if the strings are equal.</returns> public bool Equals(ISpanString a, ISpanString b) { // Find optimized comparison methods. if (a is SpanString1 a1) { if (b is SpanString1 b1) { return(_ignoreCase ? SpanString1.EqualsIgnoreCase(a1, b1) : SpanString1.Equals(a1, b1)); } if (b is SpanString2 b2) { return(_ignoreCase ? SpanString1.EqualsIgnoreCase(a1, b2) : SpanString1.Equals(a1, b2)); } throw new ArgumentException($"Second param 'b' is an unknown SpanString type '{b.GetType().Name}', is this a bug?"); } if (a is SpanString2 a2) { if (b is SpanString1 b1) { return(_ignoreCase ? SpanString2.EqualsIgnoreCase(a2, b1) : SpanString2.Equals(a2, b1)); } if (b is SpanString2 b2) { return(_ignoreCase ? SpanString2.EqualsIgnoreCase(a2, b2) : SpanString2.Equals(a2, b2)); } throw new ArgumentException($"Second param 'b' is an unknown SpanString type '{b.GetType().Name}', is this a bug?"); } throw new ArgumentException($"First param 'a' is an unknown SpanString type '{a.GetType().Name}', is this a bug?"); }
public Enumerator(SpanString2 ss) { _currentSegmentPosition = 0; _currentSegment = ss._segment1; _currentSegmentIndex = 0; _spanString = ss; }
/// <summary> /// Gets a hash code for a SpanString. If strings A and B are such that A.Equals(B), then /// they will return the same hash code. /// </summary> public int GetHashCode(SpanString2 s) { if (!_ignoreCase) { return(s.GetHashCode()); } return(s.GetHashCodeIgnoreCase()); }
/// <summary> /// Compares two SpanStrings using an ordinal comparison. /// </summary> /// <param name="a">The first string to compare.</param> /// <param name="b">The second string to compare.</param> /// <returns>True if the strings are equal.</returns> public static bool EqualsIgnoreCase(SpanString1 a, SpanString2 b) { if (a.Length != b.Length) { return false; } var s1Enum = new Enumerator(a); var s2Enum = new SpanString2.Enumerator(b); for (int i = 0; i < a.Length; i++) { int c1 = SpanStringComparer.ToUpperAscii(s1Enum.Next()); int c2 = SpanStringComparer.ToUpperAscii(s2Enum.Next()); if (c1 != c2) { return false; } } return true; }
/// <summary> /// Compares two SpanStrings using an ordinal comparison. /// </summary> /// <param name="a">The first string to compare.</param> /// <param name="b">The second string to compare.</param> /// <returns>True if the strings are equal.</returns> public static bool Equals(SpanString1 a, SpanString2 b) { if (a.Length != b.Length) { return false; } var s1Enum = new Enumerator(a); var s2Enum = new SpanString2.Enumerator(b); for (int i = 0; i < a.Length; i++) { int c1 = s1Enum.Next(); int c2 = s2Enum.Next(); if (c1 != c2) { return false; } } return true; }
/// <summary> /// Compares two strings. /// </summary> /// <param name="a">The first string to compare.</param> /// <param name="b">The second string to compare.</param> /// <returns>True if the strings are equal.</returns> public bool Equals(SpanString2 a, SpanString2 b) { return(_ignoreCase ? SpanString2.EqualsIgnoreCase(a, b) : a.Equals(b)); }