示例#1
0
        internal static int FindBestMatchIndex(this string text, string pattern, int loc, MatchSettings settings)
        {
            // Check for null inputs not needed since null can't be passed in C#.

            loc = Math.Max(0, Math.Min(loc, text.Length));
            if (text == pattern)
            {
                // Shortcut (potentially not guaranteed by the algorithm)
                return 0;
            }
            if (text.Length == 0)
            {
                // Nothing to match.
                return -1;
            }
            if (loc + pattern.Length <= text.Length
                && text.Substring(loc, pattern.Length) == pattern)
            {
                // Perfect match at the perfect spot!  (Includes case of null pattern)
                return loc;
            }

            // Do a fuzzy compare.
            var bitap = new BitapAlgorithm(settings);
            return bitap.Match(text, pattern, loc);
        }
 public BitapAlgorithm(MatchSettings settings)
 {
     _matchThreshold = settings.MatchThreshold;
     _matchDistance  = settings.MatchDistance;
 }