示例#1
0
 /// <summary>
 /// データソースから現在の文字位置の文字を読み取って返します。
 /// <para>
 /// データソースから読み取った文字を呼び出し元に返す前に、文字位置を次に進めます。
 /// </para>
 /// </summary>
 /// <returns></returns>
 public int Read() => _inner.Read();
示例#2
0
        /// <summary>
        ///     Parses the token after all whitespace characters were consumed.
        ///     <para>
        ///     It must be guaranteed that the first character read is
        ///     <list type="bullet">
        ///         <item>a non-whitespace character</item>
        ///         <item>not EOF (int value -1</item>
        ///     </list>
        ///     </para>
        /// </summary>
        /// <returns></returns>
        /// <exception cref="JsonLexerException"></exception>
        private JsonToken DoParseNextToken()
        {
            reader.Mark(1);
            var nextChar = (char)reader.Read();

            switch (nextChar)
            {
            case JsonLexerConstants.LeftSquareBracket:
                return(JsonToken.LeftSquareBracketToken);

            case JsonLexerConstants.RightSquareBracket:
                return(JsonToken.RightSquareBracketToken);

            case JsonLexerConstants.LeftBrace:
                return(JsonToken.LeftBraceToken);

            case JsonLexerConstants.RightBrace:
                return(JsonToken.RightBraceToken);

            case JsonLexerConstants.Colon:
                return(JsonToken.ColonToken);

            case JsonLexerConstants.Comma:
                return(JsonToken.CommaToken);

            case JsonLexerConstants.TrueLiteralStart:     // fallthrough
            case JsonLexerConstants.FalseLiteralStart:
                // could be boolean literal (true|false)
                reader.Reset();
                return(TryParseBooleanLiteral());

            case JsonLexerConstants.NullLiteralStart:
                reader.Reset();
                return(TryParseNullLiteral());

            case JsonLexerConstants.QuotationMark:
                return(TryParseStringToken());

            default:
            {
                // check if it is a number or a completely unknown token
                if (IsDigitOrMinus(nextChar))
                {
                    reader.Reset();
                    return(TryParseNumberToken());
                }

                reader.Reset();
                var literalToken = ParseLiteral();
                throw new JsonLexerException(UnexpectedLiteralTokenMessage(literalToken));
            }
            }
        }