예제 #1
0
        public static List <XmlToken> Tokenize(string input)
        {
            XmlTokenizerMode mode      = XmlTokenizerMode.OutsideElement;
            XmlTokenizer     tokenizer = new XmlTokenizer();

            return(tokenizer.Tokenize(input, ref mode));
        }
예제 #2
0
        public void Highlight(string line)
        {
            _paragraph.Inlines.Clear();
            XmlTokenizer     tokenizer = new XmlTokenizer();
            XmlTokenizerMode mode      = XmlTokenizerMode.OutsideElement;

            List <XmlToken> tokens     = tokenizer.Tokenize(Xaml, ref mode);
            List <string>   tokenTexts = new List <string>(tokens.Count);
            List <Color>    colors     = new List <Color>(tokens.Count);
            int             position   = 0;

            foreach (XmlToken token in tokens)
            {
                string tokenText = Xaml.Substring(position, token.Length);
                tokenTexts.Add(tokenText);
                Color color = ColorForToken(token, tokenText);
                colors.Add(color);
                position += token.Length;
            }
            for (int i = 0; i < tokens.Count; i++)
            {
                Run run = new Run();
                run.Foreground = new SolidColorBrush(colors[i]);
                run.Text       = tokenTexts[i];
                _paragraph.Inlines.Add(run);
            }
        }
예제 #3
0
 public static List<XmlToken> Tokenize(string input)
 {
     XmlTokenizerMode mode = XmlTokenizerMode.OutsideElement;
     XmlTokenizer tokenizer = new XmlTokenizer();
     return tokenizer.Tokenize(input, ref mode);
 }
예제 #4
0
 protected void OnTextChanged()
 {
     _paragraph.Inlines.Clear();
     var tokenizer = new XmlTokenizer();
     XmlTokenizerMode mode = XmlTokenizerMode.OutsideElement;
     List<XmlToken> tokens = tokenizer.Tokenize(Xaml, ref mode);
     var tokenTexts = new List<string>(tokens.Count);
     var colors = new List<Color>(tokens.Count);
     int position = 0;
     foreach (XmlToken token in tokens)
     {
         string tokenText = Xaml.Substring(position, token.Length);
         tokenTexts.Add(tokenText);
         Color color = ColorForToken(token, tokenText);
         colors.Add(color);
         position += token.Length;
     }
     for (int i = 0; i < tokens.Count; i++)
     {
         Run run = new Run();
         run.Foreground = new SolidColorBrush(colors[i]);
         run.Text = tokenTexts[i];
         _paragraph.Inlines.Add(run);
     }
 }