예제 #1
0
        /// <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?");
        }
예제 #2
0
 public Enumerator(SpanString2 ss)
 {
     _currentSegmentPosition = 0;
     _currentSegment         = ss._segment1;
     _currentSegmentIndex    = 0;
     _spanString             = ss;
 }
예제 #3
0
        /// <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());
        }
예제 #4
0
        /// <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;
        }
예제 #5
0
        /// <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;
        }
예제 #6
0
 /// <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));
 }