Ejemplo n.º 1
0
        private ScanState ScanNextPrivate()
        {
            reader.StartNewAtom();
            if (!reader.ReadNext(out char c))
            {
                return(ScanState.Error);
            }
            switch (c)
            {
            case '"':
            case '\'':
                return(ScanDelimitedString(c));

            case '.':
                if (reader.CheckNext(char.IsDigit))
                {
                    reader.UndoRead();
                    return(ScanDecimal());
                }
                return(ScanState.Error);

            case '-':
                reader.UndoRead();
                return(ScanDecimal());

            case ',':
                currentToken = JsonToken.Comma;
                return(ScanState.HasValue);

            case ':':
                currentToken = JsonToken.Colon;
                return(ScanState.HasValue);

            case '{':
                currentToken = JsonToken.BeginObject;
                return(ScanState.HasValue);

            case '}':
                currentToken = JsonToken.EndObject;
                return(ScanState.HasValue);

            case '[':
                currentToken = JsonToken.BeginArray;
                return(ScanState.HasValue);

            case ']':
                currentToken = JsonToken.EndArray;
                return(ScanState.HasValue);

            default:
                if (char.IsWhiteSpace(c))
                {
                    reader.AdvanceWhile(char.IsWhiteSpace, condition: true);
                    return(ScanNextPrivate());
                }
                if (char.IsDigit(c))
                {
                    if (c == '0' && reader.ReadNextIfEquals('x', 'X'))
                    {
                        return(ScanHexNumber());
                    }
                    reader.UndoRead();
                    return(ScanDecimal());
                }
                return(ScanUnquotedString());
            }
        }