trimming spaces around material names

pull/709/head
Vitaly Ovchinnikov 2015-12-14 08:32:09 +13:00
parent c9ef6132a8
commit af40c99a6a
3 changed files with 11 additions and 0 deletions

View File

@ -284,6 +284,8 @@ void ObjFileMtlImporter::createMaterial()
} }
} }
name = trim_whitespaces(name);
std::map<std::string, ObjFile::Material*>::iterator it = m_pModel->m_MaterialMap.find( name ); std::map<std::string, ObjFile::Material*>::iterator it = m_pModel->m_MaterialMap.find( name );
if ( m_pModel->m_MaterialMap.end() == it) { if ( m_pModel->m_MaterialMap.end() == it) {
// New Material created // New Material created

View File

@ -473,6 +473,7 @@ void ObjFileParser::getMaterialDesc()
// Get name // Get name
std::string strName(pStart, &(*m_DataIt)); std::string strName(pStart, &(*m_DataIt));
strName = trim_whitespaces(strName);
if (strName.empty()) if (strName.empty())
skip = true; skip = true;

View File

@ -238,6 +238,14 @@ unsigned int tokenize( const string_type& str, std::vector<string_type>& tokens,
return static_cast<unsigned int>( tokens.size() ); return static_cast<unsigned int>( tokens.size() );
} }
template <class string_type>
string_type trim_whitespaces(string_type str)
{
while (!str.empty() && IsSpace(str[0])) str.erase(0);
while (!str.empty() && IsSpace(str[str.length() - 1])) str.erase(str.length() - 1);
return str;
}
} // Namespace Assimp } // Namespace Assimp
#endif // OBJ_TOOLS_H_INC #endif // OBJ_TOOLS_H_INC