void ResetState() { complexTextMode = JsonComplexTextMode.None; expectingFirstElementInNonPrimitiveChild = false; charactersToSkipOnNextRead = new byte[2]; scopeDepth = 0; if ((scopes != null) && (scopes.Length > JsonGlobals.maxScopeSize)) { scopes = null; } }
void ReadNumericalText() { byte[] buffer; int offset; int offsetMax; int length; if (buffered) { buffer = BufferReader.GetBuffer(out offset, out offsetMax); length = ComputeNumericalTextLength(buffer, offset, offsetMax); } else { buffer = BufferReader.GetBuffer(MaxTextChunk, out offset, out offsetMax); length = ComputeNumericalTextLength(buffer, offset, offsetMax); length = BreakText(buffer, offset, length); } BufferReader.Advance(length); if (offset <= offsetMax - length) { MoveToAtomicText().Value.SetValue(ValueHandleType.UTF8, offset, length); complexTextMode = JsonComplexTextMode.None; } else { MoveToComplexText().Value.SetValue(ValueHandleType.UTF8, offset, length); complexTextMode = JsonComplexTextMode.NumericalText; } }
void ReadQuotedText(bool moveToText) { byte[] buffer; int offset; int offsetMax; int length; bool escaped; bool endReached; if (buffered) { buffer = BufferReader.GetBuffer(out offset, out offsetMax); length = ComputeQuotedTextLengthUntilEndQuote(buffer, offset, offsetMax, out escaped); endReached = offset < offsetMax - length; } else { buffer = BufferReader.GetBuffer(MaxTextChunk, out offset, out offsetMax); length = ComputeQuotedTextLengthUntilEndQuote(buffer, offset, offsetMax, out escaped); endReached = offset < offsetMax - length; length = BreakText(buffer, offset, length); } if (escaped && BufferReader.GetByte() == 0xEF) { offset = BufferReader.Offset; length = ReadNonFFFE(); } BufferReader.Advance(length); if (!escaped && endReached) { if (moveToText) { MoveToAtomicText().Value.SetValue(ValueHandleType.UTF8, offset, length); } SkipExpectedByteInBufferReader(JsonGlobals.QuoteByte); complexTextMode = JsonComplexTextMode.None; } else { if ((length == 0) && escaped) { ReadEscapedCharacter(moveToText); } else { if (moveToText) { MoveToComplexText().Value.SetValue(ValueHandleType.UTF8, offset, length); } complexTextMode = JsonComplexTextMode.QuotedText; } } }
/// <summary> /// Reset State /// </summary> private void ResetState() { complexTextMode = JsonComplexTextMode.None; // Set this bool to false // indicate than the first child is a complex type (beetween "{" and "}" ) expectingFirstElementInNonPrimitiveChild = false; charactersToSkipOnNextRead = new byte[2]; // Reset depth to 0 scopeDepth = 0; // Clear the scopes dictionary scopes.Clear(); }
void ReadEscapedCharacter(bool moveToText) { BufferReader.SkipByte(); char ch = (char)BufferReader.GetByte(); if (ch == 'u') { BufferReader.SkipByte(); int offset; byte[] buffer = BufferReader.GetBuffer(5, out offset); string bufferAsString = Encoding.UTF8.GetString(buffer, offset, 4); BufferReader.Advance(4); int charValue = ParseChar(bufferAsString, NumberStyles.HexNumber); if (Char.IsHighSurrogate((char)charValue)) { byte nextByte = BufferReader.GetByte(); if (nextByte == (byte)'\\') { BufferReader.SkipByte(); SkipExpectedByteInBufferReader((byte)'u'); buffer = BufferReader.GetBuffer(5, out offset); bufferAsString = Encoding.UTF8.GetString(buffer, offset, 4); BufferReader.Advance(4); char lowChar = ParseChar(bufferAsString, NumberStyles.HexNumber); if (!Char.IsLowSurrogate(lowChar)) { XmlExceptionHelper.ThrowXmlException(this, new XmlException(System.Runtime.Serialization.SR.GetString(System.Runtime.Serialization.SR.XmlInvalidLowSurrogate, bufferAsString))); } charValue = new SurrogateChar(lowChar, (char)charValue).Char; } } if (buffer[offset + 4] == JsonGlobals.QuoteByte) { BufferReader.SkipByte(); if (moveToText) { MoveToAtomicText().Value.SetCharValue(charValue); } complexTextMode = JsonComplexTextMode.None; } else { if (moveToText) { MoveToComplexText().Value.SetCharValue(charValue); } complexTextMode = JsonComplexTextMode.QuotedText; } } else { switch (ch) { case 'b': ch = '\b'; break; case 'f': ch = '\f'; break; case 'n': ch = '\n'; break; case 'r': ch = '\r'; break; case 't': ch = '\t'; break; case '\"': case '\\': case '/': // Do nothing. These are the actual unescaped values. break; default: XmlExceptionHelper.ThrowXmlException(this, new XmlException(SR.GetString(SR.JsonEncounteredUnexpectedCharacter, (char)ch))); break; } BufferReader.SkipByte(); if (BufferReader.GetByte() == JsonGlobals.QuoteByte) { BufferReader.SkipByte(); if (moveToText) { MoveToAtomicText().Value.SetCharValue(ch); } complexTextMode = JsonComplexTextMode.None; } else { if (moveToText) { MoveToComplexText().Value.SetCharValue(ch); } complexTextMode = JsonComplexTextMode.QuotedText; } } }
private void ReadNumericalText() { int offset; int offsetMax; int num; byte[] buffer = this.BufferReader.GetBuffer(MaxTextChunk, out offset, out offsetMax); int numericalTextLength = ComputeNumericalTextLength(buffer, offset, offsetMax); num = BreakText(buffer, offset, numericalTextLength); this.BufferReader.Advance(num); if (offset <= offsetMax - num) { this.MoveToAtomicText().Value.SetValue(ValueHandleType.UTF8, offset, num); complexTextMode = JsonComplexTextMode.None; } else { this.MoveToComplexText().Value.SetValue(ValueHandleType.UTF8, offset, num); complexTextMode = JsonComplexTextMode.NumericalText; } }
/// <summary> /// Read Quoted Text /// </summary> /// <param name="moveToText"></param> private void ReadQuotedText(bool moveToText) { int offset; int offsetMax; bool escaped; int num; byte[] buffer = this.BufferReader.GetBuffer(MaxTextChunk, out offset, out offsetMax); int lengthUntilEndQuote = ComputeQuotedTextLengthUntilEndQuote(buffer, offset, offsetMax, out escaped); num = BreakText(buffer, offset, lengthUntilEndQuote); if (escaped && this.BufferReader.GetByte() == 239) { offset = this.BufferReader.Offset; num = ReadNonFFFE(); } this.BufferReader.Advance(num); // If there is no escaped char && offset is not at the end if (!escaped && offset < offsetMax - num) { if (moveToText) this.MoveToAtomicText().Value.SetValue(ValueHandleType.UTF8, offset, num); SkipExpectedByteInBufferReader(Keys.DoubleQuote); complexTextMode = JsonComplexTextMode.None; } else if (num == 0 && escaped) { ReadEscapedCharacter(moveToText); } else { if (moveToText) this.MoveToComplexText().Value.SetValue(ValueHandleType.UTF8, offset, num); complexTextMode = JsonComplexTextMode.QuotedText; } }
/// <summary> /// Read Escaped Character and set this.complexTextMode = JsonComplexTextMode.Non or QuotedText /// </summary> /// <param name="moveToText"></param> private void ReadEscapedCharacter(bool moveToText) { // Skip current byte this.BufferReader.SkipByte(); // Get Byte var ch1 = (char)this.BufferReader.GetByte(); //The Unicode character with encoding xxxx, where xxxx is one to four hexidecimal digits. //Unicode escapes are distinct from the other escape types listed here; they are described below in more detail. if (ch1 == Keys.LowerU) { // Skip the lower u this.BufferReader.SkipByte(); int offset; // Get next 5 char byte[] buffer = this.BufferReader.GetBuffer(5, out offset); string string1 = Encoding.UTF8.GetString(buffer, offset, 4); this.BufferReader.Advance(4); int ch2 = ParseChar(string1, NumberStyles.HexNumber); if (char.IsHighSurrogate((char)ch2) && this.BufferReader.GetByte() == Keys.BackSlash) { this.BufferReader.SkipByte(); // Skip the lower U this.SkipExpectedByteInBufferReader(Keys.LowerU); buffer = this.BufferReader.GetBuffer(5, out offset); string string2 = Encoding.UTF8.GetString(buffer, offset, 4); this.BufferReader.Advance(4); char ch3 = ParseChar(string2, NumberStyles.HexNumber); if (!char.IsLowSurrogate(ch3)) throw new XmlException("XmlInvalidLowSurrogate"); // ch2 = new SurrogateChar(ch3, (char)ch2).Char; } if (buffer[offset + 4] == Keys.DoubleQuote) { this.BufferReader.SkipByte(); if (moveToText) this.MoveToAtomicText().Value.SetCharValue(ch2); this.complexTextMode = JsonComplexTextMode.None; } else { if (moveToText) this.MoveToComplexText().Value.SetCharValue(ch2); this.complexTextMode = JsonComplexTextMode.QuotedText; } } else { switch (ch1) { case 'n': ch1 = '\n'; break; case 'r': ch1 = '\r'; break; case 't': ch1 = '\t'; break; case 'b': ch1 = '\b'; break; case 'f': break; case '"': case '/': case '\\': break; default: throw new XmlException("JsonEncounteredUnexpectedCharacter"); } // skip current byte this.BufferReader.SkipByte(); if (this.BufferReader.GetByte() == Keys.DoubleQuote) { this.BufferReader.SkipByte(); if (moveToText) this.MoveToAtomicText().Value.SetCharValue(ch1); complexTextMode = JsonComplexTextMode.None; } else { if (moveToText) this.MoveToComplexText().Value.SetCharValue(ch1); complexTextMode = JsonComplexTextMode.QuotedText; } } }
private void ReadQuotedText(bool moveToText) { int offset; int num2; int num3; bool flag; if (this.buffered) { num3 = ComputeQuotedTextLengthUntilEndQuote(base.BufferReader.GetBuffer(out offset, out num2), offset, num2, out flag); } else { byte[] buffer = base.BufferReader.GetBuffer(0x800, out offset, out num2); num3 = ComputeQuotedTextLengthUntilEndQuote(buffer, offset, num2, out flag); num3 = BreakText(buffer, offset, num3); } if (flag && (base.BufferReader.GetByte() == 0xef)) { offset = base.BufferReader.Offset; num3 = this.ReadNonFFFE(); } base.BufferReader.Advance(num3); if (!flag && (offset < (num2 - num3))) { if (moveToText) { base.MoveToAtomicText().Value.SetValue(ValueHandleType.UTF8, offset, num3); } this.SkipExpectedByteInBufferReader(0x22); this.complexTextMode = JsonComplexTextMode.None; } else if ((num3 == 0) && flag) { this.ReadEscapedCharacter(moveToText); } else { if (moveToText) { base.MoveToComplexText().Value.SetValue(ValueHandleType.UTF8, offset, num3); } this.complexTextMode = JsonComplexTextMode.QuotedText; } }
private void ReadNumericalText() { int num; int num2; int num3; if (this.buffered) { num3 = ComputeNumericalTextLength(base.BufferReader.GetBuffer(out num, out num2), num, num2); } else { byte[] buffer = base.BufferReader.GetBuffer(0x800, out num, out num2); num3 = ComputeNumericalTextLength(buffer, num, num2); num3 = BreakText(buffer, num, num3); } base.BufferReader.Advance(num3); if (num <= (num2 - num3)) { base.MoveToAtomicText().Value.SetValue(ValueHandleType.UTF8, num, num3); this.complexTextMode = JsonComplexTextMode.None; } else { base.MoveToComplexText().Value.SetValue(ValueHandleType.UTF8, num, num3); this.complexTextMode = JsonComplexTextMode.NumericalText; } }
private void ReadEscapedCharacter(bool moveToText) { base.BufferReader.SkipByte(); char @byte = (char) base.BufferReader.GetByte(); switch (@byte) { case '"': case '/': case '\\': break; case 'r': @byte = '\r'; break; case 't': @byte = '\t'; break; case 'n': @byte = '\n'; break; case 'b': @byte = '\b'; break; case 'f': @byte = '\f'; break; case 'u': { int num; base.BufferReader.SkipByte(); byte[] bytes = base.BufferReader.GetBuffer(5, out num); string str = Encoding.UTF8.GetString(bytes, num, 4); base.BufferReader.Advance(4); int ch = ParseChar(str, NumberStyles.HexNumber); if (char.IsHighSurrogate((char) ch) && (base.BufferReader.GetByte() == 0x5c)) { base.BufferReader.SkipByte(); this.SkipExpectedByteInBufferReader(0x75); bytes = base.BufferReader.GetBuffer(5, out num); str = Encoding.UTF8.GetString(bytes, num, 4); base.BufferReader.Advance(4); char c = ParseChar(str, NumberStyles.HexNumber); if (!char.IsLowSurrogate(c)) { XmlExceptionHelper.ThrowXmlException(this, new XmlException(System.Runtime.Serialization.SR.GetString("XmlInvalidLowSurrogate", new object[] { str }))); } SurrogateChar ch3 = new SurrogateChar(c, (char) ch); ch = ch3.Char; } if (bytes[num + 4] == 0x22) { base.BufferReader.SkipByte(); if (moveToText) { base.MoveToAtomicText().Value.SetCharValue(ch); } this.complexTextMode = JsonComplexTextMode.None; return; } if (moveToText) { base.MoveToComplexText().Value.SetCharValue(ch); } this.complexTextMode = JsonComplexTextMode.QuotedText; return; } default: XmlExceptionHelper.ThrowXmlException(this, new XmlException(System.Runtime.Serialization.SR.GetString("JsonEncounteredUnexpectedCharacter", new object[] { @byte }))); break; } base.BufferReader.SkipByte(); if (base.BufferReader.GetByte() == 0x22) { base.BufferReader.SkipByte(); if (moveToText) { base.MoveToAtomicText().Value.SetCharValue(@byte); } this.complexTextMode = JsonComplexTextMode.None; } else { if (moveToText) { base.MoveToComplexText().Value.SetCharValue(@byte); } this.complexTextMode = JsonComplexTextMode.QuotedText; } }
private void ResetState() { this.complexTextMode = JsonComplexTextMode.None; this.expectingFirstElementInNonPrimitiveChild = false; this.charactersToSkipOnNextRead = new byte[2]; this.scopeDepth = 0; if ((this.scopes != null) && (this.scopes.Length > 0x19)) { this.scopes = null; } }