Merge pull request #11951 from dback2/polymaterialurl

Allow space characters in material library name
This commit is contained in:
Brad Hefta-Gaub 2017-12-15 19:42:25 -08:00 committed by GitHub
commit 637e24504c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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()); return std::stof((nextToken() != OBJTokenizer::DATUM_TOKEN) ? nullptr : getDatum().data());
} }
int OBJTokenizer::nextToken() { int OBJTokenizer::nextToken(bool allowSpaceChar /*= false*/) {
if (_pushedBackToken != NO_PUSHBACKED_TOKEN) { if (_pushedBackToken != NO_PUSHBACKED_TOKEN) {
int token = _pushedBackToken; int token = _pushedBackToken;
_pushedBackToken = NO_PUSHBACKED_TOKEN; _pushedBackToken = NO_PUSHBACKED_TOKEN;
@ -93,7 +93,7 @@ int OBJTokenizer::nextToken() {
_datum = ""; _datum = "";
_datum.append(ch); _datum.append(ch);
while (_device->getChar(&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 ungetChar(ch); // read until we encounter a special character, then replace it
break; break;
} }
@ -399,7 +399,7 @@ bool OBJReader::parseOBJGroup(OBJTokenizer& tokenizer, const QVariantHash& mappi
currentMaterialName = QString("part-") + QString::number(_partCounter++); currentMaterialName = QString("part-") + QString::number(_partCounter++);
} }
} else if (token == "mtllib" && !_url.isEmpty()) { } else if (token == "mtllib" && !_url.isEmpty()) {
if (tokenizer.nextToken() != OBJTokenizer::DATUM_TOKEN) { if (tokenizer.nextToken(true) != OBJTokenizer::DATUM_TOKEN) {
break; break;
} }
QByteArray libraryName = tokenizer.getDatum(); QByteArray libraryName = tokenizer.getDatum();

View file

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