Fix some recently implemented comparisons of token strings (#6452)
* Fix some recently implemented comparisons of token strings. Previously, the `keyword` included the following space along with the token, which broke the string comparison using the equality operator. * Rename `getEndOfToken` -> `getNextDelimiter`, to reflect the actual usage
This commit is contained in:
committed by
GitHub
parent
cf7b652190
commit
d5091bbb71
@@ -253,10 +253,10 @@ void ObjFileMtlImporter::load() {
|
||||
{
|
||||
// Save start of token (after 'm')
|
||||
auto tokenStart = m_DataIt; // points to 'm'
|
||||
auto tokenEnd = getNextToken(m_DataIt, m_DataItEnd); // move iterator to end of token
|
||||
auto tokenEnd = getNextDelimiter(m_DataIt, m_DataItEnd); // move iterator to end of token
|
||||
|
||||
std::string keyword(tokenStart, tokenEnd);
|
||||
m_DataIt = tokenEnd; // advance iterator
|
||||
m_DataIt = getNextWord(tokenEnd, m_DataItEnd); // advance iterator
|
||||
|
||||
if (keyword.compare(0, 3, "map") == 0) {
|
||||
// starts with "map", treat as texture map
|
||||
@@ -279,9 +279,9 @@ void ObjFileMtlImporter::load() {
|
||||
case 'r': // refl (map) or roughness (float)
|
||||
{
|
||||
auto tokenStart = m_DataIt; // points to 'r'
|
||||
auto tokenEnd = getNextToken(m_DataIt, m_DataItEnd);
|
||||
auto tokenEnd = getNextDelimiter(m_DataIt, m_DataItEnd);
|
||||
std::string keyword(tokenStart, tokenEnd);
|
||||
m_DataIt = tokenEnd;
|
||||
m_DataIt = getNextWord(tokenEnd, m_DataItEnd);
|
||||
|
||||
if (keyword == "roughness" || keyword == "rough") {
|
||||
getFloatIfMaterialValid(&ObjFile::Material::roughness);
|
||||
@@ -303,9 +303,9 @@ void ObjFileMtlImporter::load() {
|
||||
|
||||
case 'a': {
|
||||
auto tokenStart = m_DataIt;
|
||||
auto tokenEnd = getNextToken(m_DataIt, m_DataItEnd);
|
||||
auto tokenEnd = getNextDelimiter(m_DataIt, m_DataItEnd);
|
||||
std::string keyword(tokenStart, tokenEnd);
|
||||
m_DataIt = tokenEnd;
|
||||
m_DataIt = getNextWord(tokenEnd, m_DataItEnd);
|
||||
|
||||
if (keyword == "aniso" || keyword == "anisotropy") {
|
||||
getFloatIfMaterialValid(&ObjFile::Material::anisotropy);
|
||||
@@ -322,9 +322,9 @@ void ObjFileMtlImporter::load() {
|
||||
|
||||
case 's': {
|
||||
auto tokenStart = m_DataIt;
|
||||
auto tokenEnd = getNextToken(m_DataIt, m_DataItEnd);
|
||||
auto tokenEnd = getNextDelimiter(m_DataIt, m_DataItEnd);
|
||||
std::string keyword(tokenStart, tokenEnd);
|
||||
m_DataIt = tokenEnd;
|
||||
m_DataIt = getNextWord(tokenEnd,m_DataItEnd);
|
||||
|
||||
if (keyword == "subsurface" || keyword == "scattering") {
|
||||
getFloatIfMaterialValid(&ObjFile::Material::subsurface_scattering);
|
||||
@@ -343,9 +343,9 @@ void ObjFileMtlImporter::load() {
|
||||
|
||||
case 'c': {
|
||||
auto tokenStart = m_DataIt;
|
||||
auto tokenEnd = getNextToken(m_DataIt, m_DataItEnd);
|
||||
auto tokenEnd = getNextDelimiter(m_DataIt, m_DataItEnd);
|
||||
std::string keyword(tokenStart, tokenEnd);
|
||||
m_DataIt = tokenEnd;
|
||||
m_DataIt = getNextWord(tokenEnd, m_DataItEnd);
|
||||
|
||||
if (ai_stdStrToLower(keyword) == "clearcoat") {
|
||||
getFloatIfMaterialValid(&ObjFile::Material::clearcoat);
|
||||
|
||||
@@ -85,6 +85,23 @@ inline Char_T getNextWord(Char_T pBuffer, Char_T pEnd) {
|
||||
return pBuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns next space
|
||||
* @param[in] pBuffer Pointer to data buffer
|
||||
* @param[in] pEnd Pointer to end of buffer
|
||||
* @return Pointer to next space
|
||||
*/
|
||||
template <class Char_T>
|
||||
inline Char_T getNextDelimiter(Char_T pBuffer, Char_T pEnd) {
|
||||
while (!isEndOfBuffer(pBuffer, pEnd)) {
|
||||
if (IsSpaceOrNewLine(*pBuffer)) {
|
||||
break;
|
||||
}
|
||||
++pBuffer;
|
||||
}
|
||||
return pBuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns pointer a next token
|
||||
* @param[in] pBuffer Pointer to data buffer
|
||||
@@ -93,12 +110,7 @@ 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 (!isEndOfBuffer(pBuffer, pEnd)) {
|
||||
if (IsSpaceOrNewLine(*pBuffer)) {
|
||||
break;
|
||||
}
|
||||
++pBuffer;
|
||||
}
|
||||
pBuffer = getNextDelimiter(pBuffer, pEnd);
|
||||
return getNextWord(pBuffer, pEnd);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user