From 82380084c5c7fcae57dfda452e5cd746371498d6 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 31 May 2017 16:36:08 +0200 Subject: [PATCH] ObjImporter: next try for multiple line stuff. --- code/IOStreamBuffer.h | 27 ++++++++++++++++++++++++--- code/ObjFileParser.cpp | 4 ++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/code/IOStreamBuffer.h b/code/IOStreamBuffer.h index d8c7d00ab..98ed11267 100644 --- a/code/IOStreamBuffer.h +++ b/code/IOStreamBuffer.h @@ -96,7 +96,7 @@ public: /// @brief Will read the next line. /// @param buffer The buffer for the next line. /// @return true if successful. - bool getNextLine( std::vector &buffer ); + bool getNextDataLine( std::vector &buffer, T continuationToken ); private: IOStream *m_stream; @@ -227,15 +227,35 @@ size_t IOStreamBuffer::getFilePos() const { template inline -bool IOStreamBuffer::getNextLine( std::vector &buffer ) { +bool IOStreamBuffer::getNextDataLine( std::vector &buffer, T continuationToken ) { buffer.resize( m_cacheSize ); if ( m_cachePos == m_cacheSize || 0 == m_filePos ) { if ( !readNextBlock() ) { return false; } } + + bool continuationFound( false ), endOfDataLine( false ); size_t i = 0; - while ( !IsLineEnd( m_cache[ m_cachePos ] ) ) { + while ( !endOfDataLine ) { + if ( continuationToken == m_cache[ m_cachePos ] ) { + continuationFound = true; + } + if ( IsLineEnd( m_cache[ m_cachePos ] ) ) { + if ( !continuationFound ) { + // the end of the data line + i++; + break; + } else { + // skip line end + while ( m_cache[m_cachePos] != '\n') { + ++m_cachePos; + } + ++m_cachePos; + break; + } + } + buffer[ i ] = m_cache[ m_cachePos ]; m_cachePos++; i++; @@ -245,6 +265,7 @@ bool IOStreamBuffer::getNextLine( std::vector &buffer ) { } } } + buffer[ i ] = '\n'; m_cachePos++; diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index decfacbf5..3289708cf 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -123,7 +123,7 @@ void ignoreNewLines(IOStreamBuffer &streamBuffer, std::vector &buffe std::vector tempBuf; do { - streamBuffer.getNextLine(tempBuf); + streamBuffer.getNextDataLine(tempBuf, '\\' ); } while (tempBuf[0]=='\n'); *curPosition = ' '; std::copy(tempBuf.cbegin(), tempBuf.cend(), ++curPosition); @@ -142,7 +142,7 @@ void ObjFileParser::parseFile( IOStreamBuffer &streamBuffer ) { size_t lastFilePos( 0 ); std::vector buffer; - while ( streamBuffer.getNextLine( buffer ) ) { + while ( streamBuffer.getNextDataLine( buffer, '\\' ) ) { m_DataIt = buffer.begin(); m_DataItEnd = buffer.end();