Anyone else have their code broken with the change to InputStream::readNextLine() ?
Thanks,
Rail
Anyone else have their code broken with the change to InputStream::readNextLine() ?
Thanks,
Rail
My .CSV file I’m reading doesn’t have CR/LF – just LF… so the position of the stream is never incremented. Debugging more, it seems to choke on an empty line instead of continuing…
So the empty line is just a ‘\n’
identifier, x, y, w, h\n
\n
# Color Wells\n
It just keeps trying to read the second line over and over…
Debugging code:
MemoryOutputStream buffer;
for (;;)
{
auto c = readByte();
buffer.writeByte (c);
if (c == 0 || c == '\n')
{
DBG ("Break One");
break;
}
if (c == '\r')
{
auto lastPos = getPosition();
if (readByte() != '\n')
setPosition (lastPos);
DBG ("Break Two");
break;
}
}
auto pos = getPosition();
DBG ("Output String...");
String szTemp = buffer.toUTF8();
DBG ("szTemp: " + szTemp + ", Buffer Size: " + String ((int) buffer.getDataSize()) + ", Position in stream: " + String (pos));
return buffer.toUTF8();
Debug output:
Break One
Output String...
szTemp: identifier, x, y, w, h
, Buffer Size: 23, Position in stream: 23
Break One
Output String...
szTemp: identifier, x, y, w, h
, Buffer Size: 23, Position in stream: 23
Break One
Output String...
szTemp: identifier, x, y, w, h
, Buffer Size: 23, Position in stream: 23
:
Rail
Perhaps try:
String InputStream::readNextLine()
{
MemoryOutputStream buffer;
for (;;)
{
auto c = readByte();
if (c == 0 || c == '\n')
break;
if (c == '\r')
{
auto lastPos = getPosition();
if (readByte() != '\n')
setPosition (lastPos);
break;
}
buffer.writeByte (c);
}
return buffer.toUTF8();
}
Rail
Thanks - yes, looks like a blooper. Will post a fix shortly!
Is it possible to add unit tests to prevent this regression from happening in the future?
Yes, good idea.