Beispiel #1
0
        public static bool RegionMatchesAscii(ICharSequence cs, bool ignoreCase, int csStart, ICharSequence seq, int start, int length)
        {
            if (cs is null || seq is null)
            {
                return(false);
            }

            switch (cs)
            {
            case StringCharSequence _ when !ignoreCase && seq is StringCharSequence:
                //we don't call regionMatches from String for ignoreCase==true. It's a general purpose method,
                //which make complex comparison in case of ignoreCase==true, which is useless for ASCII-only strings.
                //To avoid applying this complex ignore-case comparison, we will use regionMatchesCharSequences
                return(cs.RegionMatches(csStart, seq, start, length));

            case AsciiString asciiString:
                return(ignoreCase
                        ? asciiString.RegionMatchesIgnoreCase(csStart, seq, start, length)
                        : asciiString.RegionMatches(csStart, seq, start, length));

            default:
                return(RegionMatchesCharSequences(cs, csStart, seq, start, length,
                                                  ignoreCase ? AsciiCaseInsensitiveCharComparator : DefaultCharComparator));
            }
        }
Beispiel #2
0
 public static bool StartsWith(this ICharSequence seq, ICharSequence prefix, int start)
 => seq.RegionMatches(start, prefix, 0, prefix.Count) ? true : false;