address bugs and add tests

This commit is contained in:
EliotJones
2025-07-06 17:42:47 -05:00
parent 7134032188
commit 8176903b4e
2 changed files with 884 additions and 803 deletions

View File

@@ -400,7 +400,7 @@
// Token is at end of stream or is followed by whitespace // Token is at end of stream or is followed by whitespace
if (!inputBytes.MoveNext() || ReadHelper.IsWhitespace(inputBytes.CurrentByte)) if (!inputBytes.MoveNext() || ReadHelper.IsWhitespace(inputBytes.CurrentByte))
{ {
var location = inputBytes.CurrentOffset - EndstreamBytes.Length; var location = inputBytes.CurrentOffset - EndstreamBytes.Length - 1;
endLocations.Push(new EndLoc(true, location, !isEndData)); endLocations.Push(new EndLoc(true, location, !isEndData));
isEndData = true; isEndData = true;
@@ -412,6 +412,12 @@
endStreamPosition = 0; endStreamPosition = 0;
commonPartPosition = 0; commonPartPosition = 0;
} }
else
{
endStreamPosition = 0;
commonPartPosition = 0;
isEndData = false;
}
} }
} }
else if (inputBytes.CurrentByte == objPart[endObjPosition]) else if (inputBytes.CurrentByte == objPart[endObjPosition])
@@ -444,6 +450,10 @@
} }
} }
} }
else if (inputBytes.CurrentByte == endWordPart[0])
{
commonPartPosition = 1;
}
else else
{ {
// We were reading 'end' but then we had a character mismatch. // We were reading 'end' but then we had a character mismatch.
@@ -488,20 +498,22 @@
var dataLength = endLoc.Offset - startDataOffset; var dataLength = endLoc.Offset - startDataOffset;
// 3 characters, 'e', '\n' and possibly '\r' inputBytes.Seek(endLoc.Offset - 1);
inputBytes.Seek(endLoc.Offset - 3);
inputBytes.MoveNext();
if (inputBytes.CurrentByte == '\r') var adjustment = 0;
bool isWhitespace;
do
{ {
dataLength -= 3; inputBytes.MoveNext();
} isWhitespace = ReadHelper.IsWhitespace(inputBytes.CurrentByte);
else if (isWhitespace)
{ {
dataLength -= 2; adjustment++;
} }
inputBytes.Seek(endLoc.Offset - 1 - adjustment);
} while (isWhitespace);
Memory<byte> data = new byte[dataLength]; Memory<byte> data = new byte[dataLength - adjustment];
inputBytes.Seek(streamDataStart); inputBytes.Seek(streamDataStart);
inputBytes.Read(data.Span); inputBytes.Read(data.Span);