Allow space characters in material library name

This commit is contained in:
David Back 2017-12-07 17:40:58 -08:00
parent e7d7e9abb8
commit 8b38c03a56
2 changed files with 4 additions and 4 deletions

View file

@ -56,7 +56,7 @@ float OBJTokenizer::getFloat() {
return std::stof((nextToken() != OBJTokenizer::DATUM_TOKEN) ? nullptr : getDatum().data());
}
int OBJTokenizer::nextToken() {
int OBJTokenizer::nextToken(bool allowSpaceChar /*= false*/) {
if (_pushedBackToken != NO_PUSHBACKED_TOKEN) {
int token = _pushedBackToken;
_pushedBackToken = NO_PUSHBACKED_TOKEN;
@ -93,7 +93,7 @@ int OBJTokenizer::nextToken() {
_datum = "";
_datum.append(ch);
while (_device->getChar(&ch)) {
if (QChar(ch).isSpace() || ch == '\"') {
if ((QChar(ch).isSpace() || ch == '\"') && (!allowSpaceChar || ch != ' ')) {
ungetChar(ch); // read until we encounter a special character, then replace it
break;
}
@ -399,7 +399,7 @@ bool OBJReader::parseOBJGroup(OBJTokenizer& tokenizer, const QVariantHash& mappi
currentMaterialName = QString("part-") + QString::number(_partCounter++);
}
} else if (token == "mtllib" && !_url.isEmpty()) {
if (tokenizer.nextToken() != OBJTokenizer::DATUM_TOKEN) {
if (tokenizer.nextToken(true) != OBJTokenizer::DATUM_TOKEN) {
break;
}
QByteArray libraryName = tokenizer.getDatum();

View file

@ -11,7 +11,7 @@ public:
DATUM_TOKEN = 0x100,
COMMENT_TOKEN = 0x101
};
int nextToken();
int nextToken(bool allowSpaceChar = false);
const QByteArray& getDatum() const { return _datum; }
bool isNextTokenFloat();
const QByteArray getLineAsDatum(); // some "filenames" have spaces in them