void HighlightStringFormatItems(PrimitiveExpression expr)
        {
            if (!(expr.Value is string))
            {
                return;
            }
            int          line  = expr.StartLocation.Line;
            int          col   = expr.StartLocation.Column;
            TextLocation start = TextLocation.Empty;

            for (int i = 0; i < expr.LiteralValue.Length; i++)
            {
                char ch = expr.LiteralValue [i];

                if (NewLine.GetDelimiterType(ch, i + 1 < expr.LiteralValue.Length ? expr.LiteralValue [i + 1] : '\0') != UnicodeNewline.Unknown)
                {
                    line++;
                    col = 1;
                    continue;
                }


                if (ch == '{' && start.IsEmpty)
                {
                    char next = i + 1 < expr.LiteralValue.Length ? expr.LiteralValue [i + 1] : '\0';
                    if (next == '{')
                    {
                        i++;
                        col += 2;
                        continue;
                    }
                    start = new TextLocation(line, col);
                }
                col++;
                if (ch == '}' && !start.IsEmpty)
                {
                    char next = i + 1 < expr.LiteralValue.Length ? expr.LiteralValue [i + 1] : '\0';
                    if (next == '}')
                    {
                        i++;
                        col += 2;
                        continue;
                    }
                    Colorize(start, new TextLocation(line, col), stringFormatItemColor);
                    start = TextLocation.Empty;
                }
            }
        }
        static internal Delimiter NextDelimiter(string text, int offset)
        {
            int pOffset   = offset;
            int endOffset = text.Length;

            while (pOffset < endOffset)
            {
                int  nextOffset = pOffset + 1;
                char nextChar   = nextOffset < endOffset ? text[nextOffset] : '\0';
                var  type       = NewLine.GetDelimiterType(text[pOffset], nextChar);
                if (type != UnicodeNewline.Unknown)
                {
                    return(new Delimiter(pOffset, type));
                }
                ++pOffset;
            }

            return(Delimiter.Invalid);
        }
Esempio n. 3
0
        static unsafe internal Delimiter NextDelimiter(string text, int offset)
        {
            fixed(char *start = text)
            {
                char *p      = start + offset;
                char *endPtr = start + text.Length;

                while (p < endPtr)
                {
                    char *nextp    = p + 1;
                    char  nextChar = nextp < endPtr ? *nextp : '\0';
                    var   type     = NewLine.GetDelimiterType(*p, nextChar);
                    if (type != UnicodeNewline.Unknown)
                    {
                        return(new Delimiter((int)(p - start), type));
                    }
                    p++;
                }
                return(Delimiter.Invalid);
            }
        }
        void HighlightStringFormatItems(LiteralExpressionSyntax expr)
        {
            if (!expr.Token.IsKind(SyntaxKind.StringLiteralToken))
            {
                return;
            }
            var text  = expr.Token.Text;
            int start = -1;

            for (int i = 0; i < text.Length; i++)
            {
                char ch = text [i];

                if (NewLine.GetDelimiterType(ch, i + 1 < text.Length ? text [i + 1] : '\0') != UnicodeNewline.Unknown)
                {
                    continue;
                }

                if (ch == '{' && start < 0)
                {
                    char next = i + 1 < text.Length ? text [i + 1] : '\0';
                    if (next == '{')
                    {
                        i++;
                        continue;
                    }
                    start = i;
                }

                if (ch == '}' && start >= 0)
                {
                    Colorize(new TextSpan(expr.SpanStart + start, i - start + 1), stringFormatItemColor);
                    start = -1;
                }
            }
        }