Пример #1
0
        public int CompareTo(IMatchItem obj)
        {
            var item = obj as FileModel;

            if (item == null)
            {
                return(-1);
            }

            if (((item.Rank == 0) && (this.Rank == 0)) || (item.Rank == this.Rank))
            {
                var result = string.Compare(this.ProjectName, item.ProjectName, StringComparison.OrdinalIgnoreCase);
                if (result == 0)
                {
                    result = string.Compare(this.FileName, item.FileName, StringComparison.OrdinalIgnoreCase);
                }

                return(result);
            }
            else
            {
                // Higher ranked item must goes first
                return(item.Rank.CompareTo(this.Rank));
            }
        }
Пример #2
0
        public int CompareTo(IMatchItem obj)
        {
            var member = obj as MemberCodeModel;

            if (member == null)
            {
                return(-1);
            }

            if (((member.Rank == 0) && (this.Rank == 0)) || (member.Rank == this.Rank))
            {
                return(this.Line.CompareTo(member.Line));
            }
            else
            {
                // Higher ranked item must goes first
                return(member.Rank.CompareTo(this.Rank));
            }
        }
Пример #3
0
        public int CompareTo(IMatchItem obj)
        {
            var item = obj as FileCodeModel;

            if (item == null)
            {
                return(-1);
            }

            if (((item.Rank == 0) && (this.Rank == 0)) || (item.Rank == this.Rank))
            {
                return(this.Line.CompareTo(item.Line));
            }
            else
            {
                // Higher ranked item must goes first
                return(item.Rank.CompareTo(this.Rank));
            }
        }
Пример #4
0
        /// <summary>
        /// Matches an item to the filter and sets match rank.
        /// </summary>
        private bool MatchItem(IList <SearchToken> tokens, IMatchItem item, out int rank)
        {
            rank = 0;
            if ((item == null) || (tokens?.Count == 0))
            {
                return(false);
            }

            var match = false;

            foreach (var token in tokens)
            {
                match = false;

                var filter = token.Filter;

                // Check the actual filter (this should never happen)
                if (string.IsNullOrEmpty(filter))
                {
                    match = true;
                    continue;
                }

                var wildcard         = token.Wildcard;
                var filterRank       = 0;
                var filterPascalRank = 0;

                // Match the actual filter
                var itemData = item.Data;
                if (wildcard.WildcardPresent)
                {
                    match = wildcard.Match(itemData);
                }
                else
                {
                    var pos = itemData.IndexOf(filter, StringComparison.OrdinalIgnoreCase);
                    match = pos != -1;
                    if (match)
                    {
                        if (pos == 0)
                        {
                            if ((filter.Length == itemData.Length) ||
                                ((item.DataEndingIndex > 0) && (filter.Length == item.DataEndingIndex)))
                            {
                                filterRank += RANK_EXACT;
                            }
                            else
                            {
                                filterRank += RANK_FROM_START;
                            }
                        }
                        else
                        {
                            filterRank += GetMatchRank(pos, filter.Length, itemData.Length, RANK_NOT_FROM_START);
                        }
                    }
                }

                // Pascal case match
                var itemPascalCasedData = item.PascalCasedData;
                if (!string.IsNullOrEmpty(itemPascalCasedData))
                {
                    var pos = itemPascalCasedData.IndexOf(filter, StringComparison.OrdinalIgnoreCase);
                    if (pos >= 0)
                    {
                        match = true;
                        if (pos == 0)
                        {
                            if (itemPascalCasedData.Length == filter.Length)
                            {
                                filterPascalRank += RANK_PASCAL_CASE_EXACT;
                            }
                            else if (itemPascalCasedData.Length == 1)
                            {
                                filterPascalRank += RANK_PASCAL_CASE_START_SINGLE;
                            }
                            else
                            {
                                filterPascalRank += RANK_PASCAL_CASE_START_MULTIPLE;
                            }
                        }
                        else
                        {
                            if (itemPascalCasedData.Length == 1)
                            {
                                filterPascalRank += RANK_PASCAL_CASE_NOT_FROM_START_SINGLE;
                            }
                            else
                            {
                                filterPascalRank += GetMatchRank(pos, filter.Length, itemPascalCasedData.Length,
                                                                 RANK_PASCAL_CASE_NOT_FROM_START_MULTIPLE);
                            }
                        }
                    }
                }

                // Pick the highest rank
                if ((filterRank > 0) || (filterPascalRank > 0))
                {
                    // Ranks are applied on either/or basis
                    if (filterRank >= filterPascalRank)
                    {
                        rank += filterRank;
                    }
                    else
                    {
                        rank += filterPascalRank;
                    }
                }

                if (!match)
                {
                    break;
                }
            }             // for index

            return(match);
        }
Пример #5
0
 public int CompareTo(IMatchItem other)
 {
     return(0);
 }