Beispiel #1
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(SpanString2 a, SpanString1 b)
        {
            if (a.Length != b.Length)
            {
                return(false);
            }

            var s1Enum = new Enumerator(a);
            var s2Enum = new SpanString1.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);
        }
Beispiel #2
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(SpanString2 a, SpanString1 b)
        {
            if (a.Length != b.Length)
            {
                return(false);
            }

            var s1Enum = new Enumerator(a);
            var s2Enum = new SpanString1.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);
        }
Beispiel #3
0
        /// <summary>
        /// Compares this instance with a specified SpanString1 using an ordinal
        /// comparison and case-insensitivity, and indicates whether this
        /// instance precedes, follows, or appears in the same position
        /// in the sort order as the specified string.
        /// </summary>
        /// <param name="other">The string to compare with this instance.</param>
        /// <returns>A 32-bit signed integer that indicates whether this instance precedes, follows, or appears in the same position in the sort order as the strB parameter.</returns>
        public int CompareToIgnoreCase(SpanString1 other)
        {
            // Adapted from https://referencesource.microsoft.com/#mscorlib/system/string.cs CompareOrdinalHelper()

            int length = Math.Min(Length, other.Length);

            var s1Enum = new Enumerator(this);
            var s2Enum = new SpanString1.Enumerator(other);

            for (int i = 0; i < length; i++)
            {
                int c1  = SpanStringComparer.ToUpperAscii(s1Enum.Next());
                int c2  = SpanStringComparer.ToUpperAscii(s2Enum.Next());
                int cmp = c1.CompareTo(c2);
                if (cmp != 0)
                {
                    return(cmp);
                }
            }

            // At this point, we have compared all the characters in at least one string.
            // The longer string will be larger.
            return(Length - other.Length);
        }