Beispiel #1
0
        private object ReadRegExp()
        {
            var resultArray = new List <object>();

            resultArray.Add(_input.ReadStringUTF8(int.MaxValue));
            resultArray.Add(_input.ReadStringUTF8(int.MaxValue));

            return(_factory.CreateArray(resultArray));
        }
Beispiel #2
0
        /// <summary>
        /// Read an array from input stream.
        /// </summary>
        private object ReadArray()
        {
            List <object>       result = new List <object>();
            JSonReaderTokenInfo currentToken;
            int commas = 0;

            while ((currentToken = ReadNextToken(true)).Type != JSonReaderTokenType.EndOfText)
            {
                if (currentToken.Type == JSonReaderTokenType.ArrayEnd)
                {
                    PopTopToken();

                    // if number of commas is greater than number of added elements,
                    // then value was not passed between:
                    if (result.Count > 0 && commas != result.Count - 1)
                    {
                        throw new JSonReaderException("Too many commas at closing array token, expected none", currentToken);
                    }
                    break;
                }

                switch (currentToken.Type)
                {
                case JSonReaderTokenType.ArrayStart:
                    // read embedded array:
                    AddValue(result, ReadArray(), commas, currentToken);
                    break;

                case JSonReaderTokenType.ObjectStart:
                    // read embedded object:
                    AddValue(result, ReadObject(), commas, currentToken);
                    break;

                case JSonReaderTokenType.Keyword:
                    // add embedded value of reserved keyword:
                    AddValue(result, ReadKeyword(), commas, currentToken);
                    break;

                case JSonReaderTokenType.Number:
                    // add embedded numeric value:
                    AddValue(result, ReadNumber(), commas, currentToken);
                    break;

                case JSonReaderTokenType.String:
                    // add embedded string value:
                    AddValue(result, ReadString(), commas, currentToken);
                    break;

                case JSonReaderTokenType.Comma:
                    // go to next array element:
                    currentToken = PopTopToken();
                    commas++;

                    // if number of commas is greater than number of added elements,
                    // then value was not passed between:
                    if (commas > result.Count)
                    {
                        throw new JSonReaderException("Missing value for array element", currentToken);
                    }
                    break;

                default:
                    throw new JSonReaderException("Invalid token", currentToken);
                }
            }

            JSonReaderTokenInfo topToken = PopTopToken();

            if (topToken.Type != JSonReaderTokenType.ArrayStart || currentToken.Type == JSonReaderTokenType.EndOfText)
            {
                throw new JSonReaderException("Missing close array token", topToken);
            }

            return(_factory.CreateArray(result));
        }