{
++m_DataIt;
if (*m_DataIt == ' ' || *m_DataIt == '\t') {
- size_t numComponents = getNumComponentsInLine();
+ size_t numComponents = getNumComponentsInDataDefinition();
if (numComponents == 3) {
// read in vertex definition
getVector3(m_pModel->m_Vertices);
pBuffer[index] = '\0';
}
-size_t ObjFileParser::getNumComponentsInLine() {
+static bool isDataDefinitionEnd( const char *tmp ) {
+ if ( *tmp == '\\' ) {
+ tmp++;
+ if ( IsLineEnd( tmp ) ) {
+ return false;
+ }
+ } else {
+ return IsLineEnd( tmp );
+ }
+ return false;
+}
+
+size_t ObjFileParser::getNumComponentsInDataDefinition() {
size_t numComponents( 0 );
const char* tmp( &m_DataIt[0] );
- while( !IsLineEnd( *tmp ) ) {
+ while ( !isDataDefinitionEnd( tmp ) ) {
+ //while( !IsLineEnd( *tmp ) ) {
if ( !SkipSpaces( &tmp ) ) {
break;
}
+ const bool isNum( IsNumeric( *tmp ) );
SkipToken( tmp );
- ++numComponents;
+ if ( isNum ) {
+ ++numComponents;
+ }
+ if ( !SkipSpaces( &tmp ) ) {
+ break;
+ }
}
return numComponents;
}
void ObjFileParser::getVector( std::vector<aiVector3D> &point3d_array ) {
- size_t numComponents = getNumComponentsInLine();
+ size_t numComponents = getNumComponentsInDataDefinition();
ai_real x, y, z;
if( 2 == numComponents ) {
copyNextWord( m_buffer, Buffersize );
void copyNextWord(char *pBuffer, size_t length);
/// Method to copy the new line.
// void copyNextLine(char *pBuffer, size_t length);
+ /// Get the number of components in a line.
+ size_t getNumComponentsInDataDefinition();
/// Stores the vector
void getVector( std::vector<aiVector3D> &point3d_array );
/// Stores the following 3d vector.
bool needsNewMesh( const std::string &rMaterialName );
/// Error report in token
void reportErrorTokenInFace();
- /// Get the number of components in a line.
- size_t getNumComponentsInLine();
private:
// Copy and assignment constructor should be private
class TestObjFileParser : public ObjFileParser {
public:
- TestObjFileParser() : ObjFileParser(){}
- ~TestObjFileParser() {}
+ TestObjFileParser() : ObjFileParser(){
+ // empty
+ }
+
+ ~TestObjFileParser() {
+ // empty
+ }
+
void testCopyNextWord( char *pBuffer, size_t length ) {
copyNextWord( pBuffer, length );
}
+ size_t testGetNumComponentsInDataDefinition() {
+ return getNumComponentsInDataDefinition();
+ }
};
+
TEST_F( utObjTools, skipDataLine_OneLine_Success ) {
std::vector<char> buffer;
std::string data( "v -0.5 -0.5 0.5\nend" );
test_parser.testCopyNextWord( data_buffer, Size );
EXPECT_EQ( data_buffer[ 0 ], '-' );
-}
\ No newline at end of file
+}
+
+TEST_F( utObjTools, countComponents_TwoLines_Success ) {
+ TestObjFileParser test_parser;
+ std::string data( "-2.061493116917992e-15 -0.9009688496589661 \\n-0.4338837265968323" );
+ std::vector<char> buffer;
+ buffer.resize( data.size() );
+ ::memcpy( &buffer[ 0 ], &data[ 0 ], data.size() );
+ test_parser.setBuffer( buffer );
+ static const size_t Size = 4096UL;
+ char data_buffer[ Size ];
+
+ size_t numComps = test_parser.testGetNumComponentsInDataDefinition();
+ EXPECT_EQ( 3U, numComps );
+}