Пример #1
0
        public static IEnumerable <Inline> SyntaxHighlight(string text, Color color)
        {
            var lines = text.Split("\r\n", StringSplitOptions.None);

            foreach (var line in lines)
            {
                var words = line.Split(' ', StringSplitOptions.None);
                foreach (var word in words)
                {
                    if (KeyWords.Any(keyWord => keyWord.Equals(word.Replace("\r", "").Replace("\t", "").Replace(";", ""))))
                    {
                        yield return(new Run {
                            Text = word, Foreground = new SolidColorBrush(color)
                        });
                    }
                    else
                    {
                        yield return(new Run {
                            Text = word
                        });
                    }
                    yield return(new Run {
                        Text = " "
                    });
                }
                yield return(new Run {
                    Text = "\r\n"
                });
            }
        }
Пример #2
0
        protected MatchingRuleItem(IEnumerable <string> keyWords, IEnumerable <string> val, MatchingRuleType matchingRuleType)
        {
            Value    = val?.ToList() ?? throw new ArgumentNullException(nameof(keyWords));
            KeyWords = keyWords?.Where(x => !string.IsNullOrEmpty(x)).ToList() ?? throw new ArgumentNullException(nameof(keyWords));
            if (!KeyWords.Any())
            {
                throw new ArgumentException($"{nameof(keyWords)} cannot be empty", nameof(keyWords));
            }

            Type = matchingRuleType;
        }
        protected Func <string, bool> GetMatchMethod()
        {
            switch (Options.Match)
            {
            case KeyWordSearchMatch.AllWords:
                return((item) => KeyWords.All((keyWord) => item.Contains(keyWord)));

            case KeyWordSearchMatch.AnyWord:
                return((item) => KeyWords.Any((keyWord) => item.Contains(keyWord)));

            case KeyWordSearchMatch.ExactMatch:
                return((item) => item.Contains(Options.SearchString));

            default:
                throw new ArgumentOutOfRangeException(
                          paramName: nameof(Options.Match),
                          actualValue: Options.Match,
                          message: "Unknown Search Match Filter"
                          );
            }
        }