Obj: support line continuations with \ (fixes #91)

pull/95/head
Alexander Gessler 2013-09-18 19:34:03 +02:00
parent 0f5272cb50
commit e80886f12c
1 changed files with 24 additions and 8 deletions

View File

@ -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';
}