Skip to content

Commit

Permalink
Fixed the MarkableStreamReader to copy previously buffered data into …
Browse files Browse the repository at this point in the history
…the new buffer when there are still unread characters in the old buffer.
  • Loading branch information
fubar-coder committed Jul 10, 2015
1 parent 5991ffa commit eb70926
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion BeanIO.Test/Stream/FixedLengthReaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void TestComments()
"/+" +
"+" +
"// ignored+" +
"//++");
"//");

var reader = new FixedLengthReader(input, config);
Assert.Equal("one", reader.Read());
Expand Down
16 changes: 14 additions & 2 deletions BeanIO/Internal/Util/MarkableTextReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,20 @@ public override int Read()

public virtual void Mark(int readAheadLimit)
{
_markBuffer = new int[readAheadLimit];
_markBufferSize = _markBufferPosition = 0;
var oldBuffer = _markBuffer;
if (oldBuffer != null && _markBufferPosition != _markBufferSize)
{
var remainingSize = _markBufferSize - _markBufferPosition;
_markBuffer = new int[Math.Max(readAheadLimit, remainingSize)];
Array.Copy(oldBuffer, _markBufferPosition, _markBuffer, 0, remainingSize);
_markBufferSize = remainingSize;
}
else
{
_markBuffer = new int[readAheadLimit];
_markBufferSize = 0;
}
_markBufferPosition = 0;
}

public virtual void Reset()
Expand Down

0 comments on commit eb70926

Please sign in to comment.