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