Example #1
0
        public IList <string> GetSuggestionStrings(string input, AutoSuggestionsMatchMode mode, string separators)
        {
            var strings = new List <string>();

            CollectSuggestions(input, mode, separators, null, strings);
            return(strings);
        }
Example #2
0
        public IList GetSuggestions(string input, AutoSuggestionsMatchMode mode, string separators)
        {
            var suggestions = new List <object>();

            CollectSuggestions(input, mode, separators, suggestions, null);
            return(suggestions);
        }
Example #3
0
        public virtual string Match(string input, object item, AutoSuggestionsMatchMode mode, char[] separators)
        {
            if (item == null)
            {
                return(null);
            }

            var text = DisplayText(item);

            if (String.IsNullOrEmpty(input))
            {
                return(text);
            }

            if ((mode & AutoSuggestionsMatchMode.IgnoreCase) != 0)
            {
                text  = text.ToLower();
                input = input.ToLower();
            }

            bool match;
            var  matching = mode & (AutoSuggestionsMatchMode.MatchStart | AutoSuggestionsMatchMode.MatchWords | AutoSuggestionsMatchMode.Substrings);

            switch (matching)
            {
            default:
                //case AutoSuggestionsMatchMode.Default:
                match = text.Contains(input);
                break;

            case AutoSuggestionsMatchMode.MatchStart:
                match = text.StartsWith(input);
                break;

            case AutoSuggestionsMatchMode.MatchWords:
            case AutoSuggestionsMatchMode.Substrings:
                var subs  = input.Split(separators);
                var words = (matching == AutoSuggestionsMatchMode.MatchWords) ? text.Split(separators) : null;
                match = true;
                foreach (var sub in subs)
                {
                    if (String.IsNullOrEmpty(sub))
                    {
                        continue;
                    }
                    if (!ContainsSub(sub, text, words))
                    {
                        match = false;
                        break;
                    }
                }
                break;
            }
            return(match ? text : null);
        }
Example #4
0
        public virtual bool ExactMatch(string input, object item, AutoSuggestionsMatchMode mode)
        {
            if (item == null || String.IsNullOrEmpty(input))
            {
                return(false);
            }

            var text = DisplayText(item);

            if ((mode & AutoSuggestionsMatchMode.IgnoreCase) != 0)
            {
                text  = text.ToLower();
                input = input.ToLower();
            }

            return(input == text);
        }
Example #5
0
        protected override void CollectSuggestions(string input, AutoSuggestionsMatchMode mode, string separators, IList suggestions, IList <string> strings)
        {
            if (SuggestionSource == null)
            {
                return;
            }

            foreach (var item in SuggestionSource)
            {
                var text = Match(input, item, mode, separators.ToCharArray());
                if (text != null)
                {
                    if (suggestions != null)
                    {
                        suggestions.Add(item);
                    }
                    if (strings != null)
                    {
                        strings.Add(text);
                    }
                }
            }
        }
Example #6
0
 protected abstract void CollectSuggestions(string input, AutoSuggestionsMatchMode mode, string separators, IList suggestions, IList <string> strings);