Example #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", "obj");
            }

            int minLength = Math.Min(this.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(this.Length - other.Length);
        }
Example #2
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)
 {
     if (Object.ReferenceEquals(this, other))
     {
         return(true);
     }
     return(this.CompareTo(other) == 0);
 }
Example #3
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 > this.Length)
     {
         throw new ArgumentOutOfRangeException("start must lie within the string bounds", "start");
     }
     return(this.IndexOf(value, start, this.Length - start));
 }
Example #4
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;

            if (other == null)
            {
                return(false);
            }
            return(this.Equals(other));
        }
Example #5
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 is null or
 /// is lexicographically before strB; a positive number otherwise</returns>
 public static int Compare(Utf32String strA, Utf32String strB)
 {
     if (object.ReferenceEquals(strA, strB))
     {
         return(0);
     }
     if ((object)strA == null || (object)strB == null)
     {
         return((object)strA == null ? -1 : 1);
     }
     return(strA.CompareTo(strB));
 }
Example #6
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)
 {
     if (value == null)
     {
         throw (new System.ArgumentNullException("value"));
     }
     if (start < 0 || start > this.Length)
     {
         throw new ArgumentOutOfRangeException("start must lie within the string bounds", "start");
     }
     if (count < 0)
     {
         throw new ArgumentOutOfRangeException("count must be non-negative", "count");
     }
     if (start + count > this.Length)
     {
         throw new ArgumentOutOfRangeException
                   ("start+count must be less than or equal to the length of the string");
     }
     for (int i = start; i < start + count; i++)
     {
         if (i + value.Length > this.Length)
         {
             return(-1);
         }
         int j;
         for (j = 0; j < value.Length; j++)
         {
             if (this.characters[i + j] != value.characters[j])
             {
                 break;
             }
         }
         if (j == value.Length)
         {
             return(i);
         }
     }
     return(-1);
 }
Example #7
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 Utf32String[] { strA, strB, strC, strD }));
 }
Example #8
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 Utf32String[] { strA, strB }));
 }
Example #9
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);
 }
Example #10
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(this.IndexOf(value, 0, this.Length));
 }