fix obj parser on Windows

This commit is contained in:
MihailRis 2024-07-17 17:21:19 +03:00
parent a02d626c0a
commit b6ceadcee7
3 changed files with 11 additions and 2 deletions

View File

@ -208,6 +208,14 @@ std::string_view BasicParser::readUntil(char c) {
return source.substr(start, pos-start); return source.substr(start, pos-start);
} }
std::string_view BasicParser::readUntilEOL() {
int start = pos;
while (hasNext() && source[pos] != '\r' && source[pos] != '\n') {
pos++;
}
return source.substr(start, pos-start);
}
std::string BasicParser::parseName() { std::string BasicParser::parseName() {
char c = peek(); char c = peek();
if (!is_identifier_start(c)) { if (!is_identifier_start(c)) {

View File

@ -98,6 +98,7 @@ protected:
public: public:
std::string_view readUntil(char c); std::string_view readUntil(char c);
std::string_view readUntilEOL();
std::string parseName(); std::string parseName();
bool hasNext(); bool hasNext();
char peek(); char peek();

View File

@ -88,7 +88,7 @@ public:
while (hasNext()) { while (hasNext()) {
if (peek() != '#' && parseName() == "usemtl") { if (peek() != '#' && parseName() == "usemtl") {
skipWhitespace(); skipWhitespace();
texture = readUntil('\n'); texture = readUntilEOL();
break; break;
} }
skipLine(); skipLine();
@ -103,7 +103,7 @@ public:
auto cmd = parseName(); auto cmd = parseName();
if (cmd == "usemtl") { if (cmd == "usemtl") {
skipWhitespace(); skipWhitespace();
texture = readUntil('\n'); texture = readUntilEOL();
mesh = &model->addMesh(texture); mesh = &model->addMesh(texture);
break; break;
} else if (cmd == "f") { } else if (cmd == "f") {