コード例 #1
0
        private static void SplitByContains(string text, string value, StringComparison stringComparison, IList <AutoCompleteHighlightingSplitPart> parts)
        {
            int index = text.ReplaceDiacritics().IndexOf(value.ReplaceDiacritics(), stringComparison);

            if (index >= 0)
            {
                while (index >= 0)
                {
                    if (index > 0)
                    {
                        var part = new AutoCompleteHighlightingSplitPart(text.Substring(0, index), false);
                        parts.Add(part);
                    }

                    var matchText = text.Substring(index, value.Length);
                    var matchPart = new AutoCompleteHighlightingSplitPart(matchText, true);
                    parts.Add(matchPart);

                    text  = text.Substring(index + value.Length);
                    index = text.IndexOf(value, stringComparison);
                }

                if (text.Length > 0)
                {
                    var part = new AutoCompleteHighlightingSplitPart(text, false);
                    parts.Add(part);
                }
            }
            else
            {
                var part = new AutoCompleteHighlightingSplitPart(text, false);
                parts.Add(part);
            }
        }
コード例 #2
0
        public static IEnumerable <AutoCompleteHighlightingSplitPart> Split(string text, string value)
        {
            List <AutoCompleteHighlightingSplitPart> parts = new List <AutoCompleteHighlightingSplitPart>();

            if (string.IsNullOrEmpty(text))
            {
                return(parts);
            }

            if (string.IsNullOrEmpty(value))
            {
                var part = new AutoCompleteHighlightingSplitPart(text, false);
                parts.Add(part);
                return(parts);
            }

            SplitByContains(text, value, StringComparison.CurrentCultureIgnoreCase, parts);

            return(parts);
        }
コード例 #3
0
        private static void SplitByContains(string text, string value, StringComparison stringComparison, IList<AutoCompleteHighlightingSplitPart> parts)
        {
            int index = text.ReplaceDiacritics().IndexOf(value.ReplaceDiacritics(), stringComparison);

            if (index >= 0)
            {
                while (index >= 0)
                {
                    if (index > 0)
                    {
                        var part = new AutoCompleteHighlightingSplitPart(text.Substring(0, index), false);
                        parts.Add(part);
                    }

                    var matchText = text.Substring(index, value.Length);
                    var matchPart = new AutoCompleteHighlightingSplitPart(matchText, true);
                    parts.Add(matchPart);

                    text = text.Substring(index + value.Length);
                    index = text.IndexOf(value, stringComparison);
                }

                if (text.Length > 0)
                {
                    var part = new AutoCompleteHighlightingSplitPart(text, false);
                    parts.Add(part);
                }
            }
            else
            {
                var part = new AutoCompleteHighlightingSplitPart(text, false);
                parts.Add(part);
            }
        }
コード例 #4
0
        public static IEnumerable<AutoCompleteHighlightingSplitPart> Split(string text, string value)
        {
            List<AutoCompleteHighlightingSplitPart> parts = new List<AutoCompleteHighlightingSplitPart>();

            if (string.IsNullOrEmpty(text))
            {
                return parts;
            }

            if (string.IsNullOrEmpty(value))
            {
                var part = new AutoCompleteHighlightingSplitPart(text, false);
                parts.Add(part);
                return parts;
            }

            SplitByContains(text, value, StringComparison.CurrentCultureIgnoreCase, parts);

            return parts;
        }