static bool RegionMatchesCharSequences(ICharSequence cs, int csStart,
                                               ICharSequence seq, int start, int length, ICharEqualityComparator charEqualityComparator)
        {
            //general purpose implementation for CharSequences
            if (csStart < 0 || length > cs.Count - csStart)
            {
                return(false);
            }
            if (start < 0 || length > seq.Count - start)
            {
                return(false);
            }

            int csIndex     = csStart;
            int csEnd       = csIndex + length;
            int stringIndex = start;

            while (csIndex < csEnd)
            {
                char c1 = cs[csIndex++];
                char c2 = seq[stringIndex++];

                if (!charEqualityComparator.CharEquals(c1, c2))
                {
                    return(false);
                }
            }

            return(true);
        }
        static bool Contains(ICharSequence a, ICharSequence b, ICharEqualityComparator comparator)
        {
            if (a is null || b is null || (uint)a.Count < (uint)b.Count)
            {
                return(false);
            }
            if (0u >= (uint)b.Count)
            {
                return(true);
            }

            int bStart = 0;

            for (int i = 0; i < a.Count; ++i)
            {
                if (comparator.CharEquals(b[bStart], a[i]))
                {
                    // If b is consumed then true.
                    if (++bStart == b.Count)
                    {
                        return(true);
                    }
                }
                else if (a.Count - i < b.Count)
                {
                    // If there are not enough characters left in a for b to be contained, then false.
                    return(false);
                }
                else
                {
                    bStart = 0;
                }
            }

            return(false);
        }