From e80886f12c748870c73fff8a0258d3a9612118e9 Mon Sep 17 00:00:00 2001 From: Alexander Gessler Date: Wed, 18 Sep 2013 19:34:03 +0200 Subject: [PATCH] Obj: support line continuations with \ (fixes #91) --- code/ObjFileParser.cpp | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index 83f25c40a..ab8fdd124 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -200,6 +200,8 @@ void ObjFileParser::copyNextWord(char *pBuffer, size_t length) break; ++m_DataIt; } + + ai_assert(index < length); pBuffer[index] = '\0'; } @@ -207,16 +209,30 @@ void ObjFileParser::copyNextWord(char *pBuffer, size_t length) // Copy the next line into a temporary buffer void ObjFileParser::copyNextLine(char *pBuffer, size_t length) { - size_t index = 0; - while (m_DataIt != m_DataItEnd) - { - if (*m_DataIt == '\n' || *m_DataIt == '\r' || index == length-1) - break; + size_t index = 0u; - pBuffer[ index ] = *m_DataIt; - ++index; - ++m_DataIt; + // some OBJ files have line continuations using \ (such as in C++ et al) + bool continuation = false; + for (;m_DataIt != m_DataItEnd && index < length-1; ++m_DataIt) + { + const char c = *m_DataIt; + if (c == '\\') { + continuation = true; + continue; + } + + if (c == '\n' || c == '\r') { + if(continuation) { + pBuffer[ index++ ] = ' '; + continue; + } + break; + } + + continuation = false; + pBuffer[ index++ ] = c; } + ai_assert(index < length); pBuffer[ index ] = '\0'; }