write null token to output if null encountered #743

This commit is contained in:
Eliot Jones 2024-01-10 21:55:00 +00:00
parent 88a148374e
commit e54709776d

View File

@ -94,8 +94,10 @@
{
if (token == null)
{
throw new ArgumentNullException(nameof(token));
WriteNullToken(outputStream);
return;
}
switch (token)
{
case ArrayToken array:
@ -305,8 +307,6 @@
/// <summary>
/// Write a hex value to the output stream
/// </summary>
/// <param name="hex"></param>
/// <param name="stream"></param>
protected void WriteHex(HexToken hex, Stream stream)
{
stream.WriteByte(HexStart);
@ -317,8 +317,6 @@
/// <summary>
/// Write an array to the output stream, with whitespace at the end.
/// </summary>
/// <param name="array"></param>
/// <param name="outputStream"></param>
protected void WriteArray(ArrayToken array, Stream outputStream)
{
outputStream.WriteByte(ArrayStart);
@ -337,8 +335,6 @@
/// <summary>
/// Write a boolean "true" or "false" to the output stream, with whitespace at the end.
/// </summary>
/// <param name="boolean"></param>
/// <param name="outputStream"></param>
protected void WriteBoolean(BooleanToken boolean, Stream outputStream)
{
var bytes = boolean.Data ? TrueBytes : FalseBytes;
@ -349,8 +345,6 @@
/// <summary>
/// Write a "%comment" in the output stream, with a line break at the end.
/// </summary>
/// <param name="comment"></param>
/// <param name="outputStream"></param>
protected void WriteComment(CommentToken comment, Stream outputStream)
{
var bytes = OtherEncodings.StringAsLatin1Bytes(comment.Data);
@ -359,6 +353,17 @@
WriteLineBreak(outputStream);
}
/// <summary>
/// Write "null" in the output stream with a whitespace at the end.
/// </summary>
protected void WriteNullToken(Stream outputStream)
{
var bytes = OtherEncodings.StringAsLatin1Bytes("null");
outputStream.Write(bytes, 0, bytes.Length);
WriteWhitespace(outputStream);
}
/// <summary>
/// Writes dictionary key/value pairs to output stream as Name/Token pairs.
/// </summary>