Beispiel #1
0
        /// <summary>
        /// Compares this string to another UTF32String.
        /// </summary>
        /// <param name="obj">The other UTF32String to compare this string to.</param>
        /// <returns>
        /// &lt;0 if this string &lt;> obj; 0 if this==object; &gt;0 if this string &gt; obj,
        /// with the relation defines in a culture-insensitive way in lexicographic order.
        /// </returns>
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }
            UTF32String other = obj as UTF32String;

            if (other == null)
            {
                throw new ArgumentException("Can only compare Utf32Strings", nameof(obj));
            }

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

            for (int i = 0; i < minLength; i++)
            {
                int result = this[i] - other[i];
                if (result != 0)
                {
                    return(result);
                }
            }
            // Both strings are the same for all the characters in the shorter
            // one. The longer one is now greater, or they're the same.
            return(Length - other.Length);
        }
Beispiel #2
0
        /// <summary>
        /// Finds the index of another UTF32String within this one,
        /// starting at the specified position and considering the
        /// specified number of positions.
        /// </summary>
        /// <param name="value">Value to find</param>
        /// <param name="start">First position to consider when finding value within this UTF32String</param>
        /// <param name="count">Number of positions to consider</param>
        /// <returns>The index of value within this string, or -1 if it isn't found</returns>
        public int IndexOf(UTF32String value, int start, int count)
        {
            _characters.Length.ValidateRange(start, ref count);
            if (_characters.Length == 0 || count == 0)
            {
                return(-1);
            }

            for (int i = start; i < start + count; i++)
            {
                if (i + value.Length > Length)
                {
                    return(-1);
                }
                int j;

                for (j = 0; j < value.Length; j++)
                {
                    if (_characters[i + j] != value._characters[j])
                    {
                        break;
                    }
                }

                if (j == value.Length)
                {
                    return(i);
                }
            }
            return(-1);
        }
Beispiel #3
0
 /// <summary>
 /// Returns a concatenation of the given strings.
 /// </summary>
 /// <param name="strA">The first string</param>
 /// <param name="strB">The second string</param>
 /// <returns>A string consisting of the first string followed by the second</returns>
 public static UTF32String Concat(UTF32String strA, UTF32String strB)
 {
     return(Concat(new[]
     {
         strA,
         strB
     }));
 }
Beispiel #4
0
 /// <summary>
 /// Finds the index of another UTF32String within this one,
 /// starting at the specified position.
 /// </summary>
 /// <param name="value">Value to find</param>
 /// <param name="start">First position to consider when finding value within this UTF32String</param>
 /// <returns>The index of value within this string, or -1 if it isn't found</returns>
 public int IndexOf(UTF32String value, int start)
 {
     if (start < 0 || start > Length)
     {
         throw new ArgumentOutOfRangeException(nameof(start), "start must lie within the string bounds");
     }
     return(IndexOf(value, start, Length - start));
 }
Beispiel #5
0
 /// <summary>
 /// Returns a concatenation of the given strings.
 /// </summary>
 /// <param name="strA">The first string</param>
 /// <param name="strB">The second string</param>
 /// <param name="strC">The third string</param>
 /// <param name="strD">The fourth string</param>
 /// <returns>
 /// A string consisting of the first string
 /// followed by the second, followed by the third,
 /// followed by the fourth
 /// </returns>
 public static UTF32String Concat(UTF32String strA, UTF32String strB, UTF32String strC, UTF32String strD)
 {
     return(Concat(new[]
     {
         strA,
         strB,
         strC,
         strD
     }));
 }
Beispiel #6
0
 /// <summary>
 /// Compares the two specified strings.
 /// </summary>
 /// <param name="strA">The first string to compare</param>
 /// <param name="strB">The second string to compare</param>
 /// <returns>
 /// 0 if both strings are null or they are equal; a negative number if strA == null or
 /// is lexicographically before strB; a positive number otherwise
 /// </returns>
 public static int Compare(UTF32String strA, UTF32String strB)
 {
     return(ReferenceEquals(strA, strB)
                                         ? 0
                                         : (object)strA == null || (object)strB == null
                                                 ? (object)strA == null
                                                         ? -1
                                                         : 1
                                                 : strA.CompareTo(strB));
 }
Beispiel #7
0
 /// <summary>
 /// Compares one string with another for equality.
 /// </summary>
 /// <param name="strA">The first string to compare</param>
 /// <param name="strB">The second string to compare</param>
 /// <returns>true if the strings are equivalent; false otherwise</returns>
 public static bool Equals(UTF32String strA, UTF32String strB)
 {
     return(Compare(strA, strB) == 0);
 }
Beispiel #8
0
 /// <summary>
 /// Compares two UTF-32 strings (in a culture-insensitive manner) for equality.
 /// </summary>
 /// <param name="other">The other string to compare this one to.</param>
 /// <returns>Whether or not this string is equal to the other one.</returns>
 public bool Equals(UTF32String other)
 {
     return(ReferenceEquals(this, other) || CompareTo(other) == 0);
 }
Beispiel #9
0
 /// <summary>
 /// Finds the index of another UTF32String within this one.
 /// </summary>
 /// <param name="value">Value to find</param>
 /// <returns>The index of value within this string, or -1 if it isn't found</returns>
 public int IndexOf(UTF32String value)
 {
     return(IndexOf(value, 0, Length));
 }
Beispiel #10
0
        /// <summary>
        /// Returns whether or not this UTF-32 string is equal to another object.
        /// </summary>
        /// <param name="obj">The object to compare this UTF-32 string to.</param>
        /// <returns>Whether or not this object is equal to the other one.</returns>
        public override bool Equals(object obj)
        {
            UTF32String other = obj as UTF32String;

            return(other != null && Equals(other));
        }