|
@@ -49,11 +49,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
namespace Assimp
|
|
|
{
|
|
|
|
|
|
+/** @brief Returns true, if the last entry of the buffer is reached.
|
|
|
+ * @param it Iterator of current position.
|
|
|
+ * @param end Iterator with end of buffer.
|
|
|
+ * @return true, if the end of the buffer is reached.
|
|
|
+ */
|
|
|
+template<class char_t>
|
|
|
+inline bool isEndOfBuffer( char_t it, char_t end )
|
|
|
+{
|
|
|
+ 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 isSpace( char token )
|
|
|
+inline bool isSeparator( char token )
|
|
|
{
|
|
|
return ( token == ' ' ||
|
|
|
token == '\n' ||
|
|
@@ -79,9 +91,9 @@ inline bool isNewLine( char token )
|
|
|
template<class Char_T>
|
|
|
inline Char_T getNextWord( Char_T pBuffer, Char_T pEnd )
|
|
|
{
|
|
|
- while (pBuffer != pEnd)
|
|
|
+ while ( !isEndOfBuffer( pBuffer, pEnd ) )
|
|
|
{
|
|
|
- if (!isSpace(*pBuffer))
|
|
|
+ if ( !isSeparator( *pBuffer ) )
|
|
|
break;
|
|
|
pBuffer++;
|
|
|
}
|
|
@@ -96,9 +108,9 @@ inline Char_T getNextWord( Char_T pBuffer, Char_T pEnd )
|
|
|
template<class Char_T>
|
|
|
inline Char_T getNextToken( Char_T pBuffer, Char_T pEnd )
|
|
|
{
|
|
|
- while (pBuffer != pEnd)
|
|
|
+ while ( !isEndOfBuffer( pBuffer, pEnd ) )
|
|
|
{
|
|
|
- if ( isSpace( *pBuffer ) )
|
|
|
+ if ( isSeparator( *pBuffer ) )
|
|
|
break;
|
|
|
pBuffer++;
|
|
|
}
|
|
@@ -114,14 +126,14 @@ inline Char_T getNextToken( Char_T pBuffer, Char_T pEnd )
|
|
|
template<class char_t>
|
|
|
inline char_t skipLine( char_t it, char_t end, unsigned int &uiLine )
|
|
|
{
|
|
|
- while ( it != end && *it != '\n' )
|
|
|
+ while ( !isEndOfBuffer( it, end ) && *it != '\n' )
|
|
|
++it;
|
|
|
if ( it != end )
|
|
|
{
|
|
|
++it;
|
|
|
++uiLine;
|
|
|
}
|
|
|
- /* fix .. from time to time there are spaces at the beginning of a material line */
|
|
|
+ // fix .. from time to time there are spaces at the beginning of a material line
|
|
|
while ( it != end && (*it == '\t' || *it == ' ') )
|
|
|
++it;
|
|
|
return it;
|
|
@@ -138,15 +150,15 @@ inline char_t getName( char_t it, char_t end, std::string &name )
|
|
|
{
|
|
|
name = "";
|
|
|
it = getNextToken<char_t>( it, end );
|
|
|
- if ( it == end )
|
|
|
+ if ( isEndOfBuffer( it, end ) )
|
|
|
return end;
|
|
|
|
|
|
- char *pStart = &(*it);
|
|
|
- while ( !isSpace(*it) && it != end )
|
|
|
+ char *pStart = &( *it );
|
|
|
+ while ( !isEndOfBuffer( it, end ) && !isSeparator( *it ) )
|
|
|
++it;
|
|
|
|
|
|
// Get name
|
|
|
- std::string strName(pStart, &(*it));
|
|
|
+ std::string strName( pStart, &(*it) );
|
|
|
if ( strName.empty() )
|
|
|
return it;
|
|
|
else
|
|
@@ -167,7 +179,7 @@ inline char_t CopyNextWord( char_t it, char_t end, char *pBuffer, size_t length
|
|
|
{
|
|
|
size_t index = 0;
|
|
|
it = getNextWord<char_t>( it, end );
|
|
|
- while (!isSpace( *it ) && it != end )
|
|
|
+ while ( !isSeparator( *it ) && !isEndOfBuffer( it, end ) )
|
|
|
{
|
|
|
pBuffer[index] = *it ;
|
|
|
index++;
|
|
@@ -175,7 +187,7 @@ inline char_t CopyNextWord( char_t it, char_t end, char *pBuffer, size_t length
|
|
|
break;
|
|
|
++it;
|
|
|
}
|
|
|
- pBuffer[index] = '\0';
|
|
|
+ pBuffer[ index ] = '\0';
|
|
|
return it;
|
|
|
}
|
|
|
|
|
@@ -190,7 +202,6 @@ inline char_t getFloat( char_t it, char_t end, float &value )
|
|
|
{
|
|
|
static const size_t BUFFERSIZE = 1024;
|
|
|
char buffer[ BUFFERSIZE ];
|
|
|
- //memset( buffer, '\0', BUFFERSIZE );
|
|
|
it = CopyNextWord<char_t>( it, end, buffer, BUFFERSIZE );
|
|
|
value = (float) fast_atof( buffer );
|
|
|
|