Skip trailing whitespace in mtl. Fixes #92.

This commit is contained in:
Syoyo Fujita
2016-08-02 17:04:00 +09:00
parent 1983e889dc
commit 0a85945767
4 changed files with 35 additions and 2 deletions

View File

@@ -534,8 +534,7 @@ static vertex_index parseTriple(const char **token, int vsize, int vnsize,
// Parse raw triples: i, i/j/k, i//k, i/j
static vertex_index parseRawTriple(const char **token) {
vertex_index vi(
static_cast<int>(0)); // 0 is an invalid index in OBJ
vertex_index vi(static_cast<int>(0)); // 0 is an invalid index in OBJ
vi.v_idx = atoi((*token));
(*token) += strcspn((*token), "/ \t\r");
@@ -679,6 +678,11 @@ void LoadMtl(std::map<std::string, int> *material_map,
std::string linebuf(&buf[0]);
// Trim trailing whitespace.
if (linebuf.size() > 0) {
linebuf = linebuf.substr(0, linebuf.find_last_not_of(" \t") + 1);
}
// Trim newline '\r\n' or '\n'
if (linebuf.size() > 0) {
if (linebuf[linebuf.size() - 1] == '\n')