diff --git a/code/ObjFileMtlImporter.cpp b/code/ObjFileMtlImporter.cpp index e09a16f2f..74466f2ba 100644 --- a/code/ObjFileMtlImporter.cpp +++ b/code/ObjFileMtlImporter.cpp @@ -46,6 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "ObjTools.h" #include "ObjFileData.h" #include "fast_atof.h" +#include "ParsingUtils.h" namespace Assimp { @@ -228,7 +229,7 @@ void ObjFileMtlImporter::getColorRGBA( aiColor3D *pColor ) pColor->r = r; // we have to check if color is default 0 with only one token - if( !isNewLine( *m_DataIt ) ) { + if( !IsLineEnd( *m_DataIt ) ) { m_DataIt = getFloat( m_DataIt, m_DataItEnd, g ); m_DataIt = getFloat( m_DataIt, m_DataItEnd, b ); } @@ -257,7 +258,7 @@ void ObjFileMtlImporter::getFloatValue( float &value ) void ObjFileMtlImporter::createMaterial() { std::string line( "" ); - while ( !isNewLine( *m_DataIt ) ) { + while( !IsLineEnd( *m_DataIt ) ) { line += *m_DataIt; ++m_DataIt; } diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index 6e73f0bf4..34bb01e0a 100644 --- a/code/ObjFileParser.cpp +++ b/code/ObjFileParser.cpp @@ -186,12 +186,12 @@ void ObjFileParser::copyNextWord(char *pBuffer, size_t length) { size_t index = 0; m_DataIt = getNextWord(m_DataIt, m_DataItEnd); - while ( m_DataIt != m_DataItEnd && !isSeparator(*m_DataIt) ) - { + while( m_DataIt != m_DataItEnd && !IsSpaceOrNewLine( *m_DataIt ) ) { pBuffer[index] = *m_DataIt; index++; - if (index == length-1) - break; + if( index == length - 1 ) { + break; + } ++m_DataIt; } @@ -345,7 +345,7 @@ void ObjFileParser::getFace(aiPrimitiveType type) } iPos++; } - else if ( isSeparator(*pPtr) ) + else if( IsSpaceOrNewLine( *pPtr ) ) { iPos = 0; } @@ -463,8 +463,9 @@ void ObjFileParser::getMaterialDesc() return; char *pStart = &(*m_DataIt); - while ( m_DataIt != m_DataItEnd && !isSeparator(*m_DataIt) ) - ++m_DataIt; + while( m_DataIt != m_DataItEnd && !IsSpaceOrNewLine( *m_DataIt ) ) { + ++m_DataIt; + } // Get name std::string strName(pStart, &(*m_DataIt)); @@ -518,12 +519,14 @@ void ObjFileParser::getMaterialLib() { // Translate tuple m_DataIt = getNextToken(m_DataIt, m_DataItEnd); - if (m_DataIt == m_DataItEnd) - return; + if( m_DataIt == m_DataItEnd ) { + return; + } char *pStart = &(*m_DataIt); - while (m_DataIt != m_DataItEnd && !isNewLine(*m_DataIt)) - m_DataIt++; + while( m_DataIt != m_DataItEnd && !IsLineEnd( *m_DataIt ) ) { + ++m_DataIt; + } // Check for existence const std::string strMatName(pStart, &(*m_DataIt)); @@ -557,7 +560,7 @@ void ObjFileParser::getNewMaterial() char *pStart = &(*m_DataIt); std::string strMat( pStart, *m_DataIt ); - while( m_DataIt != m_DataItEnd && isSeparator( *m_DataIt ) ) { + while( m_DataIt != m_DataItEnd && IsSpaceOrNewLine( *m_DataIt ) ) { ++m_DataIt; } std::map::iterator it = m_pModel->m_MaterialMap.find( strMat ); @@ -662,7 +665,7 @@ void ObjFileParser::getObjectName() return; } char *pStart = &(*m_DataIt); - while( m_DataIt != m_DataItEnd && !isSeparator( *m_DataIt ) ) { + while( m_DataIt != m_DataItEnd && !IsSpaceOrNewLine( *m_DataIt ) ) { ++m_DataIt; } diff --git a/code/ObjTools.h b/code/ObjTools.h index 047c9a4cd..a785d41a4 100644 --- a/code/ObjTools.h +++ b/code/ObjTools.h @@ -45,6 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define OBJ_TOOLS_H_INC #include "fast_atof.h" +#include "ParsingUtils.h" namespace Assimp { @@ -68,28 +69,6 @@ inline bool isEndOfBuffer( char_t it, char_t end ) return ( it == end ); } -/** @brief Returns true, if token is a space on any supported platform -* @param token Token to search in -* @return true, if token is a space -*/ -inline bool isSeparator( char token ) -{ - return ( token == ' ' || - token == '\n' || - token == '\f' || - token == '\r' || - token == '\t' ); -} - -/** @brief Returns true, fi token id a new line marking token. - * @param token Token to search in - * @return true, if token is a newline token. - */ -inline bool isNewLine( char token ) -{ - return ( token == '\n' || token == '\f' || token == '\r' ); -} - /** @brief Returns next word separated by a space * @param pBuffer Pointer to data buffer * @param pEnd Pointer to end of buffer @@ -100,7 +79,7 @@ inline Char_T getNextWord( Char_T pBuffer, Char_T pEnd ) { while ( !isEndOfBuffer( pBuffer, pEnd ) ) { - if ( !isSeparator( *pBuffer ) || isNewLine( *pBuffer ) ) + if( !IsSpaceOrNewLine( *pBuffer ) || IsLineEnd( *pBuffer ) ) break; pBuffer++; } @@ -117,7 +96,7 @@ inline Char_T getNextToken( Char_T pBuffer, Char_T pEnd ) { while ( !isEndOfBuffer( pBuffer, pEnd ) ) { - if ( isSeparator( *pBuffer ) ) + if( IsSpaceOrNewLine( *pBuffer ) ) break; pBuffer++; } @@ -127,14 +106,14 @@ inline Char_T getNextToken( Char_T pBuffer, Char_T pEnd ) /** @brief Skips a line * @param it Iterator set to current position * @param end Iterator set to end of scratch buffer for readout - * @param uiLine Current linenumber in format + * @param uiLine Current line number in format * @return Current-iterator with new position */ template -inline char_t skipLine( char_t it, char_t end, unsigned int &uiLine ) -{ - while ( !isEndOfBuffer( it, end ) && !isNewLine( *it ) ) - ++it; +inline char_t skipLine( char_t it, char_t end, unsigned int &uiLine ) { + while( !isEndOfBuffer( it, end ) && !IsLineEnd( *it ) ) { + ++it; + } if ( it != end ) { ++it; @@ -157,15 +136,16 @@ template inline char_t getName( char_t it, char_t end, std::string &name ) { name = ""; - if ( isEndOfBuffer( it, end ) ) - return end; + if( isEndOfBuffer( it, end ) ) { + return end; + } char *pStart = &( *it ); - while ( !isEndOfBuffer( it, end ) && !isNewLine( *it ) ) { + while( !isEndOfBuffer( it, end ) && !IsLineEnd( *it ) ) { ++it; } - while(isEndOfBuffer( it, end ) || isNewLine( *it ) || isSeparator(*it)) { + while( isEndOfBuffer( it, end ) || IsLineEnd( *it ) || IsSpaceOrNewLine( *it ) ) { --it; } ++it; @@ -196,7 +176,7 @@ inline char_t CopyNextWord( char_t it, char_t end, char *pBuffer, size_t length { size_t index = 0; it = getNextWord( it, end ); - while ( !isSeparator( *it ) && !isEndOfBuffer( it, end ) ) + while( !IsSpaceOrNewLine( *it ) && !isEndOfBuffer( it, end ) ) { pBuffer[index] = *it ; index++; diff --git a/code/ParsingUtils.h b/code/ParsingUtils.h index 1ed8ee923..25495fd51 100644 --- a/code/ParsingUtils.h +++ b/code/ParsingUtils.h @@ -98,7 +98,7 @@ AI_FORCE_INLINE bool IsSpace( char_t in) template AI_FORCE_INLINE bool IsLineEnd( char_t in) { - return (in == (char_t)'\r' || in == (char_t)'\n' || in == (char_t)'\0'); + return (in==(char_t)'\r'||in==(char_t)'\n'||in==(char_t)'\0'||in==(char_t)'\f'); } // ---------------------------------------------------------------------------------