예제 #1
0
        private static IEnumerable <Run> makeRunsFromContent(string content, Brush hlColor, string hlContent)
        {
            List <Run> listRtn = new List <Run>();

            if (!string.IsNullOrWhiteSpace(content))
            {
                string hlInfo = hlContent;//HighlightContent.ToHighlight; //hlContent;
                if (string.IsNullOrWhiteSpace(hlInfo))
                {
                    listRtn.Add(new Run(content));
                }
                else
                {
                    List <string> searchInfos = hlInfo.ToLower().Split(separator, StringSplitOptions.RemoveEmptyEntries).ToList();
                    if (searchInfos.Count == 0)
                    {
                        listRtn.Add(new Run(content));
                    }
                    else
                    {
                        bool[] hlKeys = new bool[content.Length];
                        var    szms   = PinYinConverter.ToShouZiMuArray(content);
                        foreach (var info in searchInfos)
                        {
                            int index = szms.IndexOf(info);
                            if (index >= 0)
                            {
                                for (int i = 0; i < info.Length; i++)
                                {
                                    hlKeys[index + i] = true;
                                }
                            }
                        }
                        for (int i = 0; i < content.Length;)
                        {
                            int length = getHighlightLength(hlKeys, i);
                            if (hlKeys[i])
                            {
                                listRtn.Add(new Run(content.Substring(i, length))
                                {
                                    Foreground = hlColor
                                });
                            }
                            else
                            {
                                listRtn.Add(new Run(content.Substring(i, length)));
                            }
                            i += length;
                        }
                    }
                }
            }
            return(listRtn);
        }
예제 #2
0
        private static bool isSearched(string name, List <string> searchInfos)
        {
            if (searchInfos.Count == 0)
            {
                return(true);
            }
            ShouZiMuArray szms = PinYinConverter.ToShouZiMuArray(name);

            foreach (var info in searchInfos)
            {
                int index = szms.IndexOf(info);
                if (index < 0)
                {
                    return(false);
                }
            }
            return(true);
        }