Esempio n. 1
0
 private void ColorizeSegment(ColorizedSegment currentSegment)
 {
     if (Keywords.Contains(currentSegment.Value.Trim()))
     {
         currentSegment.Color = EditorColors.Keyword;
     }
     else if (ValueWords.Contains(currentSegment.Value.Trim()))
     {
         currentSegment.Color = EditorColors.ValueWord;
     }
     else if (int.TryParse(currentSegment.Value, out int _))
     {
         currentSegment.Color = EditorColors.Number;
     }
     else if (IsHexWithPrefix(currentSegment.Value))
     {
         currentSegment.Color = EditorColors.Number;
     }
 }
Esempio n. 2
0
        public List <ColorizedSegment> Colorize(string line)
        {
            //todo: clean this code up

            var ret = new List <ColorizedSegment>();

            var currentSegment = new ColorizedSegment();

            for (var i = 0; i < line.Length; i++)
            {
                if (line[i] == '"')
                {
                    ret.Add(currentSegment);
                    currentSegment = new ColorizedSegment
                    {
                        Color = EditorColors.String
                    };

                    currentSegment.Value += line[i++];

                    i += GetEnclosedString(line, out string token, i);

                    currentSegment.Value += token;

                    ret.Add(currentSegment);
                    currentSegment = new ColorizedSegment();
                }
                else if (line[i] == '/' && i + 1 < line.Length && line[i + 1] == '/')
                {
                    ColorizeSegment(currentSegment);
                    ret.Add(currentSegment);
                    currentSegment = new ColorizedSegment
                    {
                        Color = EditorColors.Comment,
                    };

                    currentSegment.Value += line[i++];
                    currentSegment.Value += line[i++];

                    while (i < line.Length)
                    {
                        currentSegment.Value += line[i++];
                    }

                    break;
                }
                else if (line[i] == ' ')
                {
                    ColorizeSegment(currentSegment);
                    currentSegment.Value += " ";

                    ret.Add(currentSegment);
                    currentSegment = new ColorizedSegment();
                }
                else if (Operators.Contains(line[i]))
                {
                    ColorizeSegment(currentSegment);
                    ret.Add(currentSegment);

                    currentSegment = new ColorizedSegment {
                        Color = EditorColors.Operator
                    };
                    currentSegment.Value += line[i];
                    ret.Add(currentSegment);

                    currentSegment = new ColorizedSegment();
                }
                else
                {
                    currentSegment.Value += line[i];
                }
            }

            if (!string.IsNullOrEmpty(currentSegment.Value))
            {
                ColorizeSegment(currentSegment);
                ret.Add(currentSegment);
            }

            return(ret);
        }