More robust check for EOF in input stream.
This commit is contained in:
parent
c9f0641b06
commit
e192ce6716
@ -109,10 +109,12 @@ stream::size_type parserInputStreamAdapter::findNext
|
|||||||
size_type findBufferLen = 0;
|
size_type findBufferLen = 0;
|
||||||
size_type findBufferOffset = 0;
|
size_type findBufferOffset = 0;
|
||||||
|
|
||||||
|
bool isEOF = false;
|
||||||
|
|
||||||
// Fill in initial buffer
|
// Fill in initial buffer
|
||||||
findBufferLen = read(findBuffer, BUFFER_SIZE * sizeof(value_type));
|
findBufferLen = read(findBuffer, BUFFER_SIZE * sizeof(value_type));
|
||||||
|
|
||||||
for (;;)
|
while (findBufferLen != 0)
|
||||||
{
|
{
|
||||||
// Find token
|
// Find token
|
||||||
for (value_type *begin = findBuffer, *end = findBuffer + findBufferLen - token.length() ;
|
for (value_type *begin = findBuffer, *end = findBuffer + findBufferLen - token.length() ;
|
||||||
@ -133,17 +135,25 @@ stream::size_type parserInputStreamAdapter::findNext
|
|||||||
memcpy(findBuffer1, findBuffer2, (BUFFER_SIZE / 2) * sizeof(value_type));
|
memcpy(findBuffer1, findBuffer2, (BUFFER_SIZE / 2) * sizeof(value_type));
|
||||||
|
|
||||||
// Read more bytes
|
// Read more bytes
|
||||||
if (findBufferLen < BUFFER_SIZE && eof())
|
if (findBufferLen < BUFFER_SIZE && (eof() || isEOF))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const size_type bytesRead = read(findBuffer2, (BUFFER_SIZE / 2) * sizeof(value_type));
|
const size_type bytesRead = read(findBuffer2, (BUFFER_SIZE / 2) * sizeof(value_type));
|
||||||
|
|
||||||
|
if (bytesRead == 0)
|
||||||
|
{
|
||||||
|
isEOF = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
findBufferLen = (BUFFER_SIZE / 2) + bytesRead;
|
findBufferLen = (BUFFER_SIZE / 2) + bytesRead;
|
||||||
findBufferOffset += (BUFFER_SIZE / 2);
|
findBufferOffset += (BUFFER_SIZE / 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
seek(initialPos);
|
seek(initialPos);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user