Esempio n. 1
0
        protected virtual bool ContainsHighlight(string msg)
        {
            Regex regex;

            //go through the user's custom highlight words and check for them.
            foreach (string HighlightString in (string[])Session.UserConfig["Interface/Chat/HighlightWords"])
            {
                if (String.IsNullOrEmpty(HighlightString))
                {
                    continue;
                }

                if (HighlightString.StartsWith("/") && HighlightString.EndsWith("/"))
                {
                    // This is a regex, so just build a regex out of the string.
                    regex = new Regex(HighlightString.Substring(1, HighlightString.Length - 2));
                }
                else
                {
                    // Plain text - make a regex that matches the word as long as it's separated properly.
                    string regex_string = String.Format("(^|\\W){0}($|\\W)", Regex.Escape(HighlightString));
                    regex = new Regex(regex_string, RegexOptions.IgnoreCase);
                }

                if (regex.Match(msg).Success)
                {
                    return(true);
                }
            }

            return(false);
        }
        private void RefreshHighlight()
        {
            List <Run> runs = new List <Run>();

            if (DisplayString != null && HighlightString != null)
            {
                string displayStringLower   = DisplayString.ToLower();
                string highlightStringLower = HighlightString.ToLower().Trim();
                int    highlightStartIndex  = displayStringLower.IndexOf(highlightStringLower);
                if (highlightStartIndex > 0)
                {
                    runs.Add(GenerateRun(DisplayString.Substring(0, highlightStartIndex)));
                    runs.Add(GenerateRun(DisplayString.Substring(highlightStartIndex, highlightStringLower.Length), true));
                    if (highlightStartIndex + highlightStringLower.Length <= DisplayString.Length)
                    {
                        runs.Add(GenerateRun(DisplayString.Substring(highlightStartIndex + highlightStringLower.Length, DisplayString.Length - highlightStartIndex - highlightStringLower.Length)));
                    }
                }
                else if (highlightStartIndex == 0)
                {
                    runs.Add(GenerateRun(DisplayString.Substring(0, highlightStringLower.Length), true));
                    if (highlightStringLower.Length + highlightStartIndex < displayStringLower.Length)
                    {
                        runs.Add(GenerateRun(DisplayString.Substring(highlightStringLower.Length, DisplayString.Length - highlightStringLower.Length)));
                    }
                }
            }
            runsToRender = runs;
        }