static int LastIndexOf(SubsetStringView source, StringView other, StringComparison sc)
        {
            if (source.length < other.length)
            {
                return(-1);
            }

            int otherIndex = other.length - 1;

            for (var i = source.length - 1; i >= 0 && otherIndex >= 0; --i)
            {
                if (!StringView.Compare(source[i], other[otherIndex], sc))
                {
                    otherIndex = other.length - 1;
                }
                else
                {
                    if (otherIndex == 0)
                    {
                        return(i);
                    }
                    otherIndex--;
                }
            }

            return(-1);
        }
        public int LastIndexOf(IStringView other, StringComparison sc = StringComparison.Ordinal)
        {
            if (length < other.length)
            {
                return(-1);
            }

            int otherIndex = other.length - 1;

            for (var i = length - 1; i >= 0 && otherIndex >= 0; --i)
            {
                if (!StringView.Compare(this[i], other[otherIndex], sc))
                {
                    otherIndex = other.length - 1;
                }
                else
                {
                    if (otherIndex == 0)
                    {
                        return(i);
                    }
                    otherIndex--;
                }
            }

            return(-1);
        }
 public bool EndsWith(char c, StringComparison sc = StringComparison.Ordinal)
 {
     if (length == 0)
     {
         return(false);
     }
     return(StringView.Compare(this[length - 1], c, sc));
 }
 public bool StartsWith(char c, StringComparison stringComparison = StringComparison.Ordinal)
 {
     if (length == 0)
     {
         return(false);
     }
     return(StringView.Compare(this[0], c, stringComparison));
 }
 public bool Contains(char c, StringComparison ordinal = StringComparison.Ordinal)
 {
     for (var i = 0; i < length; ++i)
     {
         if (StringView.Compare(this[i], c, ordinal))
         {
             return(true);
         }
     }
     return(false);
 }
        public bool Equals(SubsetStringView other, StringComparison comparisonOptions = StringComparison.OrdinalIgnoreCase)
        {
            if (other.length != length)
            {
                return(false);
            }

            for (var i = 0; i < length; ++i)
            {
                if (!StringView.Compare(this[i], other[i], comparisonOptions))
                {
                    return(false);
                }
            }

            return(true);
        }
        public bool EndsWith(IStringView v, StringComparison sc = StringComparison.Ordinal)
        {
            if (v.length > length)
            {
                return(false);
            }

            for (var i = 0; i < v.length; ++i)
            {
                if (!StringView.Compare(this[length - v.length + i], v[i], sc))
                {
                    return(false);
                }
            }

            return(true);
        }
        public bool StartsWith(string v, StringComparison sc = StringComparison.Ordinal)
        {
            if (v.Length > length)
            {
                return(false);
            }

            for (var i = 0; i < v.Length; ++i)
            {
                if (!StringView.Compare(this[i], v[i], sc))
                {
                    return(false);
                }
            }

            return(true);
        }
        static int LastIndexOf(SubsetStringView source, char other, StringComparison sc)
        {
            if (!source.valid)
            {
                return(-1);
            }

            for (var i = source.length - 1; i >= 0; --i)
            {
                if (StringView.Compare(source[i], other, sc))
                {
                    return(i);
                }
            }

            return(-1);
        }
Пример #10
0
        static int IndexOf(SubsetStringView source, char other, StringComparison sc)
        {
            if (!source.valid)
            {
                return(-1);
            }

            for (var i = 0; i < source.Length; ++i)
            {
                if (StringView.Compare(source[i], other, sc))
                {
                    return(i);
                }
            }

            return(-1);
        }
        static int IndexOf(SubsetStringView source, StringView other, StringComparison sc)
        {
            if (!source.valid || !other.valid)
            {
                return(-1);
            }
            if (source.length < other.length)
            {
                return(-1);
            }

            int foundStartIndex = -1;
            int otherIndex      = 0;

            for (var i = 0; i < source.length && otherIndex < other.length; ++i)
            {
                if (!StringView.Compare(source[i], other[otherIndex], sc))
                {
                    if (foundStartIndex > -1)
                    {
                        foundStartIndex = -1;
                        otherIndex      = 0;
                    }
                }
                else
                {
                    if (foundStartIndex == -1)
                    {
                        foundStartIndex = i;
                    }
                    otherIndex++;
                }
            }

            if (otherIndex != other.length)
            {
                return(-1);
            }
            return(foundStartIndex);
        }
        public int IndexOf(IStringView other, StringComparison sc = StringComparison.Ordinal)
        {
            if (!valid || !other.valid)
            {
                return(-1);
            }
            if (length < other.length)
            {
                return(-1);
            }

            int foundStartIndex = -1;
            int otherIndex      = 0;

            for (var i = 0; i < length && otherIndex < other.length; ++i)
            {
                if (!StringView.Compare(this[i], other[otherIndex], sc))
                {
                    if (foundStartIndex > -1)
                    {
                        foundStartIndex = -1;
                        otherIndex      = 0;
                    }
                }
                else
                {
                    if (foundStartIndex == -1)
                    {
                        foundStartIndex = i;
                    }
                    otherIndex++;
                }
            }

            if (otherIndex != other.length)
            {
                return(-1);
            }
            return(foundStartIndex);
        }