private int InternalLastIndexOf(ASCIIString value, int startIndex, int count, bool ignoreCase)
        {
            Debug.Assert(value != null);
            Debug.Assert(startIndex >= 0);
            Debug.Assert(count <= this.Length - startIndex);

            int matchLength = value.Length;
            int matchChars  = matchLength - 1;

            for (int i = (startIndex + count) - 1; i >= startIndex; i--)
            {
                ASCIIChar curr    = ignoreCase ? ASCIIChar.ToLower(this[i]) : this[i];
                ASCIIChar toMatch = ignoreCase ? ASCIIChar.ToLower(value[matchChars]) : value[matchChars];
                if (curr == toMatch)
                {
                    matchChars--;
                    if (matchChars == -1)
                    {
                        return(i);
                    }
                    continue;
                }
                matchChars = matchLength - 1;
            }

            return(-1);
        }
        private int InternalIndexOf(ASCIIString value, int startIndex, int count, bool ignoreCase)
        {
            Debug.Assert(value != null);
            Debug.Assert(startIndex >= 0 && startIndex < this.Length);
            Debug.Assert(count <= this.Length - startIndex);

            int matchChars  = 0;
            int matchLength = value.Length;

            for (int i = startIndex; i < startIndex + count; i++)
            {
                ASCIIChar curr    = ignoreCase ? ASCIIChar.ToLower(this[i]) : this[i];
                ASCIIChar toMatch = ignoreCase ? ASCIIChar.ToLower(value[matchChars]) : value[matchChars];
                if (curr == toMatch)
                {
                    matchChars++;
                    if (matchChars == matchLength)
                    {
                        return(i - (matchLength - 1));
                    }
                    continue;
                }
                matchChars = 0;
            }

            return(-1);
        }
 /// <summary>
 /// Determines whether the specified substring appears within this string.
 /// </summary>
 /// <param name="value">The string to seek.</param>
 /// <param name="ignoreCase">True to ignore case; otherwise, false.</param>
 /// <returns></returns>
 public bool Contains(ASCIIString value, bool ignoreCase = false)
 {
     if (value is null)
     {
         throw new ArgumentNullException(nameof(value));
     }
     return(IndexOf(value, ignoreCase) >= 0);
 }
        /// <summary>
        /// Reports the zero-based index position of the last occurence of a specified string within this instance.
        /// The search starts at a specified character position and proceeds backwards toward the beginning of the string for the specified number of character positions.
        /// </summary>
        /// <param name="value">The string to seek.</param>
        /// <param name="startIndex">The search starting position. The search proceeds from startIndex toward the beginning of this instance.</param>
        /// <param name="count">The number of character positions to examine.</param>
        /// <param name="ignoreCase">True to ignore case; otherwise, false.</param>
        /// <exception cref="ArgumentNullException"/>
        /// <exception cref="ArgumentOutOfRangeException"/>
        public int LastIndexOf(ASCIIString value, int startIndex, int count, bool ignoreCase = false)
        {
            if (startIndex < 0 || startIndex >= this.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(startIndex));
            }
            if (count < 0 || count > this.Length - startIndex)
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }

            if (value.Length > this.Length)
            {
                return(-1);
            }
            if (count == 0)
            {
                return(-1);
            }

            return(InternalLastIndexOf(value, startIndex, count, ignoreCase));
        }
 /// <summary>
 /// Reports the zero-based index of the first occurence of the specified string in the current <see cref="ASCIIString"/> object.
 /// Parameters specify the starting search position in the current string and the type of search to use for the specified string.
 /// </summary>
 /// <param name="value">The string to seek.</param>
 /// <param name="ignoreCase">True to ignore case; otherwise, false.</param>
 public int IndexOf(ASCIIString value, bool ignoreCase = false)
 {
     return(IndexOf(value, 0, this.Length, ignoreCase));
 }
 /// <summary>
 /// Reports the zero-based index position of the last occurence of a specified string within this instance.
 /// The search starts at a specified character position and proceeds backwards toward the beginning of the string.
 /// </summary>
 /// <param name="value">The string to seek.</param>
 /// <param name="startIndex">The search starting position. The search proceeds from startIndex toward the beginning of this instance.</param>
 /// <param name="ignoreCase">True to ignore case; otherwise, false.</param>
 /// <exception cref="ArgumentNullException"/>
 /// <exception cref="ArgumentOutOfRangeException"/>
 public int LastIndexOf(ASCIIString value, int startIndex, bool ignoreCase = false)
 {
     return(LastIndexOf(value, startIndex, this.Length, ignoreCase));
 }