[RESOLVED] Commit change to InputStream::readNextLine() broke my code


#1

https://github.com/WeAreROLI/JUCE/commit/a7c56fd89b4cc9eaacf56e25554bdfe47cb353d6#diff-2e3c9aaaaec198f3ed0d5bf7bd5ef0c0

Anyone else have their code broken with the change to InputStream::readNextLine() ?

Thanks,

Rail


#2

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


#3

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


#4

Thanks - yes, looks like a blooper. Will post a fix shortly!


#5

Is it possible to add unit tests to prevent this regression from happening in the future?


#6

Yes, good idea.