/// <summary> /// Parses the next element in the array. /// </summary> private JsonToken ParseArrayNext() { switch (NextClean()) { case ';': case ',': { if (NextClean() == ']') { return(Yield(JsonToken.EndArray())); } else { _reader.Back(); } break; } case ']': { return(Yield(JsonToken.EndArray())); } default: throw SyntaxError("Expected a ',' or ']'."); } Push(ParseArrayNextMethod); return(Parse()); }
private JsonToken ParseArrayFirst() { if (NextClean() == ']') { return(Yield(JsonToken.EndArray())); } _reader.Back(); Push(ParseArrayNextMethod); return(Parse()); }
public void BufferValueOnBOF() { var writer = new JsonBufferWriter(); writer.WriteFromReader(JsonText.CreateReader("[]")); var buffer = writer.GetBuffer().CreateReader().BufferValue(); Assert.AreEqual(2, buffer.Length); Assert.AreEqual(JsonToken.Array(), buffer[0]); Assert.AreEqual(JsonToken.EndArray(), buffer[1]); }
static JsonBuffer() { JsonBuffer buffer = new JsonBufferStorage(5) // [null,true,false] .Write(JsonToken.Array()) .Write(JsonToken.Null(), JsonToken.True(), JsonToken.False()) .Write(JsonToken.EndArray()) .ToBuffer(); _null = buffer.Slice(1, 2); _true = buffer.Slice(2, 3); _false = buffer.Slice(3, 4); }
public void JsonTokenString() { Assert.AreEqual("String:hello", JsonToken.String("hello").ToString()); Assert.AreEqual("Number:123", JsonToken.Number("123").ToString()); Assert.AreEqual("Boolean:true", JsonToken.Boolean(true).ToString()); Assert.AreEqual("Boolean:false", JsonToken.Boolean(false).ToString()); Assert.AreEqual("Null:null", JsonToken.Null().ToString()); Assert.AreEqual("Array", JsonToken.Array().ToString()); Assert.AreEqual("EndArray", JsonToken.EndArray().ToString()); Assert.AreEqual("Object", JsonToken.Object().ToString()); Assert.AreEqual("EndObject", JsonToken.EndObject().ToString()); Assert.AreEqual("Member:test", JsonToken.Member("test").ToString()); Assert.AreEqual("BOF", JsonToken.BOF().ToString()); Assert.AreEqual("EOF", JsonToken.EOF().ToString()); }
private JsonToken ParseArrayNext() { switch (NextClean()) { case ',': case ';': if (NextClean() == ']') { return(Yield(JsonToken.EndArray())); } _reader.Back(); Push(ParseArrayNextMethod); return(Parse()); case ']': return(Yield(JsonToken.EndArray())); default: throw new JsonException("Expected a ',' or ']'."); } }
protected override JsonToken ReadTokenImpl() { if (_buffer.IsStructured) { Debug.Assert(!EOF); // sanity check if (++_index < _buffer.Length) { return(_buffer[_index]); } } else { switch (++_index) { case 0: return(JsonToken.Array()); case 1: return(_buffer[0]); case 2: return(JsonToken.EndArray()); } } return(JsonToken.EOF()); }
protected override void WriteEndArrayImpl() { Write(JsonToken.EndArray()); }
public void ArrayTokens() { Assert.AreEqual(JsonTokenClass.Array, JsonToken.Array().Class); Assert.AreEqual(JsonTokenClass.EndArray, JsonToken.EndArray().Class); }
public MockedJsonReader EndArray() { return(Append(JsonToken.EndArray())); }