Skip to content

Commit

Permalink
write null token to output if null encountered #743
Browse files Browse the repository at this point in the history
  • Loading branch information
EliotJones authored and BobLd committed Jan 11, 2024
1 parent 33e4ead commit 5fadf9a
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/UglyToad.PdfPig/Writer/TokenWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ public void WriteToken(IToken token, Stream outputStream)
{
if (token == null)
{
throw new ArgumentNullException(nameof(token));
WriteNullToken(outputStream);
return;
}

switch (token)
{
case ArrayToken array:
Expand Down Expand Up @@ -305,8 +307,6 @@ public void WriteObject(long objectNumber, int generation, byte[] data, Stream o
/// <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);
Expand All @@ -317,8 +317,6 @@ protected void WriteHex(HexToken hex, Stream stream)
/// <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);
Expand All @@ -337,8 +335,6 @@ protected void WriteArray(ArrayToken array, Stream outputStream)
/// <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;
Expand All @@ -349,8 +345,6 @@ protected void WriteBoolean(BooleanToken boolean, Stream outputStream)
/// <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);
Expand All @@ -359,6 +353,17 @@ protected void WriteComment(CommentToken comment, Stream 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>
/// Writes dictionary key/value pairs to output stream as Name/Token pairs.
/// </summary>
Expand Down

0 comments on commit 5fadf9a

Please sign in to comment.