Core/Stream: Fix ReadLine
Former-commit-id: 81e89bb4b11264371d7cbcf9cf5275ec0ce3f7ba [formerly 8ac037f30540faebc51efa5953fc01d9659a1f19] [formerly b599cef23b34132171373aee1cca81daf259b65e [formerly 053ef5248717e56f5e943f6dbdddf8092ae9dda2]] Former-commit-id: c14803c0471a6bfa347f0f512886dae2d8cc7871 [formerly dc174bdb2cb49e68b57b85267ac72178d7e202af] Former-commit-id: 815fe25a962845d091de7a02a0c0ff2e62f45b51
This commit is contained in:
parent
c087d916a1
commit
8c7dee81e8
|
|
@ -44,14 +44,19 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Reads characters in the stream
|
* \brief Reads a line from the stream
|
||||||
|
*
|
||||||
|
* Reads the stream until a line separator or the end of the stream is found.
|
||||||
|
*
|
||||||
|
* If lineSize does not equal zero, it represents the maximum character count to be read from the stream.
|
||||||
|
*
|
||||||
|
* \param lineSize Maximum number of characters to read, or zero for no limit
|
||||||
|
*
|
||||||
* \return Line containing characters
|
* \return Line containing characters
|
||||||
*
|
*
|
||||||
* \param lineSize Number of characters to read, if lineSize is 0, read as much as possible
|
* \remark With the text stream option, "\r\n" is treated as "\n"
|
||||||
*
|
* \remark The line separator character is not returned as part of the string
|
||||||
* \remark Produces a NazaraWarning if cursor position could not be reset
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
String Stream::ReadLine(unsigned int lineSize)
|
String Stream::ReadLine(unsigned int lineSize)
|
||||||
{
|
{
|
||||||
String line;
|
String line;
|
||||||
|
|
@ -71,19 +76,33 @@ namespace Nz
|
||||||
if (ptr)
|
if (ptr)
|
||||||
{
|
{
|
||||||
std::ptrdiff_t pos = ptr - buffer;
|
std::ptrdiff_t pos = ptr - buffer;
|
||||||
|
if (ptr != buffer)
|
||||||
if (m_streamOptions & StreamOption_Text && pos > 0 && buffer[pos - 1] == '\r')
|
{
|
||||||
line.Append(buffer, pos - 1);
|
if (m_streamOptions & StreamOption_Text && buffer[pos - 1] == '\r')
|
||||||
else
|
line.Append(buffer, pos - 1);
|
||||||
line.Append(buffer, pos);
|
else
|
||||||
|
line.Append(buffer, pos);
|
||||||
|
}
|
||||||
|
|
||||||
if (!SetCursorPos(GetCursorPos() - readSize + pos + 1))
|
if (!SetCursorPos(GetCursorPos() - readSize + pos + 1))
|
||||||
NazaraWarning("Failed to reset cursos pos");
|
NazaraWarning("Failed to reset cursor pos");
|
||||||
|
|
||||||
break;
|
if (!line.IsEmpty())
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
line.Append(buffer, readSize);
|
{
|
||||||
|
std::size_t length = readSize;
|
||||||
|
if (m_streamOptions & StreamOption_Text && buffer[length - 1] == '\r')
|
||||||
|
{
|
||||||
|
if (!SetCursorPos(GetCursorPos() - 1))
|
||||||
|
NazaraWarning("Failed to reset cursor pos");
|
||||||
|
|
||||||
|
length--;
|
||||||
|
}
|
||||||
|
|
||||||
|
line.Append(buffer, length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while (readSize == bufferSize);
|
while (readSize == bufferSize);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue