public BestMatchSelector(string searchText) { this.searchText = searchText ?? throw new ArgumentNullException(nameof(searchText)); matchPriority = MatchPriority.Nothing; bestCompletion = null; acronymMatchIndexes = AcronymSearchHelpers.TryCreateMatchIndexes(searchText); }
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)
/// <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); }
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); }
bool TryUpdateAcronymIndexes(string completionText) => AcronymSearchHelpers.TryUpdateAcronymIndexes(acronymMatchIndexes, searchText, completionText);