Esempio n. 1
0
 public BestMatchSelector(string searchText)
 {
     this.searchText     = searchText ?? throw new ArgumentNullException(nameof(searchText));
     matchPriority       = MatchPriority.Nothing;
     bestCompletion      = null;
     acronymMatchIndexes = AcronymSearchHelpers.TryCreateMatchIndexes(searchText);
 }
Esempio n. 2
0
        MatchPriority GetMatchPriority(Completion completion)
        {
            var filterText = completion.TryGetFilterText();

            Debug.Assert(!(filterText is null));
            if (filterText is null)
            {
                return(MatchPriority.Other);
            }

            if (filterText.Equals(searchText, StringComparison.CurrentCulture))
            {
                return(MatchPriority.Full);
            }

            bool matchedAcronym = !(acronymMatchIndexes is null) && AcronymSearchHelpers.TryUpdateAcronymIndexes(acronymMatchIndexes, searchText, filterText);

            if (matchedAcronym && CountUpperCaseLetters(filterText) == acronymMatchIndexes !.Length)
            {
                return(MatchPriority.FullAcronym);
            }

            if (filterText.Equals(searchText, StringComparison.CurrentCultureIgnoreCase))
            {
                return(MatchPriority.FullIgnoringCase);
            }

            int index = filterText.IndexOf(searchText, StringComparison.CurrentCulture);

            if (index == 0)
            {
                return(MatchPriority.Start);
            }

            if (matchedAcronym && acronymMatchIndexes ![0] == 0)
Esempio n. 3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="searchText">Search text</param>
 public CompletionFilter(string searchText)
 {
     if (searchText == null)
     {
         throw new ArgumentNullException(nameof(searchText));
     }
     this.searchText          = searchText;
     this.acronymMatchIndexes = AcronymSearchHelpers.TryCreateMatchIndexes(searchText);
 }
Esempio n. 4
0
        MatchPriority GetMatchPriority(Completion completion)
        {
            var filterText = completion.FilterText;

            if (filterText.Equals(searchText, StringComparison.CurrentCulture))
            {
                return(MatchPriority.Full);
            }

            bool matchedAcronym = acronymMatchIndexes != null && AcronymSearchHelpers.TryUpdateAcronymIndexes(acronymMatchIndexes, searchText, filterText);

            if (matchedAcronym && CountUpperCaseLetters(filterText) == acronymMatchIndexes.Length)
            {
                return(MatchPriority.FullAcronym);
            }

            if (filterText.Equals(searchText, StringComparison.CurrentCultureIgnoreCase))
            {
                return(MatchPriority.FullIgnoringCase);
            }

            int index = filterText.IndexOf(searchText, StringComparison.CurrentCulture);

            if (index == 0)
            {
                return(MatchPriority.Start);
            }

            if (matchedAcronym && acronymMatchIndexes[0] == 0)
            {
                return(MatchPriority.StartAcronym);
            }

            int indexIgnoringCase = filterText.IndexOf(searchText, StringComparison.CurrentCultureIgnoreCase);

            if (indexIgnoringCase == 0)
            {
                return(MatchPriority.StartIgnoringCase);
            }

            if (index > 0)
            {
                return(MatchPriority.AnyLocation);
            }
            if (matchedAcronym)
            {
                return(MatchPriority.AnyLocationAcronym);
            }
            if (indexIgnoringCase > 0)
            {
                return(MatchPriority.AnyLocationIgnoringCase);
            }

            return(MatchPriority.Other);
        }
Esempio n. 5
0
 bool TryUpdateAcronymIndexes(string completionText) =>
 AcronymSearchHelpers.TryUpdateAcronymIndexes(acronymMatchIndexes, searchText, completionText);