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 static bool IsNullOrEmpty(this SubsetStringView sv)
 {
     if (!sv.valid)
     {
         return(true);
     }
     return(sv.length == 0);
 }
 public static bool IsNullOrWhiteSpace(this SubsetStringView sv)
 {
     if (sv.IsNullOrEmpty())
     {
         return(true);
     }
     for (var i = 0; i < sv.length; ++i)
     {
         if (!char.IsWhiteSpace(sv[i]))
         {
             return(false);
         }
     }
     return(true);
 }
        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);
        }
        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);
        }
Пример #6
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 bool Contains(SubsetStringView s, StringComparison ordinal = StringComparison.Ordinal)
 {
     return(IndexOf(s) != -1);
 }
 public int LastIndexOf(SubsetStringView other, StringComparison sc = StringComparison.Ordinal)
 {
     return(LastIndexOf(this, other, sc));
 }