From f28d2eef887f392c9ce46e18594e8021cdfac25b Mon Sep 17 00:00:00 2001 From: CoolerExtreme Date: Thu, 12 Feb 2015 23:31:06 +0530 Subject: [PATCH 1/2] Fix parseString ? and slight change to fixIndex function parseString seemed to not increment token after it used strspn to get the length of the whitespace characters at the beginning of token. So strcspn called right after that would return 0 and the created string would be an empty string. Seems to have been working so far since it gets passed strings that don't begin with whitespace characters. --- tiny_obj_loader.cc | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/tiny_obj_loader.cc b/tiny_obj_loader.cc index 2b7bd9c..dde2bc7 100755 --- a/tiny_obj_loader.cc +++ b/tiny_obj_loader.cc @@ -67,26 +67,18 @@ static inline bool isNewLine(const char c) { // Make index zero-base, and also support relative index. static inline int fixIndex(int idx, int n) { - int i; - - if (idx > 0) { - i = idx - 1; - } else if (idx == 0) { - i = 0; - } else { // negative value = relative - i = n + idx; - } - return i; + if (idx > 0) return idx - 1; + if (idx == 0) return 0; + return n + idx; // negative value = relative } static inline std::string parseString(const char*& token) { std::string s; - int b = strspn(token, " \t"); + token += strspn(token, " \t"); int e = strcspn(token, " \t\r"); - s = std::string(&token[b], &token[e]); - - token += (e - b); + s = std::string(&token, &token[e]); + token += e; return s; } From 011e1b3ebdc3e16f3f0a8d8ee8f537a067f06e91 Mon Sep 17 00:00:00 2001 From: CoolerExtreme Date: Fri, 13 Feb 2015 06:37:37 +0530 Subject: [PATCH 2/2] Slight typo --- tiny_obj_loader.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tiny_obj_loader.cc b/tiny_obj_loader.cc index dde2bc7..a974d6e 100755 --- a/tiny_obj_loader.cc +++ b/tiny_obj_loader.cc @@ -77,7 +77,7 @@ static inline std::string parseString(const char*& token) std::string s; token += strspn(token, " \t"); int e = strcspn(token, " \t\r"); - s = std::string(&token, &token[e]); + s = std::string(token, &token[e]); token += e; return s; }