ACAT.Extensions.Default.WordPredictors.PresageWCF.PresageWordPredictor.matchPrefix C# (CSharp) Method

matchPrefix() private method

Checks to see how much of the prefix matches with the specified word. The preference setting WordPredictionFilterMatchPrefixLengthAdjust controls how many chars to match. If a match if found, returns true
private matchPrefix ( String prefix, String word ) : bool
prefix String partially entered word
word String word to match with
return bool
        private bool matchPrefix(String prefix, String word)
        {
            if (!Common.AppPreferences.WordPredictionFilterMatchPrefix)
            {
                return true;
            }

            prefix = prefix.Trim();
            if (String.IsNullOrEmpty(prefix))
            {
                return true;
            }

            int numCharsToMatch = prefix.Length - Common.AppPreferences.WordPredictionFilterMatchPrefixLengthAdjust;
            if (numCharsToMatch <= 0)
                numCharsToMatch = prefix.Length;

            if (numCharsToMatch > 0)
            {
                if (word.Length > numCharsToMatch)
                    word = word.Substring(0, numCharsToMatch);
                if (prefix.Length > numCharsToMatch)
                    prefix = prefix.Substring(0, numCharsToMatch);
            }

            return (word.Length > prefix.Length) ?
                word.StartsWith(prefix, StringComparison.InvariantCultureIgnoreCase) :
                prefix.StartsWith(word, StringComparison.InvariantCultureIgnoreCase);
        }