Added InputStream::GetLine(size);
Former-commit-id: 4c5afc038877bfa9865285d044663df3f7932d58
This commit is contained in:
@@ -100,7 +100,7 @@ bool NzFile::EndOfFile() const
|
||||
return m_impl->EndOfFile();
|
||||
}
|
||||
|
||||
bool NzFile::EndOfStream() const;
|
||||
bool NzFile::EndOfStream() const
|
||||
{
|
||||
return EndOfFile();
|
||||
}
|
||||
@@ -211,50 +211,9 @@ NzString NzFile::GetLine(unsigned int lineSize)
|
||||
}
|
||||
#endif
|
||||
|
||||
NzString line;
|
||||
if (lineSize == 0) // Taille maximale indéterminée
|
||||
{
|
||||
while (!m_impl->EndOfFile())
|
||||
{
|
||||
char c;
|
||||
if (m_impl->Read(&c, sizeof(char)) == sizeof(char))
|
||||
{
|
||||
if (c == '\n')
|
||||
{
|
||||
if (m_openMode & Text && line.EndsWith('\r'))
|
||||
line.Resize(-1);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
line += c;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
line.Reserve(lineSize);
|
||||
for (unsigned int i = 0; i < lineSize; ++i)
|
||||
{
|
||||
char c;
|
||||
if (m_impl->Read(&c, sizeof(char)) == sizeof(char))
|
||||
{
|
||||
if (c == '\n')
|
||||
{
|
||||
if (m_openMode & Text && line.EndsWith('\r'))
|
||||
line.Resize(-1);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
line += c;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
NzString line = NzInputStream::GetLine(lineSize);
|
||||
if (m_openMode & Text && !m_impl->EndOfFile() && line.EndsWith('\r'))
|
||||
line.Resize(-1);
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,49 @@
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/InputStream.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
NzInputStream::~NzInputStream() = default;
|
||||
// Copyright (C) 2012 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/InputStream.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
NzInputStream::~NzInputStream() = default;
|
||||
|
||||
NzString NzInputStream::GetLine(unsigned int lineSize)
|
||||
{
|
||||
NzString line;
|
||||
if (lineSize == 0) // Taille maximale indéterminée
|
||||
{
|
||||
while (!EndOfStream())
|
||||
{
|
||||
char c;
|
||||
if (Read(&c, sizeof(char)) == sizeof(char))
|
||||
{
|
||||
if (c == '\n')
|
||||
break;
|
||||
|
||||
line += c;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
line.Reserve(lineSize);
|
||||
for (unsigned int i = 0; i < lineSize; ++i)
|
||||
{
|
||||
char c;
|
||||
if (Read(&c, sizeof(char)) == sizeof(char))
|
||||
{
|
||||
if (c == '\n')
|
||||
break;
|
||||
|
||||
line += c;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user