-string RollingBuffer::ReadLine(size_t max) {
-
- ByteArray result;
- result.Resize(max);
-
- size_t numBytesRead = 0;
-
- // if max not provided, we need to read incrementally
- if ( max == 0 ) {
- max = UINT_MAX;
-
- // make sure we leave room for null terminator
- result.Resize(1);
-
- size_t readResult;
- do {
- result.Resize(std::min(max, result.Size()+m_bufferGrowth));
- readResult = ReadLine(result.Data() + numBytesRead, result.Size() - numBytesRead);
- if ( readResult > 0 || numBytesRead == 0 )
- numBytesRead += readResult;
- } while ( readResult == m_bufferGrowth && result[numBytesRead-1] != '\n');
- }
-
- // otherwise read line with provided max
- else numBytesRead = ReadLine(result.Data(), result.Size());
-
- // adjust byte array depending on numBytesRead
- if ( numBytesRead == 0 )
- result.Clear();
- else
- result.Resize(numBytesRead);
-
- // return string from byte array
- return string(result.ConstData(), result.Size());
-}
-